/* Tokens and components follow the BI kiosk store, so the apps read as one family. */
@font-face { font-family: Inter; font-weight: 400; font-display: swap; src: url(/fonts/inter_regular.ttf) format("truetype"); }
@font-face { font-family: Inter; font-weight: 600; font-display: swap; src: url(/fonts/inter_semibold.ttf) format("truetype"); }
@font-face { font-family: Inter; font-weight: 700 800; font-display: swap; src: url(/fonts/inter_bold.ttf) format("truetype"); }

:root {
  --bg: #F8FAFC; --surface: #FFFFFF; --surface2: #F1F5F9; --border: #E2E8F0;
  --text: #0F172A; --muted: #64748B;
  --primary: #1D4ED8; --primary-dark: #1E3A8A; --primary-light: #DBEAFE;
  --accent: #F97316; --success: #16A34A; --warning: #D97706; --danger: #DC2626;
  --on-danger: #FFFFFF;
  --radius: 10px; --radius-sm: 8px; --page-x: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F172A; --surface: #1E293B; --surface2: #334155; --border: #475569;
    --text: #F1F5F9; --muted: #94A3B8;
    --primary: #3B82F6; --primary-dark: #1D4ED8; --primary-light: #1E3A8A;
    --accent: #FB923C; --success: #22C55E; --warning: #F59E0B; --danger: #F87171;
    --on-danger: #0F172A;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 400 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
p { margin: 0; }
.muted { color: var(--muted); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px var(--page-x); background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; }
.brand b { display: block; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: -2px; }
.mark {
  flex: none; width: 34px; height: 34px; border-radius: 9px; background: #000; color: var(--accent);
  display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .02em;
}
.top-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 12px; }

main { max-width: 1040px; margin: 0 auto; padding: 14px var(--page-x) 40px; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; align-items: start; }
.col { display: grid; gap: 12px; min-width: 0; }
main > .card:not(.mode-card) { margin-top: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; min-width: 0;
}
.card-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 8px;
}
.tag { font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--warning); }

.btn {
  min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 12px; }
a.btn { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn.stop {
  display: block; width: 100%; min-height: 64px; font-size: 20px; font-weight: 800; letter-spacing: .06em;
  background: var(--danger); border-color: var(--danger); color: var(--on-danger);
}

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--muted); background: var(--surface2);
}
.badge.off { color: var(--muted); }
.badge.on { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
.badge.wait { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }
.badge.bad { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.badge.info { color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent); }

.banners { max-width: 1040px; margin: 0 auto; padding: 0 var(--page-x); }
.banner { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid; }
.banner.danger { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.banner.warn { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface)); }

