/* AccessGate admin UI */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e8ebef;
  --border: #e1e4e9;
  --border-strong: #c9cfd8;
  --text: #15181d;
  --text-2: #444c58;
  --text-3: #6b7380;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #3730a3;
  --on-accent: #ffffff;
  --ok: #157a3d;
  --ok-soft: #e4f6ea;
  --warn: #965c00;
  --warn-soft: #fdf2d8;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --muted-soft: #eceef2;
  --focus: 0 0 0 3px rgba(79, 70, 229, .28);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f14;
    --surface: #151920;
    --surface-2: #1b2029;
    --surface-3: #232a35;
    --border: #262d38;
    --border-strong: #364050;
    --text: #e8eaee;
    --text-2: #b8bfca;
    --text-3: #8a93a1;
    --accent: #8b93ff;
    --accent-hover: #a5abff;
    --accent-soft: #1f2047;
    --accent-text: #c9ccff;
    --on-accent: #0c0f14;
    --ok: #5fd28d;
    --ok-soft: #0f2a1a;
    --warn: #f0bf5a;
    --warn-soft: #2e2309;
    --bad: #ff8b80;
    --bad-soft: #321412;
    --muted-soft: #222833;
    --focus: 0 0 0 3px rgba(139, 147, 255, .35);
    --shadow-sm: none;
    --shadow: 0 1px 0 rgba(255, 255, 255, .02);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.5 var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
