:root {
  --ink: #372735;
  --paper: #edefe8;
  --accent: #e9530d;
  --accent-ink: #b0400a;            /* the accent, darkened until it is readable as text */
  --ink-hover: #4a3647;
  --surface: #f8f9f5;
  --muted: rgb(55 39 53 / .7);
  --line: rgb(55 39 53 / .11);
  --line-soft: rgb(55 39 53 / .055);
  --work-from: 8;                   /* working hours, 08–17: white. Everything else is --off */
  --work-to: 17;
  --off: color-mix(in oklab, var(--ink) 4%, var(--paper));      /* outside working hours: the page's own paper */
  --gone: color-mix(in oklab, var(--ink) 36%, var(--paper));    /* time that has passed: paper sinking towards the ink */
  --gone-ink: color-mix(in oklab, var(--ink) 74%, var(--paper)); /* bookings that are over */
  --gone-line: rgb(248 249 245 / .34);                           /* hour lines on --gone are light, not dark */
  --gone-line-soft: rgb(248 249 245 / .16);
  --h: 56px;                        /* height of one hour */
  --gutter: 56px;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);
}
* { box-sizing: border-box; }
html { font: 100%/1.45 ui-sans-serif, system-ui, "Segoe UI Variable Text", "Segoe UI", -apple-system, "Helvetica Neue", sans-serif; }
body {
  margin: 0; height: 100dvh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); font-size: .9375rem;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Top bar ─────────────────────────────────────────── */
