/* Licence admin dashboard — an editorial "ledger": paper, thin rules, big serif numerals and the Pink Cuts rose.
   Colour carries meaning only: green = in use, amber = quiet > 10 days or a limit hit, grey = suspended,
   red = revoked or modified files. No web fonts (CSP 'self'): Apple's Sukhumvit Set for Thai, the system serif for
   numerals. Phone first (one column at 375 px), two columns from 900 px; light and dark follow the system. */
:root {
  --paper: #fff6f9;
  --sheet: #ffffff;
  --ink: #1c1828;
  --muted: #6b6784;
  --rule: #ecdbe2;
  --rule-strong: #d9c2cc;
  --rose: #f391a9;
  --rose-deep: #e2528a;
  --rose-ink: #b8346b;
  --rose-wash: #fde4ec;
  --green: #1e8c64;
  --green-wash: #dff5ec;
  --amber: #9a6200;
  --amber-wash: #fdf0d6;
  --grey: #5f5b70;
  --grey-wash: #ecebf1;
  --red: #c2304a;
  --red-wash: #fbe2e6;
  --shadow: 0 1px 0 rgb(28 24 40 / 4%), 0 12px 32px -18px rgb(184 52 107 / 28%);
  --serif: "Iowan Old Style", "New York", ui-serif, Georgia, "Sukhumvit Set", "Thonburi", serif;
  --sans: "Sukhumvit Set", "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --radius-s: 6px;
  --radius-m: 14px;
  --gap: clamp(16px, 4vw, 28px);
  --fast: 140ms;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e0b14;
    --sheet: #17131f;
    --ink: #ffeaf1;
    --muted: #c9b8cf;
    --rule: #2c2536;
    --rule-strong: #43394f;
    --rose-ink: #f7a8bf;
    --rose-wash: #3a1b2b;
    --green: #5fd3a6;
    --green-wash: #11352a;
    --amber: #f5c160;
    --amber-wash: #3a2c10;
    --grey: #b4afc4;
    --grey-wash: #27222f;
    --red: #ff8c9f;
    --red-wash: #3d1720;
    --shadow: 0 1px 0 rgb(0 0 0 / 40%), 0 16px 36px -20px rgb(0 0 0 / 70%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  overflow-wrap: anywhere;
}
a { color: var(--rose-ink); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--rose-deep); outline-offset: 2px; border-radius: var(--radius-s); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -48px; background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: var(--radius-s); z-index: 5; }
.skip:focus { top: 12px; }
.mono { font-family: var(--mono); font-size: 0.86em; letter-spacing: 0.01em; }
.kicker { margin: 0; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* ---------- masthead ---------- */
.masthead {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 16px;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) var(--gap) 0;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 3;
}
.brand { display: flex; gap: 12px; align-items: center; }
.mark {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(140deg, var(--rose) 0%, var(--rose-deep) 100%);
  color: #fff; font: 700 15px/1 var(--serif); letter-spacing: 0.04em; box-shadow: var(--shadow);
}
.title { margin: 0; font: 600 22px/1.15 var(--serif); }
.tabs { grid-column: 1 / -1; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--gap) * -1); padding: 0 var(--gap); }
.tabs a {
  flex: none; padding: 10px 12px 12px; color: var(--muted); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent; transition: color var(--fast), border-color var(--fast);
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current] { color: var(--ink); border-bottom-color: var(--rose-deep); }
.count:not(:empty) { margin-left: 4px; padding: 1px 7px; border-radius: 999px; background: var(--rose-deep); color: #fff; font-size: 12px; }
.signout { grid-row: 1; grid-column: 2; }

main { max-width: 1120px; margin: 0 auto; padding: var(--gap) var(--gap) 64px; }
main:focus { outline: none; }
.loading, .problem { color: var(--muted); }
.problem { color: var(--red); }

/* ---------- buttons and fields ---------- */
button, .button {
  font: 600 15px/1 var(--sans); border-radius: 999px; padding: 12px 18px; min-height: 44px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--fast), border-color var(--fast), transform var(--fast);
}
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
.primary { background: var(--rose-deep); color: #fff; }
.primary:hover:not(:disabled) { background: var(--rose-ink); }
.primary.danger { background: var(--red); }
.ghost { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.ghost:hover:not(:disabled) { border-color: var(--rose-deep); background: var(--rose-wash); }
.ghost.danger { color: var(--red); }
.ghost.danger:hover:not(:disabled) { border-color: var(--red); background: var(--red-wash); }
.small { padding: 8px 14px; min-height: 36px; font-size: 14px; }
.field { display: grid; gap: 6px; margin: 0 0 14px; font-weight: 600; font-size: 14px; }
input, textarea {
  font: 16px/1.4 var(--sans); color: var(--ink); background: var(--sheet); width: 100%;
  border: 1px solid var(--rule-strong); border-radius: 10px; padding: 12px 14px; min-height: 46px;
}
input:focus-visible, textarea:focus-visible { outline: 3px solid var(--rose); outline-offset: 0; border-color: var(--rose-deep); }

/* ---------- login ---------- */
.login-wrap { max-width: 460px; margin: clamp(12px, 6vh, 64px) auto 0; }
.display { margin: 6px 0 10px; font: 600 clamp(32px, 8vw, 52px)/1.05 var(--serif); letter-spacing: -0.01em; }
.display.small { font-size: clamp(28px, 6vw, 40px); margin: 0; }
.lede { margin: 0 0 22px; color: var(--muted); font-size: 17px; }
.login { padding: 22px; border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--sheet); box-shadow: var(--shadow); }
.login button { width: 100%; justify-content: center; }
.hint { min-height: 1.5em; margin: 12px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- overview ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 2px solid var(--ink); }
.stat { display: grid; padding: 16px 12px 18px 0; border-bottom: 1px solid var(--rule); }
.stat:nth-child(odd) { border-right: 1px solid var(--rule); }
.stat:nth-child(even) { padding-left: 14px; }
.num { font: 600 clamp(44px, 13vw, 76px)/0.95 var(--serif); font-variant-numeric: tabular-nums lining-nums; letter-spacing: -0.02em; }
.stat:first-child .num { color: var(--rose-deep); }
.label { font-weight: 700; margin-top: 6px; }
.note { color: var(--muted); font-size: 13px; }
.alerts { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 26px; }
.alert { display: inline-flex; gap: 4px; align-items: center; padding: 8px 14px; border-radius: 999px; text-decoration: none; font-size: 14px; font-weight: 600; min-height: 40px; border: 1px solid transparent; }
.alert b { font: 700 17px/1 var(--serif); }
.alert.rose { background: var(--rose-wash); color: var(--rose-ink); }
.alert.amber { background: var(--amber-wash); color: var(--amber); }
.alert.red { background: var(--red-wash); color: var(--red); }
.alert.plain { background: var(--grey-wash); color: var(--grey); }
.alert:hover { border-color: currentColor; }
.calm { color: var(--green); font-weight: 600; padding: 8px 0; }
.split { display: grid; gap: var(--gap); }
.card { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 18px 18px 14px; box-shadow: var(--shadow); }
.section { margin: 0 0 12px; font: 600 19px/1.2 var(--serif); }
.versions h3 { margin: 4px 0 8px; font-size: 14px; color: var(--muted); }
.bar-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.ver { font-family: var(--mono); }
.bar { height: 10px; background: var(--rose-wash); border-radius: 999px; overflow: hidden; }
.fill { display: block; height: 100%; background: var(--rose-deep); border-radius: inherit; }
.w1 { width: 10%; } .w2 { width: 20%; } .w3 { width: 30%; } .w4 { width: 40%; } .w5 { width: 50%; }
.w6 { width: 60%; } .w7 { width: 70%; } .w8 { width: 80%; } .w9 { width: 90%; } .w10 { width: 100%; }
.n { color: var(--muted); font-variant-numeric: tabular-nums; }
.feed ol, .plain { list-style: none; margin: 0; padding: 0; }
.feed li, .plain li { display: grid; gap: 2px; padding: 10px 0; border-top: 1px solid var(--rule); }
.feed li:first-child, .plain li:first-child { border-top: 0; }
.feed a, .plain a { color: var(--ink); text-decoration: none; }
.feed a:hover, .plain a:hover { color: var(--rose-ink); text-decoration: underline; }
time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.by { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); margin: 6px 0; }
.empty.big { font: 500 22px/1.3 var(--serif); padding: 32px 0; }

