/* OFFCHATs control panel. Light and dark from the system, or forced with data-theme. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4e9;
  --text: #16191f;
  --text-2: #4b5260;
  --muted: #7a8190;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefd;
  --good: #18794e;
  --good-soft: #e3f5ec;
  --warn: #9a6200;
  --warn-soft: #fdf2dc;
  --bad: #c9302c;
  --bad-soft: #fde8e7;
  --bar: #2f6fed;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaef;
    --text-2: #b5bac5;
    --muted: #8a909c;
    --accent: #6b9bff;
    --accent-ink: #0b1020;
    --accent-soft: #1c2740;
    --good: #4cc38a;
    --good-soft: #15291f;
    --warn: #f0b545;
    --warn-soft: #2d2412;
    --bad: #ff6b63;
    --bad-soft: #331715;
    --bar: #6b9bff;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaef;
  --text-2: #b5bac5;
  --muted: #8a909c;
  --accent: #6b9bff;
  --accent-ink: #0b1020;
  --accent-soft: #1c2740;
  --good: #4cc38a;
  --good-soft: #15291f;
  --warn: #f0b545;
  --warn-soft: #2d2412;
  --bad: #ff6b63;
  --bad-soft: #331715;
  --bar: #6b9bff;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
code, .mono { font-family: var(--mono); font-size: 13px; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; display: grid; gap: 8px; }
.who { font-size: 13px; color: var(--text-2); padding: 0 8px; overflow-wrap: anywhere; }
.who b { color: var(--text); font-weight: 600; display: block; }
.main { padding: 28px 32px 64px; min-width: 0; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.topbar { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    position: sticky; top: 0; z-index: 5;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 10px 16px;
  }
  .tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
    display: flex; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar svg { width: 22px; height: 22px; }
  .main { padding: 18px 16px 96px; }
}
@media (min-width: 821px) { .tabbar { display: none; } }

/* Surfaces */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 16px; }
.grid > .card, .stack > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stack { display: grid; gap: 16px; }
.section-title { margin: 28px 0 12px; }

/* Stat tiles */
.tile .label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.tile .value { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.tile .sub { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.tile .sub b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Bars (single hue, magnitude) */
.bars { display: grid; gap: 8px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.bar-track { display: block; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; background: var(--bar); min-width: 2px; }

/* Status */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; padding: 3px 10px 3px 8px; border-radius: 999px; }
.status svg { width: 14px; height: 14px; }
.status.good { color: var(--good); background: var(--good-soft); }
.status.bad { color: var(--bad); background: var(--bad-soft); }
.status.warn { color: var(--warn); background: var(--warn-soft); }
.status.neutral { color: var(--text-2); background: var(--surface-2); }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.checklist li { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* Badges */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.good { background: var(--good-soft); color: var(--good); }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

input[type="text"], input[type="search"], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-height: 38px;
  width: 100%;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; }
.field { display: grid; gap: 6px; }
.field + .field { margin-top: 16px; }
.field label { font-weight: 600; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 13px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 44px; height: 24px; appearance: none; background: var(--border); border-radius: 999px; position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:disabled { opacity: .5; cursor: default; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
td .primary-text { font-weight: 600; }
td .secondary-text { color: var(--muted); font-size: 13px; }

/* User cards on small screens */
.user-cards { display: none; }
@media (max-width: 820px) {
  .users-table { display: none; }
  .user-cards { display: grid; gap: 10px; }
}
.user-card { display: block; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.user-card:hover { text-decoration: none; background: var(--surface-2); }
.user-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.user-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

/* Key-value lists */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { dl.kv { grid-template-columns: 1fr; gap: 2px; } dl.kv dd { margin-bottom: 8px; } }

.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.note { color: var(--muted); font-size: 13px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 12px; }

/* Sign-in */
.center { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.signin { width: 100%; max-width: 380px; text-align: center; }
.signin .brand-mark { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 16px; }
.signin .brand-mark svg { width: 28px; height: 28px; }
.signin h1 { margin-bottom: 6px; }
.signin p { color: var(--muted); margin: 0 0 22px; }
.signin .btn { width: 100%; min-height: 44px; }

/* Boot, spinner, skeleton */
.boot { min-height: 60vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .spinner, .skeleton { animation: none; } }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 12, 16, 0.5); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog p { margin: 0; color: var(--text-2); }
dialog .actions { justify-content: flex-end; }

/* Toasts */
#toasts { position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); bottom: 24px; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
@media (max-width: 820px) { #toasts { bottom: calc(80px + env(safe-area-inset-bottom)); } }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--bad); color: #fff; }

/* User map */
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented a.btn:hover { text-decoration: none; }
.map-card { padding: 0; overflow: hidden; }
/* isolation keeps Leaflet's panes (z-index 400+) under the sticky top bar and the tab bar. */
.map-box { position: relative; z-index: 0; isolation: isolate; height: min(60vh, 520px); min-height: 280px; background: var(--surface-2); }
.map-box .boot { height: 100%; }
.map-credit { margin: 0; padding: 10px 16px; border-top: 1px solid var(--border); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.leaflet-popup-content { font: 13px/1.45 var(--font); color: #16191f; }
@media (max-width: 820px) { .map-box { height: 52vh; } .tabbar a { padding: 4px 4px; } }

/* System page: chart series (fixed order: blue, orange, aqua), stepped per theme. */
:root { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; }
}
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; }

.status-tile { border-top: 4px solid var(--border); }
.status-tile.green { border-top-color: var(--good); }
.status-tile.amber { border-top-color: var(--warn); }
.status-tile.red { border-top-color: var(--bad); }
.tile-state { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; }
.tile-state .latency { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.note.err { color: var(--bad); overflow-wrap: anywhere; margin: 8px 0 0; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
td.wrap { white-space: normal; min-width: 200px; overflow-wrap: anywhere; }

.uptime-row { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.uptime-row:first-child { padding-top: 0; }
.uptime-name { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; }
.uptime-bar { display: flex; gap: 2px; height: 28px; }
.uptime-bar span { flex: 1; min-width: 1px; border-radius: 2px; background: var(--surface-2); }
.uptime-bar span.good { background: var(--good); }
.uptime-bar span.warn { background: var(--warn); }
.uptime-bar span.bad { background: var(--bad); }
@media (max-width: 600px) { .uptime-bar { gap: 1px; height: 22px; } .uptime-bar span { border-radius: 1px; } }

.gauges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 600px) { .gauges { grid-template-columns: repeat(2, 1fr); } }
.gauge { text-align: center; }
.gauge svg { width: 88px; height: 88px; }
.gauge circle { fill: none; stroke-width: 8; }
.gauge .track { stroke: var(--surface-2); }
.gauge .fill { stroke-linecap: round; stroke: var(--muted); }
.gauge.good .fill { stroke: var(--good); }
.gauge.warn .fill { stroke: var(--warn); }
.gauge.bad .fill { stroke: var(--bad); }
.gauge text { fill: var(--text); font: 600 17px var(--font); }
.gauge-label { font-weight: 600; font-size: 14px; }
.gauge .note { overflow-wrap: anywhere; }

.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 8px; flex-wrap: wrap; }
.chart-box { position: relative; height: 220px; }
.chart-box.small { height: 110px; }
.spark-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
@media (max-width: 600px) { .spark-grid { grid-template-columns: 1fr; } }
.spark-title { font-size: 12px; color: var(--text-2); font-weight: 600; }
.grid.charts { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.grid.servers { grid-template-columns: 1fr; }
.status-grid { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
