:root {
  --bg: #f4f5f7; --card: #fff; --fg: #1b1f24; --muted: #6b7280; --line: #e5e7eb; --soft: #f3f4f6;
  --side: #111827; --side-fg: #d1d5db; --side-active: #1f2937;
  --pos: #15803d; --neg: #b91c1c; --warn: #b45309; --accent: #2563eb;
  --pos-bg: #dcfce7; --neg-bg: #fee2e2; --zone: rgba(245, 158, 11, .08);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0f13; --card: #161a21; --fg: #e5e7eb; --muted: #9ca3af; --line: #262b35; --soft: #1d222b;
    --side: #0a0c10; --side-fg: #9ca3af; --side-active: #1d222b;
    --pos: #4ade80; --neg: #f87171; --warn: #fbbf24; --accent: #60a5fa;
    --pos-bg: rgba(74, 222, 128, .12); --neg-bg: rgba(248, 113, 113, .12); --zone: rgba(251, 191, 36, .07); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--accent); text-decoration: none; }
small { color: var(--muted); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }

/* App shell */
.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-fg); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 18px; color: #fff; padding: 0 10px; }
.brand span { color: var(--accent); margin-left: 4px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-fg); padding: 8px 10px; border-radius: 6px; }
.side nav a:hover { background: var(--side-active); color: #fff; }
.side nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { margin-top: auto; font-size: 12px; padding: 0 10px; opacity: .6; }
.main { min-width: 0; }
.content { padding: 16px 20px 32px; max-width: 1400px; }
.page-title { font-size: 20px; margin: 4px 0 14px; }

/* Status bar */
.status { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; }
.badge.sim { background: #dbeafe; color: #1e40af; border-color: transparent; }
.badge.live { background: #fee2e2; color: #991b1b; border-color: transparent; font-weight: 700; }
.badge.ok { color: var(--pos); } .badge.bad { color: var(--neg); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.feeds { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.dot.ok { background: var(--pos); } .dot.bad { background: var(--neg); }
.stat-chip { font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 6px; background: var(--soft); font-size: 13px; }
.stat-chip.hot { color: var(--warn); font-weight: 600; }
button { font: inherit; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-color: var(--neg); color: var(--neg); }

/* Cards & grid */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 14px; }
.grid.hero { grid-template-columns: 2fr 1fr; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; margin-bottom: 14px; }
.grid > .card { margin-bottom: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.hero-row { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; margin-bottom: 8px; }
.big { font-size: 40px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big.hot { color: var(--warn); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 10px 18px; flex: 1; }
.kpis div { display: flex; flex-direction: column; }
.kpis b { font-size: 17px; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 170px; display: block; }
.chart .zone { fill: var(--zone); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .start { stroke: var(--muted); stroke-dasharray: 5 4; stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .line.up { stroke: var(--pos); } .chart .line.down { stroke: var(--neg); }
.chart .dot-up { fill: var(--pos); } .chart .dot-down { fill: var(--neg); }
.book { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.side-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; align-items: center; }
.side-box b { font-size: 26px; font-variant-numeric: tabular-nums; }
.side-box.up.lead { background: var(--pos-bg); border-color: var(--pos); }
.side-box.down.lead { background: var(--neg-bg); border-color: var(--neg); }
.side-box.up small:first-child { color: var(--pos); font-weight: 600; }
.side-box.down small:first-child { color: var(--neg); font-weight: 600; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 8px 0 0; }
dt { color: var(--muted); } dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl.wide dd { text-align: left; }
.decision { margin: 0 0 12px; padding: 10px; border-radius: 6px; background: var(--soft); }
.decision.go { color: var(--pos); background: var(--pos-bg); font-weight: 600; }
.pos-box { border-top: 1px solid var(--line); padding-top: 10px; }
.notice { padding: 8px 12px; border-radius: 8px; background: #fef3c7; color: #92400e; margin-bottom: 14px; }

/* Tables & scroll areas */
.scroll { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.scroll.short { max-height: 240px; }
.scroll.tall { max-height: calc(100vh - 300px); min-height: 240px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child, th.left, td.left { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.scroll thead th { position: sticky; top: 0; background: var(--card); z-index: 1; box-shadow: inset 0 -1px 0 var(--line); }
.list tbody tr:hover { background: var(--soft); }
td.why { white-space: normal; min-width: 280px; max-width: 520px; color: var(--muted); font-size: 12px; }
td.empty, .empty { text-align: center; color: var(--muted); padding: 20px; }
td small { margin-left: 4px; }
.stats td, .stats th { padding: 5px 6px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--soft); }
.tag.live { background: var(--neg-bg); color: var(--neg); }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.chips { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.chips a { padding: 5px 12px; color: var(--fg); border-right: 1px solid var(--line); font-size: 13px; }
.chips a:last-child { border-right: 0; }
.chips a.on { background: var(--accent); color: #fff; }
.pager { display: flex; align-items: center; gap: 14px; padding-top: 10px; color: var(--muted); font-size: 13px; }

/* Log */
.log { font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 6px 10px; }
.log time { color: var(--muted); margin-right: 8px; }
.log .hl { color: var(--accent); }

/* Flash & forms */
.flash { position: fixed; bottom: 16px; right: 16px; padding: 10px 14px; border-radius: 8px; background: var(--card); border: 1px solid var(--pos); z-index: 10; }
.flash.err { border-color: var(--neg); color: var(--neg); }
.flash:empty { display: none; }
form fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 18px; }
legend { color: var(--muted); padding: 0 6px; font-weight: 600; }
label { display: grid; gap: 3px; align-content: start; }
label input[type=number], label input[type=text], label input[type=password] { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); width: 100%; }
label input[type=checkbox] { justify-self: start; width: 18px; height: 18px; }
.form-foot { position: sticky; bottom: 0; background: var(--card); padding: 10px 0 2px; }

/* Mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; }
  .status { position: static; }
  .chart { height: auto; }
  .side nav { flex-direction: row; }
  .side-foot { display: none; }
  .grid.hero, .grid.two { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 14px 16px 28px; }
  .status { padding: 8px 16px; }
  .big { font-size: 32px; }
}

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { color: var(--fg); padding: 0; }
.login label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login input { font: inherit; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.login-msg { color: var(--neg); font-size: 13px; }
.side-foot form { margin-bottom: 8px; }
button.link { background: none; border: 0; padding: 0; color: var(--side-fg); cursor: pointer; }
button.link:hover { color: #fff; }

/* Settings lock / account */
.notice { padding: 9px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--pos-bg); color: var(--pos); }
.notice.err { background: var(--neg-bg); color: var(--neg); }
.lockbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.lockbar span { flex: 1 1 260px; }
.lockbar input[type=password] { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); flex: 0 1 220px; min-width: 0; }
.account { display: flex; flex-direction: column; gap: 10px; max-width: 460px; }
.account label { display: flex; flex-direction: column; gap: 4px; }
.account input { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
fieldset:disabled { opacity: .65; }
