:root {
  --bg: #f7f8fb; --surface: #ffffff; --text: #141821; --muted: #5d6676; --line: #e3e7ee; --grid: #eef1f5;
  --accent: #2f6df6; --accent-ink: #ffffff; --accent-soft: #e8efff;
  --ok: #1f9d55; --ok-soft: #e3f6ea; --warn: #b7791f; --warn-soft: #fdf3e1; --bad: #c53030; --bad-soft: #fde8e8;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600; --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #161a21; --text: #e8ebf1; --muted: #98a2b3; --line: #262b35; --grid: #1f242d;
    --accent: #4d84ff; --accent-soft: #1a2540; --ok: #4ccf7f; --ok-soft: #13291d; --warn: #f0b955; --warn-soft: #2d2412;
    --bad: #ff8080; --bad-soft: #2e1515; --shadow: none;
    --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #161a21; --text: #e8ebf1; --muted: #98a2b3; --line: #262b35; --grid: #1f242d;
  --accent: #4d84ff; --accent-soft: #1a2540; --ok: #4ccf7f; --ok-soft: #13291d; --warn: #f0b955; --warn-soft: #2d2412;
  --bad: #ff8080; --bad-soft: #2e1515; --shadow: none;
  --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
a { color: var(--accent); }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--grid); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.top { border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.top-nav { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who { color: var(--muted); font-size: 14px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 15px; border-radius: 9px; padding: 9px 16px; border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: var(--text); padding: 7px 12px; font-size: 14px; border-color: var(--line); }
.btn-mini { padding: 3px 10px; font-size: 13px; background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-mini.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }

input, select { font: inherit; font-size: 15px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0; font-size: 19px; }
.card.center { text-align: center; margin-top: 64px; }
.card.center p { color: var(--muted); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 32px 0 18px; flex-wrap: wrap; }
.dash-head h1 { font-size: 28px; margin: 0; }
.filters { display: flex; align-items: center; gap: 8px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { margin: 0; color: var(--muted); font-size: 14px; }
.tile-value { margin: 4px 0 0; font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-value.tile-text { font-size: 20px; padding: 5px 0 3px; }
.tile-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart { width: 100%; height: 220px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .empty { fill: var(--muted); font-size: 14px; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.14); min-width: 150px; }
.tip b { display: block; margin-bottom: 3px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .acts { text-align: right; white-space: nowrap; }
.tbl .acts .btn + .btn { margin-left: 6px; }
.tbl .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; }
.state { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.state[data-s=ok] { background: var(--ok-soft); color: var(--ok); }
.state[data-s=wait] { background: var(--warn-soft); color: var(--warn); }
.state[data-s=bad] { background: var(--bad-soft); color: var(--bad); }

.records { margin: 14px 0 4px; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--bg); }
.records h3 { margin: 0 0 8px; font-size: 15px; }
.records .tbl { font-size: 13px; }
.records .tbl td { padding: 6px 8px; }
.records code { word-break: break-all; }

.row-form { display: flex; gap: 8px; margin: 16px 0 6px; }
.row-form input { flex: 1; }
.grid-form { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto; gap: 10px; align-items: end; margin: 16px 0 6px; }
.grid-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid-form:has(#sPassWrap:not([hidden])) { grid-template-columns: 1.3fr 1fr 1fr 1fr auto; }
.keybox { border: 1px solid var(--ok); background: var(--ok-soft); border-radius: 10px; padding: 12px 14px; margin: 14px 0; }
.keybox p { margin: 0 0 8px; }
.keyline { display: flex; gap: 8px; align-items: center; }
.keyline code { flex: 1; padding: 6px 8px; }

.foot { padding: 22px 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px; font-size: 14px; margin: 0; max-width: calc(100% - 32px); z-index: 30; }

@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form, .grid-form:has(#sPassWrap:not([hidden])) { grid-template-columns: 1fr; }
  .row-form { flex-direction: column; }
  .card { padding: 16px; }
  .who { display: none !important; }
}
