:root {
  --bg: #f5f6f8; --surface: #ffffff; --text: #18202b; --muted: #687385; --border: #e2e5ea;
  --primary: #1f5eff; --primary-ink: #ffffff; --danger: #c62f3b; --ok: #1d8a4e; --warn: #b7791f;
  --ok-bg: #e6f4ec; --warn-bg: #fbf2e1; --danger-bg: #fbe9ea; --code: #f0f2f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --surface: #1a2029; --text: #e7eaef; --muted: #95a0b0; --border: #2b3340;
    --primary: #4c7dff; --danger: #ef6b74; --ok: #4cc283; --warn: #e2a64a;
    --ok-bg: #18301f; --warn-bg: #352a16; --danger-bg: #3a1c20; --code: #232a35;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--danger); margin: 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--code); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
button, input { font: inherit; }
input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: grid; gap: 4px; font-weight: 500; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 6px; }
button:disabled { opacity: .6; cursor: progress; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 3px 9px; font-size: 12px; }
button.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: #fff; font-size: 15px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; display: grid; gap: 14px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.topbar .spacer { flex: 1; }
.nav-count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--warn); color: #111; font-size: 11px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { padding: 5px 12px; border-radius: 999px; font-size: 13px; background: transparent; color: var(--muted); }
.chip:hover { color: var(--text); }
.chip.active { background: var(--code); color: var(--text); border-color: var(--primary); }
#license-filters { margin-top: -4px; }
.chip-count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--warn); color: #111; font-size: 11px; font-weight: 700; }
.lic { display: grid; gap: 2px; justify-items: start; }
.lic .sub { font-size: 12px; color: var(--muted); }
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }
#license-info a, #license-devices a { color: var(--primary); text-decoration: none; }
.head-actions { display: flex; gap: 8px; }
.history { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; max-height: 360px; overflow: auto; }
.history li { border-left: 2px solid var(--border); padding-left: 10px; }
.small { font-size: 12px; }
#license-devices a { color: var(--primary); text-decoration: none; }
#license-devices td { white-space: normal; }
#license-devices td.actions { white-space: nowrap; }
.cards > .card { min-width: 0; }
.mainnav { display: flex; gap: 4px; }
.mainnav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 6px; font-weight: 500; white-space: nowrap; }
.mainnav a:hover { color: var(--text); background: var(--code); }
.mainnav a.active { color: var(--text); background: var(--code); }
.cards.admins { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.table-wrap.flat { border: 0; border-radius: 0; background: transparent; }
td.actions { text-align: right; width: 1%; }
.you { margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--code); padding: 1px 7px; border-radius: 999px; }
form.stack { display: grid; gap: 10px; margin-top: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 900px) { .cards.admins { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px) {
  .row2 { grid-template-columns: 1fr; }
  .topbar { gap: 8px; }
  .topbar .brand { font-size: 0; gap: 0; }
  .topbar .logo { font-size: 15px; }
  .mainnav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .mainnav a { padding: 6px 8px; }
  .topbar .spacer { display: none; }
}
main { padding: 24px; max-width: 1440px; margin: 0 auto; }
#devices-view th, #devices-view td { padding: 10px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.search { display: flex; gap: 8px; width: min(440px, 100%); }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; min-width: 140px; }
.stat b { display: block; font-size: 20px; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
#devices-body tr { cursor: pointer; }
#devices-body tr:hover { background: var(--code); }
td.empty { text-align: center; color: var(--muted); padding: 32px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--danger); background: var(--danger-bg); }
.badge.off { color: var(--muted); background: var(--code); }

.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); }

.cards { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .cards { grid-template-columns: 1fr; } main { padding: 16px; } .topbar { padding: 12px 16px; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.card dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.card dt { color: var(--muted); }
.card dd { margin: 0; word-break: break-word; }
.restore form { display: grid; gap: 10px; margin: 12px 0; }
.steps { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; color: var(--muted); }
.steps li { color: var(--text); }
.cmd { display: flex; gap: 8px; align-items: flex-start; margin-top: 4px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.list { display: grid; gap: 8px; }
.list > * { min-width: 0; }
.entry { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; min-width: 0; }
.entry .src { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.entry .badge, .entry .cat { flex: none; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); font-size: 12.5px; font-weight: 600; white-space: nowrap; flex: none; }
button.link:hover { text-decoration: underline; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: min(960px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head .spacer { flex: 1; }
.modal-head .src { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--primary); word-break: break-all; }
.modal-head .cat { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--code); padding: 1px 8px; border-radius: 4px; }
.modal-head .count { font-size: 12px; font-weight: 600; color: var(--warn); }
.modal-head .when { color: var(--muted); font-size: 12px; }
.modal pre { margin: 0; padding: 16px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; background: var(--code); flex: 1; }
.card h2.section { margin-top: 18px; }
.problems { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
select { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.entry .cat { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--code); padding: 1px 8px; border-radius: 4px; white-space: nowrap; }
.entry .count { font-size: 12px; font-weight: 600; color: var(--warn); white-space: nowrap; }
.entry .src { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--primary); }
.entry .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.entry .first { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; max-width: calc(100% - 32px); z-index: 10; }
.warn-text { color: var(--warn); margin: 0; }
@media (max-width: 700px) { .entry { flex-wrap: wrap; } .entry .first { flex-basis: 100%; order: 10; } }
.cards.single { grid-template-columns: minmax(0, 1fr); }
#device-info > h2.section:first-child { margin-top: 0; }
.date-field { position: relative; display: flex; gap: 6px; }
.date-field input[type="text"] { flex: 1; }
.date-field button { padding: 6px 12px; }
#license-date-native { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.tab-count { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; color: var(--danger); background: var(--danger-bg); }
.modal { overflow-y: auto; }
.modal .modal-part { flex: none; max-height: 30vh; border-bottom: 1px solid var(--border); }
.modal .modal-label { margin: 0; padding: 8px 16px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }

/* Numeric table columns (coupon counts). */
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
