:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --wash: #f0efec;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --s1: #2a78d6;
  --s2: #eb6834;
  --good: #006300;
  --good-bg: #e4f3e1;
  --warn: #7a5200;
  --warn-bg: #fdf0cf;
  --bad: #b02a2a;
  --bad-bg: #fbe4e2;
  --p-game: #d9e7fa;
  --p-pack: #fde3d6;
  --p-ticket: #d9f1e7;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a09e97;
    --line: #2c2c2a;
    --line-strong: #44443f;
    --wash: #262624;
    --accent: #3987e5;
    --accent-ink: #0b0b0b;
    --s1: #3987e5;
    --s2: #d95926;
    --good: #5fd05f;
    --good-bg: #12301a;
    --warn: #fab219;
    --warn-bg: #3a2c08;
    --bad: #f08a8a;
    --bad-bg: #3d1717;
    --p-game: #173456;
    --p-pack: #4a2413;
    --p-ticket: #123c2c;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { font-size: 15px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: var(--accent); }

h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 0 0 0.8rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
h3 { font-size: 0.95rem; margin: 1.4rem 0 0.5rem; }
p { margin: 0.4rem 0; }

.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.nowrap { white-space: nowrap; }

/* ---- indeling ---- */

.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }

.nav {
  position: sticky; top: 0; align-self: start; height: 100vh;
  padding: 1.4rem 0.9rem; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 0.15rem;
}
.brand { font-weight: 700; font-size: 1.1rem; padding: 0 0.6rem 1.1rem; }
.brand span { display: block; font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.nav a {
  color: var(--ink-2); text-decoration: none; padding: 0.5rem 0.6rem; border-radius: 6px;
}
.nav a:hover { background: var(--wash); color: var(--ink); }
.nav a.current { background: var(--wash); color: var(--ink); font-weight: 600; }

.nav #logout { margin-top: auto; justify-content: flex-start; }
body.locked .nav a { display: none; }
.login { max-width: 420px; margin-top: 3rem; }
.login h1 { margin-bottom: 1rem; }

main { padding: 1.6rem 2rem 4rem; max-width: 1120px; width: 100%; outline: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 0.6rem 1rem; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 0.8rem 0 0; }
  .brand span { display: none; }
  main { padding: 1rem 1rem 3rem; }
}

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}

.step {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--ink); color: var(--surface); font-size: 0.8rem; font-weight: 600;
}

/* ---- formulieren ---- */

.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.row.actions { align-items: center; margin-top: 0.9rem; }
.add-row { margin-top: 0.9rem; }
.grow { flex: 1 1 240px; }
.grow .field, .grow input { width: 100%; }

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field.inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.field-label { font-size: 0.82rem; color: var(--ink-2); }
.hint { font-size: 0.8rem; color: var(--muted); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.42rem 0.55rem; min-height: 2.3rem;
}
textarea { width: 100%; margin-top: 0.7rem; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input.money { width: 8.5rem; text-align: right; font-variant-numeric: tabular-nums; }
input.narrow { width: 5.5rem; text-align: right; font-variant-numeric: tabular-nums; }
select.todo { border-color: var(--warn); background: var(--warn-bg); }

.check { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 2.3rem; }

.btn {
  font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.3rem; padding: 0.42rem 0.85rem; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--wash); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 1.8rem; padding: 0.15rem 0.55rem; font-size: 0.87rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.file-btn input { display: none; }

.week-nav { display: flex; gap: 0.4rem; align-items: center; }

details { margin-top: 0.9rem; }
summary { cursor: pointer; color: var(--ink-2); }

fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.7rem 0.7rem; display: flex; gap: 0.6rem; margin: 0; }
legend { font-size: 0.82rem; padding: 0 0.3rem; border-radius: 4px; }
fieldset.p-game legend, .ruler .p-game { background: var(--p-game); }
fieldset.p-pack legend, .ruler .p-pack { background: var(--p-pack); }
fieldset.p-ticket legend, .ruler .p-ticket { background: var(--p-ticket); }

.ruler { display: flex; flex-wrap: wrap; gap: 2px; margin: 0.7rem 0 0.3rem; font-family: ui-monospace, Consolas, monospace; }
.ruler span { display: grid; justify-items: center; min-width: 1.6rem; padding: 0.2rem 0.1rem; border-radius: 4px; background: var(--wash); }
.ruler small { font-size: 0.65rem; color: var(--muted); }

/* ---- tabellen ---- */

.table-wrap { overflow-x: auto; margin-top: 0.6rem; }
.table-wrap.tall { max-height: 45vh; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.r { text-align: right; }
tfoot td { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--line-strong); }
table.entry td { padding-top: 0.25rem; padding-bottom: 0.25rem; }
tr.sub-row td { color: var(--ink-2); font-size: 0.88rem; padding-top: 0.2rem; padding-bottom: 0.2rem; }
tr.sub-row td:first-child { padding-left: 1.6rem; }
tr.game-row td { font-weight: 500; }

/* ---- status ---- */

.chip {
  display: inline-block; font-size: 0.8rem; font-weight: 500; padding: 0.08rem 0.5rem; border-radius: 999px;
  background: var(--wash); color: var(--ink-2); white-space: nowrap;
}
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

.notice {
  background: var(--wash); border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.8rem 0; font-size: 0.92rem;
}
.notice.row { align-items: center; }

.completeness { margin: 0.8rem 0 0; }
.meter { height: 8px; border-radius: 4px; background: var(--wash); overflow: hidden; max-width: 420px; }
.meter div { height: 100%; background: var(--s1); border-radius: 4px; }

.todo, .steps { margin: 0; padding-left: 1.2rem; }
.todo li, .steps li { margin: 0.3rem 0; }

/* ---- kerncijfers ---- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.8rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem 1rem; }
.tile-label { font-size: 0.82rem; color: var(--ink-2); }
.tile-value { font-size: 1.35rem; font-weight: 600; margin: 0.15rem 0; }
.tile-value .chip { font-size: 1rem; padding: 0.15rem 0.7rem; }
.tile-sub { font-size: 0.82rem; color: var(--muted); }
.tile-sub .chip { white-space: normal; border-radius: 8px; }
.tile.hero { grid-column: span 2; }
.tile.hero .tile-value { font-size: 2.6rem; line-height: 1.1; }
@media (max-width: 520px) { .tile.hero { grid-column: auto; } }

/* ---- grafieken ---- */

.filter { margin-bottom: 0.8rem; }
.legend { display: flex; gap: 1.1rem; font-size: 0.87rem; color: var(--ink-2); margin-bottom: 0.3rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.swatch.s1, path.s1, circle.s1 { background: var(--s1); fill: var(--s1); }
.swatch.s2, path.s2 { background: var(--s2); fill: var(--s2); }

.chart { position: relative; }
.chart svg { display: block; max-width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--ink); opacity: 0.05; }
.chart .crosshair { stroke: var(--line-strong); stroke-width: 1; }
.chart path.line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 2; min-width: 190px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 0.5rem 0.65rem; font-size: 0.85rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.tooltip strong { display: block; margin-bottom: 0.25rem; }
.tip-row { display: flex; align-items: center; gap: 0.4rem; color: var(--ink-2); }
.tip-row b { margin-left: auto; padding-left: 0.8rem; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---- dialoog en melding ---- */

.dialog {
  width: min(860px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  border: 1px solid var(--line-strong); border-radius: 12px; padding: 1.2rem 1.4rem;
  background: var(--surface); color: var(--ink);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem);
  background: var(--ink); color: var(--surface); padding: 0.6rem 1rem; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s; max-width: min(560px, calc(100vw - 2rem)); z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