.bar { display: flex; align-items: center; gap: 12px 28px; padding: 14px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand i { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.when { flex: 1; display: flex; align-items: center; gap: 14px; min-width: 0; }
.nav { display: flex; gap: 6px; }
.label { display: flex; align-items: baseline; gap: 4px 12px; min-width: 0; }
h1 { margin: 0; font-size: 1.375rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h1::first-letter { text-transform: uppercase; }
#weekno { color: var(--muted); font-size: .875rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

.tools { display: flex; gap: 8px; }

/* View menu: day / work week / week / month. It opens from its button, so it grows from that corner. */
.menu {
  position: fixed; inset: auto; margin: 0; min-width: 188px; padding: 4px; border: 0; border-radius: 12px;
  background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 12px 32px -8px rgb(55 39 53 / .3);
  transform-origin: top right; opacity: 0; transform: scale(.96);
  transition: opacity .12s ease, transform .12s ease, overlay .12s allow-discrete, display .12s allow-discrete;
}
.menu:popover-open { opacity: 1; transform: none; transition-duration: .18s; transition-timing-function: var(--ease-out); }
@starting-style { .menu:popover-open { opacity: 0; transform: scale(.96); } }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 8px;
  background: none; color: inherit; font: inherit; font-weight: 550; text-align: left; cursor: pointer;
}
.menu button::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.menu button[aria-checked="true"] { font-weight: 650; }
.menu button[aria-checked="true"]::before { background: var(--accent); }
.menu button:focus-visible { outline: 0; background: rgb(55 39 53 / .07); }
.menu kbd { margin-left: auto; font: inherit; font-size: .75rem; font-weight: 500; color: var(--muted); }
@media (hover: none) { .menu kbd { display: none; } }

.btn {
  height: 36px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; user-select: none;
  transition: transform .16s var(--ease-out), background-color .16s ease, color .16s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.icon { width: 36px; padding: 0; }
.btn.primary { background: var(--ink); border-color: transparent; color: var(--paper); }
.btn.primary svg { color: var(--accent); }
.btn.quiet { color: var(--accent-ink); }
.btn.quiet.armed { background: var(--accent-ink); border-color: transparent; color: #fff; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { background: #fff; }
  .btn.primary:hover:not(:disabled) { background: var(--ink-hover); }
  .btn.quiet.armed:hover { background: var(--accent-ink); }
  .event:hover, .chip:hover { background: var(--ink-hover); }
  .day:hover:not(:disabled), .dnum:hover, .more:hover, .menu button:hover { background: rgb(55 39 53 / .06); }
  .cell:not(.over):hover { background: rgb(233 83 13 / .05); }
}

/* ── Calendar ────────────────────────────────────────── */
.scroll {
  flex: 1; min-height: 0; overflow: hidden auto; overscroll-behavior: contain; display: flex; flex-direction: column;
  margin: 0 20px 20px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px;
}
/* --n is the number of day columns on screen: 1, 5 or 7 */
.days, .grid, .month { flex: none; display: grid; grid-template-columns: var(--gutter) repeat(var(--n, 7), minmax(0, 1fr)); }
.days {
  position: sticky; top: 0; z-index: 5;
  background: rgb(248 249 245 / .78); backdrop-filter: blur(16px) saturate(160%); -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--line);
}
.day {
  position: relative; display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 10px 12px 9px;
  border: 0; border-left: 1px solid var(--line-soft); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: background-color .16s ease;
}
.day:disabled { cursor: default; }
.day .wd { font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.day .num { font-size: 1.375rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.day.over .num { color: var(--muted); font-weight: 500; }
.day.today .wd, .day.today .num { color: var(--accent-ink); }
.day.today::before { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: var(--accent); }
/* .stack: weekday above the number (phones, and the day view). .strip: the day view's week strip, a day switcher. */
.stack .day { flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; }
.stack .wd { font-size: .6875rem; }
.stack .num { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; font-size: 1.0625rem; transition: background-color .16s ease, color .16s ease; }
.strip { grid-template-columns: repeat(7, minmax(0, 1fr)); padding: 0 8px; }
.strip .corner { display: none; }
.strip .day { border-left: 0; border-radius: 12px; }
.strip .day.today::before { display: none; }
.day.selected .num { background: var(--ink); color: var(--paper); }
.names .day { padding-block: 9px; }
.names .num { display: none; }

.grid { user-select: none; }
.hours, .col { position: relative; height: calc(24 * var(--h)); }
.hours span {
  position: absolute; right: 10px; top: calc(var(--i) * var(--h)); transform: translateY(-50%);
  font-size: .6875rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.col, .past {
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(var(--line-soft) 1px, transparent 1px);
  background-size: 100% var(--h), 100% calc(var(--h) / 2);
}
/* Three tones: white for working hours, --off around them and on weekends, --gone for the past. */
.col {
  border-left: 1px solid var(--line-soft); cursor: pointer; touch-action: pan-y;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(var(--off) calc(var(--work-from) * var(--h)), transparent 0, transparent calc(var(--work-to) * var(--h)), var(--off) 0);
  background-size: 100% var(--h), 100% calc(var(--h) / 2), 100% 100%;
}
.col.weekend { background-color: var(--off); }
.past {
  position: absolute; inset: 0 0 auto; z-index: 1; background-color: var(--gone); cursor: default;
  background-image: linear-gradient(var(--gone-line) 1px, transparent 1px), linear-gradient(var(--gone-line-soft) 1px, transparent 1px);
}

.event, .ghost, .hint { position: absolute; left: 3px; right: 3px; border-radius: 8px; overflow: hidden; font-variant-numeric: tabular-nums; }
.event {
  z-index: 2; display: flex; flex-direction: column; padding: 5px 9px; border: 0;
  background: var(--ink); color: var(--paper); font: inherit; font-size: .8125rem; line-height: 1.3; text-align: left; cursor: pointer;
  transition: transform .16s var(--ease-out), background-color .16s ease;
}
.event:active { transform: scale(.98); }
.event b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event span { font-size: .75rem; opacity: .75; white-space: nowrap; }
.event.short { flex-direction: row; align-items: center; gap: 8px; padding-block: 0; }
.event.tiny { font-size: .625rem; line-height: 1; }
.event.tiny span { font-size: inherit; }
.event.over { background: var(--gone-ink); color: var(--surface); }
.ghost, .hint { pointer-events: none; padding: 4px 9px; font-size: .75rem; font-weight: 600; line-height: 1.3; color: var(--accent-ink); }
.ghost { z-index: 3; background: rgb(233 83 13 / .14); box-shadow: inset 0 0 0 1.5px var(--accent); scroll-margin: 96px 0 40px; }
.hint { z-index: 1; background: rgb(233 83 13 / .09); }
.now { position: absolute; left: 0; right: 0; z-index: 4; height: 2px; margin-top: -1px; background: var(--accent); pointer-events: none; }
.now::before, .now::after { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.now::after { animation: pulse 2.8s var(--ease-out) infinite; }          /* a soft ring, so "now" is easy to find */
@keyframes pulse { from { opacity: .5; transform: scale(1); } 70%, to { opacity: 0; transform: scale(3.4); } }
/* A booking that was just saved settles into place; one being removed fades out. */
.event.in, .chip.in { animation: book-in .32s var(--ease-out) backwards; }
.event.out, .chip.out { animation: book-out .18s ease forwards; pointer-events: none; }
@keyframes book-in { from { opacity: 0; transform: scale(.94); } }
@keyframes book-out { to { opacity: 0; transform: scale(.96); } }

/* ── Month view ──────────────────────────────────────── */
.month { flex: 1; grid-auto-rows: minmax(108px, 1fr); }
.wk { padding: 9px 10px 0 0; border-top: 1px solid var(--line); text-align: right; font-size: .6875rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 4px; overflow: hidden;
  border-top: 1px solid var(--line); border-left: 1px solid var(--line-soft); cursor: pointer; transition: background-color .16s ease;
}
.cell.weekend { background: var(--off); }
.cell.over { background: var(--gone); cursor: default; }
.cell.today { box-shadow: inset 0 2px var(--accent); }
.dnum {
  align-self: flex-start; min-width: 28px; height: 24px; padding: 0 6px; border: 0; border-radius: 7px; background: none; color: inherit;
  font: inherit; font-size: .875rem; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; transition: background-color .16s ease;
}
.cell.out .dnum { color: var(--muted); font-weight: 500; }
.cell.over .dnum { color: var(--ink); }   /* muted text is too faint on --gone */
.cell.today .dnum { color: var(--accent-ink); }
.chip, .more {
  flex: none; width: 100%; padding: 2px 7px; border: 0; border-radius: 6px; font: inherit; font-size: .75rem; font-weight: 600; line-height: 1.4;
  text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; transition: background-color .16s ease;
}
.chip { background: var(--ink); color: var(--paper); }
.chip span { margin-right: 6px; font-weight: 400; opacity: .75; font-variant-numeric: tabular-nums; }
.chip.over { background: var(--gone-ink); color: var(--surface); }
.chip.draft { background: rgb(233 83 13 / .14); box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent-ink); }
.more { background: none; color: var(--muted); }

/* ── Booking dialog ──────────────────────────────────── */
dialog {
  width: min(432px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 0 0 1px var(--line), 0 24px 64px -16px rgb(55 39 53 / .4);
  opacity: 0; transform: translateY(8px) scale(.97);
  transition: opacity .15s ease, transform .15s ease, overlay .15s allow-discrete, display .15s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; transition-duration: .24s; transition-timing-function: var(--ease-out); }
dialog::backdrop { background: rgb(55 39 53 / 0); transition: background-color .2s ease, overlay .2s allow-discrete, display .2s allow-discrete; }
dialog[open]::backdrop { background: rgb(55 39 53 / .32); }
@starting-style {
  dialog[open] { opacity: 0; transform: translateY(8px) scale(.97); }
  dialog[open]::backdrop { background: rgb(55 39 53 / 0); }
}
form { display: grid; gap: 16px; padding: 24px; }
h2 { margin: 0 0 2px; font-size: 1.25rem; font-weight: 650; letter-spacing: -.015em; }
label { display: grid; gap: 6px; min-width: 0; font-size: .8125rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; min-width: 0; height: 42px; padding: 0 12px; border: 1px solid rgb(55 39 53 / .2); border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit; font-size: 1rem; font-variant-numeric: tabular-nums;
}
textarea { height: auto; padding-block: 9px; resize: vertical; min-height: 76px; }
.row { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 10px; }
/* The list of times that opens under Från and Till. Typing a time works as well. */
.times {
  position: fixed; inset: auto; margin: 0; padding: 4px; border: 0; border-radius: 12px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 12px 32px -8px rgb(55 39 53 / .3);
}
.times button {
  display: block; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: none; color: inherit;
  font: inherit; font-variant-numeric: tabular-nums; text-align: left; cursor: pointer;
}
.times button[aria-selected="true"] { background: rgb(55 39 53 / .08); font-weight: 650; }
@media (hover: hover) and (pointer: fine) { .times button:hover { background: rgb(55 39 53 / .06); } }
#error { min-height: 1.4em; margin: -4px 0; font-size: .875rem; font-weight: 550; color: var(--accent-ink); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.actions .quiet { margin-right: auto; }
[hidden] { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); z-index: 20; translate: -50% 0;
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-size: .875rem; font-weight: 600; white-space: nowrap; pointer-events: none;
  opacity: 0; transform: translateY(12px); transition: opacity .2s ease, transform .25s var(--ease-out);
}
.toast.show { opacity: 1; transform: none; }

/* ── Narrower windows: the week number moves under the date. Phones: the date row drops below. ── */
@media (max-width: 1000px) {
  .label { flex-direction: column; align-items: flex-start; }
  .label h1 { max-width: 100%; font-size: 1.125rem; }
  #weekno { font-size: .8125rem; line-height: 1.2; }
}
@media (max-width: 720px) {
  :root { --gutter: 44px; }
  .bar { flex-wrap: wrap; gap: 10px 12px; padding: 12px 16px; }
  .brand { flex: 1; min-width: 0; }
  .brand span { overflow: hidden; text-overflow: ellipsis; }
  .when { order: 1; flex: 1 0 100%; }
  .tools .primary { width: 36px; padding: 0; }
  .tools .primary span { display: none; }
  .label h1 { font-size: 1.0625rem; }
  .scroll { margin: 0; border-width: 1px 0 0; border-radius: 0; }
  .hint { display: none; }
  .event { padding-inline: 5px; }
  .month { grid-auto-rows: minmax(92px, 1fr); }
  .cell { padding: 3px 2px; }
  .chip, .more { padding: 1px 4px; font-size: .625rem; }
  .chip span { display: none; }
}
@media (max-width: 560px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; transform: translateY(100%); opacity: 1; transition-duration: .2s; }
  dialog[open] { transition-duration: .38s; transition-timing-function: var(--ease-sheet); }
  @starting-style { dialog[open] { opacity: 1; transform: translateY(100%); } }
  form { padding: 22px 16px max(16px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  dialog, dialog[open], .toast, .toast.show, .btn:active, .event:active, .menu, .menu:popover-open { transform: none; }
  .now::after, .event.in, .event.out, .chip.in, .chip.out { animation: none; }
  @starting-style { dialog[open] { transform: none; opacity: 0; } }
}
@media (prefers-reduced-transparency: reduce) {
  .days { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
