:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16191f;
  --muted: #646b78;
  --line: #e3e6eb;
  --line-strong: #cfd4dc;
  --brand: #2f5bea;
  --brand-ink: #ffffff;
  --brand-soft: #eaf0fe;
  --ok: #157f3b;
  --ok-soft: #e6f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf3e1;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.92em; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 20px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 12px; }
form h3, .card h3 + .grid { margin-top: 0; }
.form .grid ~ h3, .form .checks ~ h3, .form details ~ h3, .form p ~ h3 { margin-top: 28px; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #111827; color: #d1d5db; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; margin-top: 18px; }
.side nav a { color: #cbd2dc; padding: 8px 12px; border-radius: 8px; }
.side nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.side nav a.on { background: #263248; color: #fff; font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid #263041; display: flex; flex-direction: column; gap: 4px; }
.side-foot .who { font-size: 12px; color: #9ca3af; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .link { color: #cbd2dc; text-align: left; padding: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; color: inherit; padding: 0 8px; }
.brand:hover { text-decoration: none; }
.side .brand { color: #fff; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 700; font-size: 12px; letter-spacing: 0.02em; }
.main { padding: 24px 32px 48px; max-width: 1180px; width: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.intro { color: var(--muted); margin: -6px 0 18px; max-width: 760px; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card > .table { margin: -20px; width: calc(100% + 40px); }
.card h3 + .table { margin-top: 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin-bottom: 16px; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-color: #f3d3cf; }
.danger-zone p { margin: 2px 0 0; }
.empty { background: var(--card); border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 40px 20px; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 14px; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.card h3 + .table th:first-child, .card h3 + .table td:first-child { padding-left: 0; }
.card h3 + .table th { background: none; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* forms */
.form .grid, .grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.grid.limits { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
label.wide { grid-column: 1 / -1; }
label small, .check small { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; }
textarea.message { font-family: var(--mono); font-size: 13px; background: #fafbfc; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 600; }
.check input { width: auto; margin-top: 3px; }
.check > span { display: flex; flex-direction: column; gap: 2px; }
.check-title .badge { margin-left: 6px; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; }
.inline-check { flex-direction: row; align-items: center; font-weight: 400; }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.form-foot .btn.primary { margin-left: auto; }
.stack { display: flex; flex-direction: column; gap: 14px; }
form.inline { display: inline; margin: 0; }
details.more { margin: 18px 0; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.search { display: flex; gap: 8px; margin-bottom: 16px; max-width: 520px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .search { margin-bottom: 16px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { text-decoration: none; background: #f3f4f6; }
.btn small { font-weight: 400; color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary small { color: #dbe4ff; }
.btn.primary:hover { background: #244ad0; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-outline { color: var(--bad); border-color: #f0b8b1; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.copied { background: var(--ok-soft); border-color: #a6d8b5; color: var(--ok); }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }

/* badges & chips */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-expired { background: var(--bad-soft); color: var(--bad); }
.badge-suspended { background: var(--warn-soft); color: var(--warn); }
.badge-off { background: #eef0f3; color: var(--muted); }
.badge-custom { background: var(--brand-soft); color: var(--brand); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; background: #f0f2f5; border-radius: 6px; padding: 1px 7px; }
.chip-off { text-decoration: line-through; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); font-weight: 600; }
.center { text-align: center; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash-ok { background: var(--ok-soft); border-color: #b7dfc3; color: #0f5c2b; }
.flash-error { background: var(--bad-soft); border-color: #f3c1bb; color: #8f1d13; }

/* tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs a.on { background: var(--ink); color: #fff; }
.tabs a:hover { text-decoration: none; background: #e9ebef; }
.tabs a.on:hover { background: var(--ink); }

/* overview */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px; color: var(--ink); }
.stat:hover { text-decoration: none; border-color: var(--line-strong); }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.stat-value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-right: 4px; letter-spacing: 0; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-warn .stat-value { color: var(--warn); }
.stat-bad .stat-value { color: var(--bad); }
.due, .sites, .log { list-style: none; margin: 0; padding: 0; }
.due li, .sites li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.due li:last-child, .sites li:last-child { border-bottom: 0; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log .muted { display: inline-block; min-width: 150px; font-size: 12px; }

/* license page */
.hero { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.hero-main { min-width: 0; }
.keyline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.key { font-size: 20px; font-weight: 600; letter-spacing: 0.04em; background: #f3f5f8; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; user-select: all; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 12px; }
.dates { margin: 10px 0 0; }
.hero-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; min-width: 220px; }
.hero-actions form, .hero-actions .btn { width: 100%; }
.hero-actions .btn { justify-content: space-between; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 12px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* usage meter */
.use { display: flex; align-items: center; gap: 8px; }
.meter { display: inline-block; width: 120px; height: 8px; background: #eceff3; border-radius: 99px; overflow: hidden; vertical-align: middle; }
.meter-fill { display: block; height: 100%; width: 0; background: var(--brand); }
.meter-fill.high { background: #d98a00; }
.meter-fill.full { background: var(--bad); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; }

/* sign-in */
.auth-body { background: #eef1f5; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 10px 30px rgba(17, 24, 39, 0.06); }
.auth-card .brand { padding: 0; margin-bottom: 22px; }
.auth-card form.center { margin-top: 14px; }
.qr { display: grid; place-items: center; margin: 8px 0; }
.qr img { border: 1px solid var(--line); border-radius: 8px; }
.pubkey { display: block; font-size: 12px; background: #f3f5f8; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; user-select: all; }
.secret { display: inline-block; margin-top: 6px; font-size: 13px; letter-spacing: 0.06em; user-select: all; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.limits { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { flex-direction: row; flex-wrap: wrap; margin-top: 12px; }
  .side-foot { flex-direction: row; align-items: center; justify-content: space-between; margin-top: 12px; }
  .main { padding: 18px 16px 40px; }
  .cols, .grid, .form .grid, .checks, .grid.limits { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { overflow-x: auto; }
  .hero-actions { min-width: 0; width: 100%; }
}