p { margin: 0 0 8px; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.ic { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ic svg { width: 100%; height: 100%; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.brand .logo .ic { width: 18px; height: 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.nav a .count { margin-left: auto; background: var(--accent); color: var(--on-accent); border-radius: 99px; font-size: 11.5px; font-weight: 700; padding: 0 7px; line-height: 19px; }
.nav hr { border: 0; border-top: 1px solid var(--border); margin: 8px 6px; }
.sidebar-foot { margin-top: auto; padding: 12px 6px 0; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.sidebar-foot .who { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 32px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.main { padding: 28px 32px 80px; max-width: 1240px; width: 100%; }
.menu-btn { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; z-index: 50; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .main { padding: 20px 16px 64px; }
}

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 220px; }
.page-head h1 { font-size: 24px; line-height: 1.25; }
.page-head .sub { color: var(--text-3); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--text-3); margin-bottom: 6px; display: inline-flex; gap: 4px; align-items: center; }

/* ---------- cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.main > .card, .main > .grid, .main > .callout, .main > .list-cards { margin-bottom: 18px; }
.mt { margin-top: 12px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px 0; flex-wrap: wrap; }
.card-head h2 { font-size: 15.5px; font-weight: 650; }
.card-head .desc { color: var(--text-3); font-size: 13px; flex-basis: 100%; margin-top: -8px; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.card-body { padding: 16px 18px 18px; }
.card-body.flush { padding: 12px 0 4px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid .span-2 { grid-column: span 2; }
@media (max-width: 1100px) { .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid.two, .grid.three, .grid.stats { grid-template-columns: minmax(0, 1fr); } .grid .span-2 { grid-column: auto; } }

.stat { padding: 16px 18px; display: block; color: inherit; }
a.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat .label { color: var(--text-3); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--text-3); font-size: 12.5px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
tr.dim td { opacity: .55; }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
td.actions .btn + .btn { margin-left: 4px; }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--text-3); font-size: 12.5px; }
.ipcell { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ipcell code { font-weight: 600; }

.empty { text-align: center; padding: 28px 16px; color: var(--text-3); }
.empty .ic { width: 28px; height: 28px; margin-bottom: 6px; opacity: .7; }
.empty b { display: block; color: var(--text-2); margin-bottom: 2px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; line-height: 20px; white-space: nowrap; background: var(--muted-soft); color: var(--text-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.xs { padding: 3px 8px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn .ic { width: 16px; height: 16px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field > label, .field > .label { font-weight: 600; font-size: 13.5px; color: var(--text); }
.field .hint { color: var(--text-3); font-size: 12.5px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 72px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.form-row .field { margin-bottom: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.form-error { color: var(--bad); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.check .t { font-weight: 600; }
.check .d { color: var(--text-3); font-size: 13px; }

.add-rule { padding: 14px 18px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.add-rule .form-row { grid-template-columns: minmax(220px, 2fr) minmax(140px, 1.4fr) minmax(110px, 1fr) minmax(110px, 1fr) auto; }
.add-rule.fixed .form-row { grid-template-columns: minmax(220px, 2fr) minmax(140px, 1.4fr) minmax(110px, 1fr) auto; }
@media (max-width: 900px) { .add-rule .form-row, .add-rule.fixed .form-row { grid-template-columns: minmax(0, 1fr); } }

/* option cards (mode picker / radio) */
.options { display: grid; gap: 8px; }
.options.row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 700px) { .options.row { grid-template-columns: minmax(0, 1fr); } }
.option { display: flex; gap: 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; background: var(--surface); }
.option:hover { border-color: var(--text-3); }
.option input { accent-color: var(--accent); margin-top: 3px; flex: none; }
.option.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.option .t { font-weight: 650; display: flex; align-items: center; gap: 6px; }
.option .d { font-size: 12.5px; color: var(--text-3); }

/* segmented control */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { font: inherit; font-weight: 600; font-size: 13.5px; border: 0; background: transparent; color: var(--text-2); padding: 6px 14px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.segmented button:hover { color: var(--text); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* ---------- misc components ---------- */
.ip-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-3); }
.ip-chip code { color: var(--text); font-weight: 600; background: var(--surface-2); padding: 3px 8px; border-radius: 6px; }
.callout { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--accent-soft); color: var(--accent-text); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.bad { background: var(--bad-soft); color: var(--bad); }
.callout.ok { background: var(--ok-soft); color: var(--ok); }
.callout .ic { margin-top: 1px; }
.callout b { font-weight: 650; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.codeblock { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: 12.8px; line-height: 1.55; white-space: pre; }
.codeblock .copy { position: absolute; top: 6px; right: 6px; }
.codeblock + .codeblock, p + .codeblock, .codeblock + p, .codeblock + h3 { margin-top: 12px; }
.copyline { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 6px 6px 12px; }
.copyline code { flex: 1; overflow-x: auto; white-space: nowrap; font-size: 13px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--text-3); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--accent-text); border-color: var(--accent); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; min-width: 150px; }
.list-cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.list-card { padding: 16px 18px; color: inherit; display: flex; flex-direction: column; gap: 6px; }
a.list-card:hover { text-decoration: none; border-color: var(--border-strong); }
.list-card h3 { font-size: 15.5px; }
.list-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.checklist { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.result { margin-top: 12px; }
.docs h3 { font-size: 15px; margin: 22px 0 8px; }
.docs h3:first-child { margin-top: 0; }
.docs p, .docs li { color: var(--text-2); }
.docs ol, .docs ul { padding-left: 20px; margin: 0 0 10px; }
.docs li { margin-bottom: 4px; }
.steps { counter-reset: step; display: flex; flex-direction: column; gap: 14px; }
.step { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; }
.step::before { counter-increment: step; content: counter(step); width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.step h4 { margin: 2px 0 4px; font-size: 14.5px; }
.step p { color: var(--text-2); margin-bottom: 8px; }
.my-ip { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 16px 18px; }
.my-ip .big { font: 700 20px var(--mono); }
.my-ip .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.my-ip select { width: auto; min-width: 190px; }
td time, td .nowrap { white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; box-shadow: 0 0 0 3px var(--ok-soft); }
.live-dot.off { background: var(--text-3); box-shadow: none; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(9, 12, 18, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 24px; overflow-y: auto; animation: fade .12s ease; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); animation: pop .14s ease; }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px 0; }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 14px 18px 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; display: flex; gap: 8px; align-items: center; animation: pop .14s ease; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; padding: 28px 26px; }
.login .brand { padding: 0 0 18px; }
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login p.muted { margin-bottom: 18px; }

.loading { padding: 48px 0; text-align: center; color: var(--text-3); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