/* ---------- list ---------- */
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; border-bottom: 2px solid var(--ink); padding-bottom: 8px; }
.total { color: var(--muted); font-variant-numeric: tabular-nums; }
.search { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  padding: 8px 13px; min-height: 38px; border-radius: 999px; border: 1px solid var(--rule-strong); background: transparent;
  color: var(--ink); font: 600 14px/1 var(--sans); text-decoration: none; display: inline-flex; align-items: center;
}
.chip:hover { border-color: var(--rose-deep); }
.chip[aria-pressed="true"], .chip[aria-current], .chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 4px; border-bottom: 1px solid var(--rule);
  color: var(--ink); text-decoration: none; transition: background var(--fast);
}
.row:hover { background: var(--rose-wash); }
.who { display: grid; }
.who b { font: 600 18px/1.25 var(--serif); }
.org { color: var(--muted); font-size: 14px; }
.code { grid-column: 2; grid-row: 1; color: var(--muted); }
.meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; color: var(--muted); font-size: 14px; margin: 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.green { background: var(--green-wash); color: var(--green); }
.pill.amber { background: var(--amber-wash); color: var(--amber); }
.pill.grey { background: var(--grey-wash); color: var(--grey); }
.pill.red { background: var(--red-wash); color: var(--red); }
.pill.plain { background: transparent; color: var(--muted); border: 1px dashed var(--rule-strong); }
.tag { padding: 2px 8px; border-radius: var(--radius-s); background: var(--grey-wash); color: var(--grey); font-size: 12px; font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0; color: var(--muted); }
.downloads { color: var(--muted); font-size: 14px; }

