/* DNI Solar — design tokens and components (spec §4.2) */
:root {
  --solar: #F5A300; --solar-ink: #9A6200; --solar-soft: #FFF4DB;
  --navy: #0F1B2D; --grid: #2F6FED; --grid-ink: #2357C4; --gen: #6B7A90; --load: #13A89E; --load-ink: #0D7C74;
  --ok: #1E9E5A; --ok-ink: #177A45; --warn: #E8A317; --warn-ink: #8F6100; --crit: #D64545; --crit-ink: #B42F2F;
  --bg: #F7F8FA; --surface: #FFFFFF; --surface-2: #F1F3F7; --border: #E3E7EE; --text: #0F1B2D; --muted: #5B6779;
  --side-bg: #0F1B2D; --side-text: #C9D3E3; --side-active: #1C2C46;
  --shadow: 0 1px 2px rgba(15,27,45,.06), 0 1px 1px rgba(15,27,45,.04);
  --r-card: 12px; --r-ctl: 8px; --focus: 0 0 0 3px rgba(47,111,237,.45);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --solar-ink: #FFC24D; --solar-soft: #3A2A05; --grid-ink: #7EA6FF; --load-ink: #4FD1C5;
    --ok-ink: #4CC984; --warn-ink: #F2C14E; --crit-ink: #FF8080;
    --bg: #0B1220; --surface: #121B2C; --surface-2: #19243A; --border: #24324B; --text: #E7ECF4; --muted: #9AA8BD;
    --side-bg: #08101D; --side-active: #16233A; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --solar-ink: #FFC24D; --solar-soft: #3A2A05; --grid-ink: #7EA6FF; --load-ink: #4FD1C5;
  --ok-ink: #4CC984; --warn-ink: #F2C14E; --crit-ink: #FF8080;
  --bg: #0B1220; --surface: #121B2C; --surface-2: #19243A; --border: #24324B; --text: #E7ECF4; --muted: #9AA8BD;
  --side-bg: #08101D; --side-active: #16233A; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
a { color: var(--grid-ink); }
.num, td.n, .kpi .val { font-variant-numeric: tabular-nums; }
svg.ic { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
[dir="rtl"] { direction: rtl; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: var(--r-ctl); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--solar); border-color: var(--solar); color: #1A1200; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 44px; min-height: 44px; padding: 0; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 550; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-ctl); min-height: 40px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; accent-color: var(--solar); }
input[type="range"] { padding: 0; accent-color: var(--solar); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-ctl); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; font: inherit; padding: 6px 12px; min-height: 34px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { background: var(--solar); color: #1A1200; }
.error-text { color: var(--crit-ink); font-size: 13px; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.shell.collapsed { grid-template-columns: 72px 1fr; }
.sidebar {
  background: var(--side-bg); color: var(--side-text); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 14px 10px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: #fff; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-name b { color: var(--solar); font-weight: 700; }
.nav { display: grid; gap: 2px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7F8DA3; padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-ctl);
  color: var(--side-text); text-decoration: none; min-height: 40px;
}
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--solar); }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav .sub { padding-left: 38px; font-size: 13px; min-height: 34px; }
.nav .badge { margin-left: auto; }
.shell.collapsed .brand-name, .shell.collapsed .nav span, .shell.collapsed .nav-group, .shell.collapsed .nav .sub { display: none; }
.side-foot { margin-top: auto; padding: 10px; font-size: 11px; color: #7F8DA3; }
.shell.collapsed .side-foot { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.site-switch { max-width: 280px; }
.bell { position: relative; }
.bell .dot { position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 4px; }
.user-menu { position: relative; }
.user-menu .menu {
  position: absolute; right: 0; top: 48px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 220px; padding: 6px; display: none;
}
.user-menu.open .menu { display: block; }
.menu a, .menu button { display: flex; width: 100%; gap: 8px; align-items: center; padding: 10px; border: 0; background: none; font: inherit; color: var(--text); text-decoration: none; border-radius: 6px; cursor: pointer; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; }
:root[data-theme="dark"] .avatar { background: var(--solar); color: #1A1200; }
.demo-ribbon { background: var(--solar-soft); color: var(--solar-ink); font-size: 12px; padding: 6px 24px; border-bottom: 1px solid var(--border); }
.viewas { background: #E8F0FF; color: #1D3F8F; font-size: 13px; padding: 6px 24px; }
:root[data-theme="dark"] .viewas { background: #14264A; color: #BFD3FF; }
.content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; }
.bottom-tabs { display: none; }

@media (max-width: 1100px) { .shell { grid-template-columns: 72px 1fr; } .shell .brand-name, .shell .nav span, .shell .nav-group, .shell .nav .sub, .shell .side-foot { display: none; } }
@media (max-width: 720px) {
  .shell, .shell.collapsed { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 8px 16px; }
  .content { padding: 16px 16px 90px; }
  .demo-ribbon, .viewas { padding: 6px 16px; }
  .bottom-tabs {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-tabs a { display: grid; justify-items: center; gap: 2px; padding: 8px 0; min-height: 56px; font-size: 11px; color: var(--muted); text-decoration: none; }
  .bottom-tabs a[aria-current="page"] { color: var(--solar-ink); }
  .bottom-tabs svg { width: 20px; height: 20px; }
  .hide-mobile { display: none !important; }
}

/* ---------------------------------------------------------------- layout */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 20px; }
.page-head .grow { flex: 1; min-width: 220px; }
.page-head .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 13px; margin-top: 6px; align-items: center; }
.grid { display: grid; gap: 16px; }
.cols-12 { grid-template-columns: repeat(12, 1fr); }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
@media (max-width: 1100px) { .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }

/* ---------------------------------------------------------------- KPI cards */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; }
@media (max-width: 1300px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .kpis { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px 16px; padding: 0 16px 4px; }
  .kpis .kpi { flex: 0 0 72%; scroll-snap-align: start; }
}
.kpi { position: relative; border-top: 3px solid var(--accent, var(--border)); }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 550; display: flex; gap: 6px; align-items: center; }
.kpi .label svg { width: 15px; height: 15px; color: var(--accent); }
.kpi .val { font-size: 26px; font-weight: 700; letter-spacing: -.3px; margin: 4px 0 2px; white-space: nowrap; }
.kpi .val .unit { font-size: 13px; font-weight: 550; color: var(--muted); margin-left: 3px; }
.kpi .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; min-height: 18px; }
.kpi .spark { height: 34px; margin-top: 6px; }
.delta.up { color: var(--ok-ink); } .delta.down { color: var(--crit-ink); }
.kpi .warnbadge { position: absolute; top: 10px; right: 10px; }
.acc-solar { --accent: var(--solar); } .acc-grid { --accent: var(--grid); } .acc-gen { --accent: var(--gen); }
.acc-load { --accent: var(--load); } .acc-ok { --accent: var(--ok); } .acc-navy { --accent: var(--navy); }
.c-solar { color: var(--solar-ink); } .c-grid { color: var(--grid-ink); } .c-gen { color: var(--gen); } .c-load { color: var(--load-ink); }

/* ---------------------------------------------------------------- status */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.pill svg { width: 13px; height: 13px; }
.pill.online, .pill.applied, .pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok-ink); }
.pill.warning, .pill.pending, .pill.sent, .pill.acknowledged, .pill.stale { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn-ink); }
.pill.fault, .pill.critical, .pill.failed, .pill.timeout, .pill.offline-red { background: color-mix(in srgb, var(--crit) 14%, transparent); color: var(--crit-ink); }
.pill.offline, .pill.cleared, .pill.decommissioned, .pill.closed, .pill.resolved { background: var(--surface-2); color: var(--muted); }
.pill.info, .pill.open, .pill.assigned, .pill.in_progress { background: color-mix(in srgb, var(--grid) 14%, transparent); color: var(--grid-ink); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; }
.fresh { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; }
.fresh svg { width: 14px; height: 14px; }
.fresh.stale { color: var(--warn-ink); } .fresh.dead { color: var(--crit-ink); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.t td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t td.n, .t th.n { text-align: right; white-space: nowrap; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover { background: var(--surface-2); }
.t tfoot td { font-weight: 650; border-top: 2px solid var(--border); }
.t .dim { opacity: .55; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.mismatch { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 80px; }
.mismatch i { display: block; height: 100%; background: var(--solar); }
.mismatch.low i { background: var(--crit); }

/* ---------------------------------------------------------------- tabs, dialogs, toasts */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 550; color: var(--muted); padding: 10px 14px; min-height: 44px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--solar); }
dialog { border: 1px solid var(--border); border-radius: var(--r-card); padding: 0; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(8,16,29,.55); }
dialog .dlg-body { padding: 20px; }
dialog .dlg-body h2 { margin-bottom: 8px; }
.drawer { position: fixed; inset: 0 0 0 auto; width: min(480px, 100vw); background: var(--surface); border-left: 1px solid var(--border); z-index: 50; box-shadow: -10px 0 40px rgba(0,0,0,.2); overflow-y: auto; padding: 20px; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(8,16,29,.4); z-index: 49; }
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: var(--r-ctl); box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 360px; font-size: 13.5px; }
.toast.err { background: var(--crit); }
@media (max-width: 720px) { .toasts { bottom: 76px; left: 16px; right: 16px; } }

