:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #5d6b7a;
  --border: #e2e6eb;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --accent-soft: #e3f3f1;
  --negative: #b42318;
  --error-bg: #fde8e7;
  --on-accent: #ffffff;
  --warn-bg: #fff4e0;
  --warn-text: #8a4b00;
  --seg-taken: #0f766e;
  --seg-booked: #5fb3aa;
  --seg-available: #8ccfc6;
  --seg-unearned: #e9edf1;
  --cal-holiday: #2563eb;
  --cal-off: #eef1f4;
  --cal-sick: #c2410c;
  --cal-bank: #f1e8fd;
  --cal-bank-text: #7e22ce;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #182029;
    --text: #e6ebf0;
    --muted: #93a1b0;
    --border: #2a3542;
    --accent: #3fb8aa;
    --accent-strong: #66cbbf;
    --accent-soft: #163a37;
    --negative: #ff8a80;
    --error-bg: #3d1a17;
    --on-accent: #062a26;
    --warn-bg: #3a2a10;
    --warn-text: #f5c26b;
    --seg-taken: #3fb8aa;
    --seg-booked: #2b7d74;
    --seg-available: #2e8077;
    --seg-unearned: #26313d;
    --cal-holiday: #60a5fa;
    --cal-off: #11181f;
    --cal-sick: #f0954f;
    --cal-bank: #2b1d3d;
    --cal-bank-text: #d4b3fb;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
