/* Terminbuchung: gemeinsamer Baustein für Startseite und Danke-Seite. Baut auf styles.css auf.
   Widget (form.book), Fenster der Startseite (dialog.tdlg) und die zwei Auslöser auf der Startseite.
   Das Widget richtet sich nach seiner eigenen Breite (Container Queries), nicht nach dem Browserfenster. */

/* ---------- Widget ---------- */
.book { display: none; max-width: 720px; margin: 20px 0 0; container-type: inline-size; }
.js .book { display: block; }
.book__set { min-width: 0; margin: 0; padding: 0; border: 0; }
.book .sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.book__day input, .book__time input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }

.book__days { display: flex; flex-wrap: wrap; gap: 8px; }
.book__day { position: relative; flex: none; display: grid; justify-items: center; gap: 2px; min-width: 64px; padding: 10px 12px 11px; border-radius: 16px; background: var(--white); box-shadow: inset 0 0 0 1px var(--line); cursor: pointer; transition: box-shadow .2s, background-color .2s, color .2s; }
.book__day span { font: 600 12.5px/1.2 var(--font); color: var(--muted); }
.book__day b { font: 700 15px/1.2 var(--font); font-variant-numeric: tabular-nums; }
.book__day:hover { box-shadow: inset 0 0 0 1.5px var(--petrol); }
.book__day:has(input:checked) { background: var(--petrol); color: var(--white); box-shadow: none; }
.book__day:has(input:checked) span { color: var(--on-dark-muted); }

.book__times { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 12px; }
.book__time { position: relative; padding: 11px 0; border-radius: 999px; background: var(--white); box-shadow: inset 0 0 0 1px var(--line); font: 600 15px/20px var(--font); font-variant-numeric: tabular-nums; color: var(--petrol); text-align: center; cursor: pointer; transition: box-shadow .2s, background-color .2s, color .2s; }
.book__time:hover { box-shadow: inset 0 0 0 1.5px var(--petrol); }
.book__time:has(input:checked) { background: var(--petrol); color: var(--white); box-shadow: none; }
.book__day:has(input:focus-visible), .book__time:has(input:focus-visible) { outline: 2px solid var(--petrol); outline-offset: 2px; }

.book__ph { display: block; height: 42px; border-radius: 999px; background: rgba(14, 28, 31, .06); animation: blink 1.4s ease-in-out infinite; }
.book__ph--day { width: 64px; height: 58px; border-radius: 16px; }

.book__fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 10px; margin-top: 20px; animation: pop .4s var(--ease); }
.book__fields[hidden] { display: none; }
.book__in { width: 100%; min-width: 0; height: 50px; margin: 0; padding: 0 20px; border: 0; border-radius: 999px; background: var(--white); box-shadow: inset 0 0 0 1.5px rgba(14, 28, 31, .12); font: 400 16px/1.4 var(--font); color: var(--ink); -webkit-appearance: none; appearance: none; transition: box-shadow .2s; }
.book__in::placeholder { color: var(--muted); opacity: 1; }
.book__in:focus { outline: 0; box-shadow: inset 0 0 0 2px var(--petrol); }
.book__in.is-error { box-shadow: inset 0 0 0 2px var(--danger); }
.book__hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.book__go { position: relative; height: 50px; padding: 0 24px; }
.book.is-busy .book__go { color: transparent; cursor: progress; }
.book.is-busy .book__go::after { content: ""; position: absolute; inset: 0; width: 18px; height: 18px; margin: auto; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); border-top-color: var(--white); animation: spin .8s linear infinite; }

