:root {
  --bg: #eef1f8;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #dfe7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #e9e3ff 0%, transparent 55%);
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --border: rgba(20, 30, 60, 0.08);
  --text: #141a2e;
  --muted: #5d6680;
  --faint: #8a92a8;
  --accent: #3b5bdb;
  --healthy: #2f9e44;
  --watch: #e8890c;
  --degraded: #e8590c;
  --critical: #e03131;
  --unknown: #868e96;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 8px 24px rgba(20, 30, 60, .06);
  --grid: rgba(20, 30, 60, .07);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d111c; --bg-grad: radial-gradient(1200px 600px at 10% -10%, #18214a 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #241a45 0%, transparent 55%);
    --surface: rgba(24, 30, 48, 0.82); --surface-solid: #171d2e; --border: rgba(255, 255, 255, .08);
    --text: #e9ecf5; --muted: #a2aac0; --faint: #737c95; --accent: #748ffc;
    --healthy: #51cf66; --watch: #fcc419; --degraded: #ff922b; --critical: #ff6b6b; --unknown: #868e96;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25); --grid: rgba(255, 255, 255, .07);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d111c; --bg-grad: radial-gradient(1200px 600px at 10% -10%, #18214a 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #241a45 0%, transparent 55%);
  --surface: rgba(24, 30, 48, 0.82); --surface-solid: #171d2e; --border: rgba(255, 255, 255, .08);
  --text: #e9ecf5; --muted: #a2aac0; --faint: #737c95; --accent: #748ffc;
  --healthy: #51cf66; --watch: #fcc419; --degraded: #ff922b; --critical: #ff6b6b; --unknown: #868e96;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25); --grid: rgba(255, 255, 255, .07);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-grad), var(--bg); background-attachment: fixed; color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ---- brand / top bar ---- */
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; flex: none; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 17h5l3-7 4 13 3-6h3' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/70% no-repeat; }
.brand-lg { font-size: 22px; font-weight: 700; }
.brand-title { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-title .sep { color: var(--faint); font-weight: 400; margin: 0 4px; }
.brand-sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
#fixture-tag { color: var(--watch); font-weight: 600; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--surface); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border);
}
.topbar .brand { flex: 1 1 280px; }
.tabs { display: flex; gap: 4px; background: var(--grid); padding: 4px; border-radius: 12px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 550; }
.tabs button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.user { display: flex; align-items: center; gap: 12px; font-size: 13.5px; }
.rotate { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.btn-ghost { border: 1px solid var(--border); background: var(--surface-solid); padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.btn-ghost:hover { border-color: var(--accent); }

main { padding: 22px 24px 40px; max-width: 1760px; margin: 0 auto; }
.glass { background: var(--surface); backdrop-filter: blur(14px); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---- summary strip ---- */
.summary { display: flex; align-items: center; gap: 18px; padding: 18px 24px; flex-wrap: wrap; }
.summary .icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 20px; flex: none; }
.summary h1 { margin: 0; font-size: 28px; letter-spacing: -.01em; }
.summary .sub { color: var(--muted); }
.summary .chips { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.s-healthy { --c: var(--healthy); } .s-watch { --c: var(--watch); } .s-degraded { --c: var(--degraded); }
.s-critical { --c: var(--critical); } .s-unknown { --c: var(--unknown); }
.dot { background: var(--c, var(--unknown)); }
.summary .icon { background: var(--c); }
.summary h1 { color: var(--c); }
.summary.s-healthy h1 { color: var(--text); }

/* ---- cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; margin-top: 18px; }
.cards.stale { opacity: .45; filter: grayscale(.8); }
.card { padding: 20px 22px 14px; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); opacity: .85; }
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.badge { width: 34px; height: 34px; border-radius: 9px; color: #fff; font-weight: 700; display: grid; place-items: center; flex: none; }
.card-name { font-weight: 650; font-size: 16.5px; }
.card-title { flex: 1 1 auto; min-width: 0; }
.card-desc { color: var(--faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-pill { flex: none; margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--c); font-weight: 600; white-space: nowrap; }
.pulse { width: 22px; height: 10px; }
.card-status { font-size: 34px; font-weight: 750; letter-spacing: -.02em; margin: 14px 0 0; color: var(--c); }
.card.s-healthy .card-status { color: var(--text); }
.card-headline { color: var(--muted); margin-bottom: 12px; }
.signals { list-style: none; margin: 0; padding: 0; }
.signal { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 9px 0; border-top: 1px solid var(--border); }
.signal-label { color: var(--muted); font-size: 14px; }
.signal-value { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; justify-self: end; text-align: right; max-width: 230px; }
.signal-value span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signal-detail { grid-column: 1 / -1; font-size: 12.5px; color: var(--c); background: color-mix(in srgb, var(--c) 9%, transparent); border-radius: 8px; padding: 6px 9px; word-break: break-word; }
.signal-detail::before { content: "✕ "; font-weight: 700; }
.signal.s-healthy .signal-detail::before, .signal.s-watch .signal-detail::before { content: "› "; }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 8px; font-size: 13px; }
.more { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-weight: 600; }
.footnote { color: var(--faint); font-size: 12.5px; margin-top: 18px; }

/* ---- KPIs ---- */
.kpi-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.kpi-head h1 { margin: 0; font-size: 24px; }
.segmented { display: flex; background: var(--grid); padding: 3px; border-radius: 10px; }
.segmented button { border: 0; background: none; padding: 5px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 550; }
.segmented button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.kpi-body { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 16px; }
.kpi-row-title { grid-column: 1 / -1; margin: 14px 0 -4px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.panel { padding: 16px 18px; min-width: 0; display: flex; flex-direction: column; }
.panel h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.panel h3 .info { cursor: help; color: var(--faint); font-size: 12px; }
.stat-value { font-size: 32px; font-weight: 750; letter-spacing: -.02em; margin-top: auto; font-variant-numeric: tabular-nums; }
.panel-state { color: var(--faint); font-size: 13px; padding: 18px 0; }
.panel-error { color: var(--critical); font-size: 12.5px; word-break: break-word; }
.chart { width: 100%; height: 220px; display: block; }
.chart text { fill: var(--faint); font-size: 11px; }
.chart .gridline { stroke: var(--grid); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }
.table-wrap { overflow: auto; max-height: 360px; margin-top: 4px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface-solid); padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 6px 10px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num { text-align: right; }
.tooltip { position: fixed; pointer-events: none; z-index: 20; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; min-width: 140px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; }

/* ---- dashboards list ---- */
.dash-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.dash { padding: 16px 18px; text-decoration: none; color: inherit; display: block; transition: transform .12s; }
.dash:hover { transform: translateY(-2px); border-color: var(--accent); }
.dash .title { font-weight: 650; }
.dash .meta { color: var(--faint); font-size: 12.5px; margin-top: 4px; }
.tag { display: inline-block; font-size: 11.5px; background: var(--grid); border-radius: 6px; padding: 1px 7px; margin: 6px 4px 0 0; color: var(--muted); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); backdrop-filter: blur(14px); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow); padding: 30px; display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.login-card input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-solid); font-weight: 400; }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px; font-weight: 650; cursor: pointer; }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.form-error { color: var(--critical); margin: 0; font-size: 13.5px; }

@media (max-width: 900px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  main { padding: 16px; }
  .kpi-body > * { grid-column: 1 / -1 !important; }
  .summary h1 { font-size: 22px; }
  .summary .chips { margin-left: 0; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .user .muted { display: none; }
}
