:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1c2330; --muted: #5f6b7a; --line: #d9dde3;
  --brand: #9b1c1c; --brand-ink: #ffffff; --head: #3f5568; --head-ink: #ffffff;
  --open: #d11a1a; --mine: #1f4fd1; --off: #1f4fd1; --pick: #7b2cbf; --ok: #1d7a3a; --warn: #a15c00; --bad: #b42318;
  --chip-ok: #e3f4e8; --chip-warn: #fff1d6; --chip-bad: #fde7e5; --chip-open: #eef1f5;
  --today: #fff8db; --focus: #2b6cff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1b2129; --ink: #e8ecf1; --muted: #9aa6b5; --line: #2e3742;
    --head: #2c3c4b; --open: #ff6b6b; --mine: #7aa2ff; --off: #7aa2ff; --pick: #c9a0ff; --ok: #58c27d; --warn: #f2b45c; --bad: #ff8577;
    --chip-ok: #193325; --chip-warn: #3a2c12; --chip-bad: #3d1d1a; --chip-open: #26303b; --today: #2c2a1a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--mine); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  background: var(--brand); color: var(--brand-ink); padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand img { width: 28px; height: 28px; border-radius: 6px; }
.nav { display: none; gap: 4px; flex: 1; }
.nav a, .tabbar a { color: inherit; text-decoration: none; }
.nav a { padding: 6px 10px; border-radius: 6px; opacity: .9; }
.nav a.on { background: rgba(255,255,255,.18); opacity: 1; font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.who button { background: rgba(255,255,255,.15); border: 0; color: inherit; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--panel);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; text-align: center; padding: 10px 2px; font-size: 12px; color: var(--muted); }
.tabbar a.on { color: var(--brand); font-weight: 700; }
.tabbar a span { display: block; font-size: 18px; line-height: 1.1; }
@media (min-width: 900px) {
  .nav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 0; }
}
.offline { background: var(--chip-warn); color: var(--warn); text-align: center; padding: 6px; font-size: 14px; }

main { padding: 16px; max-width: 1700px; margin: 0 auto; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 20px 0 8px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.bar .grow { flex: 1; }
.btn { background: var(--panel); border: 1px solid var(--line); padding: 7px 12px; border-radius: 7px; cursor: pointer; min-height: 36px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.good { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 3px 8px; min-height: 28px; font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip-open); white-space: nowrap; }
.chip.ok { background: var(--chip-ok); color: var(--ok); }
.chip.warn { background: var(--chip-warn); color: var(--warn); }
.chip.bad { background: var(--chip-bad); color: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--head); color: var(--head-ink); }
label.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

