/* TimeyWimey base styles. No build step; keep it small and mobile-first.
   Every colour, font and radius comes from a design token. Themes
   (static/themes/*.css) set the tokens; the values here are the fallback. */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #e2e2dc;
  --accent: #5a8f29;          /* brand: active nav, counts, highlights */
  --accent-text: #ffffff;
  --ok: var(--accent);        /* approved */
  --warn: #b8860b;            /* pending, warnings, holidays */
  --danger: #c0392b;          /* rejected, errors */
  --info: #2e86c1;
  --leave: #6c5ce7;           /* leave and manager-edit markers */
  --shadow: rgba(0, 0, 0, .15);
  --link: var(--accent);
  --focus: var(--accent);
  --heading: var(--text);
  --header-bg: var(--surface);
  --header-text: var(--text);
  --header-border: var(--border);
  --nav-active: var(--accent);
  --footer-bg: var(--surface);
  --footer-text: var(--muted);
  --btn-bg: var(--accent);
  --btn-text: var(--accent-text);
  --btn-transform: none;
  --btn-tracking: normal;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-heading: var(--font-body);
  --font-nav: var(--font-body);
  --heading-weight: 700;
  --radius: 8px;
  --btn-radius: var(--radius);
  --gap: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

/* App pages: the footer sits at the bottom of the viewport on short pages. */
body.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
body.app > main { flex: 1 0 auto; width: 100%; box-sizing: border-box; }

/* Themed defaults for form controls (zero specificity, so component styles win). */
:where(input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), select, textarea) {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 4px 6px;
}
:where(input[type=checkbox], input[type=radio]) { accent-color: var(--accent); }

h1, h2, h3 { font-family: var(--font-heading); font-weight: var(--heading-weight); color: var(--heading); letter-spacing: 0.01em; }

.site-header, .site-footer {
  padding: 12px var(--gap);
  border-bottom: 1px solid var(--header-border);
  background: var(--header-bg);
  color: var(--header-text);
}

.site-footer {
  border-top: 1px solid var(--header-border);
  border-bottom: 0;
  background: var(--footer-bg);
  color: var(--footer-text);
  font-size: 0.875rem;
  margin-top: 48px;
}

.brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-heading); font-weight: var(--heading-weight); color: var(--header-text); text-decoration: none; letter-spacing: 0.04em; }
.brand img { height: 54px; width: auto; display: block; }

.container { max-width: 1100px; margin: 0 auto; padding: var(--gap); }

h1 { font-size: 1.75rem; margin: 8px 0 12px; }
h2 { font-size: 1.125rem; margin: 0 0 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin: var(--gap) 0;
}

.muted { color: var(--muted); }
.result { margin-top: 12px; }

.btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: var(--btn-radius);
  border: 1px solid var(--btn-bg);
  background: var(--btn-bg);
  color: var(--btn-text);
  text-transform: var(--btn-transform);
  letter-spacing: var(--btn-tracking);
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.12); }
a.btn, a.btn:hover { text-decoration: none; display: inline-block; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent); outline-offset: 2px; }

.htmx-request.btn { opacity: 0.7; }

.site-header { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.user-menu { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.user-name { color: var(--header-text); opacity: 0.8; }
.badge { font-size: 0.75rem; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--muted); color: var(--muted); }
form.inline { display: inline; margin: 0; }
.btn-link { background: none; border: none; color: var(--link); text-transform: none; letter-spacing: normal; padding: 0; text-decoration: underline; }
.btn-block { display: block; text-align: center; text-decoration: none; }
.narrow { max-width: 440px; margin: 48px auto; }
.stack > * + * { margin-top: 12px; }
.dev-login { margin-top: 24px; border-top: 1px dashed var(--border); padding-top: 16px; display: grid; gap: 8px; }
.dev-login select { font: inherit; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 100%; }
.roles { margin: 0 0 12px; padding-left: 20px; }

/* ---- demo (D125) */
.demo-banner { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--text); border-bottom: 1px solid var(--border); padding: 6px 16px; font-size: 0.9rem; text-align: center; }
.card.narrow:has(.demo-login) { max-width: 760px; }
.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.persona { margin: 0; }
.persona-btn { display: grid; gap: 4px; width: 100%; height: 100%; text-align: left; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; cursor: pointer; }
.persona-btn:hover, .persona-btn:focus-visible { border-color: var(--link); }
.persona-role { font-size: 0.85rem; color: var(--link); }
.persona-btn .muted { font-size: 0.85rem; }
code { font-size: 0.9em; }

