:root {
  --ink: #e8edf6;
  --muted: #94a3b8;
  --surface: #0b1220;
  --panel: #131c2e;
  --line: #24304a;
  --accent: #fbbf24;
  --danger: #f87171;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--surface); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- main screen: one screen, no scrolling ---------- */
body.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
  -webkit-user-select: none;
}
.phase { display: none; }
body[data-phase="before"] .phase-before,
body[data-phase="open"] .phase-open,
body[data-phase="ended"] .phase-ended { display: flex; }

.bar {
  display: flex; align-items: center; gap: .75rem;
  padding: .4rem .75rem; min-height: 44px;
  border-bottom: 1px solid var(--line);
  font-size: clamp(.85rem, 2.2vmin, 1.1rem);
  white-space: nowrap; min-width: 0;
}
.bar > * { flex: none; }
.bar .who { font-weight: 700; text-decoration: none; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.bar .who::after { content: " ▾"; color: var(--muted); font-weight: 400; }
.bar .date, .bar .daylen { color: var(--muted); }
.bar .now { margin-left: auto; flex: 0 1 auto; min-width: 0; display: flex; gap: .5rem; font-weight: 700; }
.bar .now #nowlabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bar .now #nowtime { flex: none; font-variant-numeric: tabular-nums; color: var(--accent); }
@media (max-width: 480px) { .bar .date { display: none; } .bar { gap: .5rem; } }
.bar .offline { background: var(--danger); color: #1b0606; font-weight: 700; border-radius: 999px; padding: .1rem .6rem; }
.menu { position: relative; }
.menu summary { list-style: none; font-size: 1.5rem; line-height: 1; padding: .2rem .5rem; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute; right: 0; top: 100%; z-index: 5; min-width: 10rem;
  display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: .5rem; padding: .25rem;
}
.menu-items a, .menu-items button { display: block; width: 100%; padding: .75rem 1rem; text-align: left; text-decoration: none; }
button.link { background: none; border: 0; padding: 0; text-decoration: underline; }
.menu-items button.link { text-decoration: none; }

.stage { min-height: 0; display: flex; }
.stage > .phase { flex: 1; min-height: 0; min-width: 0; }

.phase-before { align-items: center; justify-content: center; padding: 1rem; }
.start {
  width: min(32rem, 100%); height: min(16rem, 60%); min-height: 56px;
  font-size: clamp(1.6rem, 6vmin, 3rem); font-weight: 800;
  background: #15803d; color: #fff; border: 0; border-radius: 1.25rem;
}

/* One column per company. Phone portrait: each company is a single column of
   up to eight rows. Wide screens (iPad landscape): each company is two columns
   of four, giving a 4 x 4 grid with one company on each half. */
.companies { gap: .5rem; padding: .5rem; }
.company { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.company h2 {
  margin: 0; font-size: clamp(.8rem, 2vmin, 1rem); text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); text-align: center;
}
.company + .company { border-left: 2px solid var(--line); padding-left: .5rem; }
.grid {
  flex: 1; min-height: 0; display: grid; gap: .4rem;
  grid-template-columns: 1fr; grid-auto-rows: minmax(56px, 1fr);
}
@media (min-width: 700px) and (orientation: landscape) {
  .grid { grid-template-columns: 1fr 1fr; }
}
.task, .extra {
  position: relative; min-height: 56px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
  padding: .2rem .4rem; border: 3px solid transparent; border-radius: .75rem;
  background: var(--bg, var(--panel)); color: var(--fg, var(--ink));
  font-size: clamp(.95rem, 2.6vmin, 1.5rem); font-weight: 700; line-height: 1.1; text-align: center;
  overflow: hidden;
}
.task .label { overflow-wrap: anywhere; }
.elapsed { font-variant-numeric: tabular-nums; font-size: .9em; font-weight: 800; }
.elapsed:empty { display: none; }
.task.running, .extra.running {
  border-color: #fff;
  box-shadow: 0 0 0 3px var(--accent), 0 0 1.2rem rgba(251, 191, 36, .55);
  z-index: 1;
}
body[data-running] .task:not(.running) { opacity: .62; }
.task:active, .extra:active, .start:active { transform: scale(.97); }
.task.pending, .extra.pending { outline: 2px dashed var(--accent); outline-offset: -6px; }
.empty { margin: auto; color: var(--muted); padding: 2rem; text-align: center; }

/* Break and Interrupted: outlined, not filled, so they never read as tasks. */
.extras { min-width: 0; gap: .5rem; padding: .5rem; border-top: 1px solid var(--line); align-items: stretch; }
.extra {
  flex: 1; flex-direction: row; gap: .6rem; background: transparent; color: var(--ink);
  border: 2px dashed var(--muted); border-radius: 999px;
}
.extra.break.running { background: #334155; border-style: solid; }
.extra .count {
  min-width: 1.8em; padding: .1em .45em; border-radius: 999px; background: var(--ink); color: var(--surface);
  font-variant-numeric: tabular-nums;
}
.end {
  flex: 0 0 auto; min-height: 56px; margin-left: .5rem; padding: 0 .7rem;
  background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: .5rem;
  font-size: .85rem;
}
.end.confirm { background: var(--danger); color: #1b0606; border-color: var(--danger); font-weight: 800; }

.done { flex-direction: column; align-items: center; overflow: auto; padding: 1rem; gap: .5rem; }
.done h1 { margin: .25rem 0; font-size: 1.4rem; }
.totals { display: grid; grid-template-columns: repeat(4, auto); gap: .25rem 1.25rem; margin: 0; text-align: center; }
.totals dt { color: var(--muted); font-size: .8rem; grid-row: 1; }
.totals dd { margin: 0; font-size: 1.3rem; font-weight: 800; grid-row: 2; font-variant-numeric: tabular-nums; }
.lines { list-style: none; margin: 0; padding: 0; width: min(34rem, 100%); }
.lines li { display: flex; gap: .6rem; align-items: center; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.lines .sw { width: .9rem; height: .9rem; border-radius: .2rem; background: var(--bg, var(--muted)); flex: none; }
.lines .co { color: var(--muted); font-size: .85rem; }
.lines .t { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.done-actions { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: center; }
.button, .primary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 56px; padding: 0 1.25rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: .6rem; text-decoration: none; font-weight: 700;
}
.primary { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); z-index: 10;
  max-width: 90vw; padding: .6rem 1rem; border-radius: .6rem; background: #f8fafc; color: #0b1220; font-weight: 600;
}

/* ---------- document pages: login, person, admin, reports ---------- */
body.doc { min-height: 100%; }
.docbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.docbar .brand { font-weight: 800; text-decoration: none; margin-right: auto; }
.docbar nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.docbar form { margin: 0; }
.docmain { max-width: 60rem; margin: 0 auto; padding: 1rem; }
.card {
  max-width: 24rem; margin: 8vh auto 0; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 1rem;
}
.card h1 { margin: 0; font-size: 1.4rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select {
  min-height: 48px; padding: 0 .75rem; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: .5rem;
}
.error { margin: 0; padding: .6rem .8rem; border-radius: .5rem; background: #450a0a; color: #fecaca; }
.notice { margin: 0 0 1rem; padding: .6rem .8rem; border-radius: .5rem; background: #052e16; color: #bbf7d0; }
.hint { margin: 0; color: var(--muted); font-size: .85rem; }

/* ---------- admin and reports ---------- */
.docmain h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
.docmain h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.docmain h3 { font-size: 1rem; margin: 1.5rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tabs { display: flex; gap: .5rem; flex-wrap: wrap; }
.tabs a { padding: .6rem 1rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin: .75rem 0; }
.stack { display: flex; flex-direction: column; gap: .75rem; max-width: 26rem; margin: .75rem 0; }
.inline { display: inline-flex; gap: .25rem; margin: 0; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .4rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .8rem; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
td input, td select { min-height: 40px; max-width: 12rem; }
tr.off td { opacity: .55; }
tfoot td { color: var(--muted); }
.mini { min-height: 40px; padding: 0 .7rem; background: var(--panel); border: 1px solid var(--line); border-radius: .4rem; }
.mini.danger { color: var(--danger); }
.swatch { display: inline-block; width: .9rem; height: .9rem; margin-right: .4rem; border-radius: .2rem; background: var(--bg, var(--muted)); vertical-align: middle; }
.button.disabled { opacity: .35; }
.datenav .button { min-height: 48px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .5rem; margin: 1rem 0; }
.stats div { padding: .6rem .8rem; background: var(--panel); border: 1px solid var(--line); border-radius: .6rem; }
.stats dt { color: var(--muted); font-size: .8rem; }
.stats dd { margin: 0; font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats small { display: block; font-size: .75rem; font-weight: 400; color: var(--muted); }
.timeline { width: 100%; height: 2.5rem; border-radius: .4rem; display: block; }
.timeline rect { fill: var(--bg, #334155); }
.timeline rect.k-break { fill: #64748b; }
.timeline rect.k-unallocated { fill: #1e293b; }