.book__msg { margin: 12px 0 0; font: 600 14px/1.45 var(--font); color: var(--danger); }
.book__msg:empty { display: none; }
.book__msg.is-info { font-weight: 500; color: var(--muted); }
.book__msg button { padding: 0; border: 0; background: none; font: inherit; color: var(--petrol); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.book__times:empty { display: none; }
.book:has(.book__days:empty) .book__msg { margin-top: 0; }

.book__done { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 14px; align-items: center; padding: 12px 22px 12px 12px; border-radius: 22px; background: var(--pist-soft); color: var(--petrol-deep); animation: pop .5s var(--ease); }
.book__done:focus { outline: 0; }
.book__ok { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--petrol); color: var(--white); }
.book__ok svg { width: 20px; height: 20px; stroke-width: 2.4; }
.book__done strong { display: block; font: 700 16px/1.35 var(--font); }
.book__done p { margin: 2px 0 0; font: 400 14px/1.45 var(--font); overflow-wrap: anywhere; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mittlere Breite: Name und Kanzlei, darunter E-Mail und Knopf */
@container (max-width: 639px) {
  .book__fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Schmal: Tage wischen, Felder untereinander. Die Tagesleiste läuft bis an den Rand des Kastens (20 px Innenabstand). */
@container (max-width: 419px) {
  .book__days { flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; margin: -3px -20px -3px -3px; padding: 3px 20px 3px 3px; }
  .book__days::-webkit-scrollbar { display: none; }
  .book__day { scroll-snap-align: start; }
  .book__times { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); }
  .book__fields { grid-template-columns: 1fr; }
  .book__go { width: 100%; }
  .book__done { grid-template-columns: 1fr; gap: 12px; padding: 16px 18px 18px; border-radius: 20px; }
  .book__ok { width: 36px; height: 36px; }
  .book__ok svg { width: 18px; height: 18px; }
}

/* ---------- Fenster (Startseite) ---------- */
html.is-locked { overflow: hidden; scrollbar-gutter: stable; }
.tdlg { width: min(calc(100% - 32px), 640px); max-width: none; max-height: calc(100dvh - 48px); margin: auto; padding: 0; border: 0; border-radius: 28px; background: var(--white); color: var(--ink); box-shadow: var(--shadow-2); overflow: auto; overscroll-behavior: contain; }
.tdlg::backdrop { background: rgba(7, 52, 58, .45); }
.tdlg[open] { animation: tdlg-in .3s var(--ease); }
.tdlg[open]::backdrop { animation: tdlg-fade .3s ease; }
.tdlg.is-closing { animation: tdlg-out .2s ease forwards; }
.tdlg.is-closing::backdrop { animation: tdlg-fade-out .2s ease forwards; }
.tdlg__inner { padding: 30px 32px 32px; }
.tdlg__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.tdlg__title { margin: 0; font: 800 clamp(22px, 2.4vw, 28px)/1.15 var(--font); letter-spacing: -.03em; text-wrap: balance; }
.tdlg__close { flex: none; width: 40px; height: 40px; display: grid; place-items: center; margin: -4px -8px 0 0; padding: 0; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); cursor: pointer; transition: background-color .2s; }
.tdlg__close:hover { background: var(--mint); }
.tdlg__close svg { width: 18px; height: 18px; }
@keyframes tdlg-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes tdlg-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes tdlg-fade { from { opacity: 0; } }
@keyframes tdlg-fade-out { to { opacity: 0; } }
@keyframes tdlg-up { from { transform: translateY(100%); } }
@keyframes tdlg-down { to { transform: translateY(100%); } }

/* ---------- Auslöser (Startseite) ---------- */
.termin-link, .termin-knopf { display: none; }
.js .termin-link, .js .termin-knopf { display: block; }
.termin-link { margin: 10px auto 0; max-width: 520px; font: 500 14px/1.5 var(--font); color: var(--muted); }
.termin-link button { padding: 0; border: 0; background: none; font: 600 14px/1.5 var(--font); color: var(--petrol); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.termin-link button:hover { text-decoration-thickness: 2px; }
.termin-knopf { margin-top: 20px; }

/* ---------- Handy: Fenster als Blatt von unten ---------- */
@media (max-width: 640px) {
  .tdlg { width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 24px 24px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .tdlg[open] { animation: tdlg-up .35s var(--ease); }
  .tdlg.is-closing { animation: tdlg-down .2s ease forwards; }
  .tdlg__inner { padding: 22px 20px 24px; }
  .termin-knopf .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .book__ph, .book__fields, .book__done, .tdlg[open], .tdlg[open]::backdrop, .tdlg.is-closing, .tdlg.is-closing::backdrop { animation: none; }
}