/* ---- navigation */
.main-nav { display: flex; gap: 16px; margin-right: auto; margin-left: 24px; }
.main-nav a { font-family: var(--font-nav); font-size: 0.92rem; }
.main-nav a, .sub-nav a { color: var(--header-text); text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.main-nav a:hover { border-color: var(--link); }
.main-nav a[aria-current="page"], .sub-nav a[aria-current="page"] { border-color: var(--nav-active); }
.sub-nav { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.sub-nav a { color: var(--muted); }
.sub-nav a[aria-current="page"] { color: var(--text); }
.sub-nav a:hover { color: var(--text); }

/* ---- page structure */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1, .page-head h2 { margin: 8px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap); }
.link-card { display: block; color: var(--text); text-decoration: none; margin: 0; }
.link-card:hover { border-color: var(--accent); }
h1 small, h2 small { font-weight: normal; font-size: 0.7em; }
a { color: var(--link); }

/* ---- alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin: 0 0 var(--gap); border: 1px solid; }
.alert-ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.alert-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }

/* ---- forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px 20px; align-items: start; }
.form-grid .actions, .form-grid fieldset, .form-grid .preview, .form-grid > p { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-weight: 600; font-size: 0.9rem; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea, .inline-form select, .filter input, .filter-bar input, .filter-bar select, td input {
  font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); width: 100%; max-width: 100%;
}
.field textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 6px; font-weight: normal; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.help { color: var(--muted); }
.error { color: var(--danger); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger) !important; }
.ts-grid input.bad, .cell-form input.bad { border-color: var(--danger) !important; box-shadow: 0 0 0 1px var(--danger); }
.cell-problem { display: block; color: var(--danger); font-size: 0.75rem; line-height: 1.2; max-width: 12rem; white-space: normal; }
.req { color: var(--danger); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
fieldset > legend { font-weight: 600; padding: 0 6px; }
fieldset > .preview, fieldset > .error { grid-column: 1 / -1; }
.actions { display: flex; gap: 12px; align-items: center; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.inline-form select { width: auto; }
.btn-small { padding: 4px 10px; font-size: 0.85rem; }
.narrow-input { width: 5em !important; }
.filter { margin: 8px 0 12px; max-width: 360px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin-bottom: 12px; }
.filter-bar label { display: grid; gap: 2px; font-size: 0.85rem; }

/* ---- tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.table.compact th, .table.compact td { padding: 5px 8px; }
.table tr.changed td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.table pre { white-space: pre-wrap; font-size: 0.8rem; max-width: 60ch; overflow-x: auto; }
.nowrap { white-space: nowrap; }
ul.plain { list-style: none; padding: 0; }
.pager { display: flex; gap: 16px; }

/* ---- previews */
.preview { border-left: 3px solid var(--border); padding: 4px 12px; }
.preview .ok { color: var(--ok); font-weight: 600; }
.preview .problem { color: var(--danger); }
.signature { max-height: 80px; background: #fff; border: 1px solid var(--border); padding: 4px; }

/* ---- phones: the header collapses to a Menu button */
.site-header { position: relative; }
.mobile-menu { display: none; }
.mobile-menu summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 44px; box-sizing: border-box;
  border: 1px solid var(--header-border); border-radius: var(--radius); color: var(--header-text); font-family: var(--font-nav); }
.mobile-menu summary::-webkit-details-marker { display: none; }
.menu-icon, .menu-icon::before, .menu-icon::after { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; }
.menu-icon { position: relative; }
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -6px; }
.menu-icon::after { top: 6px; }
.mobile-menu[open] .menu-icon { background: transparent; }
.mobile-menu[open] .menu-icon::before { top: 0; transform: rotate(45deg); }
.mobile-menu[open] .menu-icon::after { top: 0; transform: rotate(-45deg); }
.menu-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }
.mobile-menu-panel { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--header-bg); border-bottom: 1px solid var(--header-border);
  box-shadow: 0 8px 16px rgb(0 0 0 / 0.12); padding: 4px var(--gap) 12px; max-height: calc(100dvh - 80px); overflow-y: auto; }
