:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #18202e;
  --ink-2: #4b5567;
  --muted: #7a8396;
  --line: #e3e7ee;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e6eff6;
  --good: #1b7f52;
  --good-soft: #e3f4ec;
  --warn: #9a6400;
  --warn-soft: #fbf1dc;
  --bad: #b3372e;
  --bad-soft: #fbe7e5;
  --sidebar: #142233;
  --sidebar-ink: #c6d2df;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; font-size: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-ink); padding: 8px 10px; border-radius: 7px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8ea3; padding: 16px 10px 6px; }
.ctx { margin: 4px 0 8px; padding: 0 4px; }
.ctx label { font-size: 11px; color: #7d8ea3; text-transform: uppercase; letter-spacing: .08em; display: block; margin: 0 0 6px 6px; }
.ctx select { width: 100%; background: #1d3047; color: #fff; border: 1px solid #2c4461; border-radius: 7px; padding: 7px 8px; font: inherit; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side-foot .who { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.side-foot button { margin-top: 8px; }
.main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topbar { display: none; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; padding: 7px 13px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.sidebar .btn { background: transparent; color: var(--sidebar-ink); border-color: #2c4461; width: 100%; justify-content: center; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-2); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card.flush > .card-head h2 { margin: 0; }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* forms */
.form-section { margin-bottom: 18px; }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px 16px; }
.fields.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.span2 { grid-column: span 2; }
.field.span3 { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field label .req { color: var(--bad); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid #cfd5df; border-radius: 7px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { min-height: 72px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.hint { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 280px; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs button { border: 0; background: transparent; font: inherit; font-weight: 500; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* details list */
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12.5px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* chart */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; height: 100%; justify-content: flex-end; }
.bar-stack { width: 100%; max-width: 44px; display: flex; align-items: flex-end; gap: 3px; flex: 1; }
.bar { flex: 1; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.g { background: #9cbcd6; }
.bar.n { background: var(--accent); }
.bar-label { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.hbar { display: grid; grid-template-columns: 130px 1fr 36px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.hbar .track { background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar .fill { background: var(--accent); height: 100%; border-radius: 4px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #142233 0%, #1f5f8b 100%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 30px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card .brand { color: var(--ink); padding: 0 0 18px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 9px 12px; border-radius: 7px; margin-bottom: 14px; font-size: 13px; }
.notice { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notice.info { background: var(--accent-soft); color: var(--accent); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 36, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 680px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.line-row { display: grid; grid-template-columns: 1fr 140px 32px; gap: 8px; margin-bottom: 8px; }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--surface-2); border: 1px dashed var(--line); padding: 10px 12px; border-radius: 7px; font-size: 15px; user-select: all; }

/* toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; animation: pop .15s ease-out; }
.toast.bad { background: var(--bad); }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }

.loading { padding: 60px; text-align: center; color: var(--muted); }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .fields { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; max-width: 280px; }
  .shell.open .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--sidebar); color: #fff; font-weight: 700; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 20px; cursor: pointer; }
  .main { padding: 20px 16px 50px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .fields, .fields.two { grid-template-columns: 1fr; }
  .field.span2 { grid-column: auto; }
  dl.kv { grid-template-columns: 120px 1fr; }
}
@media (max-width: 480px) { .g4 { grid-template-columns: 1fr 1fr; } .stat .value { font-size: 18px; } }
.grid > .card + .card { margin-top: 0; }
.card-head input[type=search] { max-width: 300px; }
@media (min-width: 821px) { .shell { background: linear-gradient(90deg, var(--sidebar) 236px, var(--bg) 236px); } }
.brand { line-height: 1.1; }
.brand-sub { font-size: 11px; font-weight: 500; letter-spacing: .04em; opacity: .65; margin-top: 2px; }
.card-head input[type=search] { flex: 1; max-width: 420px; }
.drop { display: flex; align-items: center; justify-content: center; border: 2px dashed #c5cdd9; border-radius: 10px; padding: 28px 16px; text-align: center; cursor: pointer; color: var(--ink-2); background: var(--surface-2); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.nav .count { margin-left: auto; background: #d9822b; color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.renew-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.renew-opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.renew-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.renew-opt input[type=radio] { width: auto; margin-top: 3px; }
@media (max-width: 560px) { .renew-opts { grid-template-columns: 1fr; } }
