:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f7f7fa;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, 0.12);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --busy: #8e8e93;
  --busy-soft: rgba(142, 142, 147, 0.14);
  --danger: #ff3b30;
  --ok: #34c759;
  --chrome: rgba(242, 242, 247, 0.78);
  --weekend: #eceaf4;
  --weekend-text: #7a6fa8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  --ease-out: cubic-bezier(0.32, 0.72, 0, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #f2f2f7;
    --muted: #98989d;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.2);
    --busy: #8e8e93;
    --busy-soft: rgba(142, 142, 147, 0.18);
    --danger: #ff453a;
    --ok: #30d158;
    --chrome: rgba(0, 0, 0, 0.72);
    --weekend: #24222e;
    --weekend-text: #a99ee0;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 15px; }
[hidden] { display: none !important; }

/* --- Login ---------------------------------------------------------- */
#login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 32px 24px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 28px; letter-spacing: -0.02em; margin: 14px 0 6px; }
.login-card .muted { font-size: 15px; margin-bottom: 20px; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-2);
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* --- Buttons -------------------------------------------------------- */
.btn {
  display: block;
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: 14px;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  transition: transform 120ms ease-out, opacity 120ms ease-out;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.97); }
a.btn { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: rgba(255, 59, 48, 0.12); color: var(--danger); }
.btn.plain { background: transparent; color: var(--accent); height: 44px; }

/* --- Topbar --------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--chrome);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.topbar h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.1; }
.badge {
  border: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms ease-out;
  white-space: nowrap;
}
.badge:active { transform: scale(0.95); }

/* --- Day strip ------------------------------------------------------ */
.days {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 16px 12px;
  scroll-snap-type: x proximity;
  scroll-padding: 16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: 0 0 auto;
  scroll-snap-align: start;
  width: 52px;
  height: 66px;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 120ms ease-out, background 200ms ease;
  position: relative;
}
.day:active { transform: scale(0.94); }
.day .wd { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.day .dn { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.day .dot { position: absolute; bottom: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.day.weekend { background: var(--weekend); }
.day.weekend .wd { color: var(--weekend-text); }
.day.today .dn { color: var(--accent); }
.day.selected { background: var(--accent); }
.day.selected .wd, .day.selected .dn { color: #fff; }
.day.selected .dot { background: #fff; }

/* --- Content -------------------------------------------------------- */
.content {
  padding: 8px 16px 40px;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}
.day-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 8px 0 12px; }
.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 28px 0 8px 4px; font-weight: 600; }
.footnote { color: var(--muted); font-size: 13px; text-align: center; margin-top: 28px; }

/* --- Slots ---------------------------------------------------------- */
.slots { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.slot {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  padding: 14px 16px;
  min-height: 66px;
  cursor: pointer;
  transition: transform 120ms ease-out, background 200ms ease, opacity 200ms ease;
}
.slot:active { transform: scale(0.98); }
.slot .time { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.slot .sub { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }
.slot .state {
  font-size: 14px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.slot.free .state { background: var(--accent-soft); color: var(--accent); }
.slot.busy { cursor: default; }
.slot.busy .state { background: var(--busy-soft); color: var(--busy); }
.slot.mine { background: var(--accent); color: #fff; }
.slot.mine .sub { color: rgba(255, 255, 255, 0.8); }
.slot.mine .state { background: rgba(255, 255, 255, 0.22); color: #fff; }
.slot.past { opacity: 0.45; cursor: default; }
.slot.past:active { transform: none; }
.slot.busy:active { transform: none; }
.slot:focus-visible { outline: 3px solid var(--accent-soft); }

/* --- Own bookings list ---------------------------------------------- */
.mine { background: var(--card); border-radius: 16px; overflow: hidden; }
.mine-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 12px 16px;
  cursor: pointer;
}
.mine-row + .mine-row { border-top: 1px solid var(--line); }
.mine-row:active { background: var(--card-2); }
.mine-row .d { font-weight: 600; }
.mine-row .t { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.mine-row .chev { color: var(--muted); font-size: 20px; }

/* --- Sheet ---------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 20;
  opacity: 0;
  transition: opacity 320ms var(--ease-out);
}
.scrim.show { opacity: 1; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  margin: 0 auto;
  max-width: 560px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  transform: translateY(105%);
  transition: transform 380ms var(--ease-out);
  touch-action: none;
  will-change: transform;
}
.sheet.show { transform: translateY(0); }
.sheet.dragging { transition: none; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.sheet .lead { color: var(--muted); font-size: 15px; margin-bottom: 18px; }
.sheet .btn + .btn { margin-top: 10px; }
.sheet .hint { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  border: 0;
  background: var(--card-2);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 120ms ease-out;
}
.chip:active { transform: scale(0.95); }
.chip.on { background: var(--accent); color: #fff; }
.chip:disabled { opacity: 0.4; cursor: default; }

/* --- Toast ---------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  z-index: 30;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 240ms var(--ease-out), transform 320ms var(--ease-out);
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .scrim, .toast { transition: opacity 200ms ease; }
  .sheet { transform: none; opacity: 0; }
  .sheet.show { opacity: 1; }
  .btn, .slot, .day, .chip, .badge { transition: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
