:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #f1eee8;
  --text: #1f2421;
  --muted: #69716c;
  --border: #e2ddd4;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e3efe9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn-soft: #fdf3dc;
  --ok-soft: #e3efe9;
  --focus: #2f6f5e;
  --open-band: #eef5f1;
  --grid-line: #ebe7df;

  --st-confirmed: #dbe9f7;
  --st-confirmed-text: #1d4d7a;
  --st-seated: #d6eedf;
  --st-seated-text: #1e5b3a;
  --st-completed: #e8e6e1;
  --st-completed-text: #5a5f5b;
  --st-pending: #fbeccb;
  --st-pending-text: #7a5410;
  --st-cancelled: #f7dedb;
  --st-cancelled-text: #8a2a22;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1d211f;
    --surface-2: #252a27;
    --text: #e8ebe9;
    --muted: #9aa39e;
    --border: #333a36;
    --accent: #5fb49a;
    --accent-text: #0f1a16;
    --accent-soft: #1f3a31;
    --danger: #f08b80;
    --danger-soft: #3b2220;
    --warn-soft: #3a3120;
    --ok-soft: #1f3a31;
    --focus: #7cc9b0;
    --open-band: #1c2a24;
    --grid-line: #2a302d;

    --st-confirmed: #1e3550;
    --st-confirmed-text: #bcd7f2;
    --st-seated: #1d3f2c;
    --st-seated-text: #bfe8cd;
    --st-completed: #2c302e;
    --st-completed-text: #b8beba;
    --st-pending: #45391c;
    --st-pending-text: #f2d894;
    --st-cancelled: #45231f;
    --st-cancelled-text: #f3b7ae;

    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2 { line-height: 1.25; margin: 0 0 0.75rem; }
