/* ── tokens ─────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --line: #dfe4e8;
  --text: #16242a;
  --text-dim: #64757d;
  --accent: #0f5c58;
  --accent-soft: #e4efee;
  --present: #157f4a;
  --present-bg: #dff4e6;
  --absent: #b3261e;
  --absent-bg: #fce4e2;
  --leave: #2457c5;
  --leave-bg: #e1eafc;
  --sick: #a35a00;
  --sick-bg: #fdefd2;
  /* Sundays and public holidays: a darker grey day, darker green if worked */
  --off-bg: #dde3e6;
  --off-head: #c7d0d5;
  --worked-off-bg: #8fd1a6;
  --worked-off: #0b4f2a;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 38, .06), 0 4px 14px rgba(16, 32, 38, .05);
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1416;
    --surface: #151f22;
    --surface-2: #1d292d;
    --line: #2a383d;
    --text: #e6edef;
    --text-dim: #93a4ab;
    --accent: #4fd1c5;
    --accent-soft: #14312f;
    --present: #5fd08a;
    --present-bg: #14301f;
    --absent: #ff9188;
    --absent-bg: #36191a;
    --leave: #93b4ff;
    --leave-bg: #18243f;
    --sick: #f2b45c;
    --sick-bg: #33260f;
    --off-bg: #243135;
    --off-head: #34454b;
    --worked-off-bg: #1f6b3e;
    --worked-off: #c8f5d8;
    --danger: #ff9188;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

