/* TWG admin console. No external resources: system fonts only. */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e1e4ea;
  --border-strong: #c9ced8;
  --text: #16181d;
  --text-2: #50566a;
  --text-3: #7d8496;
  --accent: #1f5fbf;
  --accent-hover: #194f9f;
  --accent-soft: #e8f0fc;
  --on-accent: #ffffff;
  --danger: #c0352b;
  --danger-hover: #a02a22;
  --danger-soft: #fdecea;
  --good: #1a7f4b;
  --good-soft: #e5f5ec;
  --warn: #9a6400;
  --warn-soft: #fdf3dc;
  --neutral-soft: #eceef2;
  --sidebar: #171b26;
  --sidebar-text: #c5cad6;
  --sidebar-active: #2a3350;
  --series-1: #2a78d6;
  --series-2: #cf6a1f;
  --series-3: #6b7280;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .22);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #20242d;
    --border: #2c313c;
    --border-strong: #3d4452;
    --text: #eef0f4;
    --text-2: #b4bac8;
    --text-3: #868d9e;
    --accent: #5b9bf0;
    --accent-hover: #7bb0f5;
    --accent-soft: #1c2a42;
    --on-accent: #0b1220;
    --danger: #f0776c;
    --danger-hover: #f59188;
    --danger-soft: #3a1e1c;
    --good: #4cc38a;
    --good-soft: #17301f;
    --warn: #e2b04a;
    --warn-soft: #33290f;
    --neutral-soft: #262b35;
    --sidebar: #0c0e13;
    --sidebar-text: #b4bac8;
    --sidebar-active: #1c2233;
    --series-1: #3987e5;
    --series-2: #ef8f4a;
    --series-3: #9aa3b5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { fill: currentColor; }
