/* ---------- Colour tokens ---------- */
:root {
  --bg: #F3EED9;
  --surface: #FAF7EC;
  --surface-2: #EDE6CD;
  --text: #790B1B;
  --muted: #8E4B52;
  --label: #D1970C;
  --label-text: #9A6D05;   /* the label gold, deepened slightly so small text stays readable */
  --accent: #BFA48B;
  --line: #E2D8BD;
  --pop: #004782;
  --primary: #790B1B;
  --on-primary: #F3EED9;

  --c-birth: #D1970C;
  --c-death: #790B1B;
  --c-premiere: #004782;
  --c-other: #BFA48B;

  --radius: 14px;
  --shadow: 0 6px 24px rgba(58, 22, 16, .12);
  --nav-h: 64px;
  --top-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1C1512;
    --surface: #251C18;
    --surface-2: #30251F;
    --text: #F3EED9;
    --muted: #BFA48B;
    --label-text: #D1970C;
    --line: #3A2E28;
    --primary: #D1970C;
    --on-primary: #1C1512;
    --c-death: #D98A94;
    --c-premiere: #7FB0E0;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1C1512;
  --surface: #251C18;
  --surface-2: #30251F;
  --text: #F3EED9;
  --muted: #BFA48B;
  --label-text: #D1970C;
  --line: #3A2E28;
  --primary: #D1970C;
  --on-primary: #1C1512;
  --c-death: #D98A94;
  --c-premiere: #7FB0E0;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Satoshi', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0 16px;
  display: flex; align-items: center; gap: 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  flex: 1; margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back-btn { margin-left: -10px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: none; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Main ---------- */
main {
  padding: 12px 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto; outline: none;
}

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: 11.5px; font-weight: 500; color: var(--muted);
}
.bottomnav a svg { width: 22px; height: 22px; padding: 0; }
.bottomnav a.active { color: var(--text); font-weight: 700; }
.bottomnav a.active svg { background: color-mix(in srgb, var(--label) 28%, transparent); border-radius: 12px; width: 52px; height: 28px; padding: 3px 15px; }

.fab {
  position: fixed; z-index: 21; right: 18px;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; box-shadow: var(--shadow); cursor: pointer;
}
.fab svg { stroke-width: 2.2; }

/* ---------- Typography helpers ---------- */
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--label-text); margin: 22px 0 8px;
}
.eyebrow:first-child { margin-top: 6px; }
.hero-date { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 0; line-height: 1.15; }
.hero-sub { color: var(--muted); margin: 2px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.empty { color: var(--muted); padding: 14px 2px; }

/* ---------- Entry rows ---------- */
.list { display: flex; flex-direction: column; gap: 2px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: 0; background: var(--surface); text-align: left;
  border-radius: 10px; cursor: pointer; min-height: 56px;
}
.list .row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.list .row:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.row:active { background: var(--surface-2); }
a.row { text-decoration: none; color: inherit; }
button.row { color: inherit; font: inherit; }
.row .datebox { width: 40px; flex: none; text-align: center; line-height: 1.1; }
.row .datebox b { display: block; font-size: 19px; }
.row .datebox span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.row .body { flex: 1; min-width: 0; }
.row .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .detail { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .chev { color: var(--accent); flex: none; width: 18px; height: 18px; }
.typebar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.t-birth { background: var(--c-birth); }
.t-death { background: var(--c-death); }
.t-premiere { background: var(--c-premiere); }
.t-other { background: var(--c-other); }

.tag {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 1px 7px; border-radius: 999px; vertical-align: 1px; margin-left: 4px;
  background: color-mix(in srgb, var(--label) 22%, transparent); color: var(--label-text);
}
.tag.round { background: var(--label); color: #3A1A00; }
.tag.nl { background: color-mix(in srgb, var(--pop) 16%, transparent); color: var(--c-premiere); }

/* ---------- Filter bar ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.chip.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chip .dot { width: 8px; height: 8px; }
.chip svg { width: 16px; height: 16px; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 4px; margin: 4px 0 8px; }
.cal-head h2 { flex: 1; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.btn-small {
  height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; font-weight: 500; cursor: pointer;
}
.cal { user-select: none; touch-action: pan-y; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-dow { font-size: 11.5px; font-weight: 700; color: var(--muted); text-align: center; padding: 4px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.cal-day {
  border: 0; background: none; cursor: pointer; padding: 4px 0 6px; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; border-top: 1px solid var(--line);
}
.cal-day .num {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; font-weight: 500;
}
.cal-day.other .num { color: var(--accent); }
.cal-day.today .num { box-shadow: inset 0 0 0 1.5px var(--text); font-weight: 700; }
.cal-day.sel .num { background: var(--primary); color: var(--on-primary); font-weight: 700; box-shadow: none; }
.cal-day .dots { display: flex; gap: 3px; height: 7px; }
.cal-day .dots .dot { width: 6px; height: 6px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Cards & forms ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 10px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card p { margin: 4px 0 0; }
.banner {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--label) 20%, var(--surface)); margin-bottom: 8px;
}
.banner p { margin: 0; flex: 1; font-size: 14.5px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--label); outline-offset: 0; border-color: transparent; }
.field .hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.date-row { display: grid; grid-template-columns: 1.1fr 1.6fr .9fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 10px; margin: -2px 0 14px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg label > span {
  display: flex; align-items: center; justify-content: center; gap: 6px; height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 500; cursor: pointer;
}
.seg input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 700; }
.seg input:focus-visible + span { outline: 2px solid var(--label); }
.error { color: #B3261E; font-size: 14px; margin: -4px 0 12px; }
:root[data-theme="dark"] .error { color: #F2B8B5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .error { color: #F2B8B5; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 700; cursor: pointer; text-decoration: none; font-size: 15px;
}
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.danger { color: #B3261E; }
:root[data-theme="dark"] .btn.danger { color: #F2B8B5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.danger { color: #F2B8B5; } }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.actions .btn { flex: 1; }

.menu { display: flex; flex-direction: column; gap: 2px; }
.menu .row { min-height: 60px; }
.menu .row svg:first-child { color: var(--label-text); flex: none; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; }

.year-head { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 4px; }
.year-head h2 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.month-head { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; }

.range { display: flex; gap: 8px; align-items: end; margin-bottom: 8px; }
.range .field { flex: 1; margin: 0; }

.searchbox { position: relative; margin-bottom: 12px; }
.searchbox input { padding-left: 42px; }
.searchbox svg { position: absolute; left: 12px; top: 12px; color: var(--muted); }

table.preview { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.preview th, table.preview td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.preview th { color: var(--muted); font-weight: 700; }
.scroll-x { overflow-x: auto; }

/* ---------- Sheet (bottom panel) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20, 8, 6, .42); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 85dvh; overflow: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--accent); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 50; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  bottom: calc(var(--nav-h) + 88px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-weight: 500; font-size: 14.5px;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  main { padding-top: 20px; }
}