.mobile-menu-panel nav { display: grid; }
.mobile-menu-panel nav a { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 4px; border-bottom: 1px solid var(--header-border);
  color: var(--header-text); text-decoration: none; font-family: var(--font-nav); }
.mobile-menu-panel nav a[aria-current="page"] { font-weight: 700; box-shadow: inset 3px 0 0 var(--nav-active); padding-left: 10px; }
/* Admin pages on phones: one collapsed list instead of the sub-nav row. */
.admin-jump { display: none; margin: 0 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.admin-jump summary { cursor: pointer; padding: 0 12px; min-height: 44px; display: flex; align-items: center; color: var(--link); }
.admin-jump summary::-webkit-details-marker { display: none; }
.admin-jump summary { list-style: none; justify-content: space-between; }
.admin-jump summary::after { content: ""; width: 8px; height: 8px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); margin: -4px 4px 0 0; }
.admin-jump[open] summary::after { transform: rotate(-135deg); margin-top: 4px; }
.admin-jump nav { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; padding: 0 12px 8px; }
.admin-jump nav a { display: flex; align-items: center; min-height: 40px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; }
.admin-jump nav a[aria-current="page"] { font-weight: 700; color: var(--link); }
.mobile-user { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; margin-top: 8px; color: var(--header-text); }

@media (max-width: 900px) {
  .site-header { padding-top: 8px; padding-bottom: 8px; }
  .brand img { height: 36px; }
  .main-nav, .user-menu { display: none; }
  .mobile-menu { display: block; }
  .sub-nav.admin-nav { display: none; }
  .admin-jump { display: block; }
}
@media (max-width: 640px) {
  .table { display: block; overflow-x: auto; }

  /* List tables as stacked cards (app.js labels the cells and adds .stacked). */
  .table.stacked { display: block; overflow: visible; background: none; border: 0; border-radius: 0; }
  .table.stacked thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .table.stacked tbody, .table.stacked tfoot { display: block; }
  .table.stacked tr { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin: 0 0 10px; }
  /* Label in a left column (positioned, so the cell's own content flows normally). */
  .table.stacked td, .table.stacked tfoot th { display: block; position: relative; min-height: 1.5em; border: 0; padding: 4px 0 4px 38%;
    white-space: normal; overflow-wrap: anywhere; text-align: left; }
  .table.stacked td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: calc(38% - 10px);
    color: var(--muted); font-size: 0.8rem; font-weight: 600; line-height: 1.3; overflow-wrap: normal; }
  .table.stacked.nowrap-first td:first-child { white-space: normal; }
  .table.stacked td:not([data-label]), .table.stacked td.span { padding-left: 0; }
  .table.stacked td:not([data-label])::before, .table.stacked td.span::before { content: none; }
  /* The first cell is the card's title. */
  .table.stacked td:first-child { padding-left: 0; font-weight: 600; font-size: 1.02rem; padding-bottom: 6px; }
  .table.stacked td:first-child::before { content: none; }
  .table.stacked td:empty { display: none; }
  .table.stacked td .btn, .table.stacked td button { min-height: 40px; }
  .table.stacked td.n, .table.stacked td.num { text-align: left; }
  .table.stacked tr.changed { border-color: var(--accent); }
  /* A leading checkbox column (approvals) sits in the card's corner; the next cell is the title. */
  .table.stacked tr { position: relative; }
  .table.stacked td.check { position: absolute; top: 10px; right: 12px; padding: 0; min-height: 0; }
  .table.stacked td.check input { width: 22px; height: 22px; }
  .table.stacked td.check + td { padding-left: 0; padding-right: 36px; font-weight: 600; padding-bottom: 6px; }
  .table.stacked td.check + td::before { content: none; }
  .table.stacked td.actions { padding-left: 0; display: flex; flex-wrap: wrap; gap: 8px; }
  .table.stacked td.actions::before { content: none; }
  /* Footer totals: one plain line under the cards. */
  .table.stacked tfoot tr { display: flex; justify-content: space-between; gap: 12px; background: none; border: 0; padding: 0 12px; margin: 0; }
  .table.stacked tfoot td, .table.stacked tfoot th { padding: 0; min-height: 0; font-weight: 600; color: var(--text); font-size: 1rem; }
  .table.stacked tfoot td::before { content: none; }
}