.noscript { padding: 24px; text-align: center; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .nav-link:focus-visible, .link-btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.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 { background: var(--danger); border-color: var(--danger); color: var(--on-accent); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(128, 136, 160, .16); }
.btn-small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.link-btn {
  padding: 2px 4px; border: 0; border-radius: 4px; background: none;
  color: var(--accent); font: inherit; cursor: pointer; white-space: nowrap;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.link-btn:disabled { color: var(--text-3); cursor: not-allowed; text-decoration: none; }
.row-actions { display: flex; gap: 8px; white-space: nowrap; }

/* Login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); display: grid; gap: 16px;
}
.login-note { color: var(--text-3); font-size: 12.5px; }
.login-note code { font-family: var(--mono); font-size: 12px; }
.login-links { display: flex; justify-content: space-between; }
.code-input { font-family: var(--mono); font-size: 18px; letter-spacing: .2em; text-align: center; height: 42px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 650; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--text-3); }
.brand-login .brand-name { font-size: 17px; }

/* Shell */
.shell { display: flex; min-height: 100%; }
.sidebar {
  position: sticky; top: 0; flex: 0 0 220px; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--sidebar); color: var(--sidebar-text);
}
.sidebar .brand { padding: 18px 18px 14px; color: #fff; }
.sidebar .brand-sub { color: #8b93a7; }
.nav { display: grid; gap: 10px; padding: 8px 10px; overflow-y: auto; }
.nav-section { display: grid; gap: 2px; }
.nav-heading { padding: 6px 12px 2px; color: #8b93a7; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 6px; color: inherit; font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 16px; }
.sidebar-foot .btn { color: var(--sidebar-text); justify-content: flex-start; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.page-title { flex: 1; font-size: 17px; font-weight: 650; }
.account { position: relative; }
.account .btn { gap: 6px; padding: 0 8px; font-weight: 500; }
.account .caret { width: 14px; height: 14px; opacity: .7; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 15; min-width: 160px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg);
  display: grid; gap: 2px;
}
.menu-item {
  display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-btn { display: none; width: 36px; padding: 0; }
.view { padding: 20px 24px 40px; display: grid; gap: 16px; align-content: start; }
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); }

/* Page pieces */
.tabs { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.tabs .btn { border-color: transparent; }
.stack { display: grid; gap: 16px; align-content: start; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type="search"] { width: 260px; max-width: 100%; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 650; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.hint { color: var(--text-3); font-size: 12.5px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; }

/* Stat tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile { padding: 14px 16px; }
.tile-label { color: var(--text-2); font-size: 12.5px; }
.tile-value { margin-top: 2px; font-size: 26px; font-weight: 650; line-height: 1.25; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 14px; font-weight: 500; color: var(--text-3); }
.tile-sub { margin-top: 2px; color: var(--text-3); font-size: 12.5px; }

/* Daily traffic chart: one series, bars anchored to the baseline. */
.chart { position: relative; }
.chart-plot {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: end; gap: 2px;
  height: 180px; border-bottom: 1px solid var(--border-strong);
}
.chart-col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart-col:hover, .chart-col:focus-visible { background: var(--neutral-soft); outline: none; }
.chart-bar { width: 62%; max-width: 28px; min-height: 0; background: var(--series-1); border-radius: 4px 4px 0 0; }
.chart-axis { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; margin-top: 6px; }
.chart-tick { text-align: center; color: var(--text-3); font-size: 11.5px; white-space: nowrap; overflow: hidden; }
.chart-max { position: absolute; top: 0; left: 0; color: var(--text-3); font-size: 11.5px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, -100%);
  padding: 6px 10px; border-radius: 6px; background: var(--text); color: var(--surface);
  font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow);
}

/* Load meters: a short bar with the figure next to it. */
.meter-wrap { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.meter { width: 64px; height: 6px; flex: none; overflow: visible; }
.meter-track { fill: var(--neutral-soft); }
.meter-fill { fill: var(--series-1); }
.meter.warn .meter-fill { fill: var(--warn); }
.meter.bad .meter-fill { fill: var(--danger); }
.meter-value { font-variant-numeric: tabular-nums; min-width: 3.2em; }

/* Statistics: SVG charts whose geometry is attributes, looks are here.
   c1–c3 are categorical series, ok/failed/unusable the connect outcomes. */
.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
.chart-svg { display: block; width: 100%; height: auto; font-size: 11px; overflow: visible; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-svg .tick { fill: var(--text-3); }
.chart-svg .mark { fill: var(--series-1); }
.chart-svg .mark.c2 { fill: var(--series-2); }
.chart-svg .mark.c3 { fill: var(--series-3); }
.chart-svg .mark.ok { fill: var(--good); }
.chart-svg .mark.failed { fill: var(--danger); }
.chart-svg .mark.unusable { fill: var(--warn); }
.chart-svg .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .line.c2 { stroke: var(--series-2); }
.chart-svg .line.c3 { stroke: var(--series-3); }
.chart-svg .dot { fill: var(--surface); stroke: var(--series-1); stroke-width: 2; }
.chart-svg .dot.c2 { stroke: var(--series-2); }
.chart-svg .dot.c3 { stroke: var(--series-3); }
.chart-svg .hit { fill: transparent; }
.chart-svg .hit:hover { fill: var(--neutral-soft); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; color: var(--text-2); font-size: 12.5px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--series-1); flex: none; }
.swatch.c2 { background: var(--series-2); }
.swatch.c3 { background: var(--series-3); }
.swatch.ok { background: var(--good); }
.swatch.failed { background: var(--danger); }
.swatch.unusable { background: var(--warn); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 12.5px; }
.pill .num { color: var(--text-2); }

/* Event list */
.props { margin: 0; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; max-width: 360px; color: var(--text-2); }
.toolbar input[type="date"] { width: auto; }
.event-geo { color: var(--text-3); font-size: 12.5px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--text-2); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
td.check, th.check { width: 36px; padding-right: 0; }
.cell-main { font-weight: 550; }
.cell-sub { color: var(--text-3); font-size: 12.5px; }
.ellipsis { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--neutral-soft); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.tag {
  display: inline-block; margin: 1px 4px 1px 0; padding: 0 6px; border-radius: 4px;
  background: var(--neutral-soft); color: var(--text-2); font-size: 12px;
}

/* States */
.state { padding: 36px 16px; text-align: center; color: var(--text-3); }
.state-title { color: var(--text-2); font-weight: 600; margin-bottom: 4px; }
.state .btn { margin-top: 12px; }
.state.error .state-title { color: var(--danger); }
.spinner {
  display: inline-block; width: 22px; height: 22px; margin-bottom: 8px;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Pager */
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 13px; }
.pager .spacer { flex: 1; }

/* Forms */
.field { display: grid; gap: 5px; min-width: 0; align-content: start; }
.field-label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-3); }
input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="datetime-local"], input[type="date"], select, textarea {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--text-3); }
.toolbar select { width: auto; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.check-item { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.radios { display: grid; gap: 6px; }
.radio-item { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.radio-item input { margin-top: 3px; }
.radio-item .field-hint { display: block; }
.form-error {
  padding: 8px 10px; border-radius: 6px; background: var(--danger-soft); color: var(--danger); font-size: 13px;
}
.notice { padding: 10px 12px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.notice.info { background: var(--accent-soft); color: var(--text-2); }

/* Dialogs */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.wide { width: min(760px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 14, 24, .5); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 26px); }
.dialog-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-title { flex: 1; font-size: 15.5px; font-weight: 650; }
.dialog-body { padding: 18px; overflow-y: auto; display: grid; gap: 14px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.copy-box { display: flex; gap: 8px; align-items: flex-start; }
.copy-box code {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  word-break: break-all; white-space: pre-wrap; user-select: all;
}

/* Two-factor setup */
.qr-box { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.qr-canvas { width: 200px; height: 200px; border: 1px solid var(--border); border-radius: 6px; background: #fff; flex: none; }
.qr-side { flex: 1; min-width: 220px; display: grid; gap: 10px; }
.recovery-codes {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
  font-family: var(--mono); font-size: 14px; letter-spacing: .04em;
}
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; color: var(--text-2); }

/* Detail lists */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; word-break: break-all; }

/* Toasts */
.toasts { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: calc(100vw - 32px); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); font-size: 13.5px; }
.toast.error { background: var(--danger); color: var(--on-accent); }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .18s ease; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .view { padding: 14px 12px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  th, td { padding: 9px 10px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