/*
 * The browser's own [hidden] rule is display:none, but any author rule with a
 * display (.summary{display:grid}, .btn-row{display:flex} …) outranks it and
 * the element stays on screen. Anything toggled with el.hidden needs this.
 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── app bar ────────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--accent);
  color: #fff;
  padding-top: var(--safe-t);
}
@media (prefers-color-scheme: dark) {
  .appbar { background: #0f1b1e; border-bottom: 1px solid var(--line); }
}
.appbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; min-height: 48px;
}
.brand { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .3px; }
.bar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: rgba(255, 255, 255, .16); color: inherit; border: 0;
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 14px;
  font-weight: 600; cursor: pointer;
}

/* sync state, always visible in the bar */
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, .16); color: inherit; border: 0;
  border-radius: 999px; padding: 7px 13px; font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; max-width: 58vw;
}
.sync-chip span:last-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot {
  flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: #cbd5d3;
}
.dot.ok      { background: #5fd08a; }
.dot.pending { background: #f5c451; }
.dot.error   { background: #ff8a80; }
.dot.busy    { background: #7fd3ff; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.sync-line { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.sync-sub { margin: 0 0 12px; font-size: 13.5px; color: var(--text-dim); line-height: 1.5; }
.sync-sub:empty { margin: 0; }

#codeInput {
  text-transform: uppercase; letter-spacing: 1.5px;
  font-size: 17px; font-weight: 650; text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#connectForm .field { margin-bottom: 12px; }

/* nudge on the register when this phone is still standalone */
.sync-nudge {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 11px 13px; margin-bottom: 14px;
}
.sync-nudge p { flex: 1; margin: 0; font-size: 13.5px; color: var(--text-dim); line-height: 1.45; }
.sync-nudge button {
  flex: none; border: 0; background: none; color: var(--accent);
  font: inherit; font-size: 13.5px; font-weight: 700; cursor: pointer; padding: 6px;
}

/* ── layout ─────────────────────────────────────────────── */
#main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}
.view-title { margin: 2px 0 14px; font-size: 20px; font-weight: 650; }

/* ── date bar ───────────────────────────────────────────── */
.datebar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px; margin-bottom: 14px;
}
.datebar-center { flex: 1; min-width: 0; text-align: center; }
.step-btn {
  flex: none; width: 42px; height: 42px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.step-btn:active { transform: scale(.94); }
.date-label { position: relative; display: block; font-weight: 650; font-size: 16.5px; cursor: pointer; }
.date-label input[type="date"] {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%;
  border: 0; cursor: pointer;
}
.link-btn {
  background: none; border: 0; color: var(--accent); font: inherit;
  font-size: 13px; font-weight: 600; padding: 2px 4px; cursor: pointer;
}

/* ── chips ──────────────────────────────────────────────── */
.chiprow {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  margin-bottom: 14px; scrollbar-width: none;
}
.chiprow::-webkit-scrollbar { display: none; }
.chiprow.tight { margin-bottom: 12px; flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; padding: 9px 15px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text-dim); font: inherit; font-size: 14.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.chip.is-active {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent);
}

/* ── summary ────────────────────────────────────────────── */
.summary {
  /*
   * four tiles, plus hours only / leave / sick on a day they apply; on a
   * phone a day with all of them wraps onto a second row
   */
  display: grid; grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 8px;
  margin-bottom: 12px;
}
.summary-item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; padding: 9px 6px; text-align: center;
}
.summary-item b { display: block; font-size: 19px; font-weight: 700; line-height: 1.2; }
.summary-item span { display: block; font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.bulkrow { display: flex; gap: 8px; margin-bottom: 14px; }

/* ── roster ─────────────────────────────────────────────── */
.roster { display: flex; flex-direction: column; gap: 18px; }
.team-block { display: flex; flex-direction: column; gap: 10px; }

/* team header — one tap marks the whole crew present */
.team {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid var(--accent);
}
.team-info { flex: 1; min-width: 0; }
.team-name {
  font-size: 15.5px; font-weight: 700; color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.team-count { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }
.team-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 13px; border-radius: 11px;
  border: 1.5px solid var(--accent); background: var(--surface);
  color: var(--accent); font: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.team-btn svg { width: 17px; height: 17px; stroke-width: 3; }
.team-btn.on { background: var(--present-bg); border-color: var(--present); color: var(--present); }
.team-btn:active { transform: scale(.96); }
.worker {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px;
}
.worker-top { display: flex; align-items: center; gap: 12px; }
.worker-name {
  flex: 1; min-width: 0; font-size: 16px; font-weight: 600;
  /* the whole name, always: a long one wraps rather than being cut off */
  overflow-wrap: anywhere; line-height: 1.25;
}
.seg { display: flex; gap: 6px; flex: none; }
.seg button {
  min-width: 46px; height: 40px; padding: 0 10px;
  border-radius: 11px; border: 1.5px solid var(--line);
  background: var(--surface-2); color: var(--text-dim);
  font: inherit; font-size: 14.5px; font-weight: 700; cursor: pointer;
}
.seg button:active { transform: scale(.95); }
.seg button.on-p { background: var(--present-bg); border-color: var(--present); color: var(--present); }
.seg button.on-a { background: var(--absent-bg); border-color: var(--absent); color: var(--absent); }
/* H — came in, but worked only some hours */
.seg button.on-h { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
/* L — on leave; SL — off sick */
.seg button.on-l { background: var(--leave-bg); border-color: var(--leave); color: var(--leave); }
.seg button.on-s { background: var(--sick-bg); border-color: var(--sick); color: var(--sick); }
/*
 * On a phone A, L and SL are one button that steps through them, so the
 * name keeps its room; the PC shows all five (see the 900px block).
 */
.seg .wide-only { display: none; }
.seg button.off-cycle { position: relative; min-width: 50px; padding-bottom: 6px; }
.off-cycle .steps {
  position: absolute; left: 0; right: 0; bottom: 5px;
  display: flex; justify-content: center; gap: 3px;
}
.off-cycle .steps i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .3; }
.off-cycle .steps i.at { opacity: 1; }
.extra.short label { color: var(--accent); font-weight: 600; }

.extra {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line);
}
.extra label { flex: 1; font-size: 13px; color: var(--text-dim); font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 5px; flex: none; }
.stepper button {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.stepper input {
  width: 58px; height: 34px; text-align: center; font: inherit;
  font-size: 15px; font-weight: 650; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input[type="number"] { -moz-appearance: textfield; }

/* ── workers admin ──────────────────────────────────────── */
.addform { display: flex; gap: 8px; margin-bottom: 16px; }
.addform input {
  flex: 1; min-width: 0; height: 46px; padding: 0 13px; font: inherit;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.site-block {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 14px; overflow: hidden;
}
.site-head {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 13px; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.site-head h3 {
  flex: 1; margin: 0; font-size: 15.5px; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mini-btn {
  background: none; border: 0; color: var(--text-dim); font: inherit;
  font-size: 13px; font-weight: 600; padding: 6px 8px; cursor: pointer;
  border-radius: 8px;
}
.mini-btn.danger { color: var(--danger); }
.worker-line {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 13px; border-bottom: 1px solid var(--line);
}
.worker-line:last-child { border-bottom: 0; }
.worker-line span {
  flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; font-size: 15.5px;
}
.worker-line.inactive span { color: var(--text-dim); text-decoration: line-through; }
.site-foot { padding: 11px 13px; }

/* ── export ─────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 14px;
}
.muted-card { background: var(--surface-2); box-shadow: none; }
.card-title { margin: 0 0 11px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }
.card-note { margin: 0 0 12px; font-size: 13.5px; line-height: 1.5; color: var(--text-dim); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: block; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; height: 46px; padding: 0 11px; font: inherit;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.preview { margin: 0 0 12px; font-size: 14px; color: var(--text-dim); text-align: center; }
.hint { margin: 10px 0 20px; font-size: 13px; color: var(--text-dim); text-align: center; line-height: 1.5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── buttons ────────────────────────────────────────────── */
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 20px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font: inherit; font-size: 16px;
  font-weight: 650; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .primary-btn { color: #06201f; } }
.primary-btn.compact { height: 46px; padding: 0 16px; font-size: 15px; }
.primary-btn.wide { width: 100%; }
.primary-btn:active { transform: scale(.985); }
.primary-btn[disabled] { opacity: .45; cursor: default; }
.btn-icon { width: 19px; height: 19px; }

.ghost-btn {
  flex: 1; min-height: 44px; padding: 0 10px; border-radius: 11px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.ghost-btn.danger { color: var(--danger); }
.ghost-btn:active { transform: scale(.98); }

/* ── empty state ────────────────────────────────────────── */
.empty {
  text-align: center; padding: 40px 20px; color: var(--text-dim);
}
.empty h3 { margin: 0 0 8px; font-size: 17px; color: var(--text); font-weight: 650; }
.empty p { margin: 0 auto 18px; font-size: 14.5px; line-height: 1.55; max-width: 34ch; }

/* ── tab bar ────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; height: var(--tabbar-h);
  border: 0; background: none; color: var(--text-dim);
  font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.tab svg { width: 21px; height: 21px; }
.tab.is-active { color: var(--accent); }

/* ── toast ──────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 40;
  max-width: calc(100vw - 32px);
  background: #16242a; color: #fff; border-radius: 11px;
  padding: 11px 16px; font-size: 14.5px; font-weight: 500;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) { .toast { background: #2b393e; } }

/* ── records grid ───────────────────────────────────────── */
/*
 * A month as a table: sticky day headers across the top, sticky worker names
 * down the side. Only reachable on a wide screen — see the desktop block
 * below, which is what puts the tab there.
 */
.month-text { font-size: 16.5px; font-weight: 650; }

.grid-wrap {
  overflow: auto;
  max-height: calc(100vh - 260px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
/*
 * Fixed layout: the name and total columns take the widths set on their
 * <col>s, and the day columns split the rest evenly — so the whole month
 * fits the window instead of running off the right-hand side.
 */
.grid {
  width: 100%; table-layout: fixed;
  border-collapse: separate; border-spacing: 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.grid col.col-name { width: clamp(120px, 11vw, 190px); }
.grid col.col-tot { width: 42px; }
.grid th, .grid td {
  margin: 0; padding: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

/* header row */
.grid thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface-2);
  font-size: 11px; font-weight: 700; color: var(--text-dim);
  padding: 5px 2px;
}
.grid thead .corner { z-index: 5; left: 0; text-align: left; padding-left: 10px; }
.grid .day { overflow: hidden; }
/* Sunday or a public holiday — darker. Saturday is an ordinary day here. */
.grid .day.off { color: var(--text); background: var(--off-head); }
.grid .day.is-today { background: var(--accent); color: #fff; }
.grid .day.is-today .dwd { color: rgba(255, 255, 255, .8); }
.grid .dnum { display: block; font-size: 12.5px; color: var(--text); }
.grid .day.is-today .dnum { color: #fff; }
.grid .dwd { display: block; font-size: 9.5px; font-weight: 600; }

/* worker column */
.grid .name {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  text-align: left; font-size: 13.5px; font-weight: 500;
  padding: 5px 8px;
  /* a long name is cut with … rather than widening the column; hover shows it */
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.grid tr.gone .name { color: var(--text-dim); }
/* a team's name may run on over its (empty) banner row */
.grid tr.group .name { overflow: visible; }
.tag {
  display: inline-block; margin-left: 6px; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-dim);
}

/* one day for one worker */
.grid td.c { position: relative; }
.grid td.c.off { background: var(--off-bg); }
.grid td.c.is-today { background: var(--accent-soft); }
/*
 * The bottom strip is always reserved for the hours badge, whether or not
 * there are hours, so nothing jumps when one is added and the P never sits
 * under its own badge.
 */
.cell {
  position: relative;
  display: block; width: 100%; height: 38px; padding: 0 0 12px; border: 0;
  background: none; font: inherit; font-size: 13px; font-weight: 700;
  color: var(--text-dim); cursor: pointer;
}
.cell.on-p { background: var(--present-bg); color: var(--present); }
.cell.on-a { background: var(--absent-bg); color: var(--absent); }
.cell.on-h { background: var(--accent-soft); color: var(--accent); }
.cell.on-l { background: var(--leave-bg); color: var(--leave); }
.cell.on-s { background: var(--sick-bg); color: var(--sick); letter-spacing: -.5px; }
/*
 * A full day (P) on a Sunday or public holiday: darker green, so the days
 * that earn Sunday or holiday pay stand out. An H there keeps its own look
 * (its hours count under Extra), and an A stays plain red.
 */
.cell.worked-off { background: var(--worked-off-bg); color: var(--worked-off); }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* the strip along the bottom of a present day, which sets extra hours */
.xb {
  position: absolute; left: 2px; right: 2px; bottom: 2px;
  height: 13px; padding: 0; border: 0; border-radius: 4px;
  background: var(--surface-2); color: var(--text-dim);
  font: inherit; font-size: 9.5px; font-weight: 700; line-height: 13px;
  cursor: pointer; opacity: 0;
  overflow: hidden; white-space: nowrap; letter-spacing: -.2px;
}
.xb.set { opacity: 1; background: var(--accent); color: var(--surface); }
/* on an H the strip is the hours worked, not overtime — outlined, not filled */
.xb.short { background: var(--surface); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.grid td.c:hover .xb, .xb:focus { opacity: 1; }
.xb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/*
 * The list of every mark that opens beside a day on Records. Fixed to the
 * window rather than inside the grid, so the grid's scrolling box never
 * clips it.
 */
.markmenu {
  position: fixed; z-index: 30; min-width: 190px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px;
  box-shadow: 0 10px 30px rgba(16, 32, 38, .18), 0 2px 6px rgba(16, 32, 38, .08);
}
.mm-head {
  padding: 6px 8px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.mm-head span { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-dim); }
.mm-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 8px; background: none;
  font: inherit; font-size: 14px; color: var(--text); text-align: left; cursor: pointer;
}
.mm-item small { color: var(--text-dim); font-size: 12px; }
.mm-item:hover, .mm-item:focus-visible { background: var(--surface-2); outline: none; }
.mm-item.is-on { font-weight: 700; }
.mm-item.is-on::after { content: '\2713'; margin-left: auto; color: var(--accent); }
.mm-key {
  flex: none; width: 30px; height: 24px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); color: var(--text-dim); border: 1px dashed var(--line);
}
.mm-key.on-p { background: var(--present-bg); color: var(--present); border: 0; }
.mm-key.on-a { background: var(--absent-bg); color: var(--absent); border: 0; }
.mm-key.on-h { background: var(--accent-soft); color: var(--accent); border: 0; }
.mm-key.on-l { background: var(--leave-bg); color: var(--leave); border: 0; }
.mm-key.on-s { background: var(--sick-bg); color: var(--sick); border: 0; }
.mm-clear { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; padding-top: 8px; }

/* group and total rows */
.grid tr.group th, .grid tr.group td { background: var(--accent-soft); }
.grid tr.group .name { color: var(--accent); font-weight: 700; font-size: 14px; }
.grid tr.subtotal th, .grid tr.subtotal td { background: var(--surface-2); font-weight: 700; }

/*
 * The seven totals — Present (ordinary days), Absent, Leave, Sick leave,
 * Extra (overtime plus the hours of H days), Sundays, Holidays. The month normally fits without scrolling now; on a window too
 * narrow for that they stay pinned to the right while the days scroll under
 * them. Offsets are multiples of the 42px column set on col.col-tot.
 */
.grid .tot {
  position: sticky; z-index: 2;
  text-align: center;
  background: var(--surface); font-weight: 600; padding: 4px 2px;
  overflow: hidden; white-space: nowrap;
}
.grid .tot:nth-last-child(7) { right: 252px; border-left: 2px solid var(--line); }
.grid .tot:nth-last-child(6) { right: 210px; }
.grid .tot:nth-last-child(5) { right: 168px; }
.grid .tot:nth-last-child(4) { right: 126px; }
.grid .tot:nth-last-child(3) { right: 84px; }
.grid .tot:nth-last-child(2) { right: 42px; }
.grid .tot:last-child { right: 0; }
.grid thead .tot { z-index: 4; background: var(--surface-2); color: var(--text-dim); }
.grid tr.subtotal .tot { background: var(--surface-2); }

/* ── search ─────────────────────────────────────────────── */
.searchbar {
  position: relative; display: flex; align-items: center;
  margin-bottom: 14px;
}
.search-icon {
  position: absolute; left: 12px; width: 18px; height: 18px;
  color: var(--text-dim); pointer-events: none;
}
.searchbar input {
  width: 100%; height: 44px; padding: 0 40px; font: inherit; font-size: 15px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.searchbar input::-webkit-search-cancel-button { -webkit-appearance: none; }
.searchbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-clear {
  position: absolute; right: 6px; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: none; color: var(--text-dim);
  font: inherit; font-size: 20px; line-height: 1; cursor: pointer;
}

.filter-note {
  margin: -4px 0 12px; font-size: 13px; color: var(--text-dim); text-align: center;
}

/* ── a note against the day's mark ──────────────────────── */
.noterow { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.note-add {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: none; padding: 2px 0;
  color: var(--text-dim); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.note-add svg { width: 15px; height: 15px; stroke-width: 2.5; }
.note-input {
  width: 100%; height: 38px; padding: 0 11px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
.note-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* the corner flag on a Records cell that carries one */
.has-note {
  position: absolute; top: 2px; right: 2px;
  width: 0; height: 0;
  border-top: 5px solid var(--accent);
  border-left: 5px solid transparent;
}

/* ── a mouse can drag the chip rows sideways ────────────── */
.chiprow { touch-action: pan-x; }
.chiprow.dragging { user-select: none; cursor: grabbing; }
.chiprow.dragging .chip { pointer-events: none; }
@media (hover: hover) {
  .chiprow { cursor: grab; }
}

/* ── wide screens ───────────────────────────────────────── */
/*
 * Phone-first up to here. On a monitor the tab bar becomes a side rail, the
 * teams sit side by side instead of end to end, and the Records tab appears.
 */
.tab.wide-only { display: none; }

@media (min-width: 900px) {
  :root { --rail-w: 214px; --appbar-h: 68px; }

  .tab.wide-only { display: flex; }

  .tabbar {
    top: var(--appbar-h); right: auto; bottom: 0;
    width: var(--rail-w); z-index: 10;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    gap: 4px; padding: 14px 10px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tab {
    flex: none; flex-direction: row; justify-content: flex-start;
    gap: 12px; height: 46px; padding: 0 14px;
    border-radius: 11px; font-size: 14.5px;
  }
  .tab.is-active { background: var(--accent-soft); }

  #main {
    margin: 0 0 0 var(--rail-w);
    max-width: 1460px;
    padding: 22px 30px 56px;
  }
  /* Records wants every pixel across, so the whole month fits */
  body[data-view="records"] #main { max-width: none; padding-left: 18px; padding-right: 18px; }

  .view-title { font-size: 23px; margin-bottom: 18px; }

  /*
   * Use the monitor: the team header keeps the full width and its workers
   * flow into as many columns as fit, so a whole crew — or every crew — is
   * on screen without scrolling.
   */
  /* all five marks as their own buttons, and cards wide enough that the
     name beside them is not squeezed */
  .seg .wide-only { display: block; }
  .seg .narrow-only { display: none; }
  .team-block {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr));
    gap: 10px; align-items: start;
  }
  .team-block .team { grid-column: 1 / -1; }

  .summary { max-width: 620px; }
  .summary-item { padding: 12px 8px; }
  .summary-item b { font-size: 23px; }
  .summary-item span { font-size: 12px; }

  .datebar, .bulkrow, .chiprow, .sync-nudge,
  .searchbar, .filter-note { max-width: 620px; }
  #view-records .datebar, #view-records .chiprow,
  #view-records .searchbar { max-width: none; }
  .toast { bottom: 24px; }

  /* these screens are forms — they do not want to be 1400px wide */
  #view-workers, #view-export, #view-sync { max-width: 720px; }
}

/* ── a mouse is present ─────────────────────────────────── */
@media (hover: hover) {
  .chip:hover, .step-btn:hover, .mini-btn:hover,
  .ghost-btn:hover, .tab:hover { border-color: var(--accent); color: var(--accent); }
  .tab:hover { border: 0; }
  .seg button:hover, .team-btn:hover, .stepper button:hover { border-color: var(--accent); }
  .primary-btn:hover { filter: brightness(1.08); }
  .cell:hover { box-shadow: inset 0 0 0 2px var(--accent); }
  .xb:hover { background: var(--accent); color: var(--surface); }
  .worker:hover { border-color: var(--line); box-shadow: var(--shadow); }
}

/* ── inside the desktop shell ───────────────────────────── */
/* There is nothing to install — this is the installed thing. */
.is-desktop #installBtn { display: none !important; }

/* ── the in-app question box (replaces prompt()) ─────────── */
.ask {
  width: min(400px, calc(100vw - 32px));
  padding: 0; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.ask::backdrop { background: rgba(10, 20, 24, .45); }
.ask form { padding: 20px 20px 16px; }
.ask h3 { margin: 0 0 6px; font-size: 17px; font-weight: 650; }
.ask p {
  margin: 0 0 14px; font-size: 13.5px; line-height: 1.5;
  color: var(--text-dim); white-space: pre-line;
}
.ask input {
  width: 100%; height: 46px; padding: 0 12px; font: inherit; font-size: 17px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface-2); color: var(--text);
}
.ask input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .step-btn:active, .seg button:active, .primary-btn:active, .ghost-btn:active { transform: none; }
}
