/* RCourier panel design system. Tokens first; components below use only tokens. 8px spacing grid. */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #dfe3ea; --border-strong: #c3cad6;
  --text: #151a23; --text-2: #4a5568; --text-3: #6b7587;
  --accent: #0b6e66; --accent-hover: #095b54; --accent-soft: #e0f2f0; --on-accent: #ffffff;
  --ok: #17663a; --ok-soft: #dff3e6; --warn: #8a5a00; --warn-soft: #fcefd0; --bad: #a3262a; --bad-soft: #fbe3e3; --info: #1d4f9c; --info-soft: #e3ecfa;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px; --radius-sm: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 248px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1218; --surface: #151b24; --surface-2: #1b2330; --border: #263041; --border-strong: #38465c;
    --text: #e8edf4; --text-2: #b3bfd0; --text-3: #8b98ad;
    --accent: #3cc9bb; --accent-hover: #63d8cc; --accent-soft: #123a38; --on-accent: #06201e;
    --ok: #62d08a; --ok-soft: #12301f; --warn: #f0b84d; --warn-soft: #3a2b0a; --bad: #ff8a8d; --bad-soft: #3d1618; --info: #8db8ff; --info-soft: #14284a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1218; --surface: #151b24; --surface-2: #1b2330; --border: #263041; --border-strong: #38465c;
  --text: #e8edf4; --text-2: #b3bfd0; --text-3: #8b98ad;
  --accent: #3cc9bb; --accent-hover: #63d8cc; --accent-soft: #123a38; --on-accent: #06201e;
  --ok: #62d08a; --ok-soft: #12301f; --warn: #f0b84d; --warn-soft: #3a2b0a; --bad: #ff8a8d; --bad-soft: #3d1618; --info: #8db8ff; --info-soft: #14284a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 8px; } a { color: var(--accent); } a:hover { color: var(--accent-hover); }
code, .mono { font-family: var(--mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 16px; border-radius: var(--radius-sm); z-index: 100; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* shell */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--radius-sm); color: var(--text-2); text-decoration: none; font-weight: 500; min-height: 40px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.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; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.who { font-size: 13px; color: var(--text-3); padding: 0 8px; overflow: hidden; text-overflow: ellipsis; }
.main { padding: 32px; max-width: 1280px; width: 100%; }
.topbar { display: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { color: var(--text-3); margin: 4px 0 0; }
.stack { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-body { padding: 20px; }
.stat { padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat .label { font-size: 13px; color: var(--text-3); font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat .hint { font-size: 13px; color: var(--text-3); }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 14px; }
.field .help { font-size: 13px; color: var(--text-3); }
.input, .select, .textarea { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; }
.textarea { min-height: 96px; font-family: var(--mono); font-size: 13px; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* data */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table td.wrap { white-space: normal; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); } .chip.info { background: var(--info-soft); color: var(--info); }
.chip svg { width: 12px; height: 12px; }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 16px; }
.alert.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert.info { background: var(--info-soft); border-color: var(--info); color: var(--info); }
.empty { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.secret-box { font-family: var(--mono); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 12px 16px; word-break: break-all; user-select: all; }

/* health grid, timeline, bars */
.health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.tile .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter.warn > span { background: var(--warn); } .meter.bad > span { background: var(--bad); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13px; color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); text-align: right; } .kv dt { color: var(--text-3); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 24px; border-left: 2px solid var(--border); margin-left: 8px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline li:first-child::before { background: var(--accent); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 96px; }
.bars span { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.muted { color: var(--text-3); } .right { text-align: right; } .nowrap { white-space: nowrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .input, .toolbar .select { width: auto; min-width: 200px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; }
.auth-card .brand { padding: 0 0 24px; }

/* small screens */
@media (max-width: 960px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: column; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--border); gap: 8px; }
  .sidebar .nav { display: none; } .sidebar-foot { display: none; }
  .sidebar.open .nav, .sidebar.open .sidebar-foot { display: flex; }
  .topbar { display: flex; justify-content: space-between; align-items: center; }
  .main { padding: 16px; }
  .form-grid, .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) { .grid.cols-3 { grid-template-columns: minmax(0, 1fr); } .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stat { padding: 12px 16px; } .stat .value { font-size: 22px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.btn.block { width: 100%; }

/* meter widths in 5% steps: inline styles are blocked by the CSP */
.w-0 { width: 0%; }
.w-5 { width: 5%; }
.w-10 { width: 10%; }
.w-15 { width: 15%; }
.w-20 { width: 20%; }
.w-25 { width: 25%; }
.w-30 { width: 30%; }
.w-35 { width: 35%; }
.w-40 { width: 40%; }
.w-45 { width: 45%; }
.w-50 { width: 50%; }
.w-55 { width: 55%; }
.w-60 { width: 60%; }
.w-65 { width: 65%; }
.w-70 { width: 70%; }
.w-75 { width: 75%; }
.w-80 { width: 80%; }
.w-85 { width: 85%; }
.w-90 { width: 90%; }
.w-95 { width: 95%; }
.w-100 { width: 100%; }
.chart { width: 100%; height: 96px; } .chart rect { fill: var(--accent); opacity: .85; } .chart rect.bad { fill: var(--bad); } .chart .axis { stroke: var(--border); stroke-width: 1; }
.banner { display: flex; gap: 12px; align-items: flex-start; }
.sidebar-foot .btn { width: 100%; justify-content: flex-start; }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-top: 4px; }
