/* Design tokens. Light is the default; dark follows the OS unless the viewer picks a theme. */
:root {
  color-scheme: light;
  --bg: #f6f6f3; --surface: #ffffff; --surface-2: #fafaf8; --surface-3: #f0efea;
  --ink: #16181d; --ink-2: #4b505a; --muted: #747983; --line: #e6e5de; --line-2: #d4d3cb;
  --accent: #2a78d6; --accent-2: #1c5cab; --accent-wash: #e9f1fc;
  --primary: #16181d; --primary-ink: #ffffff; --primary-hover: #30343c;
  --good: #0ca30c; --good-text: #006300; --good-wash: #e6f5e6;
  --warn: #fab219; --warn-text: #7a5200; --warn-wash: #fff4d9;
  --serious: #ec835a; --bad: #d03b3b; --bad-text: #b02a2a; --bad-wash: #fcebeb;
  --l1: #2a78d6; --l2: #eb6834; --l3: #1baf7a; --l4: #eda100; --l5: #e87ba4; --l6: #008300; --l7: #4a3aa7; --l8: #e34948;
  --grid: #e1e0d9; --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(16, 18, 24, .04), 0 6px 20px rgba(16, 18, 24, .04);
  --shadow-lg: 0 18px 48px rgba(16, 18, 24, .18);
  --radius: 12px; --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0f12; --surface: #16181d; --surface-2: #1a1d23; --surface-3: #22262d;
    --ink: #eef0f3; --ink-2: #b7bdc7; --muted: #8c929d; --line: #272b33; --line-2: #363b45;
    --accent: #3987e5; --accent-2: #86b6ef; --accent-wash: #16263b;
    --primary: #eef0f3; --primary-ink: #111317; --primary-hover: #d3d7de;
    --good-text: #45c445; --good-wash: #12301a; --warn-text: #fab219; --warn-wash: #33290f; --bad-text: #f07a7a; --bad-wash: #3a1818;
    --l1: #3987e5; --l2: #d95926; --l3: #199e70; --l4: #c98500; --l5: #d55181; --l6: #008300; --l7: #9085e9; --l8: #e66767;
    --grid: #2c2c2a; --axis: #45453f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0f12; --surface: #16181d; --surface-2: #1a1d23; --surface-3: #22262d;
  --ink: #eef0f3; --ink-2: #b7bdc7; --muted: #8c929d; --line: #272b33; --line-2: #363b45;
  --accent: #3987e5; --accent-2: #86b6ef; --accent-wash: #16263b;
  --primary: #eef0f3; --primary-ink: #111317; --primary-hover: #d3d7de;
  --good-text: #45c445; --good-wash: #12301a; --warn-text: #fab219; --warn-wash: #33290f; --bad-text: #f07a7a; --bad-wash: #3a1818;
  --l1: #3987e5; --l2: #d95926; --l3: #199e70; --l4: #c98500; --l5: #d55181; --l6: #008300; --l7: #9085e9; --l8: #e66767;
  --grid: #2c2c2a; --axis: #45453f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0 0 12px; }
code, pre, kbd, .mono { font-family: var(--mono); font-size: .9em; }
:not(pre) > code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-wash); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.hide, [hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 15px; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: 500 14px/1 var(--font); cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--surface-3); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: var(--bad-text); }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); background: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: 16px; align-content: start; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink); }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.input, .select, .textarea { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: 14px var(--font); transition: border-color .15s, box-shadow .15s; }
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px; background-size: 5px 5px; background-repeat: no-repeat; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.input[readonly] { background: var(--surface-2); color: var(--ink-2); }
.input-group { display: flex; align-items: stretch; }
.input-group .addon { display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line-2); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--surface-2); color: var(--muted); font-size: 14px; }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { color: var(--bad-text); background: var(--bad-wash); padding: 10px 12px; border-radius: 8px; font-size: 14px; margin: 4px 0 0; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font: 500 13px var(--font); color: var(--ink-2); cursor: pointer; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-2); transition: background .15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--good); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:checked + span::after { transform: translateX(16px); }