.suppressed td { color: var(--muted); text-decoration: line-through; }
.suppressed td:last-child, .suppressed td:nth-child(2) .badge { text-decoration: none; }

/* ---- timesheet */
.ts-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.ts-title { flex: 1 1 260px; }
.ts-title h1 { margin: 0; font-size: 1.4rem; }
.ts-jump { display: flex; gap: 6px; }
.ts-jump input { font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.btn-ghost { background: transparent; color: var(--link); border-color: var(--border); }
.ts-status { padding: 6px 10px; border-radius: var(--radius); margin: 8px 0; border: 1px solid var(--border); background: var(--surface); }
.status-submitted { border-color: var(--warn); }
.status-approved { border-color: var(--ok); }
.status-rejected { border-color: var(--danger); }
.alert-info { border-color: var(--info); background: color-mix(in srgb, var(--info) 10%, var(--surface)); }
.alert-warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.ts-grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); margin: 8px 0; table-layout: fixed; }
.ts-grid th, .ts-grid td { border: 1px solid var(--border); padding: 4px; vertical-align: top; text-align: center; }
.ts-grid th.label { text-align: left; width: 22%; font-weight: normal; }
.ts-grid th.day { font-size: 0.85rem; }
.ts-grid .dow { display: block; font-weight: 600; }
.ts-grid .hol, .day-card .hol { display: block; font-size: 0.72rem; color: var(--warn); font-weight: normal; }
.ts-grid .weekend { background: color-mix(in srgb, var(--muted) 8%, var(--surface)); }
.ts-grid .holiday { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); }
.ts-grid th.today { box-shadow: inset 0 -3px 0 var(--accent); }
.ts-grid .total { width: 7%; font-weight: 600; }
.ts-grid tr.section th { text-align: left; background: var(--bg); font-weight: 600; }
.ts-grid td.na { color: var(--muted); }
.cell-form { margin: 0; }
.cell input.hours { width: 100%; text-align: center; font: inherit; padding: 6px 2px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--text); }
.cell input.hours:not(:disabled) { border-color: color-mix(in srgb, var(--border) 70%, transparent); }
.cell input.hours:hover { border-color: var(--muted); }
.cell input.hours:focus { border-color: var(--focus); background: var(--surface); outline: none; }
.cell input:disabled { color: var(--muted); cursor: not-allowed; }
.cell.filled input.hours { font-weight: 600; }
.sfb { display: grid; gap: 2px; }
.sfb input { width: 100%; font: inherit; font-size: 0.8rem; padding: 2px; text-align: center; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); }
.derived { font-size: 0.8rem; font-weight: 600; }
.flags { display: block; min-height: 1em; font-size: 0.7rem; }
.flag { text-decoration: none; margin: 0 1px; color: var(--muted); }
.hol-flag { color: var(--warn); } .po-flag { color: var(--danger); }
.cell-details summary { cursor: pointer; font-size: 0.75rem; color: var(--muted); list-style: none; }
.details-form { display: grid; gap: 4px; text-align: left; min-width: 180px; position: absolute; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; box-shadow: 0 4px 12px var(--shadow); }
.details-form textarea, .details-form input, .details-form select { width: 100%; font: inherit; }
.fill { margin-top: 4px; }
.badge.line-pending, .badge.line-submitted { border-color: var(--warn); color: var(--warn); }
.badge.line-approved { border-color: var(--ok); color: var(--ok); }
.badge.line-rejected { border-color: var(--danger); color: var(--danger); }
.badge.line-draft { border-color: var(--muted); color: var(--muted); }
.ts-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.ts-actions .muted { margin-right: auto; }
.add-leave { margin-top: 8px; }
.add-leave summary { cursor: pointer; color: var(--link); }
.ts-cards { display: none; }
@media (max-width: 760px) {
  .ts-grid { display: none; }
  .ts-cards { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
  /* The engagements, once. */
  .ts-engs { padding: 8px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; font-size: 0.9rem; }
  .ts-eng .badge { margin-left: 4px; }
  .ts-eng .fill { margin-top: 4px; }
  /* One row per day: name | entries | total. */
  .day-row { display: grid; grid-template-columns: 3.4em minmax(0, 1fr) 3.2em; gap: 8px; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--border); }
  .day-row:last-child { border-bottom: 0; }
  .day-row.weekend { background: color-mix(in srgb, var(--border) 18%, var(--surface)); }
  .day-row.holiday { box-shadow: inset 3px 0 0 var(--warn); }
  .day-row.today .day-name { color: var(--link); }
  .day-name { margin: 0; font-size: 0.95rem; line-height: 1.15; display: grid; }
  .day-name .dow { font-weight: 700; }
  .day-name .dom { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
  .day-name .hol { font-size: 0.7rem; color: var(--warn); font-weight: 400; }
  .day-entries { display: grid; gap: 4px; }
  .day-entry { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .day-entry .card-label { font-size: 0.75rem; color: var(--muted); }
  .day-entry .cell-form { display: flex; align-items: center; gap: 6px; }
  .day-entry input.hours { width: 6.5em; min-height: 40px; box-sizing: border-box; text-align: center; font: inherit; font-weight: 600;
    border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
  .day-entry .sfb { flex: 1 1 auto; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 3.2em; align-items: center; gap: 4px; }
  .day-entry .sfb input { min-height: 40px; font-size: 0.9rem; padding: 2px 2px; }
  .day-entry .sfb input[type=time] { text-align: center; }
  .day-entry .sfb input[type=time]::-webkit-calendar-picker-indicator { display: none; } /* tapping opens the picker */
  .day-entry .sfb .derived { grid-column: 1 / -1; text-align: left; color: var(--muted); font-weight: 600; }
  .day-entry .flags { display: inline; min-height: 0; }
  .day-entry .cell-details { font-size: 0.85rem; }
  .day-total { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
  .ts-weekend { border-top: 1px solid var(--border); }
  .ts-weekend > summary { cursor: pointer; padding: 10px 12px; min-height: 44px; box-sizing: border-box; color: var(--link); }
  .ts-weekend > summary .muted { font-size: 0.85rem; }
  .ts-weekend[open] > summary { border-bottom: 1px solid var(--border); }
  /* Total and Submit stay in reach at the bottom of the screen. */
  .ts-actions { position: sticky; bottom: 0; z-index: 5; margin: 12px calc(-1 * var(--gap)) 0; padding: 10px var(--gap);
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 12px rgb(0 0 0 / 0.08); flex-wrap: nowrap; }
  .ts-actions .ts-hint { display: none; }
  .ts-actions .btn { min-height: 44px; }
  .ts-head { gap: 6px; }
  .ts-head .ts-jump { order: 5; }
}

/* ---- approvals (stage 07) */
.main-nav .count { display: inline-block; min-width: 1.4em; padding: 0 5px; margin-left: 2px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 0.75rem; text-align: center; line-height: 1.4; }
.btn-danger { border-color: var(--danger); color: var(--danger); background: var(--surface); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 0.85rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 8px 0 12px; overflow-x: auto; }
.tabs a { padding: 6px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current=page] { color: var(--text); border-bottom-color: var(--nav-active); font-weight: 600; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters label { display: grid; gap: 2px; font-size: 0.85rem; }
.queue-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; overflow-x: auto; }
.queue-group h2 { font-size: 1.05rem; margin: 0; }
.queue-group .check { width: 2em; }
.queue-group .num, .table .num { text-align: right; white-space: nowrap; }
.queue-group .actions { white-space: nowrap; text-align: right; }
.badge-leave { border-color: var(--leave); color: var(--leave); }
.reject-inline { display: inline-block; vertical-align: top; }
.reject-inline summary { list-style: none; cursor: pointer; display: inline-block; }
.reject-inline summary::-webkit-details-marker { display: none; }
.reject-inline[open] > :not(summary) { display: grid; gap: 6px; margin-top: 6px; min-width: 240px; text-align: left; }
.reject-inline textarea { width: 100%; font: inherit; }
.decision { display: flex; gap: 10px; align-items: start; flex-wrap: wrap; margin: 12px 0; }
.ts-grid.readonly td.cell { padding: 6px 2px; }
.cell-note { font-size: 0.7rem; color: var(--muted); overflow-wrap: anywhere; }
.line-note { font-size: 0.75rem; color: var(--danger); max-width: 16em; }
.edit-panel, .reopen { margin: 12px 0; }
.edit-panel summary, .reopen summary { list-style: none; cursor: pointer; display: inline-block; }
.edit-form, .reopen form { display: grid; gap: 8px; margin-top: 8px; }
.edit-form textarea, .reopen textarea, .resolve-form textarea, .edit-card textarea { width: 100%; font: inherit; }
.ts-grid.edit input.hours { border: 1px solid var(--border); background: var(--surface); }
.edit-history { display: inline-block; position: relative; }
.edit-history summary { list-style: none; cursor: pointer; font-size: 0.75rem; color: var(--leave); }
.edit-history summary::-webkit-details-marker { display: none; }
.edit-history .popover { position: absolute; z-index: 6; left: 50%; transform: translateX(-50%); min-width: 220px; max-width: 300px; text-align: left; font-size: 0.8rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; box-shadow: 0 4px 12px var(--shadow); }
.edit-history .popover p { margin: 0 0 6px; }
.edit-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; overflow-x: auto; }
.edit-card h2 { font-size: 1.05rem; margin: 0 0 4px; }
.edit-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: start; }
.resolve-form { display: grid; gap: 6px; }
.edit-log { padding-left: 1.2em; }
.badge.ack-pending { border-color: var(--warn); color: var(--warn); }
.badge.ack-disputed { border-color: var(--danger); color: var(--danger); }
.badge.ack-acknowledged { border-color: var(--ok); color: var(--ok); }
@media (max-width: 760px) {
  /* The approver's grids stay as tables on phones (the consultant grid becomes cards). */
  .ts-grid.readonly, .ts-grid.edit { display: block; overflow-x: auto; font-size: 0.8rem; }
  .ts-grid.readonly .hol, .ts-grid.edit .hol { display: none; }
  .queue-group .actions { white-space: normal; }
}

/* ---- appearance settings */
.appearance { display: grid; gap: 12px; }
.theme-card { margin: 0; }
.theme-pick { display: flex; gap: 8px; align-items: center; cursor: pointer; margin-bottom: 8px; }
.theme-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.theme-preview { background: var(--bg); color: var(--text); font-family: var(--font-body); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 0.85rem; }
.tp-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; background: var(--header-bg); color: var(--header-text); border-bottom: 1px solid var(--header-border); flex-wrap: wrap; }
.tp-brand { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-heading); font-weight: var(--heading-weight); }
.tp-brand img { height: 22px; }
.tp-nav { font-family: var(--font-nav); font-size: 0.75rem; }
.tp-active { border-bottom: 2px solid var(--nav-active); }
.tp-count { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 5px; }
.tp-body { padding: 10px; }
.tp-h1 { font-family: var(--font-heading); font-weight: var(--heading-weight); color: var(--heading); font-size: 1rem; margin-bottom: 6px; }
.tp-table { width: 100%; border-collapse: collapse; background: var(--surface); margin-bottom: 8px; }
.tp-table th, .tp-table td { border: 1px solid var(--border); padding: 3px 6px; text-align: left; }
.theme-tweaks { display: grid; gap: 8px; }
.tweak { display: grid; grid-template-columns: 9em auto 1fr; gap: 6px 8px; align-items: center; }
.tweak select { grid-column: 2 / 4; font: inherit; }
.tweak input[type=color] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); }
.tweak .error { grid-column: 1 / -1; }
@media (max-width: 760px) {
  .theme-body { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  h1, .ts-title h1 { font-size: 1.2rem; }
}

/* ---- Purchase orders (stage 08) */
.po-usage { display: flex; flex-direction: column; gap: 2px; min-width: 12rem; }
.po-usage meter { width: 100%; height: 0.8rem; }
.po-figures { font-size: 0.8rem; color: var(--muted); }
.po-figures strong { color: var(--text); }
.po-over { color: var(--danger); font-weight: 600; }
.po-bar-col { width: 34%; }
.po-table tr.po-ended td { color: var(--muted); }
.po-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: var(--gap) 0 0; }
.po-facts dt { color: var(--muted); }
.po-facts dd { margin: 0; }
.po-chart { margin: 0; }
.po-chart svg { width: 100%; height: auto; max-width: 52rem; display: block; }
.po-chart .grid { stroke: var(--border); stroke-width: 1; }
.po-chart .tick, .po-chart .cap-label { fill: var(--muted); font-size: 11px; }
.po-chart .cap { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 6 4; }
.po-chart .warn { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 3 4; }
.po-chart .today { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.po-chart polyline { fill: none; stroke-width: 2; stroke-linejoin: round; }
.po-chart .used { stroke: var(--link); }
.po-chart .pending { stroke: var(--warn); stroke-dasharray: 4 3; }
.po-chart figcaption { font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.key { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 4px; }
.key-used { border-color: var(--link); }
.key-pending { border-color: var(--warn); border-top-style: dashed; }
.key-cap { border-color: var(--danger); border-top-style: dashed; }
.key-warn { border-color: var(--warn); border-top-style: dotted; }
@media (max-width: 640px) {
  .po-bar-col { width: auto; }
  .po-usage { min-width: 8rem; }
}

/* ---- Reports (stage 09) */
.report-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.report-list li { display: grid; gap: 2px; }
.report-head { margin: var(--gap) 0; }
.report-head h2 { margin-bottom: 2px; }
.report-head p { margin: 4px 0; }
.report-table tfoot th, .report-table tfoot td { border-top: 2px solid var(--border); }
.table-scroll { overflow-x: auto; max-width: 100%; }
.daily td, .daily th { white-space: nowrap; padding: 4px 6px; }
.daily td.holiday { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); }
.daily .unapproved { font-style: italic; color: var(--muted); }
.leave-mark { display: block; color: var(--leave); font-size: 0.7rem; }
.badge-warn { border-color: var(--warn); color: var(--warn); }
.close-box h3 { margin-top: 0; }
.filters label.check { display: flex; gap: 6px; align-items: center; }
.lock-flag { text-decoration: none; }

/* ---- Exports (stage 12) */
.export-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: var(--gap); align-items: start; }
.export-preview { position: sticky; top: var(--gap); }
.preview-frame { width: 100%; height: 72vh; border: 1px solid var(--border); background: #fff; border-radius: var(--radius); }
.pdf-frame { width: 100%; height: 70vh; border: 1px solid var(--border); background: #fff; }
.check-list { display: grid; gap: 4px; max-height: 12rem; overflow: auto; }
.export-file { margin-bottom: var(--gap); }
.export-file h3 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
@media (max-width: 900px) { .export-editor { grid-template-columns: 1fr; } .export-preview { position: static; } }
/* Stage 13: templates and revision review */
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: var(--gap); align-items: start; }
textarea.code { font-family: ui-monospace, "DejaVu Sans Mono", monospace; font-size: 0.85rem; min-height: 28rem; width: 100%; tab-size: 2; white-space: pre; }
textarea.code.short { min-height: 8rem; }
.report { white-space: pre-wrap; font-size: 0.85rem; margin: 4px 0 0; }
.func-list { font-size: 0.8rem; line-height: 1.6; }
.func-list code { margin-right: 4px; }
.changes-panel { border-left: 4px solid var(--warn, #c77700); }
.changes-panel .delta-up { color: var(--ok, #1a7f37); }
.changes-panel .delta-down { color: var(--danger, #b42318); }
td.cell-changed { background: #fff1c2; outline: 2px solid #e0a800; outline-offset: -2px; }
td.cell-changed small { display: block; color: #7a5a00; }

/* Narrow screens: tables scroll sideways in their container; the first column (period) stays on one line. */
.table.nowrap-first td:first-child, .table.nowrap-first th:first-child { white-space: nowrap; }
@media (max-width: 600px) { .table-scroll > .table td, .table-scroll > .table th { white-space: nowrap; } }

/* Template designer */
.dz-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: 0 var(--gap); align-items: end; }
.dz-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.dz-head h2 { margin: 0; }
.dz-block.has-error { border-color: var(--danger); }
.dz-items input, .dz-items select { width: 100%; }
.dz-items tr.has-error td { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.dz-add { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 8px; }
.dz-add .btn { display: flex; flex-direction: column; align-items: flex-start; text-align: left; height: auto; white-space: normal; }
.dz-add small { font-weight: normal; opacity: .8; }
.check-row { display: flex; flex-wrap: wrap; gap: 4px 16px; }
td.nowrap { white-space: nowrap; }
.dz-start { border-left: 4px solid var(--accent); }
.designer input[type=color] { width: 100%; height: 2.4rem; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.dz-place { padding: 6px 8px; background: color-mix(in srgb, var(--accent) 6%, var(--surface)); border-radius: var(--radius); }
.dz-items .check { font-size: .85em; margin-right: 6px; }
/* Home */
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: var(--gap); align-items: start; }
.home-card h2 { margin-top: 0; }
.home-grid > .card { margin: 0; }
.home-big { font-size: 2rem; font-weight: 700; margin: 0 0 4px; line-height: 1.1; }
.home-big small { font-size: 1rem; font-weight: normal; color: var(--muted); }
.home-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; }
.home-stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0 0 8px; }
.home-stats dt { color: var(--muted); }
.home-stats dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.po-warn { color: var(--warn); font-weight: 600; }

/* ---- phones: tighter spacing and bigger tap targets */
@media (max-width: 640px) {
  :root { --gap: 12px; }
  .container { padding: 12px var(--gap) 16px; }
  .site-footer { margin-top: 24px; }
  h1 { margin: 4px 0 10px; }
  .card { padding: 12px; margin: 10px 0; }
  .home-who { display: none; }
  .home-big { margin: 4px 0; }
  .home-card p:last-child { margin-bottom: 0; }
  /* Admin home: a compact list of pages rather than tall cards. */
  .admin-cards { gap: 0; grid-template-columns: 1fr; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
  .admin-cards > .card { margin: 0; border: 0; border-radius: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  .admin-cards > .card:last-child { border-bottom: 0; }
  .admin-cards h2 { font-size: 1rem; margin: 0 0 2px; }
  .admin-cards p { margin: 0; font-size: 0.85rem; }
  /* Tap targets. */
  .btn { min-height: 40px; }
  .btn-small { min-height: 36px; }
  .tabs a, .sub-nav a { padding-top: 8px; padding-bottom: 8px; }
  input:not([type=checkbox]):not([type=radio]), select { min-height: 40px; box-sizing: border-box; }
  .ts-grid input, .sfb input { min-height: 0; } /* dense grids keep their size */
  .filters, form.filters { gap: 8px; }
}

/* Read-only cells (approved or submitted weeks, future days) look read-only, not empty. */
.cell input:disabled, .day-entry input:disabled, .sfb input:disabled {
  background: transparent !important; border-color: transparent !important; color: var(--text); opacity: 1; cursor: not-allowed; }
.cell input:disabled::placeholder, .day-entry input:disabled::placeholder, .sfb input:disabled::placeholder { color: transparent; }
