:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #66706c;
  --line: #e1e5e2;
  --line-soft: #eef1ef;
  --accent: #12715b;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --today: #eaf5f1;
  --shadow: 0 1px 2px rgba(20, 30, 26, .06), 0 8px 24px rgba(20, 30, 26, .06);
  --hour: 56px;
  --b-bg-l: 92%;
  --b-bg-s: 65%;
  --b-text-l: 22%;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1b211f;
    --text: #e8ecea;
    --muted: #98a39f;
    --line: #2c3532;
    --line-soft: #232b28;
    --accent: #3fb594;
    --accent-text: #08211a;
    --danger: #ff8a80;
    --today: #1a2b26;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --b-bg-l: 24%;
    --b-bg-s: 35%;
    --b-text-l: 90%;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.15rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 4px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); font-weight: 500; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */

button, input, select { font: inherit; color: inherit; }

button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.icon { padding: 7px 12px; font-size: 1.1rem; line-height: 1; }
button.link, a.lang {
  padding: 0; border: 0; background: none;
  color: var(--muted); font-size: .9rem; text-decoration: underline; text-underline-offset: 3px;
}
button.link:hover, a.lang:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label { display: grid; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--muted); }
input, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
}

/* ---------- password / setup page ---------- */

.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card {
  width: 100%; max-width: 360px;
  display: grid; gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.card h1 { font-size: 1.35rem; }
.card form { display: grid; gap: 14px; }
.card .lang { justify-self: start; }

/* ---------- top bar ---------- */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.week-nav { display: flex; align-items: center; gap: 6px; }
.range { margin-left: 8px; font-weight: 600; white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.actions form { margin: 0; }

main { padding: 14px 20px 32px; max-width: 1280px; margin: 0 auto; }
.status { font-size: .85rem; margin-bottom: 10px; min-height: 1.3em; }

/* ---------- calendar ---------- */

.cal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cal-head, .cal-body {
  display: grid;
  grid-template-columns: 54px repeat(var(--days, 5), minmax(0, 1fr));
}
.cal-head { border-bottom: 1px solid var(--line); }

.day-head {
  display: flex; align-items: baseline; justify-content: center; gap: 6px;
  padding: 10px 4px;
  border: 0; border-left: 1px solid var(--line); border-radius: 0;
  background: none;
  color: var(--muted);
  text-transform: capitalize;
  cursor: default;
}
.day-head b { font-size: 1.15rem; color: var(--text); font-weight: 600; }
.day-head.today, .day-head.today b { color: var(--accent); }

.gutter, .day-col { position: relative; height: calc(var(--hours) * var(--hour)); }
.hour {
  position: absolute; right: 8px;
  transform: translateY(-50%);
  font-size: .72rem; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.hour:first-child { transform: none; }

.day-col {
  border-left: 1px solid var(--line);
  background-image: linear-gradient(to bottom, var(--line-soft) 1px, transparent 1px);
  background-size: 100% var(--hour);
  cursor: cell;
}
.day-col.today { background-color: var(--today); }
.day-col.past { opacity: .6; }

.booking {
  position: absolute; left: 3px; right: 5px;
  display: flex; flex-direction: column; justify-content: flex-start;
  padding: 3px 7px;
  overflow: hidden;
  text-align: left;
  line-height: 1.25;
  border: 0;
  border-left: 3px solid hsl(var(--hue) 55% 45%);
  border-radius: 6px;
  background: hsl(var(--hue) var(--b-bg-s) var(--b-bg-l));
  color: hsl(var(--hue) 45% var(--b-text-l));
  box-shadow: 0 0 0 1px var(--surface);
}
.booking:hover { filter: brightness(.96); }
.booking .time { display: block; font-size: .72rem; font-variant-numeric: tabular-nums; opacity: .85; }
.booking .who { display: block; font-weight: 600; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.booking .note { display: block; font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.booking.short { flex-direction: row; gap: 6px; align-items: center; padding-top: 0; padding-bottom: 0; }
.booking.tiny, .booking.tiny .who { font-size: .68rem; line-height: 1; }
.booking.short .time, .booking.short .who { display: inline; }
.booking.short .time { flex: none; }
.booking.short .note { display: none; }

.c0 { --hue: 165; } .c1 { --hue: 212; } .c2 { --hue: 268; } .c3 { --hue: 330; }
.c4 { --hue: 28; }  .c5 { --hue: 95; }  .c6 { --hue: 190; } .c7 { --hue: 355; }

.now {
  position: absolute; left: 0; right: 0;
  height: 2px; background: var(--danger);
  pointer-events: none; z-index: 2;
}
.now::before {
  content: ""; position: absolute; left: -4px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}

/* ---------- booking dialog ---------- */

dialog {
  width: min(420px, calc(100vw - 24px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 16, 14, .45); }
dialog form { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.buttons { display: flex; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }

/* ---------- phones: one day at a time ---------- */

@media (max-width: 720px) {
  .top { padding: 10px 12px; }
  .top h1 { width: 100%; }
  .range { font-size: .9rem; }
  main { padding: 10px 10px 24px; }
  .status { display: none; }

  .cal-head { display: flex; }
  .cal-head .corner { display: none; }
  .day-head {
    flex: 1; flex-direction: column; align-items: center; gap: 0;
    padding: 8px 0; border-left: 0; font-size: .75rem; cursor: pointer;
  }
  .day-head.sel { box-shadow: inset 0 -3px 0 var(--accent); }
  .day-head.sel b { color: var(--accent); }

  .cal-body { grid-template-columns: 48px minmax(0, 1fr); }
  .day-col:not(.sel) { display: none; }
}
