:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --surface: #ffffff;
  --surface-2: #f1f4f2;
  --ink: #172033;
  --muted: #627083;
  --line: #dfe5e2;
  --accent: #1a7f5a;
  --accent-2: #1e4f82;
  --cyan: #0b7f9b;
  --amber: #bd7a16;
  --red: #be3b35;
  --shadow: 0 18px 45px rgba(24, 39, 63, .08);
  --radius: 8px;
  --nav: #ffffff;
  --chart-grid: rgba(23, 32, 51, .08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1b2e;
  --surface-2: #14243a;
  --ink: #eef6ff;
  --muted: #9fb2c8;
  --line: #263a54;
  --accent: #39c586;
  --accent-2: #4da3ff;
  --cyan: #33d7e8;
  --amber: #f0ad3d;
  --red: #ff615d;
  --shadow: 0 22px 48px rgba(0, 0, 0, .28);
  --nav: #0a1728;
  --chart-grid: rgba(238, 246, 255, .1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--nav);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  overflow: auto;
}
.brand { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; padding: 8px; margin-bottom: 14px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; font-weight: 800; letter-spacing: 0; }
.brand strong { display: block; font-size: 14px; }
.brand small { display: block; color: var(--muted); margin-top: 2px; }
.nav-list { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 9px 10px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
}
.nav-item:hover, .nav-item.active { background: var(--surface-2); color: var(--ink); }
.nav-icon { width: 22px; text-align: center; color: var(--accent-2); }
.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.context { min-width: 180px; }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-weight: 700; font-size: 12px; text-transform: uppercase; }
h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; min-width: 230px; }
.search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
select, .theme-toggle, .segmented, .icon-button {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
}
select { padding: 0 10px; }
.theme-toggle { display: flex; align-items: center; gap: 7px; padding: 0 12px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; }
.segmented button { border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 6px 9px; }
.segmented button.active { background: var(--accent); color: white; }
.sidebar-toggle { display: none; width: 40px; padding: 8px; }
.sidebar-toggle span { display: block; height: 2px; background: var(--ink); margin: 4px 0; }
.page { padding: 22px 24px 44px; max-width: 1680px; margin: 0 auto; }
.section { margin-top: 20px; }
.hero {
  min-height: 440px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
  gap: 28px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 24px;
}
.hero h2 { font-size: clamp(40px, 5vw, 68px); line-height: 1.02; margin: 0 0 18px; letter-spacing: 0; }
.lead { color: var(--muted); font-size: 18px; max-width: 740px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  text-decoration: none;
  padding: 0 16px;
  border: 1px solid var(--line);
  font-weight: 700;
}
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.secondary { color: var(--ink); background: var(--surface); }
.industrial-panel, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.industrial-panel { padding: 18px; }
.plant-visual {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  background:
    linear-gradient(90deg, var(--chart-grid) 1px, transparent 1px),
    linear-gradient(var(--chart-grid) 1px, transparent 1px),
    linear-gradient(135deg, color-mix(in srgb, var(--surface-2) 70%, var(--accent) 30%), var(--surface));
  background-size: 38px 38px, 38px 38px, auto;
}
.pipe { position: absolute; height: 9px; background: var(--accent-2); border-radius: 10px; opacity: .8; }
.pipe.one { left: 36px; right: 90px; top: 88px; }
.pipe.two { left: 80px; right: 34px; bottom: 96px; background: var(--accent); }
.node { position: absolute; width: 76px; height: 76px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; font-weight: 800; }
.node.a { top: 48px; left: 44px; }
.node.b { top: 152px; right: 72px; }
.node.c { bottom: 58px; left: 112px; }
.node.d { bottom: 38px; right: 40px; }
.pulse { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--cyan); animation: move 5s linear infinite; top: 86px; left: 52px; }
@keyframes move { 0% { transform: translateX(0); } 100% { transform: translateX(430px); } }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.card { padding: 16px; min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); }
.kpi { display: flex; flex-direction: column; gap: 8px; min-height: 116px; }
.kpi .label { color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 800; letter-spacing: 0; }
.delta { color: var(--accent); font-weight: 700; }
.delta.warn { color: var(--amber); }
.delta.bad { color: var(--red); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.status-dot.warn { background: var(--amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 20%, transparent); }
.status-dot.bad { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 20%, transparent); }
.chart { width: 100%; min-height: 220px; display: block; }
.axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; background: var(--surface); }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.site-card { display: grid; gap: 12px; }
.site-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.metric { background: var(--surface-2); border-radius: 8px; padding: 10px; }
.metric small { display: block; color: var(--muted); margin-bottom: 4px; }
.carbon-level-panel { display: grid; gap: 14px; }
.carbon-legend { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-weight: 700; }
.carbon-legend span { display: inline-flex; align-items: center; gap: 7px; }
.level-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.level-dot.low { background: var(--accent); }
.level-dot.medium { background: var(--amber); }
.level-dot.high { background: var(--red); }
.carbon-site-list { display: grid; gap: 10px; }
.carbon-site-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.level-symbol {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  font-weight: 900;
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 14%, transparent);
}
.level-symbol.good { background: var(--accent); }
.level-symbol.warn { background: var(--amber); box-shadow: 0 0 0 7px color-mix(in srgb, var(--amber) 16%, transparent); }
.level-symbol.bad { background: var(--red); box-shadow: 0 0 0 7px color-mix(in srgb, var(--red) 16%, transparent); }
.carbon-site-main { display: grid; gap: 8px; min-width: 0; }
.carbon-site-head { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
.carbon-site-head b { color: var(--ink); }
.level-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.level-bar span { display: block; height: 100%; border-radius: inherit; }
.level-bar span.good { background: var(--accent); }
.level-bar span.warn { background: var(--amber); }
.level-bar span.bad { background: var(--red); }
.tabs, .view-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab, .view-tab {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  padding: 0 12px;
}
.tab.active, .view-tab.active { background: var(--accent-2); border-color: var(--accent-2); color: white; }
.map {
  min-height: 460px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--line) 62%, transparent) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--line) 62%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--line) 32%, transparent) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--line) 32%, transparent) 1px, transparent 1px),
    var(--surface);
  background-size: 34px 34px, 34px 34px, 8.5px 8.5px, 8.5px 8.5px, auto;
}
.map::before {
  content: none;
}
.map-summary {
  position: absolute;
  z-index: 5;
  left: 26px;
  top: 22px;
  display: grid;
  gap: 2px;
  color: var(--muted);
}
.map-summary strong {
  color: var(--ink);
  font-size: 22px;
}
.facility-routes {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: visible;
}
.route {
  fill: none;
  stroke-linejoin: miter;
  stroke-linecap: square;
}
.route-blue {
  stroke: #0d56ad;
  stroke-width: 22;
}
.route-purple {
  stroke: #8c1caf;
  stroke-width: 20;
}
.route-service {
  stroke: color-mix(in srgb, var(--accent-2) 76%, var(--surface));
  stroke-width: 13;
  opacity: .42;
}
.road-badge {
  fill: #ffffff;
  stroke: #0d56ad;
  stroke-width: 2;
  paint-order: stroke;
  font-size: 20px;
  font-weight: 900;
}
.map-lines {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.map-lines line {
  stroke: color-mix(in srgb, var(--ink) 42%, transparent);
  stroke-width: .28;
  stroke-dasharray: 1.2 1.4;
}
.map-marker {
  position: absolute;
  z-index: 4;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  border: 4px solid var(--surface);
  box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 18%, transparent);
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  font-weight: 900;
}
.map-marker.warn {
  background: var(--red);
  box-shadow: 0 0 0 9px color-mix(in srgb, var(--red) 18%, transparent);
}
.map-label {
  position: absolute;
  z-index: 5;
  min-width: 74px;
  max-width: 120px;
  transform: translate(-50%, -50%);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-weight: 800;
  white-space: nowrap;
  text-align: center;
  line-height: 1.25;
}
.camera-grid { display: grid; gap: 10px; }
.camera-grid.layout-4 { grid-template-columns: repeat(2, 1fr); }
.camera-grid.layout-9 { grid-template-columns: repeat(3, 1fr); }
.camera-grid.layout-16 { grid-template-columns: repeat(4, 1fr); }
.camera {
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(150deg, rgba(255,255,255,.08), transparent 35%),
    repeating-linear-gradient(0deg, transparent, transparent 16px, rgba(255,255,255,.04) 17px),
    #16283a;
  color: white;
  position: relative;
  overflow: hidden;
  padding: 10px;
}
.camera::after { content: ""; position: absolute; inset: 26% 18%; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; }
.camera strong, .camera span { position: relative; z-index: 1; display: block; }
.camera span { color: #b7c9da; font-size: 12px; margin-top: 4px; }
.formula {
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 16px;
  font-size: 20px;
  font-weight: 800;
}
.formula-stack { display: grid; gap: 12px; }
.equation {
  display: grid;
  grid-template-columns: minmax(120px, .35fr) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.equation span { color: var(--muted); }
.equation b { overflow-wrap: anywhere; }
.calculator { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field input { width: 100%; min-height: 40px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 0 10px; }
.calc-breakdown {
  display: grid;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.timeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.phase { border-top: 3px solid var(--accent); padding-top: 10px; }
.report-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.connector-list { display: grid; gap: 10px; }
.connector-list span { display: flex; align-items: center; }
.pipeline {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}
.pipeline span {
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-weight: 800;
  text-align: center;
}
.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 12px; }
.badge.critical { background: color-mix(in srgb, var(--red) 16%, var(--surface)); color: var(--red); }
.badge.warning { background: color-mix(in srgb, var(--amber) 16%, var(--surface)); color: var(--amber); }
.badge.ok { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent); }
.hidden { display: none !important; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; width: 280px; }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: inline-block; }
  .hero, .cols-2, .cols-3, .cols-4, .cols-5 { grid-template-columns: 1fr 1fr; }
  .topbar { align-items: flex-start; }
}
@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: stretch; padding: 12px; }
  .toolbar { justify-content: stretch; }
  .search, select, .theme-toggle, .segmented { width: 100%; }
  .page { padding: 14px 12px 32px; }
  .hero, .cols-2, .cols-3, .cols-4, .cols-5, .timeline { grid-template-columns: 1fr; }
  .camera-grid.layout-4, .camera-grid.layout-9, .camera-grid.layout-16 { grid-template-columns: 1fr; }
  .hero h2 { font-size: 38px; }
  .map { min-height: 520px; }
  .map-summary strong { font-size: 18px; }
  .map-label { min-width: 62px; max-width: 90px; font-size: 12px; }
  .map-marker { width: 30px; height: 30px; }
  .carbon-site-row { grid-template-columns: 40px minmax(0, 1fr); }
  .carbon-site-row .badge { grid-column: 2; width: max-content; }
  .carbon-site-head { display: grid; }
  .equation, .pipeline { grid-template-columns: 1fr; }
}
