:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --border: #ddd;
  --header-bg: #f4f4f4;
  --detail-bg: #fafafa;

  --thuis: #b3e0ff;
  --mijnkleuren: #d3f3d8;
  --geel: #fff3bf;
  --oma: #e5d4f5;
  --abrikoos: #ffbe73;
  --other: #eeeeee;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --fg: #e8e8e8;
    --border: #333;
    --header-bg: #222;
    --detail-bg: #1e1f21;

    --thuis: #163f5c;
    --mijnkleuren: #204d29;
    --geel: #5a4b12;
    --oma: #3d2a57;
    --abrikoos: #6e3b12;
    --other: #2a2a2a;
  }
}

* { box-sizing: border-box; }

/* Covers the overscroll-bounce area (Safari/trackpad rubber-banding) so it
   shows the themed background instead of the browser's default white. */
html {
  background: var(--bg);
}

body {
  margin: 0 auto;
  max-width: 1100px;
  padding: 0.75rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

header {
  margin-bottom: 1rem;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.6rem;
}
h1 { font-size: 1.15rem; margin: 0; }
.status { margin: 0; font-size: 0.7rem; opacity: 0.7; }

#login-view {
  max-width: 320px;
  margin: 3rem auto;
}

#login-view h1 { font-size: 1.2rem; }

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#login-form input {
  font-size: 1.05rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

#login-form button {
  padding: 0.7rem;
  font-size: 1.05rem;
  border: none;
  border-radius: 8px;
  background: #2f6fed;
  color: white;
  cursor: pointer;
}

.error { color: #d33; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
}

.filter-bar select {
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.zoom-controls {
  margin-left: auto;
  display: flex;
  gap: 0.25rem;
}

.zoom-controls button {
  font-family: inherit;
  line-height: 1;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.zoom-controls button:hover {
  filter: brightness(0.95);
}

@media (prefers-color-scheme: dark) {
  .zoom-controls button:hover { filter: brightness(1.15); }
}

#zoom-out { font-size: 0.7rem; }
#zoom-reset { font-size: 0.85rem; }
#zoom-in { font-size: 1.1rem; }

.table-scroll {
  margin-bottom: 2rem;
}

/* Public page only: give the table its own scrolling box instead of letting
   the whole page scroll past it. Safari's position:sticky handling inside
   tables is much more reliable against an explicit scroll container than
   against the document itself - this is an experiment to fix a WebKit bug
   where scrolled-past rows leave a stale gap above the sticky header.
   #main-view is a column flexbox filling the viewport (minus body's own
   padding) so .table-scroll can flex-grow to reach the bottom edge with the
   same margin as the sides, instead of a guessed max-height. */
#main-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 1.5rem);
  height: calc(100dvh - 1.5rem);
}

#main-view .table-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 1;
  min-height: 0;
  margin-bottom: 0;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: 100%;
  min-width: 123.5ch;
  font-size: calc(0.82rem * var(--zoom, 1));
}

thead th {
  position: sticky;
  /* -1px instead of 0: works around an iOS Safari rendering bug where a
     hairline gap of the page background shows above sticky elements pinned
     at exactly top:0 during scroll. */
  top: -1px;
  z-index: 2;
  /* Fixed, deterministic height so the month-header-row below can stick at
     a hardcoded offset instead of relying on JS measurement (which was
     unreliable - sometimes measured before layout settled, causing the
     month header to stick partially behind this row). */
  height: 2rem;
  background: var(--header-bg);
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th:first-child {
  left: 0;
  z-index: 3;
}

tbody td {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stad (last column) has no fixed width and absorbs remaining space -
   it should never truncate; let it show its full content instead. */
tbody td:last-child {
  overflow: visible;
  text-overflow: unset;
}

/* Datum column sticks to the left edge when scrolling horizontally.
   The row's own background color (row-thuis, row-geel, etc.) keeps it opaque.
   z-index below the month-header-row (2) so that always paints on top of it
   when a scrolling event row passes underneath the stuck month header. */
tbody tr.event-row td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  border-right: 1px solid var(--border);
}

/* √ column: as thin and compact as possible */
thead th:nth-child(3),
tbody td:nth-child(3) {
  font-size: 0.6rem;
  padding-left: 0.15rem;
  padding-right: 0.15rem;
  text-align: center;
}

/* Productie column: as thin as possible, no extra horizontal padding */
thead th:nth-child(2),
tbody td:nth-child(2) {
  padding-left: 0.1rem;
  padding-right: 0.1rem;
}

.optie-label {
  font-style: italic;
}

.datum-inner {
  display: flex;
  align-items: baseline;
  gap: 0.35em;
}

td.datum-cell .day-num {
  min-width: 1.5em;
  text-align: right;
}

td.datum-cell .day-abbr {
  opacity: 0.75;
}

tbody tr.event-row {
  cursor: pointer;
}

tbody tr.event-row:hover {
  filter: brightness(0.95);
}

@media (prefers-color-scheme: dark) {
  tbody tr.event-row:hover { filter: brightness(1.15); }
}

tr.row-thuis td { background: var(--thuis); }
tr.row-mijnkleuren td { background: var(--mijnkleuren); }
tr.row-geel td { background: var(--geel); }
tr.row-oma td { background: var(--oma); }
tr.row-abrikoos td { background: var(--abrikoos); }
tr.row-other td { background: var(--other); }

tr.detail-row { display: none; }
tr.detail-row.open { display: table-row; }
tr.detail-row td {
  background: var(--detail-bg);
  white-space: normal;
  padding: 0.6rem 1rem;
}

tr.month-spacer-row td {
  padding: 0.5rem;
  border-bottom: none;
}

/* Blank space after the last row, roughly 3 normal rows tall, so the table
   doesn't end flush against the bottom of its scrolling box. */
tr.end-spacer-row td {
  height: 4.5rem;
  padding: 0;
  border-bottom: none;
}

tr.month-header-row td {
  position: sticky;
  top: calc(2rem - 1px);
  z-index: 2;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.78rem;
  padding: 0.35rem 0.4rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

/* The td itself spans the whole row via colspan, so making IT sticky-left
   as well as sticky-top is unreliable in WebKit (same class of bug as the
   .datum-inner fix below) - stick an inner wrapper horizontally instead,
   independent of the td's own vertical stickiness. */
.month-label {
  display: inline-block;
  position: sticky;
  left: 0.4rem;
}

tr.year-header-row td {
  font-weight: 800;
  font-size: 1.3rem;
  padding: 0.6rem 0.4rem 0.2rem;
  background: var(--bg);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.4rem 1.5rem;
}

.detail-grid dt {
  font-size: 0.65rem;
  text-transform: uppercase;
  opacity: 0.6;
  margin: 0;
}

.detail-grid dd {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
}

@media (max-width: 480px) {
  body { padding: 0.4rem; }
}
