:root {
  --paper: #f5f5f1;
  --surface: #ffffff;
  --ink: #14213d;
  --ink-2: #3a4562;
  --muted: #6b7387;
  --line: #e2e4e9;
  --line-2: #c9cdd6;
  --accent: #f2a900;
  --accent-ink: #7a5200;
  --accent-soft: #fff3cc;
  --ok: #1e8e5a;
  --ok-soft: #e1f3e9;
  --warn: #b86e00;
  --warn-soft: #fff0d6;
  --bad: #b83227;
  --bad-soft: #fae3df;
  --flag: #6247aa;
  --flag-soft: #ebe6f7;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 33, 61, 0.05), 0 10px 28px -16px rgba(20, 33, 61, 0.25);
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
}
a { color: var(--ink); }
button { font: inherit; }
h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.15; }
.display { font-family: var(--font-display); font-weight: 500; font-size: 2rem; letter-spacing: -0.01em; font-variation-settings: 'opsz' 72; }
h2 { font-size: 1.05rem; font-weight: 600; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 0 0 0.35rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.inline { display: inline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- Top bar ---- */
.topbar { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 0.55rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-family: var(--font-display); font-size: 1.15rem; font-weight: 500; white-space: nowrap; }
.nav { display: flex; gap: 0.15rem; overflow-x: auto; flex: 1; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: rgba(255, 255, 255, 0.78); text-decoration: none; padding: 0.35rem 0.65rem; border-radius: 999px; white-space: nowrap; font-size: 0.92rem; }
.nav a.on { background: rgba(255, 255, 255, 0.14); color: #fff; }
.who { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; font-size: 0.85rem; }
.who-name { color: rgba(255, 255, 255, 0.85); }
.who-link { background: none; border: 0; color: rgba(255, 255, 255, 0.7); text-decoration: none; padding: 0.25rem 0.4rem; cursor: pointer; }
.who-link:hover { color: #fff; }
@media (max-width: 640px) {
  .who-name { display: none; }
  .topbar-inner { padding: 0.5rem 0.75rem; }
}

/* ---- Layout ---- */
.container { max-width: 720px; margin: 0 auto; padding: 1rem 1rem 4rem; }
.container.wide { max-width: 1100px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.stack > * + * { margin-top: 0.9rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }

/* ---- Login ---- */
.login { max-width: 400px; margin: 3.5rem auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem; box-shadow: var(--shadow); }

/* ---- Forms ---- */
.field { display: block; }
.field > span { display: block; font-size: 0.8rem; font-weight: 500; color: var(--ink-2); margin-bottom: 0.3rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: 0.65rem 0.75rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: #fff; color: var(--ink); font: inherit; font-size: 16px;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(242, 169, 0, 0.35); }
.field textarea { min-height: 84px; resize: vertical; }
.field .hint { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }
.field.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.field.checkbox input { width: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.65rem 1.05rem; border-radius: 999px; border: 1px solid var(--ink); background: var(--surface); color: var(--ink);
  text-decoration: none; font-weight: 500; cursor: pointer; line-height: 1.2; min-height: 44px; transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.btn-ghost { border-color: var(--line-2); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-sm { padding: 0.35rem 0.75rem; min-height: 34px; font-size: 0.86rem; }
.btn-block { width: 100%; }
.btn-lg { font-size: 1.15rem; padding: 0.95rem 1.5rem; min-height: 56px; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ---- Flash / toast ---- */
.flash { padding: 0.7rem 0.9rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; font-size: 0.95rem; }
.flash-ok { background: var(--ok-soft); color: #0f5c39; border-color: #bfe3cf; }
.flash-error { background: var(--bad-soft); color: #7d1f16; border-color: #f0c3bc; }
.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 0.7rem 1rem; border-radius: 999px; box-shadow: var(--shadow); font-size: 0.95rem; max-width: calc(100% - 2rem); z-index: 50; }
.toast.error { background: var(--bad); }

/* ---- Chips (status encodes meaning) ---- */
.chip { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 500; white-space: nowrap; background: var(--line); color: var(--ink-2); }
.chip-present, .chip-remote, .chip-half_day { background: var(--ok-soft); color: var(--ok); }
.chip-late { background: var(--warn-soft); color: var(--warn); }
.chip-absent, .chip-missing { background: var(--bad-soft); color: var(--bad); }
.chip-flagged { background: var(--flag-soft); color: var(--flag); }
.chip-leave, .chip-holiday, .chip-weekly_off, .chip-not_in { background: var(--line); color: var(--muted); }
.chip-overdue { background: var(--accent-soft); color: var(--accent-ink); }
.chip-done { background: var(--ok-soft); color: var(--ok); }
.chip-in_progress { background: var(--accent-soft); color: var(--accent-ink); }
.chip-revision { background: var(--flag-soft); color: var(--flag); }
.chip-failed { background: var(--bad-soft); color: var(--bad); }

/* ---- Day grid: one column per update slot, colour = whether it was filed ---- */
/* Containers only do layout. Colour lives on .dg / .dg.dg-<state> so a state always
   wins on specificity, wherever a cell is used (day grid, calendar, legend key). */
.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; }
.tally { display: flex; gap: 0.35rem; }

.daygrid { width: 100%; min-width: 320px; border-collapse: separate; border-spacing: 3px; table-layout: fixed; margin: 0.7rem 0 0; }
.daygrid th {
  padding: 0 0 0.3rem;
  border: 0;
  text-align: center;
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.25;
  white-space: nowrap;
}
.dg-to { display: block; color: var(--ink-2); }
.dg-from { display: block; font-size: 0.6rem; color: var(--muted); }
.daygrid td { padding: 0.4rem 0.15rem; text-align: center; vertical-align: middle; border-bottom: 0; }

/* The cell itself. */
.dg { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-sm); }
.dg-mark { display: block; font-size: 0.95rem; line-height: 1.1; font-weight: 600; color: var(--muted); }
.dg-note { display: block; font-family: var(--font-mono); font-size: 0.62rem; margin-top: 0.1rem; color: var(--muted); }

.dg.dg-done { background: var(--ok-soft); border-color: var(--ok); }
.dg.dg-done .dg-mark, .dg.dg-done .dg-note { color: var(--ok); }
.dg.dg-late { background: var(--warn-soft); border-color: var(--warn); }
.dg.dg-late .dg-mark, .dg.dg-late .dg-note { color: var(--warn); }
.dg.dg-missed { background: var(--bad-soft); border-color: var(--bad); }
.dg.dg-missed .dg-mark, .dg.dg-missed .dg-note { color: var(--bad); }
.dg.dg-due { background: var(--surface); border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-soft); }
.dg.dg-due .dg-mark, .dg.dg-due .dg-note { color: var(--accent-ink); }
.dg.dg-upcoming { background: var(--surface); border-style: dashed; }
.dg.dg-na { background: var(--paper); border-color: var(--line); }
/* A reason was given for this one. */
.dg.has-note { box-shadow: inset 0 -3px 0 var(--flag); }

.dg-btn { display: block; width: 100%; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.dg-why { display: block; font-size: 0.58rem; text-decoration: underline; opacity: 0.85; margin-top: 0.05rem; }

.reasons { list-style: none; margin: 0.6rem 0 0; padding: 0.5rem 0.7rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 0.84rem; color: var(--ink-2); display: grid; gap: 0.25rem; }
.reasons b { margin-right: 0.4rem; }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; margin: 0.65rem 0 0; padding: 0; font-size: 0.76rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 0.35rem; }
.legend .key { width: 13px; height: 13px; border-radius: 4px; flex: none; }

/* Calendar table: days down the side, update slots across the top. */
.caltable { border-collapse: separate; border-spacing: 3px; }
.caltable th[scope="col"] { text-transform: none; letter-spacing: 0; font-size: 0.72rem; border: 0; padding: 0 0.3rem 0.35rem; }
.caltable th[scope="col"].cal-slot { font-family: var(--font-mono); text-align: center; width: 34px; }
.caltable th[scope="row"] { border: 0; font-weight: 500; font-size: 0.85rem; padding: 0.3rem 0.4rem; white-space: nowrap; }
.caltable td { border-bottom: 0; padding: 0.3rem 0.4rem; vertical-align: middle; }
.caltable td.cal-cell { width: 34px; padding: 0; height: 26px; text-align: center; }
.cal-cell .dg-mark { font-size: 0.72rem; }

/* Compact variant: the admin dashboard's per-person strip. */
.daygrid.compact { width: auto; min-width: 0; border-spacing: 2px; margin: 0; table-layout: auto; }
.daygrid.compact td { padding: 0; width: 18px; min-width: 18px; height: 19px; }
.daygrid.compact .dg-mark { font-size: 0.62rem; }
.daygrid.compact .dg-note { display: none; }
.cal-head { text-transform: none; letter-spacing: 0; }
.cal-head .muted { font-family: var(--font-mono); font-size: 0.68rem; }

/* ---- Entry list ---- */
.entries { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.5rem; }
.entries > li { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.6rem 0.75rem; }
.e-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.e-project { font-size: 0.95rem; }
.e-qty { font-size: 0.84rem; color: var(--ink-2); white-space: nowrap; }
.e-desc { margin: 0.25rem 0 0.4rem; font-size: 0.9rem; color: var(--ink-2); overflow-wrap: anywhere; white-space: pre-wrap; }
.e-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.6rem; font-size: 0.78rem; color: var(--muted); }
.e-slot { font-family: var(--font-mono); color: var(--ink-2); background: var(--line); border-radius: 999px; padding: 0.1rem 0.45rem; }
.e-slot.is-late { background: var(--warn-soft); color: var(--warn); }

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.7rem 0.85rem; }
.stat b { display: block; font-family: var(--font-mono); font-size: 1.5rem; font-weight: 500; line-height: 1.1; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }
.stat.flag b { color: var(--flag); }
.stat.accent b { color: var(--accent-ink); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.1rem; padding: 0 1.1rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; white-space: nowrap; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
tr.dim td { color: var(--muted); }
tr.hi td { background: var(--accent-soft); }
.nowrap { white-space: nowrap; }
.wrap { white-space: normal; min-width: 220px; }

/* ---- Employee home ---- */
.today-card { position: relative; }
.clock { font-family: var(--font-mono); font-size: 2.6rem; font-weight: 500; letter-spacing: -0.02em; line-height: 1; }
.clock small { font-size: 1rem; color: var(--muted); font-family: var(--font-body); margin-left: 0.5rem; letter-spacing: 0; }
.status-line { margin: 0.5rem 0 0; color: var(--ink-2); }

/* The day strip: the shift as a track, with everything that happened on it. */
.daystrip { margin: 1.1rem 0 0.4rem; }
.daystrip-track { position: relative; height: 14px; background: var(--line); border-radius: 999px; overflow: visible; }
.daystrip-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--ink); border-radius: 999px; opacity: 0.18; }
.daystrip-window { position: absolute; top: 0; bottom: 0; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }
.daystrip-window.late { background: var(--bad); }
.daystrip-dot { position: absolute; top: 50%; width: 10px; height: 10px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); transform: translate(-50%, -50%); box-shadow: 0 0 0 1px var(--ink); }
.daystrip-dot.in { background: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
.daystrip-dot.out { background: var(--muted); box-shadow: 0 0 0 1px var(--muted); }
.daystrip-now { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--ink); transform: translateX(-50%); }
.daystrip-now::after { content: ''; position: absolute; top: -4px; left: 50%; width: 8px; height: 8px; background: var(--ink); border-radius: 50%; transform: translateX(-50%); }
.daystrip-labels { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); margin-top: 0.35rem; }
.daystrip-note { font-size: 0.85rem; color: var(--ink-2); margin: 0.35rem 0 0; }
.daystrip-note b { font-family: var(--font-mono); font-weight: 500; }
.daystrip-note.late b { color: var(--bad); }

.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 0.8rem; padding: 0.2rem; text-decoration: underline; }
.empty { padding: 1.2rem; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--radius-sm); }