.mode-card { display: flex; justify-content: space-between; gap: 16px; }
.mode-name { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.mode-actions { flex: none; width: 240px; display: grid; gap: 8px; align-content: start; }

.big { display: flex; align-items: baseline; gap: 6px; font-size: 44px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.unit { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.run-badge { margin-left: auto; align-self: center; letter-spacing: 0; line-height: 1.45; }
.stale { color: var(--muted); }
.big.stale { opacity: .55; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv.wide { grid-template-columns: repeat(2, auto 1fr); margin: 0; }

.why { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }
.why:empty { display: none; }
#run-btn { display: block; width: 100%; margin-top: 10px; }
.setter { margin-top: 10px; }
.setter label, .login label { display: block; font-weight: 600; margin-bottom: 4px; }
.setter-row { display: flex; gap: 8px; }
input {
  width: 100%; min-width: 0; min-height: 44px; padding: 0 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input:disabled { opacity: .6; }
.pending { margin-top: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--primary-light); font-weight: 600; }

.plain, .log { list-style: none; margin: 0; padding: 0; }
.plain li { padding: 2px 0; }
.alarm-on { color: var(--danger); font-weight: 600; }
.log { max-height: 340px; overflow-y: auto; }
.log li { padding: 7px 0; border-top: 1px solid var(--border); }
.log li:first-child { border-top: 0; padding-top: 0; }
.log-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.log-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.log-detail { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.log .lvl-alarm { color: var(--danger); font-weight: 600; }
.log .lvl-warn { color: var(--warning); font-weight: 600; }

.note { color: var(--muted); font-size: 12px; margin-top: 12px; }
.note.safety { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface2); color: var(--text); }

dialog {
  width: min(440px, calc(100vw - 32px)); padding: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
dialog::backdrop { background: rgba(15, 23, 42, .55); }
dialog h2 { margin: 0 0 8px; font-size: 18px; letter-spacing: -.01em; }
.confirm-change { font-size: 18px; font-weight: 700; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.form-error { color: var(--danger); font-weight: 600; margin-top: 8px; }

main.narrow { max-width: 760px; }
main.narrow > .card:first-child { margin-top: 0; }
.setting-note { margin: 8px 0 12px; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.option { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.option.current { border-color: var(--success); }
.option h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0; font-size: 16px; }
.option p { flex: 1; }
#loss-why { margin: 10px 0 0; }

.login-page { min-height: 100vh; display: grid; place-items: center; }
.login { width: min(380px, 100%); padding: 16px var(--page-x); }
.login .card { display: grid; gap: 4px; margin-top: 14px; padding: 16px; }
.login label:not(:first-child) { margin-top: 8px; }
.login .btn { margin-top: 12px; }
.code-links { display: flex; justify-content: space-between; gap: 8px; }

/* Admin and account pages */
select {
  width: 100%; min-width: 0; min-height: 44px; padding: 0 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
select:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.device-picker { width: auto; max-width: 180px; min-height: 34px; font-size: 12px; }
a { color: var(--primary); }
a.btn { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-top: 12px; padding-bottom: 2px; }
.tabs button {
  flex: none; min-height: 40px; padding: 0 12px; background: transparent; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm); color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--surface); border-color: var(--border); color: var(--text); }
.tabs button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head .card-title { margin: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; padding: 0 10px 6px 0; }
.table td { border-top: 1px solid var(--border); padding: 8px 10px 8px 0; vertical-align: top; overflow-wrap: break-word; }
/* Only for long unbroken values. On every cell it lets a column shrink to one letter, buttons included. */
.table td.long { overflow-wrap: anywhere; min-width: 140px; }
.table td.nowrap { white-space: nowrap; overflow-wrap: normal; }
.table .sub { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; min-width: 220px; }
.table .btn { white-space: nowrap; }
.filters { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; align-items: end; }
.filters label, dialog label, .limit-grid label { display: block; color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.filters-actions { display: flex; gap: 8px; margin-bottom: 12px; }
dialog { max-height: calc(100vh - 32px); overflow-y: auto; }
dialog.wide { width: min(620px, calc(100vw - 32px)); }
dialog .field { margin-top: 10px; }
dialog .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.checks { display: grid; gap: 6px; }
.checks label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; font-weight: 400; margin: 0; }
.checks input { width: 18px; min-height: 18px; flex: none; }
.secret { margin-top: 10px; }
.secret-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-weight: 600; }
.secret pre {
  margin: 0; padding: 8px 10px; background: var(--surface2); border-radius: var(--radius-sm);
  font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
.limit-card { padding: 12px 0; border-top: 1px solid var(--border); }
.limit-card:first-of-type { border-top: 0; padding-top: 0; }
.limit-card h3 { margin: 0 0 8px; font-size: 15px; }
.limit-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; align-items: end; }
.limit-fixed { min-height: 44px; display: flex; align-items: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.limit-card .banner { margin-top: 8px; }
.limit-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.account { display: grid; gap: 4px; }
.account .btn { margin-top: 10px; }

@media (max-width: 760px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .limit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .mode-card { flex-direction: column; }
  .mode-actions { width: auto; }
  .kv.wide { grid-template-columns: auto 1fr; }
  .brand small, .who { display: none; }
  .options { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .top .brand div { display: none; }
}