/* Cards & tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card + .card, .card + .grid-2, .grid-2 + .card, .kpis + .card { margin-top: 20px; }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); min-height: 56px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.table .sub { display: block; font-size: 12.5px; color: var(--muted); }
.table .actions { text-align: right; white-space: nowrap; }
.table-compact td, .table-compact th { padding: 8px 12px; }
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty h3 { color: var(--ink); font-size: 15px; margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }
.pager { display: flex; gap: 8px; align-items: center; }

/* Status */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-wash); color: var(--good-text); }
.badge.warn { background: var(--warn-wash); color: var(--warn-text); }
.badge.bad { background: var(--bad-wash); color: var(--bad-text); }
.badge.info { background: var(--accent-wash); color: var(--accent-2); }
.badge.plain::before { display: none; }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 16px; font-size: 14px; flex-wrap: wrap; }
.banner .icon { width: 18px; height: 18px; }
.banner.warn { background: var(--warn-wash); border-color: transparent; color: var(--ink); }
.banner.warn .icon { color: var(--warn-text); }
.banner.bad { background: var(--bad-wash); border-color: transparent; }
.banner.bad .icon { color: var(--bad-text); }
.banner.good { background: var(--good-wash); border-color: transparent; }
.banner.good .icon { color: var(--good-text); }
.banner.info { background: var(--accent-wash); border-color: transparent; }
.banner.info .icon { color: var(--accent-2); }
.meter { height: 6px; border-radius: 3px; background: var(--accent-wash); overflow: hidden; width: 110px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

/* App shell */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); background: var(--surface); padding: 16px 12px; overflow-y: auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--ink); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; flex: none; }
.side > .brand { padding: 4px 10px 16px; }
.side .tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 2px 6px; border: 1px solid var(--line-2); border-radius: 5px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; font-size: 14px; }
.nav a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--surface-3); color: var(--ink); font-weight: 600; }
.nav .count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 700; display: grid; place-items: center; }
.nav-label { font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; text-transform: uppercase; letter-spacing: .06em; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 2px; }
.who { padding: 8px 10px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who strong { display: block; color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; padding: 28px 36px 72px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 680; }
.page-head p { color: var(--muted); margin: 6px 0 0; }
.topbar { display: none; }
.scrim { display: none; }
.loading { color: var(--muted); padding: 40px 0; }
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%); transition: transform .2s ease; z-index: 60; box-shadow: none; }
  .side.open { transform: none; box-shadow: var(--shadow-lg); }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(10, 12, 16, .4); z-index: 55; }
  .topbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 40; height: 56px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .main { padding: 20px 16px 56px; }
  .grid-2, .grid-2.even { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .methods { grid-template-columns: minmax(0, 1fr); }
}

/* Stat tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.kpi .k-label { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .k-value { font-size: 26px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.kpi.hero .k-value { font-size: 48px; letter-spacing: -.03em; }
.kpi .k-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* Charts */
.chart { position: relative; min-height: 120px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 11.5px var(--font); fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .bar { transition: opacity .1s; }
.chart.hovering .bar { opacity: .45; }
.chart.hovering .bar.on { opacity: 1; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .endlabel { font-size: 12px; fill: var(--ink-2); font-weight: 600; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow-lg); white-space: nowrap; opacity: 0; transition: opacity .08s; z-index: 5; color: var(--ink); }
.tip.show { opacity: 1; }
.tip .t-head { color: var(--muted); margin-bottom: 4px; }
.tip .t-row { display: flex; align-items: center; gap: 8px; }
.tip .t-row b { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.tip .t-key { width: 12px; height: 2px; border-radius: 2px; flex: none; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 10px; padding: 0; list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.legend .l-line { width: 16px; height: 2px; border-radius: 2px; }
.chart-table summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-top: 10px; }
.chart-table table { margin-top: 8px; }

/* Code */
.code { position: relative; margin: 0; background: #0f1115; color: #e6e8eb; border-radius: 10px; padding: 14px 16px; font: 13px/1.65 var(--mono); overflow-x: auto; white-space: pre; border: 1px solid #23262d; }
.code code { display: block; padding-right: 64px; }
.code .copy { position: absolute; top: 8px; right: 8px; height: 28px; padding: 0 10px; border-radius: 6px; border: 1px solid #343944; background: #1a1d23; color: #c9ced6; font: 500 12px var(--font); cursor: pointer; opacity: .9; }
.code .copy:hover { background: #262a32; opacity: 1; }
.tk-k { color: #ff9e64; } .tk-s { color: #9ece6a; } .tk-c { color: #737a87; font-style: italic; } .tk-n { color: #7dcfff; }
.keybox { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.keybox code { flex: 1; background: none; padding: 0; word-break: break-all; font-size: 13px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button, .tabs a { border: 0; background: none; padding: 10px 12px; font: 500 14px var(--font); color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.tabs button:hover, .tabs a:hover { color: var(--ink); }
.tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .n { font-size: 12px; color: var(--muted); margin-left: 4px; }

/* Modal & toast */
dialog.modal { border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--ink); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow-lg); }
dialog.modal.wide { width: min(760px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(10, 12, 16, .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 0 20px; }
.modal-head h2 { font-size: 17px; font-weight: 650; }
.modal-body { padding: 16px 20px 8px; max-height: calc(100vh - 200px); overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 1000; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--primary); color: var(--primary-ink); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-lg); animation: toast-in .18s ease-out; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
details > summary { cursor: pointer; }
.checklist { display: grid; gap: 8px; max-height: 220px; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font-size: 14px; margin: 8px 0; }
.legal-note { background: var(--warn-wash); border-radius: 10px; padding: 12px 16px; margin-bottom: 24px; font-size: 14px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.language-switcher{display:flex;align-items:center;gap:8px;max-width:100%;padding:12px 16px;font-size:13px;color:var(--muted)}
.language-switcher .select{min-width:0;width:auto;max-width:100%;flex:1}
.auth-content{width:100%;max-width:440px}.auth-content .language-switcher{padding:0 0 24px}
