/* Apple-style system: grouped inset lists, translucent chrome, system colours.
   Light is the default theme; dark via data-theme="dark", or "auto" to follow the phone. */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.2);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.16);
  --press: rgba(0, 0, 0, 0.06);
  --bar: rgba(249, 249, 249, 0.8);
  --seg-on: #ffffff;
  --tint: #007aff;
  --blue: #0062cc;
  --green: #248a3d;
  --green-vivid: #34c759;
  --orange: #c93400;
  --amber: #a05a00;
  --red: #d70015;
  --gray: #6c6c70;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --label: #ffffff;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.3);
  --sep: rgba(84, 84, 88, 0.65);
  --fill: rgba(120, 120, 128, 0.24);
  --fill-strong: rgba(120, 120, 128, 0.32);
  --press: rgba(255, 255, 255, 0.08);
  --bar: rgba(22, 22, 24, 0.8);
  --seg-on: #636366;
  --tint: #0a84ff;
  --blue: #409cff;
  --green: #30d158;
  --green-vivid: #30d158;
  --orange: #ff9f0a;
  --amber: #ffd60a;
  --red: #ff453a;
  --gray: #98989d;
  --shadow: none;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #000000;
    --surface: #1c1c1e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.65);
    --fill: rgba(120, 120, 128, 0.24);
    --fill-strong: rgba(120, 120, 128, 0.32);
    --press: rgba(255, 255, 255, 0.08);
    --bar: rgba(22, 22, 24, 0.8);
    --seg-on: #636366;
    --tint: #0a84ff;
    --blue: #409cff;
    --green: #30d158;
    --green-vivid: #30d158;
    --orange: #ff9f0a;
    --amber: #ffd60a;
    --red: #ff453a;
    --gray: #98989d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.01em;
  padding-bottom: calc(50px + env(safe-area-inset-bottom) + 24px);
  transition: background-color 0.3s ease, color 0.3s ease; /* ease theme switches, no brightness jump */
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
code { font-size: 0.9em; background: var(--fill); padding: 1px 5px; border-radius: 5px; }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }

/* ---------- navigation bar ---------- */
.nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  transition: box-shadow 0.2s ease;
}
.nav.scrolled { box-shadow: 0 0.5px 0 var(--sep); }
.nav h1 { font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -0.025em; }

main { max-width: 680px; margin: 0 auto; padding: 4px 16px 0; }

.offline {
  margin: 8px 16px 0; padding: 8px 12px; border-radius: 10px; text-align: center;
  font-size: 13px; font-weight: 600; color: var(--orange);
  background: color-mix(in srgb, var(--orange) 14%, transparent);
}

/* ---------- buttons ---------- */
.round-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center;
  background: var(--fill); color: var(--tint);
  transition: transform 0.12s ease-out, opacity 0.12s ease-out;
}
.round-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.round-btn:active { transform: scale(0.92); opacity: 0.7; transition: none; }

.text-btn {
  border: 0; background: none; color: var(--tint);
  font-size: 17px; padding: 8px 4px; min-height: 44px;
}
.text-btn.strong { font-weight: 600; }
.text-btn:active { opacity: 0.4; }
.text-btn:disabled { opacity: 0.35; }

.btn-filled {
  width: 100%; min-height: 50px; border: 0; border-radius: 12px;
  background: var(--tint); color: #fff; font-size: 17px; font-weight: 600;
  transition: transform 0.12s ease-out;
}
.btn-filled:active { transform: scale(0.98); opacity: 0.85; transition: none; }
.btn-filled:disabled { opacity: 0.5; }

.capsule {
  flex: none; border: 0; border-radius: 99px; padding: 6px 14px; min-height: 32px;
  font-size: 15px; font-weight: 600;
  color: var(--tint); background: color-mix(in srgb, var(--tint) 14%, transparent);
  transition: transform 0.12s ease-out;
}
.capsule:active { transform: scale(0.95); opacity: 0.7; transition: none; }

.row-btn {
  display: block; width: 100%; min-height: 44px; border: 0; background: transparent;
  color: var(--tint); font-size: 17px; text-align: center; position: relative;
}
.row-btn.danger { color: var(--red); }
.row-btn:active { background: var(--press); }

