/* New Page Admin — no framework, light + dark */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --text: #17202b;
  --muted: #667085;
  --line: #e3e6eb;
  --line-2: #eef0f3;
  --accent: #2753d6;
  --accent-ink: #ffffff;
  --accent-soft: #e9efff;
  --side: #121826;
  --side-text: #c9d1e0;
  --side-muted: #7d889d;
  --side-active: #ffffff;
  --side-active-bg: #222b3d;
  --red: #b42318;   --red-bg: #fdeceb;
  --amber: #a15c07; --amber-bg: #fff3dc;
  --blue: #1f5fbf;  --blue-bg: #e8f0fc;
  --green: #18794e; --green-bg: #e6f4ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1218; --panel: #161b23; --panel-2: #1a2029; --text: #e6e9ef; --muted: #98a2b3;
    --line: #273040; --line-2: #1f2733; --accent: #6d8dff; --accent-ink: #0b1020; --accent-soft: #1d2745;
    --side: #0a0d12; --side-active-bg: #1a2130;
    --red: #ff8b80; --red-bg: #3a1c1b; --amber: #f7c56b; --amber-bg: #3a2c12;
    --blue: #8db4ff; --blue-bg: #18263f; --green: #6fd3a0; --green-bg: #142f22;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; background: linear-gradient(90deg, var(--side) 240px, transparent 240px); }
