:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --text: #16181d;
  --text-2: #525866;
  --muted: #8a909c;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fb;
  --danger: #c62f2f;
  --danger-soft: #fbe7e7;
  --warn: #9a6200;
  --warn-soft: #fff3d6;
  --ok: #17803d;
  --ok-soft: #e3f4e8;
  --series-1: #2a78d6;
  --grid: #e7e9ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);

  --st-P: #e3f4e8; --st-P-ink: #17643a;
  --st-WFH: #e0ecfb; --st-WFH-ink: #1e5aa3;
  --st-F: #ebe7fb; --st-F-ink: #4b3bb0;
  --st-HD: #fff1cc; --st-HD-ink: #8a5a00;
  --st-A: #fbe1e1; --st-A-ink: #a52626;
  --st-L: #dcf3f0; --st-L-ink: #11665c;
  --st-LWP: #f4e6d8; --st-LWP-ink: #80461a;
  --st-WO: #eceef1; --st-WO-ink: #5c6370;
  --st-MO: #ffe2cc; --st-MO-ink: #a1420c;
  --st-NA: #f4f5f7; --st-NA-ink: #8a909c;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121316;
    --surface: #1a1b1f;
    --surface-2: #202227;
    --border: #2e3138;
    --text: #eef0f3;
    --text-2: #b4b9c3;
    --muted: #7f8591;
    --accent: #3987e5;
    --accent-soft: #1b2d45;
    --danger: #ef6b6b;
    --danger-soft: #3a1d1f;
    --warn: #e4a63a;
    --warn-soft: #3a2e17;
    --ok: #4cc27a;
    --ok-soft: #173023;
    --series-1: #3987e5;
    --grid: #2a2d33;
    --shadow: none;
    --st-P: #173023; --st-P-ink: #7fd6a0;
    --st-WFH: #1b2d45; --st-WFH-ink: #8dbcf2;
    --st-F: #262044; --st-F-ink: #b1a7f2;
    --st-HD: #3a2e17; --st-HD-ink: #f0c56a;
    --st-A: #3a1d1f; --st-A-ink: #f39a9a;
    --st-L: #12322e; --st-L-ink: #7fd3c7;
    --st-LWP: #35261a; --st-LWP-ink: #e3b48b;
    --st-WO: #24262b; --st-WO-ink: #9aa0ab;
    --st-MO: #3d2516; --st-MO-ink: #f5ad7c;
    --st-NA: #1f2125; --st-NA-ink: #7f8591;
  }
}
/* Same dark values, for when someone picks Dark with the toggle. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121316;
  --surface: #1a1b1f;
  --surface-2: #202227;
  --border: #2e3138;
  --text: #eef0f3;
  --text-2: #b4b9c3;
  --muted: #7f8591;
  --accent: #3987e5;
  --accent-soft: #1b2d45;
  --danger: #ef6b6b;
  --danger-soft: #3a1d1f;
  --warn: #e4a63a;
  --warn-soft: #3a2e17;
  --ok: #4cc27a;
  --ok-soft: #173023;
  --series-1: #3987e5;
  --grid: #2a2d33;
  --shadow: none;
  --st-P: #173023; --st-P-ink: #7fd6a0;
  --st-WFH: #1b2d45; --st-WFH-ink: #8dbcf2;
  --st-F: #262044; --st-F-ink: #b1a7f2;
  --st-HD: #3a2e17; --st-HD-ink: #f0c56a;
  --st-A: #3a1d1f; --st-A-ink: #f39a9a;
  --st-L: #12322e; --st-L-ink: #7fd3c7;
  --st-LWP: #35261a; --st-LWP-ink: #e3b48b;
  --st-WO: #24262b; --st-WO-ink: #9aa0ab;
  --st-MO: #3d2516; --st-MO-ink: #f5ad7c;
  --st-NA: #1f2125; --st-NA-ink: #7f8591;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- layout */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.topbar .user { margin-left: auto; font-size: .85rem; color: var(--text-2); white-space: nowrap; }