/* ---------- grouped lists ---------- */
.group { margin-top: 28px; }
.group-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 400; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--label-2); padding: 0 16px 7px;
}
.sheet-body .group-title { margin-top: 28px; }
.footnote { font-size: 13px; color: var(--label-2); padding: 7px 16px 0; }
.footnote.err { color: var(--red); }

.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow);
}
.empty { color: var(--label-2); text-align: center; padding: 16px; font-size: 15px; }

.cell {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; min-height: 44px; cursor: pointer;
}
.cell:active { background: var(--press); }
.cell + .cell::before, .field + .field::before, .field + .row-btn::before {
  content: ""; position: absolute; top: 0; right: 0; left: 16px;
  height: 0.5px; background: var(--sep);
}
.cell + .cell::before { left: 40px; }
.cell-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.cell-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cell-top strong, .cell-main > strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.booking { align-items: flex-start; }
.booking .dot { margin-top: 6px; }
.sub { font-size: 15px; color: var(--label-2); }
.cell-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 13px; padding: 2px 8px; border-radius: 6px;
  color: var(--c, var(--label-2)); background: color-mix(in srgb, var(--c, var(--label-2)) 13%, transparent);
}
.tag.link { --c: var(--tint); text-decoration: none; }

.dot {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  background: var(--swatch); box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.25), 0 0 0 1px var(--sep);
}

/* status colours */
.pill {
  flex: none; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; white-space: nowrap;
  color: var(--c, var(--gray)); background: color-mix(in srgb, var(--c, var(--gray)) 14%, transparent);
}
.ph-booked { --c: var(--blue); }
.ph-today, .ph-late { --c: var(--amber); }
.ph-out { --c: var(--orange); }
.ph-overdue { --c: var(--red); }
.ph-returned, .ph-cancelled { --c: var(--gray); }
.ph-cancelled { text-decoration: line-through; }
.ph-free { --c: var(--green); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.stat { background: var(--surface); border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow); }
.stat span { display: block; font-size: 13px; color: var(--label-2); }
.stat strong { display: block; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .is-warn { color: var(--orange); }

/* ---------- form rows ---------- */
.field {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding: 0 16px; font-size: 17px; color: var(--label);
}
.field > span:first-child { flex: none; }
.field input:not(.switch), .field select, .field textarea {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  padding: 11px 0; text-align: right; color: var(--label-2);
}
.field input:not(.switch):focus, .field select:focus, .field textarea:focus { color: var(--label); }
.field:focus-within { background: var(--press); }
.field input::placeholder, .field textarea::placeholder { color: var(--label-3); }
.field select { appearance: none; -webkit-appearance: none; text-align-last: right; cursor: pointer; padding-right: 14px;
  background: linear-gradient(45deg, transparent 50%, var(--label-3) 50%) right 4px center / 6px 6px no-repeat,
              linear-gradient(-45deg, transparent 50%, var(--label-3) 50%) right 0 center / 6px 6px no-repeat; }
.field input[type="date"]::-webkit-date-and-time-value { text-align: right; }
.field input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.45; }
.field.stack { flex-direction: column; align-items: stretch; gap: 0; padding-top: 11px; }
.field.stack textarea { text-align: left; resize: vertical; padding: 6px 0 11px; color: var(--label); }
.field .value { color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 51px; height: 31px; border-radius: 99px; position: relative; cursor: pointer;
  background: var(--fill-strong); transition: background-color 0.2s ease;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  transition: transform 0.3s cubic-bezier(0.3, 1.25, 0.5, 1);
}
.switch:checked { background: var(--green-vivid); }
.switch:checked::after { transform: translateX(20px); }

.callout {
  margin-top: 12px; padding: 10px 14px; border-radius: 12px; font-size: 15px;
  color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent);
}
.err-box:empty { display: none; }
.err { color: var(--red); font-size: 15px; padding: 8px 16px 0; min-height: 1.2em; }
.err:empty { padding: 0; min-height: 0; }

/* ---------- segmented control & search ---------- */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  padding: 2px; border-radius: 9px; background: var(--fill); margin-top: 12px;
}
.group > .segmented { margin-top: 0; }
.segmented button {
  border: 0; background: transparent; border-radius: 7px; min-height: 32px; padding: 4px 6px;
  font-size: 13px; font-weight: 500; color: var(--label);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
.segmented button.on { background: var(--seg-on); font-weight: 600; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04); }

