:root {
  --bg: #0a0f0e;
  --surface: #121816;
  --surface-2: #18201d;
  --line: #24302c;
  --grid: #1e2825;
  --ink: #e6f0ec;
  --ink-2: #a7b8b1;
  --muted: #71837c;
  --accent: #34d399;
  --accent-strong: #10b981;
  --accent-soft: rgba(52, 211, 153, .12);
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;
  --radius: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 13px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* --- login ------------------------------------------------------------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(16,185,129,.14), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px; }
.login-card h1 { font-size: 18px; margin: 14px 0 4px; }
.login-card p { color: var(--ink-2); margin: 0 0 20px; }
.login-card label { display: block; color: var(--ink-2); font-size: 12px; margin-bottom: 6px; }
.login-card input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 12px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card input.code { font: 600 24px/1 var(--mono); letter-spacing: 10px; text-align: center; }
.login-card .btn { width: 100%; margin-top: 14px; justify-content: center; padding: 11px; }
.login-card .msg { min-height: 20px; margin-top: 12px; font-size: 12px; color: var(--ink-2); }
.login-card .msg.err { color: var(--critical); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand svg { width: 26px; height: 26px; }
.brand small { color: var(--muted); font-weight: 500; }

/* --- buttons & controls --------------------------------------------------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 8px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #33433d; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #04130d; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
select, input[type=date], input[type=text], input[type=search] {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; outline: none; }
select:focus, input:focus { border-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- layout ---------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); background: #0c1211; padding: 16px 10px; position: sticky; top: 0;
  height: 100vh; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.side .brand { padding: 4px 8px 16px; }
.side h6 { margin: 14px 8px 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.nav { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px; color: var(--ink-2);
  cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--surface); color: var(--ink); }
.nav.active { background: var(--accent-soft); color: var(--accent); }
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .6; flex: none; }
.side .foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; word-break: break-all; }
.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; background: rgba(10,15,14,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: 10px 18px; display: flex; flex-direction: column; gap: 8px; }
.top-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top h2 { margin: 0 8px 0 0; font-size: 16px; font-weight: 650; }
.spacer { flex: 1; }
.filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filters .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip.off { opacity: .45; }
.chip.off i { background: transparent !important; outline: 1px solid var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 9px; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.content { padding: 16px 18px 40px; }
.menu-btn { display: none; }

/* --- widget grid ---------------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 172px; gap: 12px; grid-auto-flow: dense; }
.w { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.w.w1 { grid-column: span 1; } .w.w2 { grid-column: span 2; } .w.w3 { grid-column: span 3; } .w.w4 { grid-column: span 4; }
.w.h1 { grid-row: span 1; } .w.h2 { grid-row: span 2; } .w.h3 { grid-row: span 3; }
.w.dragging { opacity: .4; }
.w.drop { outline: 2px dashed var(--accent); outline-offset: 2px; }
.w-head { display: flex; align-items: center; gap: 6px; min-height: 22px; }
.w-title { font-weight: 600; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-tools { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.w:hover .w-tools, .w:focus-within .w-tools, .editing .w-tools { opacity: 1; }
.icon { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 5px; font-size: 13px; line-height: 1; }
.icon:hover { color: var(--ink); background: var(--surface-2); }
.handle { cursor: grab; }
.w-body { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.w-foot { display: flex; gap: 5px; flex-wrap: nowrap; overflow: hidden; align-items: center; margin-top: 6px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.kpi-list { display: grid; grid-template-columns: auto auto 1fr; gap: 1px 10px; align-items: center; font-size: 12px; margin-top: 4px; }
.kpi-list b { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 5px; padding: 1px 6px; font-size: 10.5px;
  border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.badge.real::before { content: "●"; color: var(--good); font-size: 8px; }
.badge.est::before { content: "◐"; color: var(--warning); font-size: 9px; }
.badge.na::before { content: "○"; color: var(--muted); font-size: 9px; }
.badge.err::before { content: "▲"; color: var(--critical); font-size: 8px; }
.loading { color: var(--muted); font-size: 12px; margin: auto; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 12px; padding: 6px; max-width: 320px; }
.empty b { display: block; color: var(--ink-2); font-weight: 600; margin-bottom: 2px; }

/* KPI */
.kpis { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 4px; }
.kpi { min-width: 0; }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi.small .v { font-size: 19px; }
.kpi .app { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.kpi .app i { width: 7px; height: 7px; border-radius: 2px; }
.kpi .na { color: var(--muted); font-size: 12px; font-weight: 500; }
.delta { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--accent); } .delta.down { color: var(--critical); } .delta.flat { color: var(--muted); }
.spark { margin-top: auto; height: 34px; }

/* charts */
.chart { flex: 1; min-height: 0; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.axis text { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: #33433d; stroke-width: 1; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--ink-2); margin: 2px 0 4px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; }
.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 3px, transparent 3px 5px) !important; height: 2px; }
.tip { position: absolute; z-index: 20; pointer-events: none; background: #0b1110; border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font-size: 11.5px; min-width: 130px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.tip .t { color: var(--muted); margin-bottom: 3px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tip .r b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* tables */
.tbl-wrap { overflow: auto; flex: 1; min-height: 0; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 6px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
.tbl td { padding: 4px 6px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl td.txt { max-width: 420px; white-space: normal; color: var(--ink-2); }
.bar-cell { position: relative; }
.bar-cell .b { position: absolute; left: 0; top: 4px; bottom: 4px; border-radius: 0 3px 3px 0; opacity: .28; }
.bar-cell span { position: relative; }
.app-tag { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); }
.app-tag i { width: 7px; height: 7px; border-radius: 2px; }
.heat { text-align: center !important; border-radius: 4px; }

/* panels & modal */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.panel p { color: var(--ink-2); margin: 4px 0; }
.src-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; font-size: 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 11.5px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 640px;
  max-height: 86vh; overflow: auto; padding: 18px; }
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal .row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; margin: 8px 0; }
.modal .row label { color: var(--ink-2); }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; }
.picker button { text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 8px; cursor: pointer; }
.picker button:hover { border-color: var(--accent); }
.picker button small { display: block; color: var(--muted); font-size: 11px; }
.picker h4 { grid-column: 1 / -1; margin: 10px 0 2px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.toast { position: fixed; bottom: 18px; right: 18px; z-index: 60; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; max-width: 360px; }
.formula { color: var(--ink-2); }
.notes { margin: 6px 0 0; padding-left: 16px; color: var(--ink-2); }

/* --- responsive ------------------------------------------------------------ */
@media (max-width: 1200px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .w.w3, .w.w4 { grid-column: span 2; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .18s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .menu-btn { display: inline-flex; }
  .content { padding: 12px; }
  .top { padding: 10px 12px; }
}
@media (max-width: 620px) {
  .grid { grid-template-columns: 1fr; grid-auto-rows: 140px; }
  .w.w1, .w.w2, .w.w3, .w.w4 { grid-column: span 1; }
  .kpi .v { font-size: 22px; }
}

/* --- print / PDF ----------------------------------------------------------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #f4f6f5; --line: #d5dbd8; --grid: #eceeed; --ink: #111; --ink-2: #333; --muted: #666; }
  html, body { background: #fff; }
  .side, .w-tools, .no-print, .menu-btn { display: none !important; }
  .shell { display: block; }
  .top { position: static; backdrop-filter: none; background: #fff; }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .w { break-inside: avoid; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