/* ---- Attendance calendar list ---- */
.daylist { list-style: none; margin: 0; padding: 0; }
.daylist li { display: grid; grid-template-columns: 110px 1fr auto; gap: 0.5rem; padding: 0.55rem 0; border-top: 1px solid var(--line); align-items: center; font-size: 0.92rem; }
.daylist li:first-child { border-top: 0; }
.daylist .d { font-family: var(--font-mono); font-size: 0.85rem; }
.daylist .t { color: var(--ink-2); }

/* ---- Filters ---- */
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 130px; flex: 1; }
.filters .field input, .filters .field select { padding: 0.5rem 0.6rem; font-size: 0.95rem; }

details.settings-block { border-top: 1px solid var(--line); padding: 0.4rem 0; }
details.settings-block summary { cursor: pointer; font-weight: 600; padding: 0.5rem 0; }
.summary-text { white-space: pre-wrap; font-size: 0.92rem; line-height: 1.5; }
.pill-list { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.pill { border: 1px solid var(--line-2); background: #fff; border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.82rem; cursor: pointer; }
.pill:hover { border-color: var(--ink); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.9rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.ok-dot::before { content: '●'; color: var(--ok); margin-right: 0.35rem; }
.off-dot::before { content: '●'; color: var(--line-2); margin-right: 0.35rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- Add to home screen banner ---- */
.install { display: flex; gap: 0.75rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: 0.7rem 0.85rem; margin-bottom: 1rem; }
.install-icon img { border-radius: 10px; display: block; }
.install-text { flex: 1; font-size: 0.88rem; line-height: 1.35; }
.install-text > b { display: block; margin-bottom: 0.1rem; }
.install-text span { color: var(--muted); }
.install-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem; }
.login .install, .container > .install { max-width: 400px; margin-left: auto; margin-right: auto; }
@media (display-mode: standalone) { .install { display: none !important; } }

/* ---- Payroll ---- */
.warn-text { color: var(--warn); }
table.payroll td { vertical-align: middle; }
table.payroll tr.paid td { background: var(--ok-soft); }
input.cell { width: 82px; padding: 0.35rem 0.45rem; border: 1px solid var(--line-2); border-radius: 7px; font: inherit; font-family: var(--font-mono); font-size: 0.86rem; text-align: right; }
input.cell.wide { width: 160px; font-family: var(--font-body); text-align: left; }
.payslip-table { width: 100%; }
.payslip-table td { padding: 0.4rem 0.3rem; border-bottom: 1px solid var(--line); }
.payslip-table tr.total td { font-weight: 600; border-bottom: 0; border-top: 2px solid var(--ink); font-size: 1.05rem; }
@media print {
  .topbar, .no-print, .toast, .install { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; }
}