/* ---------- month schedule (mirrors the current layout) ---------- */
.month { display: grid; grid-template-columns: repeat(7, minmax(var(--col, 0px), 1fr)); border-left: 1px solid var(--line); border-top: 1px solid var(--line); background: var(--panel); font-size: 11.5px; letter-spacing: -0.1px; }
.month .ln > span:first-child { font-variant-numeric: tabular-nums; }
.month .dow .ds { display: none; }
.month .dow { background: var(--head); color: var(--head-ink); text-align: center; font-weight: 700; padding: 4px; border-right: 1px solid var(--line); }
.day { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 110px; padding: 2px 3px 6px; min-width: 0; overflow: hidden; }
.day.other { background: color-mix(in srgb, var(--bg) 60%, var(--panel)); }
.day.other .dnum { color: var(--muted); }
.day.today { background: var(--today); }
.dnum { font-weight: 700; font-size: 14px; padding: 2px 2px 4px; display: flex; justify-content: space-between; align-items: center; }
.dnum button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.grp { margin-bottom: 6px; }
.grp-h { font-weight: 700; font-size: 13px; padding: 2px 4px; border-left: 3px solid rgba(0,0,0,.25); color: #1c2330; }
.ln { display: grid; grid-template-columns: max-content minmax(0, 1fr) 8px; gap: 6px; padding: 1px 2px; cursor: pointer; border-radius: 3px; align-items: center; white-space: nowrap; }
.ln:hover { background: color-mix(in srgb, var(--focus) 10%, transparent); }
.ln .who { overflow: hidden; text-overflow: ellipsis; display: block; margin: 0; }
.ln.open { color: var(--open); }
.ln.mine { color: var(--pick); font-weight: 600; }
.ln .st { width: 8px; height: 8px; border-radius: 50%; }
.st.pending { background: var(--warn); } .st.approved { background: var(--ok); } .st.rejected { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin: 8px 0; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

.phone-only { display: none; }
/* month zoom (pinch / − + on phones) */
.month-wrap { overflow-x: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.month-wrap.zoomed { max-height: calc(100dvh - 170px); overflow: auto; border-bottom: 1px solid var(--line); }
.month-wrap.zoomed .month .dow { position: sticky; top: 0; z-index: 2; }
.month.zoomed { font-size: 12.5px; }
.month.zoomed .ln { padding: 3px 2px; }
.month.zoomed .grp-h { font-size: 13.5px; }
.seg.zoom button { min-width: 38px; font-size: 15px; padding: 6px 10px; }
.legend-wrap { margin: 6px 0; font-size: 13px; color: var(--muted); }
.legend-wrap summary { cursor: pointer; }
@media (max-width: 759px) {
  main { padding: 10px; }
  .month { font-size: 11px; }
  .month .ln { gap: 4px; }
  .day { min-height: 90px; }
  .desk-only { display: none; }
  .phone-only { display: inline; }
  /* zoomed in on a phone: time on its own row, then the person (two-line lines) */
  .month.zoomed .ln { grid-template-columns: minmax(0, 1fr) 8px; gap: 0 4px; row-gap: 0; padding: 3px 2px; border-bottom: 1px dotted var(--line); }
  .month.zoomed .ln > span:first-child { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
  .month.zoomed .ln.open > span:first-child, .month.zoomed .ln.off > span:first-child { color: inherit; }
  .month.zoomed .ln .who { white-space: nowrap; }
  .month:not(.zoomed) .pos:not(.off-code) { display: none; }
  /* squeezed to fit a phone: just start time + name, smaller headers */
  .month:not(.zoomed) .dur { display: none; }
  .month:not(.zoomed) .ln { grid-template-columns: 1fr; gap: 0; padding: 2px 1px; border-bottom: 1px dotted var(--line); }
  .month:not(.zoomed) .ln .st { display: none; }
  .month:not(.zoomed) .grp-h { font-size: 10.5px; padding: 1px 2px; }
  .month:not(.zoomed) .dow { font-size: 11px; padding: 4px 0; }
  .month:not(.zoomed) .dow .dl { display: none; }
  .month:not(.zoomed) .dow .ds { display: inline; }
  .month:not(.zoomed) .dnum { font-size: 12px; }
  .bar h1 { font-size: 19px; }
  .bar label.chk { font-size: 13px; }
}

/* agenda (phones) */
.agenda .aday { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.agenda .aday.today { outline: 2px solid var(--brand); }
.agenda .ah { background: var(--head); color: var(--head-ink); padding: 6px 10px; font-weight: 700; display: flex; justify-content: space-between; }
.agenda .grp { padding: 4px 8px 0; }
.agenda .ln { grid-template-columns: max-content minmax(0,1fr) 10px; font-size: 14px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.agenda .ln:last-child { border-bottom: 0; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: color-mix(in srgb, var(--head) 12%, var(--panel)); font-size: 13px; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.sub td { background: color-mix(in srgb, var(--head) 7%, var(--panel)); font-weight: 700; }
tr:last-child td { border-bottom: 0; }

/* ---------- payroll steps ---------- */
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.step { flex: 1; min-width: 140px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.step b { display: block; font-size: 14px; }
.step.done { border-color: var(--ok); background: var(--chip-ok); }
.step.now { border-color: var(--warn); background: var(--chip-warn); }

/* ---------- dialog & forms ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,15,20,.5); }
#dlgForm { padding: 18px; max-height: 85vh; overflow: auto; }
#dlgForm h3 { margin: 0 0 12px; }
.f { display: grid; gap: 4px; margin-bottom: 10px; font-size: 14px; }
.f input, .f select, .f textarea { padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.actions .left { margin-right: auto; }
.err { color: var(--bad); font-size: 14px; min-height: 1em; }
.dows { display: flex; gap: 4px; flex-wrap: wrap; }
.dows label { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 13px; cursor: pointer; }
.dows input { margin: 0 4px 0 0; }

.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: #1c2330; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.bad { background: var(--bad); }

.signin { max-width: 420px; margin: 10vh auto; text-align: center; }
.signin img { width: 84px; height: 84px; border-radius: 16px; }
.signin .btn { width: 100%; margin-top: 12px; padding: 12px; font-size: 16px; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.grid-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }

@media print {
  .topbar, .tabbar, .bar, .noprint { display: none !important; }
  main { padding: 0; }
  .day { min-height: 0; }
}

/* compact inputs inside tables (admin editors) */
.tbl-wrap input:not([type=checkbox]), .tbl-wrap select, table input:not([type=checkbox]), table select {
  padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); max-width: 100%;
}
dialog td, dialog th { white-space: nowrap; }
.daylink { border: 0; background: none; font: inherit; font-weight: 700; color: var(--ink); cursor: pointer; padding: 0 4px; border-radius: 4px; text-decoration: underline dotted; text-underline-offset: 3px; }
.daylink:hover { background: color-mix(in srgb, var(--focus) 15%, transparent); }
details summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
dialog ul { margin: 8px 0 0; padding-left: 20px; }
.ln.off { color: var(--off); font-style: italic; font-weight: 400; }
.ln.off .who::before { content: ''; }