/* ---------------------------------------------------------------- states */
.skel { background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: skel 1.2s infinite; border-radius: 6px; }
@keyframes skel { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty svg { width: 36px; height: 36px; color: var(--border); margin-bottom: 8px; }
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r-ctl); background: var(--surface-2); font-size: 13.5px; }
.callout.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.callout.err { background: color-mix(in srgb, var(--crit) 12%, transparent); }
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.chart { width: 100%; height: 300px; }
.chart.sm { height: 220px; }

/* ---------------------------------------------------------------- power flow */
.flow svg { width: 100%; height: auto; max-height: 360px; display: block; }
.flow .node circle.bg { fill: var(--surface-2); stroke: var(--border); }
.flow .node text { fill: var(--text); font-size: 13px; font-weight: 600; text-anchor: middle; }
.flow .node text.kw { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.flow .node text.lbl { fill: var(--muted); font-size: 11.5px; font-weight: 550; }
.flow path.track { fill: none; stroke: var(--border); }
.flow path.live { fill: none; stroke-linecap: round; stroke-dasharray: 2 14; animation: dash 1s linear infinite; }
.flow path.live.rev { animation-direction: reverse; }
@keyframes dash { to { stroke-dashoffset: -16; } }
.flow .node.off { opacity: .45; }

/* ---------------------------------------------------------------- stepper */
.stepper { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; counter-reset: step; }
.stepper li { list-style: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 550; }
.stepper li::before { counter-increment: step; content: counter(step); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--border); color: var(--text); font-size: 12px; }
.stepper li.done::before { content: "✓"; background: var(--ok); color: #fff; }
.stepper li.cur { background: var(--solar-soft); color: var(--solar-ink); }
.stepper li.cur::before { background: var(--solar); color: #1A1200; }
.stepper { padding: 0; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(120% 90% at 20% 10%, #1D3354 0%, var(--navy) 55%, #08101D 100%); color: #E7ECF4; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art .promise { max-width: 440px; position: relative; z-index: 1; }
.login-art h1 { font-size: 34px; line-height: 1.15; margin: 12px 0 14px; font-weight: 700; }
.login-art p { color: #B7C3D6; font-size: 15px; }
.login-art .sun { position: absolute; right: -120px; bottom: -120px; width: 520px; height: 520px; opacity: .9; }
.login-form { display: grid; place-items: center; padding: 32px 16px; background: var(--bg); }
.login-form .box { width: min(400px, 100%); }
.login-form h2 { font-size: 22px; margin-bottom: 4px; }
.demo-roles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
@media (max-width: 860px) { .login { grid-template-columns: 1fr; } .login-art { padding: 28px 20px; min-height: 0; } .login-art h1 { font-size: 24px; } .login-art .sun { width: 260px; height: 260px; right: -80px; bottom: -80px; } }

/* ---------------------------------------------------------------- print (PDF reports) */
@media print {
  .sidebar, .topbar, .bottom-tabs, .demo-ribbon, .no-print, .toasts { display: none !important; }
  .shell { display: block; } .content { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; color: #000; }
  .print-head { display: flex !important; }
}
.print-head { display: none; justify-content: space-between; align-items: center; margin-bottom: 16px; border-bottom: 2px solid var(--solar); padding-bottom: 8px; }
