/* Transition OS — "field ledger": warm paper, dark ink, colour only where it means something. */
:root {
  --paper: #f3efe6;
  --card: #fffdf7;
  --ink: #1d1b17;
  --muted: #6c675c;
  --line: #e1dbcd;
  --line-strong: #cfc7b5;
  --good: #19613f;
  --good-soft: #dcebdf;
  --warn: #9a5f0c;
  --warn-soft: #f5e6c6;
  --bad: #a1372a;
  --bad-soft: #f4dbd5;
  --plan: #2f4f8a;
  --plan-soft: #dfe6f3;
  --shadow: 0 1px 0 rgba(29, 27, 23, 0.04), 0 8px 24px -16px rgba(29, 27, 23, 0.35);
  --radius-lg: 18px;
  --radius-sm: 10px;
  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --nav-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131210;
    --card: #1c1a17;
    --ink: #f0ebe0;
    --muted: #a49e90;
    --line: #2e2b26;
    --line-strong: #403c35;
    --good: #63c48f;
    --good-soft: #1d3327;
    --warn: #e2a64c;
    --warn-soft: #3a2c15;
    --bad: #ef7d69;
    --bad-soft: #3d1f1a;
    --plan: #8fb0ec;
    --plan-soft: #1e2840;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 28px -18px rgba(0, 0, 0, 0.9);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 var(--font-body);
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-family: var(--font-body); }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* ── top bar ─────────────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding-top: 18px; padding-bottom: 14px; }
.brand { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; text-decoration: none; letter-spacing: -0.02em; }
.brand span { color: var(--good); }
.topbar .meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9rem; }
.icon-link { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; text-decoration: none; border: 1px solid var(--line); }
.icon-link:hover, .icon-link:focus-visible { border-color: var(--ink); }

/* ── bottom nav ─────────────────────────────── */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav ul { list-style: none; margin: 0 auto; padding: 0 8px; max-width: 640px; height: var(--nav-h); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; font-size: 0.72rem; color: var(--muted); padding: 6px 0; border-radius: 12px; }
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
.nav a.log { color: var(--card); background: var(--ink); margin: 0 6px; padding: 8px 0; font-weight: 600; }
.nav a.log[aria-current="page"] { background: var(--good); }