/* ---------- detail ---------- */
.back { display: inline-block; margin-bottom: 10px; font-weight: 600; text-decoration: none; }
.confirmed { margin: 0 0 16px; padding: 12px 14px; border-left: 4px solid var(--green); background: var(--green-wash); color: var(--green); font-weight: 600; border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.person { border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 14px; }
.person .lede { margin-bottom: 10px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin: 0; color: var(--muted); font-size: 14px; }
.reason, .person .note { margin: 10px 0 0; padding: 8px 12px; background: var(--grey-wash); border-radius: var(--radius-s); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.devices, .cards { list-style: none; margin: 0 0 26px; padding: 0; display: grid; gap: 12px; }
.device { background: var(--sheet); border: 1px solid var(--rule); border-left: 4px solid var(--green); border-radius: var(--radius-m); padding: 14px 16px; box-shadow: var(--shadow); }
.device:not(.active) { border-left-color: var(--rule-strong); opacity: 0.85; }
.device-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.device-head b { font: 600 18px/1.25 var(--serif); }
.device .meta { margin-top: 4px; }
.days { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0 4px; font-size: 14px; }
.dots { display: grid; grid-template-columns: repeat(15, 8px); gap: 3px; }
.dots i { width: 8px; height: 8px; border-radius: 2px; background: var(--rule); }
.dots i.on { background: var(--rose-deep); }
.flags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; }
.usage ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; }
.usage .empty { font-size: 14px; }
.device button { margin-top: 10px; }
.detail section { margin-bottom: 18px; }
.request h3 { margin: 4px 0 6px; font: 600 20px/1.25 var(--serif); }
.request h3 a { color: var(--ink); text-decoration: none; }
.order { border-left: 4px solid var(--green); }
.order.waiting { border-left-color: var(--amber); }
.order.trouble { border-left-color: var(--red); }
.order h3 { margin: 4px 0 4px; font: 600 20px/1.25 var(--serif); }
.order .money { font: 600 22px/1 var(--serif); font-variant-numeric: tabular-nums lining-nums; color: var(--ink); }
.order .meta { margin: 6px 0; }
.order .actions { margin: 10px 0 0; }
.order-error { margin: 8px 0 0; color: var(--red); font-size: 14px; }
blockquote { margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--rose); background: var(--rose-wash); border-radius: 0 var(--radius-s) var(--radius-s) 0; }

/* ---------- confirm sheet and toast ---------- */
dialog {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: min(100vw, 520px); max-width: 100vw; margin: auto auto 0; max-height: 92vh;
}
dialog::backdrop { background: rgb(14 11 20 / 52%); }
.sheet { background: var(--sheet); border-radius: 22px 22px 0 0; padding: 22px 20px max(20px, env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
.sheet h2 { margin: 6px 0 8px; font: 600 22px/1.25 var(--serif); }
.sheet-target { margin: 0 0 8px; padding: 10px 12px; border-radius: var(--radius-s); background: var(--rose-wash); color: var(--rose-ink); font-weight: 700; }
.sheet-effect { margin: 0 0 14px; color: var(--muted); }
.sheet-error { min-height: 1.4em; color: var(--red); margin: 0 0 6px; font-weight: 600; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.choices { border: 0; padding: 0; margin: 0 0 14px; display: grid; gap: 6px; }
.choices legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.choice { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--rule-strong); border-radius: 10px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--rose-deep); background: var(--rose-wash); }
.choice input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--rose-deep); }
.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: var(--paper);
  font-weight: 600; box-shadow: var(--shadow); opacity: 0; transition: transform 220ms ease, opacity 220ms ease; z-index: 9;
}
.toast.on { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { background: var(--red); color: #fff; }

@media (min-width: 900px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat, .stat:nth-child(odd), .stat:nth-child(even) { border-right: 1px solid var(--rule); padding-left: 18px; }
  .stat:first-child { padding-left: 0; }
  .stat:last-child { border-right: 0; }
  .split { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
  .devices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .masthead { grid-template-columns: auto 1fr auto; }
  .tabs { grid-column: 2; grid-row: 1; margin: 0; align-self: end; }
  .signout { grid-column: 3; }
  dialog { margin: auto; }
  .sheet { border-radius: 22px; }
  .row { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; align-items: center; }
  .meta { grid-column: 2; grid-row: 1; }
  .code { grid-column: 3; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