.sidebar {
  background: var(--side); color: var(--side-text); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.brand b { display: block; font-size: 14px; font-weight: 650; }
.brand small { display: block; font-size: 11.5px; color: var(--side-muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: var(--side-text); padding: 7px 10px; border-radius: 7px; font-size: 13.5px; display: flex; align-items: center; gap: 8px;
}
.sidebar nav a:hover { background: var(--side-active-bg); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--side-active-bg); color: var(--side-active); font-weight: 600; }
.sidebar nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--side-muted); flex: none; }
.sidebar nav a.active .dot { background: var(--accent); }
.nav-label {
  color: var(--side-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  padding: 16px 10px 6px; font-weight: 600;
}
.nav-module { color: #e7ebf3; font-size: 12.5px; font-weight: 600; padding: 6px 10px 2px; }
.nav-sub a { padding-left: 18px !important; }
.sidebar-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid #222a38; font-size: 12.5px; }
.sidebar-foot .who { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .role { color: var(--side-muted); text-transform: capitalize; }
.sidebar-foot form { margin-top: 8px; }
.sidebar-foot button {
  background: transparent; border: 1px solid #2c3546; color: var(--side-text); border-radius: 7px;
  padding: 5px 10px; font: inherit; cursor: pointer; width: 100%;
}
.sidebar-foot button:hover { background: var(--side-active-bg); color: #fff; }

.main { padding: 26px 32px 60px; min-width: 0; max-width: 1360px; }
.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; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; background: none; }
  .nav-sub { display: contents; }
  .sidebar { position: static; height: auto; flex-direction: column; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .nav-label, .nav-module { display: none; }
  .sidebar-foot { margin-top: 8px; }
  .main { padding: 18px 16px 40px; }
}

/* ---------- surfaces ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-head .meta { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 16px 18px; }
.card + .card, .grid + .card, .card + .grid, .stats + .card, .stats + .grid { margin-top: 18px; }
.grid > .card { margin-top: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 1100px) { .grid-2, .grid-3, .grid-side { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.red .n { color: var(--red); } .stat.amber .n { color: var(--amber); } .stat.blue .n { color: var(--blue); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
  background: var(--panel-2); white-space: nowrap;
}
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th.sorted-asc::after { content: " ↑"; } .table th.sorted-desc::after { content: " ↓"; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--panel-2); }
.table td.name a { color: var(--text); font-weight: 600; }
.table td.name a:hover { color: var(--accent); }
.table .empty td { text-align: center; color: var(--muted); padding: 30px; }
tr.expired td.name a, tr.soon td.name a { color: var(--text); }

.kv { width: 100%; border-collapse: collapse; }
.kv th, .kv td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; font-size: 13px; }
.kv th { color: var(--muted); font-weight: 500; width: 34%; white-space: nowrap; }
.kv .kv th { width: auto; }
.kv-list th, .kv-list td { padding: 6px 10px; border-bottom: 1px solid var(--line-2); font-size: 12.5px; text-align: left; }
.kv-list th { color: var(--muted); font-weight: 600; background: var(--panel-2); }
.masked { font-family: var(--mono); font-size: 11.5px; background: var(--panel-2); border: 1px dashed var(--line); padding: 1px 6px; border-radius: 4px; color: var(--muted); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; }
.fact { padding: 12px 16px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
.fact .k { color: var(--muted); font-size: 12px; }
.fact .v { font-weight: 600; margin-top: 2px; word-break: break-word; }
.fact .v.list { font-weight: 500; font-family: var(--mono); font-size: 12.5px; }

/* ---------- pills / badges ---------- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--green-bg); color: var(--green); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.pill.month { background: var(--blue-bg); color: var(--blue); }
.pill.soon { background: var(--amber-bg); color: var(--amber); }
.pill.expired { background: var(--red-bg); color: var(--red); }
.pill.none, .pill.neutral { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--green); border-color: transparent; background: var(--green-bg); }
.badge.warn { color: var(--amber); border-color: transparent; background: var(--amber-bg); }
.badge.err { color: var(--red); border-color: transparent; background: var(--red-bg); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: 1px; }
.status-dot.ok { background: var(--green); } .status-dot.partial { background: var(--amber); } .status-dot.failed { background: var(--red); }

/* ---------- forms / buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { text-decoration: none; background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.inline { display: inline; }
label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=search], select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font: inherit;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.field { margin-bottom: 14px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
input.code-input { font-family: var(--mono); font-size: 22px; letter-spacing: .3em; text-align: center; }

.filters { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; min-width: 150px; }
.filters .count { margin-left: auto; align-self: center; color: var(--muted); font-size: 12.5px; }

/* ---------- alerts ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.flash.success { background: var(--green-bg); color: var(--green); }
.flash.error { background: var(--red-bg); color: var(--red); }
.flash.warning { background: var(--amber-bg); color: var(--amber); }
.flash.info { background: var(--blue-bg); color: var(--blue); }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.notice.error { background: var(--red-bg); border-color: transparent; color: var(--red); }
.notice.ok { background: var(--green-bg); border-color: transparent; color: var(--green); }
.notice.warn { background: var(--amber-bg); border-color: transparent; color: var(--amber); }

details.raw { border-top: 1px solid var(--line-2); }
details.raw summary { cursor: pointer; padding: 12px 18px; color: var(--muted); font-weight: 550; }
details.raw[open] summary { border-bottom: 1px solid var(--line-2); }
details.raw .card-body { max-height: 640px; overflow: auto; }

.module-row { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); align-items: center; }
.module-row:last-child { border-bottom: 0; }
.module-row .title { font-weight: 650; }
.module-row .desc { color: var(--muted); font-size: 12.5px; }
.module-row .nums { display: flex; gap: 6px; flex-wrap: wrap; }

.pager { display: flex; gap: 6px; justify-content: flex-end; padding: 12px 14px; }

/* ---------- guest pages ---------- */
.guest { min-height: 100vh; display: grid; place-items: center; padding: 30px 16px; }
.guest-box { width: 100%; max-width: 400px; }
.guest-box.wide { max-width: 520px; }
.guest-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; justify-content: center; }
.guest-brand .logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.guest-brand b { font-size: 16px; }
.guest .card-body { padding: 24px; }
.guest h1 { font-size: 19px; margin-bottom: 6px; }
.guest .lead { color: var(--muted); margin-bottom: 18px; }
.guest .btn.primary { width: 100%; justify-content: center; padding: 10px 14px; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 10px; border: 1px solid var(--line); margin: 6px 0 12px; }
.qr svg { width: 196px; height: 196px; display: block; }
.secret { font-family: var(--mono); font-size: 13px; letter-spacing: .08em; word-break: break-all; background: var(--panel-2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; }
ol.steps { padding-left: 18px; margin: 0 0 14px; color: var(--muted); }
ol.steps li { margin-bottom: 4px; }
