:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c2128;
  --muted: #5d6673;
  --line: #dde1e6;
  --accent: #1f5fbf;
  --in: #1e8e4e;
  --in-bg: #e6f5ec;
  --out: #b88600;
  --out-bg: #fff6d6;
  --over: #c62828;
  --over-bg: #fde7e7;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---- top bar ---- */
#nav { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: #182230; color: #fff; flex-wrap: wrap; }
#nav .brand { display: flex; flex-direction: column; line-height: 1.15; }
#nav .brand span { font-size: .78rem; opacity: .75; }
#nav .links { display: flex; gap: .25rem; flex: 1; }
#nav .links a { color: #cfd8e3; text-decoration: none; padding: .4rem .8rem; border-radius: 6px; }
#nav .links a.active, #nav .links a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
#nav .who { display: flex; gap: .9rem; align-items: center; font-size: .9rem; }
#nav .who a, #nav .who .link { color: #cfd8e3; }

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }

/* ---- forms ---- */
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #c3c9d1; border-radius: 6px; background: #fff; width: 100%; }
input[type="checkbox"], input[type="radio"] { width: auto; padding: 0; margin: 0 .35rem 0 0; vertical-align: middle; }
label:has(> input[type="checkbox"]) { display: inline-flex; align-items: center; color: var(--text); }
textarea { min-height: 4rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.field { margin-bottom: .8rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; margin-bottom: 0; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 6px; padding: .5rem 1rem; background: var(--accent); color: #fff; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .55; cursor: default; }
button.secondary { background: #e6e9ed; color: var(--text); }
button.danger { background: var(--over); }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; padding: 0; color: var(--accent); text-decoration: underline; }
.error-text { color: var(--over); min-height: 1.2em; margin: .5rem 0 0; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.voided td { color: #98a0aa; text-decoration: line-through; }
tr.voided td.keep { text-decoration: none; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e6e9ed; color: var(--text); }
.badge-in { background: var(--in-bg); color: var(--in); }
.badge-out { background: var(--out-bg); color: #8a6500; }
.badge-over, .badge-bad { background: var(--over-bg); color: var(--over); }
.badge-ok { background: var(--in-bg); color: var(--in); }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px; border: 1px solid var(--line); padding: 2rem; }
.login-card h1 { margin-bottom: .25rem; }
.login-card p { margin-top: 0; }
.login-card button { width: 100%; padding: .7rem; margin-top: .5rem; }

/* ---- board (dashboard): IN | OUT columns, "Today's trips" underneath ----
   The columns grow up to a height that fits the screen; board-view.js sets --cols (cards side by side)
   and --s (card scale, at most 1) so every card fits without scrolling; all card sizes use --s. */
.board { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.board .today { grid-column: 1 / -1; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.board .col-in, .board .col-out { display: flex; flex-direction: column; max-height: clamp(320px, calc(100vh - 165px), 640px); }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; font-weight: 700; letter-spacing: .03em; }
.col-in .col-head { background: var(--in); color: #fff; }
.col-out .col-head { background: #e0a800; color: #1c1c1c; }
.card-in { background: var(--in-bg); border-color: #bfe3cd; }
.card-back { font-size: calc(.95rem * var(--s, 1)); color: var(--in); font-weight: 700; }
.today .col-head { background: #2b3a4a; color: #fff; }
.col-head .count { background: rgba(0, 0, 0, .15); border-radius: 999px; padding: 0 .6rem; }
.cards { --s: 1; list-style: none; margin: 0; padding: .6rem; display: grid; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); gap: .5rem; align-content: start; flex: 1; min-height: 0; overflow: hidden; }
.cards.measuring { grid-template-columns: max-content; }
.card { display: flex; gap: calc(.75rem * var(--s, 1)); align-items: center; padding: calc(.7rem * var(--s, 1)) calc(.85rem * var(--s, 1)); border-radius: 8px; border: 1px solid var(--line); min-width: 0; }
.card-body { min-width: 0; }
.card-name, .card-meta, .card-timer, .card-back { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-out { background: var(--out-bg); border-color: #f0d98a; }
.card-over { background: var(--over-bg); border-color: #f2a7a7; animation: pulse 2s ease-in-out infinite; }
.card-over .card-timer { color: var(--over); }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(198, 40, 40, .18); } }
.avatar { width: calc(48px * var(--s, 1)); height: calc(48px * var(--s, 1)); border-radius: 50%; object-fit: cover; flex: none; }
.avatar-initials { display: grid; place-items: center; background: #cfd6de; color: #334; font-weight: 700; font-size: calc(1rem * var(--s, 1)); }
.card-name { font-weight: 700; font-size: calc(1.1rem * var(--s, 1)); }
.card-meta { font-size: calc(.88rem * var(--s, 1)); color: var(--muted); }
.card-timer { font-size: calc(1.05rem * var(--s, 1)); color: #6b5100; font-weight: 700; }
.cards .empty, .trips-table .empty { color: var(--muted); padding: .75rem; list-style: none; }
.cards .empty { grid-column: 1 / -1; }
.today .table-wrap { margin: 0; }
.trips-table tr.row-over td { background: var(--over-bg); }
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.dash-head h1 { margin: 0; }
.dash-tools { display: flex; gap: .75rem; align-items: center; }
.live-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: var(--in); margin-right: .35rem; }
.live-dot.stale { background: var(--over); }

/* ---- tabs ---- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); border-radius: 6px 6px 0 0; padding: .55rem 1rem; }
.tabs button.active { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-bottom-color: var(--panel); margin-bottom: -1px; font-weight: 600; }
.toolbar { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .field { margin: 0; }
.actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.tag-chip { display: inline-flex; gap: .35rem; align-items: center; font-family: Consolas, monospace; font-size: .85rem; background: #eef1f4; padding: .1rem .4rem; border-radius: 4px; margin: 0 .25rem .25rem 0; }
.pin { font-size: 2.4rem; font-family: Consolas, monospace; letter-spacing: .25em; text-align: center; padding: .5rem; background: #eef1f4; border-radius: 8px; }
.scan-wait { text-align: center; padding: 1.5rem 1rem; border: 2px dashed #b7c0cb; border-radius: 10px; margin-bottom: 1rem; }
.scan-wait.got { border-color: var(--in); background: var(--in-bg); }
.scan-wait .big { font-size: 1.3rem; font-weight: 600; }
pre.detail { white-space: pre-wrap; word-break: break-word; margin: 0; font-size: .8rem; color: var(--muted); max-width: 520px; }

/* ---- modal / toast ---- */
dialog.modal { border: 0; border-radius: 12px; padding: 1.25rem 1.5rem; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog.modal::backdrop { background: rgba(10, 20, 30, .45); }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translate(-50%, 150%); background: #1c2128; color: #fff; padding: .7rem 1.2rem; border-radius: 8px; transition: transform .2s; z-index: 100; max-width: 90vw; }
.toast.show { transform: translate(-50%, 0); }
.toast-error { background: var(--over); }

@media (max-width: 800px) {
  .board { grid-template-columns: 1fr; }
}

.badge-manual { background: #e8e3f8; color: #4b3a8c; }
.flag { color: var(--over); font-weight: 700; }

/* ---- settings: store hours ---- */
.hours-table { width: auto; margin-bottom: 1rem; }
.hours-table td { padding: .25rem .6rem .25rem 0; border: 0; vertical-align: middle; }
.hours-table input { width: auto; }

/* ---- reports: print / PDF ---- */
.print-only { display: none; }
.report-title { font-size: 1.25rem; font-weight: 700; }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; }
  .no-print, .toast { display: none !important; }
  .print-only { display: block; }
  .report-head { margin-bottom: .4rem; font-size: 9.5pt; }
  main { padding: 0; max-width: none; }
  .panel { border: 0; padding: 0; margin: 0 0 10pt; }
  .table-wrap { overflow: visible; }
  table { font-size: 8.5pt; }
  th { color: #000; border-bottom: 1px solid #000; }
  td { padding: 2pt 4pt; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
  .badge { background: none !important; color: #000 !important; padding: 0; font-weight: 600; }
  .flag { color: #000 !important; }
  #day-note { color: #333; }
}

/* ---- checkbox with its label ---- */
label.check { display: inline-flex; align-items: center; gap: .4rem; margin: .4rem 0; font-weight: 500; }