/* ── cards & figures ────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card > h2 { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; }
.card > h2 a { text-transform: none; letter-spacing: 0; font-weight: 500; }

.hero-figure { font-family: var(--font-display); font-weight: 800; font-size: clamp(2.6rem, 11vw, 3.6rem); line-height: 1; letter-spacing: -0.03em; }
.hero-sub { color: var(--muted); margin-top: 6px; }
.hero-sub strong { color: var(--ink); }

.track { position: relative; height: 12px; border-radius: 99px; background: var(--line); margin: 34px 0 30px; }
.track .fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--ink); transform-origin: left; transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1); }
.track .mark { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--line-strong); }
.track .mark span { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-size: 0.68rem; color: var(--muted); white-space: nowrap; }
.track .mark.target { background: var(--ink); }
.track .mark.target span { color: var(--ink); font-weight: 600; top: -22px; }
.track .mark.strong span { display: none; }
.tier-row { margin-top: 12px; }

.tier { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 0.8rem; font-weight: 600; }
.tier::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tier.below-floor { color: var(--bad); background: var(--bad-soft); }
.tier.floor { color: var(--warn); background: var(--warn-soft); }
.tier.target, .tier.strong, .tier.excellent { color: var(--good); background: var(--good-soft); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); }
.stats > div { background: var(--card); padding: 12px 14px; }
.stats.four { grid-template-columns: repeat(4, 1fr); }
.stats.four > div { padding: 10px; }
.stat-label { font-size: 0.75rem; color: var(--muted); }
.stat-value { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; letter-spacing: -0.02em; }
.stats.four .stat-value { font-size: 1.1rem; }
.stat-value.good { color: var(--good); }
.stat-value.bad { color: var(--bad); }
.stat-note { font-size: 0.72rem; color: var(--muted); }

.alert { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; background: var(--warn-soft); color: var(--warn); font-weight: 500; text-decoration: none; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }

.cta { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 16px 18px; margin-bottom: 14px; border-radius: var(--radius-lg); background: var(--ink); color: var(--paper); text-decoration: none; font-weight: 600; font-size: 1.05rem; box-shadow: var(--shadow); }
.cta small { display: block; font-weight: 400; opacity: 0.75; font-size: 0.85rem; }
.cta:hover { background: var(--good); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .when { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 0.85rem; }
.list a.row { display: contents; text-decoration: none; }
.empty { color: var(--muted); font-size: 0.92rem; margin: 0; }

.chart-box { position: relative; height: 220px; }

/* ── forms ───────────────────────────────────── */
form { margin: 0; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); padding: 11px 12px; min-height: 46px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--good) 45%, transparent); outline-offset: 1px; border-color: var(--good); }
.money { position: relative; }
.money::before { content: '£'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 26px; }
.money.big input { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; min-height: 60px; padding-left: 32px; }
.money.big::before { font-size: 1.4rem; left: 14px; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--paper); border: 1px solid var(--line); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { margin: 0; text-align: center; padding: 10px 4px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 0.88rem; color: var(--muted); }
.segmented input:checked + label { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 3px solid color-mix(in srgb, var(--good) 45%, transparent); }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; font: inherit; font-weight: 600; border-radius: 12px; padding: 12px 18px; min-height: 46px; cursor: pointer; border: 1.5px solid var(--ink); background: var(--ink); color: var(--paper); text-decoration: none; }
.btn:hover { background: var(--good); border-color: var(--good); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { border-color: var(--ink); background: transparent; }
.btn.danger { background: transparent; color: var(--bad); border-color: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.actions { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 6px; }

.breakdown { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.breakdown td { padding: 5px 0; }
.breakdown td:last-child { text-align: right; }
.breakdown tr.minus td { color: var(--muted); }
.breakdown tr.total td { border-top: 1.5px solid var(--ink); padding-top: 9px; font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; }
.breakdown tr.payable td { color: var(--muted); font-size: 0.82rem; }

.hidden { display: none !important; }

/* ── rota calendar ──────────────────────────── */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav h1 { font-size: 1.5rem; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 0.7rem; text-align: center; color: var(--muted); font-weight: 600; padding-bottom: 2px; }
.cal .dow.workday { color: var(--ink); }
.cal a.cell {
  min-height: 64px; border-radius: 10px; padding: 5px; text-decoration: none; display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border: 1px solid var(--line); font-size: 0.7rem; overflow: hidden;
}
.cal a.cell.workday { border-color: var(--line-strong); }
.cal a.cell.outside { visibility: hidden; }
.cal a.cell .num { font-weight: 700; font-size: 0.85rem; }
.cal a.cell .site { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.cal a.cell.today { outline: 2px solid var(--ink); outline-offset: -1px; }
.cal a.cell.planned { background: var(--plan-soft); border-color: transparent; }
.cal a.cell.planned .num { color: var(--plan); }
.cal a.cell.worked { background: var(--good-soft); border-color: transparent; }
.cal a.cell.worked .num, .cal a.cell.worked .amt { color: var(--good); font-weight: 700; }
.cal a.cell.off, .cal a.cell.cancelled { background: transparent; border-style: dashed; }
.cal a.cell.cancelled .num { text-decoration: line-through; color: var(--bad); }
.cal a.cell:hover { border-color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.75rem; color: var(--muted); margin: 10px 0 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .planned { background: var(--plan); }
.legend .worked { background: var(--good); }
.legend .off { border: 1px dashed var(--muted); }
.legend .cancelled { background: var(--bad); }

/* ── toast ───────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 99px; font-weight: 500; transition: opacity 200ms, transform 200ms; z-index: 20; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }

/* ── login ───────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { font-size: 1.8rem; margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.error { color: var(--bad); font-size: 0.9rem; min-height: 1.3em; margin: 8px 0 0; }

@media (max-width: 380px) {
  .stats.four { grid-template-columns: 1fr 1fr; }
  .cal a.cell { min-height: 54px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
