:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #e3e2de;
  --text: #1b1b1a;
  --muted: #6b6a66;
  --accent: #2f5bd3;
  --accent-soft: #e6ecfb;
  --ok: #1f8a4c;
  --ok-soft: #e3f3e9;
  --warn: #b26b00;
  --warn-soft: #fbf0dc;
  --bad: #c2352b;
  --bad-soft: #fbe5e3;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 1px rgba(0, 0, 0, .03);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111112; --surface: #1a1a1c; --surface-2: #232326; --border: #2e2e32; --text: #ececea; --muted: #9a9a96;
    --accent: #7c9bff; --accent-soft: #1f2744; --ok: #4cc27f; --ok-soft: #16301f; --warn: #e6a53d; --warn-soft: #34270f;
    --bad: #ff6b5f; --bad-soft: #3a1917; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111112; --surface: #1a1a1c; --surface-2: #232326; --border: #2e2e32; --text: #ececea; --muted: #9a9a96;
  --accent: #7c9bff; --accent-soft: #1f2744; --ok: #4cc27f; --ok-soft: #16301f; --warn: #e6a53d; --warn-soft: #34270f;
  --bad: #ff6b5f; --bad-soft: #3a1917; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--border); background: var(--surface); padding: 16px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.logo { font-weight: 700; padding: 4px 10px 14px; letter-spacing: -.01em; }
.logo span { color: var(--muted); font-weight: 500; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { font-size: 12px; background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; min-width: 20px; text-align: center; }
.side-foot { margin-top: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
main { padding: 22px 26px 60px; max-width: 1280px; width: 100%; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .logo { padding: 0 8px 0 4px; white-space: nowrap; }
  .nav { display: flex; gap: 2px; }
  .nav a { white-space: nowrap; padding: 6px 9px; }
  .side-foot { display: none; }
  main { padding: 16px 16px 60px; }
}

/* Surfaces */
.grid { display: grid; gap: 12px; }
.grid > * { min-width: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.agents { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
@media (max-width: 980px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .section + .section { margin-top: 12px; }
.section { margin-top: 18px; }
.section > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.list { display: flex; flex-direction: column; }
.item { padding: 12px 0; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; padding-top: 2px; }
.pre { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; max-height: 360px; overflow: auto; }
details > summary { cursor: pointer; color: var(--accent); font-size: 13px; }

/* Badges and dots */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* Controls */
button, .btn {
  font: inherit; font-size: 13.5px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.ok { color: var(--ok); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 4px; }
.field + .field { margin-top: 10px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.toggle { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text); margin: 0; }
.toggle input { margin-top: 3px; }
.toggle input { width: auto; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }

/* Board */
.board { display: grid; grid-template-columns: repeat(4, minmax(190px, 1fr)); gap: 12px; overflow-x: auto; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { margin: 2px 2px 10px; display: flex; justify-content: space-between; }
.col .card { padding: 10px; }

/* Sparkline */
.spark { width: 100%; height: 40px; display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.8; }
.spark .area { fill: var(--accent-soft); stroke: none; }
.meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter > div { height: 100%; background: var(--accent); }
.meter.warn > div { background: var(--warn); }
.meter.bad > div { background: var(--bad); }

/* Login + toast */
.login { max-width: 360px; margin: 14vh auto; padding: 0 16px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); }
video { width: 100%; border-radius: 8px; background: #000; max-height: 420px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
