:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #dfe4ea;
  --text: #17202b;
  --muted: #5d6b7a;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --down: #2563eb;
  --up: #0d9488;
  --cap: #9aa5b1;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --idle-bg: #eef1f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1e2731;
    --border: #2a3542;
    --text: #e6ebf0;
    --muted: #93a1af;
    --accent: #4c8dff;
    --down: #5b9bff;
    --up: #2dd4bf;
    --cap: #66727f;
    --ok: #4ade80;
    --ok-bg: #12321f;
    --warn: #fbbf24;
    --warn-bg: #3a2d0b;
    --bad: #f87171;
    --bad-bg: #3b1414;
    --idle-bg: #232c36;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button, input, select { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 34px; height: 34px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { fill: #fff; }
.brand p { margin: 0; font-size: 12px; }
.backend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.sim { background: var(--warn); }

.tabs {
  display: flex; gap: 4px; padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tabs button {
  border: 0; background: none; padding: 12px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

main { padding: 20px 24px 40px; max-width: 1280px; margin: 0 auto; }
#warnings { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.banner { margin-top: 16px; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0;
}
.card.flush { padding: 0; overflow-x: auto; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .meter { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.kpi .meter i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.kpi .meter i.hot { background: var(--bad); }

.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
canvas { width: 100%; display: block; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 8px; }
.sw.down { background: var(--down); }
.sw.up { background: var(--up); }
.sw.cap { background: var(--cap); height: 2px; }

.talkers { display: flex; flex-direction: column; gap: 10px; }
.talker { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; font-size: 13px; }
.talker .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.talker .rate { font-variant-numeric: tabular-nums; color: var(--muted); }
.talker .bar { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.talker .bar i { display: block; height: 100%; background: var(--down); transition: width .4s; }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.alerts li:first-child { border-top: 0; }
.alerts li.read { opacity: .55; }
.alerts .lvl { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--warn); }
.alerts .lvl.critical { background: var(--bad); }
.alerts .msg { flex: 1; }
.alerts time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { color: var(--muted); padding: 12px 0; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type="search"] { min-width: 220px; flex: 0 1 300px; }
.spacer { flex: 1; }

input, select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 7px 12px; cursor: pointer;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button.sm { padding: 4px 9px; font-size: 12px; }

table.users { width: 100%; border-collapse: collapse; min-width: 820px; }
.users th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.users td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tr:last-child td { border-bottom: 0; }
.users .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.users .uname { font-weight: 600; }
.users .sub { font-size: 12px; color: var(--muted); }
.users td.acts { text-align: right; white-space: nowrap; }
.users td.acts button { margin-left: 4px; }
.usage { min-width: 140px; }
.usage .bar { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: var(--accent); }
.usage .bar i.w { background: var(--warn); }
.usage .bar i.x { background: var(--bad); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.pill.active { background: var(--ok-bg); color: var(--ok); }
.pill.limited { background: var(--warn-bg); color: var(--warn); }
.pill.blocked { background: var(--bad-bg); color: var(--bad); }
.pill.idle { background: var(--idle-bg); color: var(--muted); }
.prio { font-size: 12px; text-transform: capitalize; }
.prio.high { color: var(--ok); font-weight: 600; }
.prio.low { color: var(--muted); }

.sched-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.sched { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.sched .top-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sched .when { font-variant-numeric: tabular-nums; }
.sched.off { opacity: .6; }
.sched .live { color: var(--ok); font-size: 12px; font-weight: 600; }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form.narrow { max-width: 640px; }
.form h2 { margin-top: 4px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form label input, .form label select { color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 600px) { .row2, .row3 { grid-template-columns: 1fr; } }
.hint { margin: -4px 0 0; font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.form-msg { font-size: 13px; color: var(--ok); }
.form-msg.error { color: var(--bad); margin: 0; }
.form-msg:empty { display: none; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
fieldset.seg label, fieldset.days label { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; margin-right: 16px; color: var(--text); }

dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: min(720px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgb(0 0 0 / 40%); }
.dev-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.dev-head div { display: flex; gap: 6px; }
.devices { display: flex; flex-direction: column; gap: 6px; }
.device-row { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr auto; gap: 6px; }
@media (max-width: 600px) { .device-row { grid-template-columns: 1fr 1fr; } }
.discover { border: 1px dashed var(--border); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow: auto; }
.discover .lease { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.discover .lease span { flex: 1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 10;
}

@media (max-width: 600px) {
  .top, .tabs, main, #warnings { padding-left: 16px; padding-right: 16px; }
}

.card.narrow { max-width: 640px; }
.due { list-style: none; margin: 0; padding: 0; }
.due li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.due li:first-child { border-top: 0; }
.due .who { flex: 1; min-width: 160px; }
.sub-text { font-size: 13px; white-space: nowrap; }
.sub-text.expiring, .sub-text.grace { color: var(--warn); font-weight: 600; }
.sub-text.expired { color: var(--bad); font-weight: 600; }
.sub-text.none { color: var(--muted); }
.renew { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.renew label { width: 110px; }
.renew label.grow { flex: 1; min-width: 140px; width: auto; }
.login-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 6px; }
.pays { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.pays li { padding: 4px 0; border-top: 1px solid var(--border); display: flex; gap: 12px; flex-wrap: wrap; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
table.plans { width: 100%; border-collapse: collapse; }
.plans th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.plans td { padding: 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.plans td:last-child { text-align: right; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(400px, 100%); padding: 24px; }
.auth-card .brand { margin-bottom: 8px; }
.top-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.admins { list-style: none; margin: 0 0 8px; padding: 0; }
.admins li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.admins li:first-child { border-top: 0; }
.admins li span { flex: 1; }

/* user page */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 18px; }
.up-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 960px) { .up-grid { grid-template-columns: 1fr; } }
.up-main .card { margin-bottom: 16px; }
.up-side { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 0; }
@media (max-width: 960px) { .up-side { position: static; } }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; margin-right: 6px; }
.form h3 { margin-top: 6px; }
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px; resize: vertical; }
.sub-panel { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; font-family: ui-monospace, Menlo, monospace; }
fieldset.seg label { margin-bottom: 4px; }
.logins { display: flex; flex-direction: column; gap: 6px; }
.login-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; flex-wrap: wrap; }
.login-item .lname { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
.login-item .spacer { flex: 1; }
.login-item select { padding: 4px 8px; font-size: 12px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; color: var(--text); }
.period-preview { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.period-preview:empty { display: none; }
.usage-line { font-size: 13px; color: var(--muted); }
.usage-line:empty { display: none; }
.summary dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 10px 0 14px; font-size: 13px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary dd.total { font-weight: 700; font-size: 15px; }
button.block { display: block; width: 100%; margin-top: 8px; }
.danger-zone h3 { margin-bottom: 4px; }
.creds { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 15px; }
.creds dt { color: var(--muted); }
.creds dd { margin: 0; font-family: ui-monospace, Menlo, monospace; font-weight: 600; user-select: all; }

/* users list: devices and logins under each user */
.users tr.child td { padding-top: 5px; padding-bottom: 5px; border-bottom: 0; font-size: 13px; background: var(--surface-2); }
.users tr.child + tr:not(.child) td { border-top: 1px solid var(--border); }
.users tr.child:last-of-type td { border-bottom: 1px solid var(--border); }
.users tbody tr:not(.child) td { border-bottom: 0; }
.users tbody tr:not(.child) + tr:not(.child) td, .users tbody tr:first-child td { border-top: 1px solid var(--border); }
.tree { color: var(--muted); margin: 0 8px 0 10px; }
.users .tag { margin-right: 4px; }
.users .lname { font-family: ui-monospace, Menlo, monospace; }
.dot-on { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 5px; }
.add-dev { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.add-dev input { padding: 4px 8px; font-size: 13px; width: 170px; }
.inline-check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

/* hotspot page settings */
.hs-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; }
@media (max-width: 900px) { .hs-grid { grid-template-columns: 1fr; } }
.hs-preview { display: flex; flex-direction: column; gap: 8px; }
.hs-preview iframe { width: 100%; height: 620px; border: 1px solid var(--border); border-radius: 12px; background: #eef2f7; }
.seg-row { display: flex; gap: 4px; flex-wrap: wrap; }
.seg-row button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.steps { margin: 0; padding-left: 20px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.steps b, .steps code { color: var(--text); }
.dl-list { display: flex; gap: 6px; flex-wrap: wrap; }
.dl-list a { font-size: 12px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 7px; color: var(--text); text-decoration: none; background: var(--surface); }
.dl-list a:hover { background: var(--surface-2); }
.hs-grid label.check { align-self: flex-start; padding-bottom: 0; }

/* Staff accounts don't see admin-only sections. */
body.role-staff .admin-only { display: none !important; }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.notice code { font-size: 15px; user-select: all; }
.tag.warn { color: #9a5b00; background: #fff4dc; border-color: transparent; }
.admins select { width: auto; }
.alerts .lvl.info { background: var(--ok); }