.theme-btn {
  flex: none; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; display: inline-grid; place-items: center; padding: 0;
}
.theme-btn:hover { border-color: var(--muted); }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .moon { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .moon { display: block; }
.topbar .theme-btn { margin-left: auto; }  /* signed out: nothing else on the right */
.topbar .user + .theme-btn { margin-left: 0; }
/* The menu wraps onto more lines instead of hiding links off-screen. */
.nav { max-width: 1180px; margin: 0 auto; padding: 0 12px; display: flex; flex-wrap: wrap; gap: 0 2px; align-items: center; }
.nav .group-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 9px 4px 9px 12px; border-left: 1px solid var(--border); margin-left: 6px; }
.nav a {
  padding: 9px 10px; color: var(--text-2); white-space: nowrap; border-bottom: 2px solid transparent; font-size: .92rem;
}
.nav a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nav a:hover { text-decoration: none; color: var(--text); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .75rem; text-align: center; margin-left: 3px; line-height: 18px; }
main { max-width: 1180px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-end; justify-content: space-between; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- messages / alerts */
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; border: 1px solid transparent; }
.msg.success { background: var(--ok-soft); color: var(--ok); }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.warning, .msg.info { background: var(--accent-soft); color: var(--text); }
.alert { border-left: 4px solid var(--danger); background: var(--danger-soft); padding: 12px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert.warn { border-color: var(--warn); background: var(--warn-soft); }
.alert strong { display: block; }

/* ---------- forms */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; color: var(--text-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=file], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
/* iPhone Safari gives date/time boxes their own min width (they overflow the card) and centres the text. */
input[type=date], input[type=time] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%;
  min-height: 42px; line-height: 1.4; text-align: left;
}
input[type=date]::-webkit-date-and-time-value, input[type=time]::-webkit-date-and-time-value { text-align: left; margin: 0; }
.filters input[type=date] { display: inline-block; width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; vertical-align: middle; }
.field { margin-bottom: 12px; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.field .err, .errorlist { color: var(--danger); font-size: .85rem; margin: 4px 0 0; padding: 0; list-style: none; }
.inline-check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
/* Settings-style forms: equal columns; label, box and notes each share one line across a row. */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); column-gap: 14px; row-gap: 6px; margin-bottom: 8px; }
.form-grid > .field { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 4px; margin: 0 0 8px; align-content: start; }
.form-grid > .field > label { align-self: end; margin: 0; }
.form-grid .notes .help, .form-grid .notes .err { margin-top: 0; }
.form-grid .check-box { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 2px; font-weight: 500; color: var(--text); cursor: pointer; }
.form-grid .label-gap { min-height: 1em; }
.row > .field { flex: 1 1 160px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.big { padding: 14px 18px; font-size: 1rem; width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select, .filters input { width: auto; min-width: 140px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }

/* ---------- status chips */
.st { display: inline-block; min-width: 34px; padding: 2px 7px; border-radius: 6px; font-weight: 700; font-size: .78rem; text-align: center; background: var(--st-NA); color: var(--st-NA-ink); }
.st-P { background: var(--st-P); color: var(--st-P-ink); }
.st-WFH { background: var(--st-WFH); color: var(--st-WFH-ink); }
.st-F { background: var(--st-F); color: var(--st-F-ink); }
.st-HD { background: var(--st-HD); color: var(--st-HD-ink); }
.st-A { background: var(--st-A); color: var(--st-A-ink); }
.st-L, .st-HL { background: var(--st-L); color: var(--st-L-ink); }
.st-LWP { background: var(--st-LWP); color: var(--st-LWP-ink); }
.st-WO, .st-H { background: var(--st-WO); color: var(--st-WO-ink); }
.st-MO { background: var(--st-MO); color: var(--st-MO-ink); }
.st-PA { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1.5px var(--warn); }
.st-IN { background: var(--surface); color: var(--st-P-ink); box-shadow: inset 0 0 0 1.5px var(--st-P-ink); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.pill.pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.approved { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.rejected { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.flag { color: var(--danger); font-weight: 600; }

/* ---------- calendar */
.cal { width: 100%; table-layout: fixed; }
.cal th { text-align: center; position: static; }
.cal td { height: 64px; padding: 4px; text-align: center; border: 1px solid var(--border); vertical-align: top; }
.cal td.out { background: var(--surface-2); }
.cal td.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .dn { font-size: .78rem; color: var(--muted); display: block; text-align: right; }
.cal .st { min-width: 0; width: 100%; padding: 3px 0; margin-top: 2px; }
.cal .tm { font-size: .7rem; color: var(--text-2); display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .8rem; color: var(--text-2); margin-top: 10px; }

/* ---------- today card / punch */
.today-status { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.today-status .st { font-size: 1rem; padding: 6px 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.punch-list { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.punch-list li { padding: 5px 0; border-bottom: 1px dashed var(--border); display: flex; justify-content: space-between; gap: 8px; }
.punch-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .v { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .k { font-size: .8rem; color: var(--muted); }
.tile .s { font-size: .78rem; color: var(--text-2); }

/* ---------- approvals */
.req-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface); }
.req-card + .req-card { margin-top: 12px; }
.req-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.evidence { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: .88rem; }
.evidence ul { margin: 4px 0 0; padding-left: 18px; }
.decide { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.decide input { flex: 1 1 200px; }

/* ---------- charts */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(90px, 40%) 1fr auto; gap: 8px; align-items: center; padding: 4px 0; font-size: .88rem; }
.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bars .track { height: 10px; }
.bars .bar { height: 10px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 3px; }
.bars .val { font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 2.5em; text-align: right; }
.bars li:hover .name { font-weight: 600; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 6px;
  font-size: .8rem; white-space: nowrap; transform: translate(-50%, -120%); display: none; z-index: 5;
}
.chart { position: relative; }

/* ---------- login */
.login-wrap { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.login-wrap .card { padding: 22px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .cal td { height: 52px; padding: 2px; }
  .cal .tm { display: none; }
  .hide-sm { display: none; }
  .filters select, .filters input { min-width: 0; flex: 1 1 140px; }
}
@media print {
  .topbar, .nav, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