.search {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 8px; margin-top: 8px;
  border-radius: 10px; background: var(--fill); color: var(--label-2);
}
.search svg { width: 18px; height: 18px; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 17px; color: var(--label); }
.search input::placeholder { color: var(--label-2); }
#booking-list { margin-top: 16px; }

/* ---------- calendar ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 10px; }
.cal-wrap { overflow-x: auto; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); overscroll-behavior-x: contain; }
.cal { border-collapse: collapse; font-size: 13px; }
.cal thead th { padding: 8px 0 6px; min-width: 42px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal thead th small { display: block; color: var(--label-2); font-weight: 400; font-size: 11px; }
.cal thead th span { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; margin-top: 2px; }
.cal thead th.is-today span { background: var(--red); color: #fff; }
.cal th.sc {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  text-align: left; padding: 0 10px 0 14px; min-width: 116px; max-width: 132px; font-weight: 600;
  box-shadow: 0.5px 0 0 var(--sep);
}
.sc-in { display: flex; align-items: center; gap: 8px; line-height: 1.15; font-size: 13px; }
.cal tbody tr > * { border-top: 0.5px solid var(--sep); }
.cal td { height: 52px; min-width: 42px; padding: 0; cursor: pointer; }
.cal td.free:active { background: var(--press); }
.cal .bar {
  position: relative; height: 30px; margin: 0 -1px;
  color: var(--c); background: color-mix(in srgb, var(--c) 20%, var(--surface)); /* opaque: no seams where cells meet */
}
.cal .bar.first { margin-left: 3px; border-radius: 8px 0 0 8px; }
.cal .bar.last { margin-right: 3px; border-radius: 0 8px 8px 0; }
.cal .bar.first.last { border-radius: 8px; }
.cal .bar span {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; font-weight: 600; font-size: 12px; z-index: 1; pointer-events: none;
}
.cal td.busy:active .bar { filter: brightness(0.92); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -0.5px 0 var(--sep);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 50px; padding: 6px 0 4px; border: 0; background: none;
  font-size: 10px; font-weight: 500; letter-spacing: 0.01em; color: var(--gray);
}
.tabbar svg { width: 26px; height: 26px; }
.tabbar button.on { color: var(--tint); }
.tabbar button:active svg { transform: scale(0.9); }

/* ---------- bottom sheet ---------- */
dialog.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto;
  width: min(640px, 100%); max-width: 100%;
  max-height: calc(100dvh - max(env(safe-area-inset-top), 10px) - 26px);
  padding: 0; border: 0; border-radius: 14px 14px 0 0;
  background: var(--bg); color: var(--label);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  will-change: transform; overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.4); opacity: var(--p, 1); }
#booking-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sheet-head {
  flex: none; padding-top: 6px; touch-action: none; cursor: grab;
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 0.5px 0 var(--sep);
}
.sheet-head:active { cursor: grabbing; }
.grabber { display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 0 auto; }
.sheet-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 12px; }
.sheet-bar .text-btn:first-child { justify-self: start; }
.sheet-bar .text-btn:last-child { justify-self: end; }
.sheet-bar h2 { font-size: 17px; font-weight: 600; outline: none; }
.sheet-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}
.sheet-body > .callout:first-child { margin-top: 16px; }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 0 auto; padding: calc(12vh + env(safe-area-inset-top)) 16px 40px; text-align: center; }
.app-icon { border-radius: 20px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); }
.login h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 18px; }
.lede { color: var(--label-2); margin: 6px 0 28px; }
.login form { text-align: left; }
.login .btn-filled { margin-top: 20px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; z-index: 30; max-width: calc(100% - 32px);
  top: calc(env(safe-area-inset-top) + 10px);
  transform: translate(-50%, -16px) scale(0.96); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 99px; font-size: 15px; font-weight: 600;
  background: var(--bar); color: var(--label);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16), 0 0 0 0.5px var(--sep);
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.25s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- accessibility preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::after { transition-duration: 0.01ms !important; }
  #toast { transform: translate(-50%, 0); transition: opacity 0.2s ease !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .nav, .tabbar, .sheet-head, #toast { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .list, .stat, .cal-wrap { box-shadow: 0 0 0 1px var(--label-3); }
  .nav, .tabbar { background: var(--surface); }
}