h3 { font-size: .9rem; margin: 1.5rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.muted { color: var(--muted); margin: 0; }
.hint { display: block; font-size: .8rem; font-weight: 400; color: var(--muted); }
.nowrap { white-space: nowrap; }
.negative { color: var(--negative) !important; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: .7rem 16px;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 8px; background: var(--accent); color: var(--on-accent);
}
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { padding: .35rem .7rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.account { display: flex; align-items: center; gap: .75rem; font-size: .875rem; color: var(--muted); }
.account form { margin: 0; }
.link-button {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

/* Layout */
.page { max-width: 1200px; margin: 0 auto; padding: 1.75rem 16px 3rem; }
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.25rem;
}
.crumbs { margin: 0; font-size: .875rem; color: var(--muted); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 560px; }
.columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 1rem; align-items: start; }
.columns .card { margin-bottom: 0; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .toolbar { margin-bottom: 0; }

/* Buttons and forms */
.button {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; font-size: .875rem;
  cursor: pointer;
}
.button:hover { text-decoration: none; border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.subtle { background: transparent; }
.button.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn-text); }

input[type=email], input[type=text], input[type=password], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.stack { display: grid; gap: .5rem; }
.stack label { font-weight: 550; font-size: .875rem; }
.stack .button { margin-top: .5rem; }
.field-error { color: var(--negative); margin: 0; font-size: .875rem; }

.year-picker { display: flex; align-items: center; gap: .5rem; }
.year-picker label { font-size: .875rem; color: var(--muted); white-space: nowrap; }
.year-picker select { width: auto; }

/* Messages */
.messages { margin-bottom: 1rem; display: grid; gap: .5rem; }
.message { padding: .7rem 1rem; border-radius: 8px; background: var(--accent-soft); }
.message-error { background: var(--error-bg); color: var(--negative); }
.message-warning { background: var(--warn-bg); color: var(--warn-text); }
.login-help { margin: 1rem 0 0; }
.login-card .dev-note { margin-top: 1.5rem; }
.message-warning a { color: inherit; text-decoration: underline; }

/* Login */
.login-wrap { display: grid; place-items: center; min-height: 60vh; }
.login-card { width: 100%; max-width: 420px; padding: 2rem; }
.login-card h1 { margin-bottom: .5rem; }
.login-card > p { margin-bottom: 1.25rem; }
.dev-note {
  background: var(--warn-bg); color: var(--warn-text); border-radius: 8px;
  padding: .7rem .9rem; font-size: .85rem; margin-bottom: 1rem;
}

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.15rem; box-shadow: var(--shadow);
}
.stat h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0; }
.stat-value { font-size: 2rem; font-weight: 700; margin: .25rem 0 0; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value span { font-size: 1rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.stat-note { margin: .15rem 0 0; font-size: .8rem; color: var(--muted); }
.stat.highlight { background: var(--accent-soft); border-color: transparent; }
.stat.highlight .stat-value { color: var(--accent-strong); }

/* Allowance bar */
.bar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--seg-unearned); gap: 2px; }
.seg { display: block; height: 100%; }
.seg-taken { background: var(--seg-taken); }
.seg-booked { background: var(--seg-booked); }
.seg-available { background: var(--seg-available); }
.seg-unearned { background: var(--seg-unearned); }
.legend { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; font-size: .85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .4rem; }
.legend strong { color: var(--text); font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.seg-unearned { box-shadow: inset 0 0 0 1px var(--muted); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
.table-scroll { overflow-x: auto; }
.sums th, .sums td { padding: .5rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.sums th { text-align: left; font-weight: 500; }
.sums td { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 1rem; }
.sums .subtotal th, .sums .subtotal td { font-weight: 650; }
.sums .total th, .sums .total td { font-weight: 700; font-size: 1.05rem; border-bottom: 0; color: var(--accent-strong); }
.sums .pending-row th, .sums .pending-row td { color: var(--warn-text); border-bottom: 0; }

.list th, .list td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.list thead th {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; background: var(--surface); white-space: nowrap;
}
.list tbody tr:last-child td { border-bottom: 0; }
.list .num { text-align: right; font-variant-numeric: tabular-nums; }
.list .strong { font-weight: 650; }
.card:not(.flush) .list th:first-child, .card:not(.flush) .list td:first-child { padding-left: 0; }
.card:not(.flush) .list th:last-child, .card:not(.flush) .list td:last-child { padding-right: 0; }
.team-table { font-size: .875rem; }
.team-table th, .team-table td { padding: .6rem .55rem; }
.team-table th:first-child, .team-table td:first-child { padding-left: 1rem; }
.team-table th:last-child, .team-table td:last-child { padding-right: 1rem; }
.team-table thead th { white-space: normal; vertical-align: bottom; line-height: 1.25; }
.team-table td { white-space: nowrap; }
.team-table tbody tr:hover { background: var(--bg); }
.team-table tr.left td { color: var(--muted); }
.team-table td:first-child { font-weight: 550; }
.status-rejected td, .status-cancelled td { color: var(--muted); }
.status-rejected .num, .status-cancelled .num { text-decoration: line-through; }
.row-link { margin-left: .5rem; font-size: .8rem; }
.empty { padding: 1.5rem; margin: 0; color: var(--muted); }

.pill {
  display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .75rem; font-weight: 600;
  background: var(--seg-unearned); color: var(--muted); margin-left: .25rem; vertical-align: 1px;
}
.list td > .pill:first-child { margin-left: 0; }
.pill-approved { background: var(--accent-soft); color: var(--accent-strong); }
.pill-pending { background: var(--warn-bg); color: var(--warn-text); }
.pill-admin { background: var(--accent-soft); color: var(--accent-strong); }

.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }

.explain { margin-top: 1.25rem; font-size: .875rem; color: var(--muted); }
.explain summary { cursor: pointer; color: var(--accent); font-weight: 550; }
.explain ul { padding-left: 1.1rem; margin: .5rem 0 0; }
.explain li { margin-bottom: .3rem; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Team: Balances / Calendar tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 0 0 1rem; }
.tabs a { padding: .45rem .9rem; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent-strong); border-bottom-color: var(--accent); }

/* Team calendar */
.cal-toolbar { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.cal-toolbar h2 { margin: 0; min-width: 10rem; text-align: center; font-size: 1.1rem; }
.cal-toolbar .button { padding: .35rem .8rem; }
.calendar { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .8rem; }
.calendar th, .calendar td { padding: 0; }
.calendar .cal-name {
  position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; white-space: nowrap;
  padding: .5rem .9rem; font-weight: 550; border-right: 1px solid var(--border);
}
.calendar thead .cal-name, .calendar tfoot .cal-name { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.calendar tbody th, .calendar tbody td, .calendar tfoot th, .calendar tfoot td { border-top: 1px solid var(--border); }
.calendar .cal-day { min-width: 30px; padding: .45rem 0; text-align: center; font-weight: 500; color: var(--muted); line-height: 1.25; }
.cal-dow { display: block; font-size: .62rem; text-transform: uppercase; letter-spacing: .03em; }
.cal-date { display: block; font-variant-numeric: tabular-nums; color: var(--text); }
.cal-day.weekend .cal-date { color: var(--muted); }
.calendar .cal-day.bank-holiday { background: var(--cal-bank); color: var(--cal-bank-text); cursor: help; }
.cal-day.bank-holiday .cal-date { color: var(--cal-bank-text); font-weight: 700; }
.cal-day.today { box-shadow: inset 0 -3px 0 var(--accent); }
.cal-day.today .cal-date { color: var(--accent-strong); font-weight: 700; }
.cal-cell { height: 38px; position: relative; }
.cal-cell.nonwork, .cal-cell.out { background: var(--cal-off); }
.cal-cell .cal-bar { position: absolute; left: 0; right: 0; top: 10px; bottom: 10px; background: var(--cal-holiday); }
.cal-cell.type-sick .cal-bar { background: var(--cal-sick); }
.cal-cell.pending .cal-bar { background: repeating-linear-gradient(135deg, var(--cal-holiday) 0 4px, transparent 4px 8px); box-shadow: inset 0 0 0 1.5px var(--cal-holiday); }
.cal-cell.pending.type-sick .cal-bar { background: repeating-linear-gradient(135deg, var(--cal-sick) 0 4px, transparent 4px 8px); box-shadow: inset 0 0 0 1.5px var(--cal-sick); }
.cal-cell.nonwork.in-leave .cal-bar { opacity: .3; }
/* Bank holidays: a coloured column, with no leave bar across it, because they're never leave. */
.cal-cell.bank-holiday, .cal-count.bank-holiday { background: var(--cal-bank); }
.cal-cell.bank-holiday .cal-bar { display: none; }
.cal-cell.starts .cal-bar { left: 3px; border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.cal-cell.ends .cal-bar { right: 3px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.cal-count { height: 30px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted); }
.cal-count.clash { background: var(--warn-bg); color: var(--warn-text); }
.cal-legend { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; margin: -.25rem 0 1rem; font-size: .8rem; color: var(--muted); }
.cal-month-title { margin: 0; padding: .75rem .9rem; font-size: 1rem; font-weight: 650; color: var(--text); text-transform: none; letter-spacing: 0; border-bottom: 1px solid var(--border); }
.cal-month .calendar thead th { border-top: 0; }
.cal-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.key { display: inline-block; width: 18px; height: 10px; border-radius: 3px; }
.key.holiday { background: var(--cal-holiday); }
.key.holiday.pending { background: repeating-linear-gradient(135deg, var(--cal-holiday) 0 3px, transparent 3px 6px); box-shadow: inset 0 0 0 1.5px var(--cal-holiday); }
.key.sick { background: var(--cal-sick); }
.key.nonwork { background: var(--cal-off); box-shadow: inset 0 0 0 1px var(--border); }
.key.bank { background: var(--cal-bank); box-shadow: inset 0 0 0 1px var(--cal-bank-text); }
.cal-bank-list { margin-left: .6rem; font-size: .8rem; font-weight: 500; color: var(--cal-bank-text); }

/* My holiday: one person's month, under their list of leave */
/* minmax(0, ...) lets the column shrink to the screen; wide tables then scroll inside their card. */
.column-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-content: start; min-width: 0; }
.columns .column-stack .card { margin-bottom: 0; }
.my-cal-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.my-cal-head h2 { margin: 0; }
.my-cal-nav { display: flex; align-items: center; gap: .35rem; }
.my-cal-nav .button { padding: .3rem .75rem; }
.my-cal-month { min-width: 8.5rem; text-align: center; font-size: .95rem; }
.my-calendar .cal-bank-list { margin: 0 0 .6rem; }
.calendar.compact { table-layout: fixed; min-width: 520px; }
.calendar.compact .cal-day { min-width: 0; padding: .35rem 0; }
.calendar.compact .cal-cell { height: 32px; }
.my-calendar .cal-legend { margin: .75rem 0 0; }
.key.clash { background: var(--warn-bg); box-shadow: inset 0 0 0 1px var(--warn-text); }
.overlaps { margin: 0; padding-left: 1.1rem; }
.overlaps li { margin-bottom: .3rem; }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .columns { grid-template-columns: minmax(0, 1fr); }
  .columns .card { margin-bottom: 1rem; }
}

@media (max-width: 560px) {
  .topbar-inner { gap: .5rem 1rem; }
  .nav { order: 3; flex-basis: 100%; }
  .account-email { display: none; }
  .account { margin-left: auto; }
  .stat-value { font-size: 1.6rem; }
  .page-head { align-items: stretch; flex-direction: column; }
  .year-picker { flex-direction: column; align-items: stretch; gap: .25rem; }
  .year-picker select { width: 100%; }
}
