/* FDS Live — light/dark follows the device, with a manual toggle (data-theme on <html>). */
:root {
  color-scheme: light;
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e8;
  --text: #15181d; --text-2: #4d5562; --muted: #7a8391;
  --accent: #2a78d6; --accent-ink: #ffffff;
  --pos: #12804a; --neg: #c8312f; --warn: #a86500;
  --warn-bg: #fff4dc; --error-bg: #fde8e8; --ok-bg: #e5f5ec;
  --bar-pos: #2a78d6; --bar-neg: #e34948;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111315; --surface: #1a1c1f; --surface-2: #23262a; --border: #2f3338;
    --text: #eef0f2; --text-2: #b8bec6; --muted: #8a919b;
    --accent: #3987e5; --accent-ink: #ffffff;
    --pos: #3fbf7a; --neg: #f06a68; --warn: #e3a33a;
    --warn-bg: #3a2c10; --error-bg: #3d1a1a; --ok-bg: #12301f;
    --bar-pos: #3987e5; --bar-neg: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315; --surface: #1a1c1f; --surface-2: #23262a; --border: #2f3338;
  --text: #eef0f2; --text-2: #b8bec6; --muted: #8a919b;
  --accent: #3987e5; --accent-ink: #ffffff;
  --pos: #3fbf7a; --neg: #f06a68; --warn: #e3a33a;
  --warn-bg: #3a2c10; --error-bg: #3d1a1a; --ok-bg: #12301f;
  --bar-pos: #3987e5; --bar-neg: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 52px;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--text-2); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top-actions { display: flex; gap: 8px; align-items: center; }
main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.narrow { max-width: 440px; margin: 40px auto; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--surface); }
tbody tr:hover { background: var(--surface-2); }
tr.total td { font-weight: 650; border-top: 2px solid var(--border); }
tr.sub td { background: var(--surface-2); font-size: 13px; }
tr.sub td:first-child { padding-left: 24px; }
.chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap;
}
.chip.icc { color: var(--accent); border-color: var(--accent); }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.chip.bad { color: var(--neg); border-color: var(--neg); }

/* ---------- forms ---------- */
label { display: block; font-size: 12.5px; color: var(--text-2); margin: 10px 0 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; font: inherit;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; }
.inline-form { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--neg); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 7px; padding: 5px 8px; cursor: pointer; font: inherit; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters > * { width: auto; }
.filters input, .filters select { width: auto; min-width: 120px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 7px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); }
.tabs a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- messages ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid var(--border); background: var(--ok-bg); }
.flash.error { background: var(--error-bg); border-color: var(--neg); }
.flash.warn { background: var(--warn-bg); border-color: var(--warn); }
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--warn); background: var(--warn-bg); }
.alert.bad { border-color: var(--neg); background: var(--error-bg); }
.link-box { display: flex; gap: 8px; margin-top: 8px; }
.link-box input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 20px; font-family: ui-monospace, Menlo, monospace; font-size: 16px; margin: 14px 0; }
.qr svg {
  display: block; margin: 0 auto; width: 240px; max-width: 100%; height: auto; aspect-ratio: 1;
  background: #fff; border-radius: 8px; color-scheme: light; forced-color-adjust: none; filter: none;
}

/* ---------- charts ---------- */
.chart-box { position: relative; height: 260px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.live-dot.on { background: var(--pos); }
.live-dot.err { background: var(--neg); }
.flash-up { animation: up 1s; } .flash-down { animation: down 1s; }
@keyframes up { from { background: rgba(18, 128, 74, .25); } to { background: transparent; } }
@keyframes down { from { background: rgba(200, 49, 47, .25); } to { background: transparent; } }

.mobile-note { display: none; }

/* ---------- phone: read-only, stacked ---------- */
@media (max-width: 820px) {
  .desk { display: none !important; }
  .mobile-note { display: block; }
  main { padding: 14px 16px; }
  .topbar { padding: 8px 12px 0; gap: 8px 10px; height: auto; flex-wrap: wrap; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 6px; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .cols-4.keep-2, .cols-3.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 19px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  th, td { padding: 6px; }
  .hide-sm { display: none; }
}
@media print { .topbar, .desk, .btn { display: none !important; } }
