:root {
  --bg: #eceff2;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --ink: #1b2430;
  --muted: #5b6672;
  --line: #d4d9df;
  --accent: #e8a317;          /* school-bus amber: the one loud colour, used for the issued link */
  --accent-ink: #4a3300;
  --online: #1f7a4d;
  --offline: #b23a48;
  --sleep: #8a6d00;
  --focus: #2b6cb0;
  --radius: 4px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a20; --surface: #1e252d; --surface-2: #242c35; --ink: #e6e9ed; --muted: #9aa5b1; --line: #343e49;
    --accent: #f0b429; --accent-ink: #2a1d00; --online: #4cc38a; --offline: #ef6f7b; --sleep: #e3c35a; --focus: #7cb3ff;
  }
}
:root[data-theme="dark"] {
  --bg: #151a20; --surface: #1e252d; --surface-2: #242c35; --ink: #e6e9ed; --muted: #9aa5b1; --line: #343e49;
  --accent: #f0b429; --accent-ink: #2a1d00; --online: #4cc38a; --offline: #ef6f7b; --sleep: #e3c35a; --focus: #7cb3ff;
}
* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--bg); }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; text-decoration: none; }
.brand .env { font-weight: 400; color: var(--muted); margin-left: 6px; }
.nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.nav a { text-decoration: none; }
.nav .who { color: var(--muted); }
.nav .quiet { color: var(--muted); }
.page { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 20px 16px; }
.foot { padding: 12px 16px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
.lead { color: var(--muted); max-width: 60ch; margin: 0 0 16px; }
.error { color: var(--offline); border-left: 3px solid var(--offline); padding: 6px 10px; background: var(--surface-2); margin: 0 0 16px; }
.notice { color: var(--muted); border-left: 3px solid var(--line); padding: 6px 10px; background: var(--surface-2); margin: 0 0 16px; }

.login { max-width: 420px; margin: 48px auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 500; }
input[type=email], input[type=password], input[type=search], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius); padding: 7px 12px; }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* Column view: Partner → Company → Device */
.columns { display: grid; grid-template-columns: 220px 260px 1fr; gap: 0; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); min-height: 480px; }
.col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.col:last-child { border-right: 0; }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.col-head .count { color: var(--muted); font-size: 13px; }
.col-search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.list li button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.list li button:hover { background: var(--surface-2); }
.list li button[aria-current="true"] { background: var(--ink); color: var(--bg); }
.list .sub { display: block; color: var(--muted); font-size: 13px; }
.list li button[aria-current="true"] .sub { color: inherit; opacity: .75; }
.empty { padding: 24px 12px; color: var(--muted); }

/* Device table */
table.devices { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.devices th { text-align: left; font-weight: 500; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; }
.devices td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.status { font-weight: 500; }
.status.online { color: var(--online); }
.status.offline { color: var(--offline); }
.status.sleep { color: var(--sleep); }
.chan { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chan button { padding: 4px 9px; }

/* The issued link: a ticket with an amber edge */
.ticket { margin-top: 16px; border: 1px solid var(--line); border-left: 6px solid var(--accent); background: var(--surface); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: start; }
.ticket h2 { grid-column: 1 / -1; }
.ticket code { display: block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius); }
.ticket .meta { color: var(--muted); font-size: 13px; grid-column: 1 / -1; }
.ticket .big { font-size: 28px; font-weight: 600; line-height: 1; }

/* Links page */
table.links { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.links th, .links td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.links th { color: var(--muted); font-weight: 500; background: var(--surface-2); }
.links form { display: inline; }
.state { font-weight: 500; }
.state.active { color: var(--online); }
.state.failed, .state.expired { color: var(--offline); }
.state.starting { color: var(--sleep); }

@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; min-height: 0; }
  .col { border-right: 0; border-bottom: 1px solid var(--line); }
  .list { max-height: 220px; }
  .ticket { grid-template-columns: 1fr; }
}