h2 { font-size: 1.05rem; }
code { font: 0.9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
code.wrap { word-break: break-all; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
.loading { padding: 2rem; text-align: center; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-height: 38px; padding: 0.4rem 0.9rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { min-height: 32px; padding: 0.2rem 0.65rem; font-size: 0.875rem; }
.btn-icon { width: 38px; padding: 0; font-size: 1.3rem; }
.btn-block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 32px; height: 32px; border-radius: 6px; font-size: 1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Forms */
.form { display: grid; gap: 0.9rem; }
label { display: grid; gap: 0.3rem; font-weight: 550; font-size: 0.9rem; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 0.45rem 0.6rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 400;
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 400; }
.hint { font-weight: 400; font-size: 0.8rem; color: var(--muted); margin: 0; }
.grid-2, .grid-3 { display: grid; gap: 0.9rem; }
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
.form-inline { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.form-inline label { flex: 1 1 140px; }
.form-inline label.grow { flex: 3 1 220px; }
.narrow { max-width: 320px; }
.segmented { display: flex; flex-wrap: wrap; gap: 0.5rem; border: 0; padding: 0; margin: 0; }
.segmented label {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.8rem; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-weight: 500;
}
.segmented label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }
.actions-start { justify-content: flex-start; margin-top: 1rem; }
.actions-split { justify-content: space-between; }

/* Layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0.6rem 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
}
.topbar-title { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.brand { font-weight: 750; letter-spacing: -0.01em; color: var(--accent); }
.restaurant-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; gap: 0.25rem; overflow-x: auto; order: 3; width: 100%; scrollbar-width: none; }
.nav a { padding: 0.4rem 0.7rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.topbar-actions { margin-left: auto; display: flex; gap: 0.4rem; }
@media (min-width: 900px) {
  .nav { order: 0; width: auto; }
}
.page { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.page-title { font-size: 1.45rem; margin-top: 0.25rem; }
.tag { font-size: 0.75rem; vertical-align: middle; background: var(--accent-soft); color: var(--accent); padding: 0.15rem 0.5rem; border-radius: 999px; font-weight: 650; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-bottom: 0.5rem; }
.card-head h2 { margin: 0; }
.empty { color: var(--muted); margin: 0.25rem 0; }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.65rem 0.9rem; margin: 0 0 1rem; }
.notice p { margin: 0.25rem 0; }
.notice-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.notice-warn { background: var(--warn-soft); border-color: transparent; }
.notice-ok { background: var(--ok-soft); border-color: transparent; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; display: grid; gap: 0.9rem; padding: 1.5rem; }
.login-card .brand { font-size: 1.6rem; margin: 0; }
.login-card > .muted { margin: -0.6rem 0 0.2rem; }

/* Day view */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 0.75rem; }
.date-nav { display: flex; gap: 0.35rem; align-items: center; }
.date-nav input { width: auto; }
.search { flex: 1 1 200px; }
.toolbar-actions { display: flex; gap: 0.4rem; margin-left: auto; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 1rem; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.9rem; display: grid; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.timeline-card { padding-bottom: 0.5rem; }
.timeline { overflow-x: auto; padding-bottom: 0.5rem; position: relative; }
.tl-row { display: grid; grid-template-columns: 96px 1fr; min-width: calc(96px + var(--hours) * 72px); }
.tl-label { display: grid; align-content: center; padding: 0 0.5rem 0 0; border-right: 1px solid var(--border); line-height: 1.2; }
.tl-track { position: relative; height: 46px; border-bottom: 1px solid var(--grid-line); cursor: copy; }
.tl-track:not([data-table]), .tl-track[data-table=""] { cursor: default; }
.tl-header .tl-track { height: 24px; cursor: default; border-bottom: 0; }
.tl-hour { position: absolute; top: 2px; transform: translateX(-50%); font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-hour:first-child { transform: none; }
.tl-hour:last-child { transform: translateX(-100%); }
.tl-grid { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--grid-line); }
.tl-open { position: absolute; top: 0; bottom: 0; background: var(--open-band); }
.tl-block {
  position: absolute; top: 5px; bottom: 5px; z-index: 1;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  padding: 0 0.45rem; overflow: hidden; border: 1px solid rgb(0 0 0 / 0.06); border-radius: 6px;
  font: inherit; font-size: 0.78rem; line-height: 1.15; text-align: left; cursor: pointer;
}
.tl-block:hover { filter: brightness(0.97); box-shadow: 0 0 0 2px var(--focus); }
.tl-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tl-meta { opacity: 0.85; white-space: nowrap; }
.tl-now { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--danger); z-index: 2; pointer-events: none; }

/* Status colours */
.pill { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.pill-confirmed { background: var(--st-confirmed); color: var(--st-confirmed-text); }
.pill-seated { background: var(--st-seated); color: var(--st-seated-text); }
.pill-completed { background: var(--st-completed); color: var(--st-completed-text); }
.pill-pending_payment { background: var(--st-pending); color: var(--st-pending-text); }
.pill-cancelled, .pill-no_show, .pill-expired { background: var(--st-cancelled); color: var(--st-cancelled-text); }

/* Tables and lists */
.table-wrap { overflow-x: auto; position: relative; }
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.list td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--grid-line); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list tr.row-cancelled, .list tr.row-no_show, .list tr.row-expired { color: var(--muted); }
.list.rules input { max-width: 120px; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 0.3rem; }
.plain-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--grid-line); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list li.revoked { color: var(--muted); text-decoration: line-through; }
.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.result {
  width: 100%; display: grid; gap: 0.15rem; justify-items: start; text-align: left;
  padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.result:hover { background: var(--surface-2); }

/* Opening hours */
.week { display: grid; gap: 0; }
.day-row { display: grid; gap: 0.5rem; padding: 0.7rem 0; border-bottom: 1px solid var(--grid-line); }
@media (min-width: 720px) { .day-row { grid-template-columns: 120px 1fr auto; align-items: center; } }
.day-name { font-weight: 650; }
.windows { display: grid; gap: 0.4rem; }
.window { display: flex; align-items: center; gap: 0.4rem; }
.window input { width: 130px; }
.day-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* Dialogs */
.dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
}
.dialog-wide { width: min(680px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.9rem 1rem 0; }
.dialog-head h2 { margin: 0; font-size: 1.15rem; }
.dialog-body { padding: 1rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; }
.details dt { color: var(--muted); font-size: 0.9rem; }
.details dd { margin: 0; min-width: 0; }
details.edit { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
details.edit summary { cursor: pointer; font-weight: 600; color: var(--accent); margin-bottom: 0.75rem; }
.copy-row { display: flex; gap: 0.4rem; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

/* Toasts */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 0.5rem; z-index: 100; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 0.65rem 0.9rem; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); transition: opacity 0.4s; }
.toast-error { background: var(--danger); color: #fff; }
.toast-out { opacity: 0; }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* Settings: booking page and embed code */
details.embed { margin-top: 0.9rem; }
details.embed summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details.embed p { margin: 0.75rem 0 0.35rem; }
.copy-row textarea { font: 0.82rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 0; }
.copy-row .btn { flex: none; }
#settings-form h2 { margin: 0.5rem 0 0; }
.check-top { align-self: end; min-height: 40px; }
.check-top .hint { display: block; }
.email-log { list-style: none; margin: 0.25rem 0 0; padding: 0; font-size: 0.88rem; }
.email-log li { display: flex; gap: 0.5rem; justify-content: space-between; padding: 0.3rem 0; border-bottom: 1px solid var(--grid-line); }
.email-log li:last-child { border-bottom: 0; }
.email-failed { color: var(--danger); }
