:root {
  --bg: #f5f7f8;
  --card: #ffffff;
  --text: #1d2730;
  --muted: #5d6b77;
  --line: #dde3e8;
  --accent: #1f6f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e4f1f5;
  --ok-bg: #e7f5ec; --ok-line: #9fd3b2; --ok-text: #1d5a34;
  --err-bg: #fdecec; --err-line: #f1b0b0; --err-text: #8a1f1f;
  --info-bg: #eaf2fb; --info-line: #b5cfee; --info-text: #1f4a7a;
  --danger: #b42318;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171c; --card: #1b2229; --text: #e6ebef; --muted: #9aa7b2; --line: #2d3740;
    --accent: #5fb3cf; --accent-ink: #0d1a20; --accent-soft: #1d3540;
    --ok-bg: #16301f; --ok-line: #2e6b43; --ok-text: #a8e0bb;
    --err-bg: #3a1a1a; --err-line: #7a3333; --err-text: #f5b5b5;
    --info-bg: #182a3d; --info-line: #2f4f73; --info-text: #b9d4f2;
    --danger: #f07167;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .75rem; }
ul { margin: 0; padding-left: 1.2rem; }
li { margin-bottom: .35rem; }

.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.wrap.wide { max-width: 1180px; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: baseline; padding-top: 14px; padding-bottom: 14px; }
.brand { font-weight: 700; }
.sub { color: var(--muted); font-size: .9rem; }
main.wrap { padding-top: 28px; padding-bottom: 12px; }
.footer { color: var(--muted); font-size: .85rem; padding-bottom: 32px; }

.hero { margin-bottom: 20px; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; font-weight: 600; color: var(--accent); margin-bottom: .35rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 640px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mt { margin-top: 1.5rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.card.narrow { max-width: 420px; margin: 0 auto 16px; }
.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; margin-bottom: 16px; }
.info .card { margin: 0; }

.slots { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.slot input { position: absolute; opacity: 0; pointer-events: none; }
.slot span {
  display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--card);
}
.slot span:hover { border-color: var(--accent); }
.slot input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.slot input:focus-visible + span { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; }
input:not([type=radio]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-weight: 400;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 12px; }

.btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: .875rem; }
form .btn.primary, form .btn.danger { margin-top: 8px; }

.alert { border: 1px solid; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; }
.alert p:last-child { margin-bottom: 0; }
.alert.error { background: var(--err-bg); border-color: var(--err-line); color: var(--err-text); }
.alert.success { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-text); }
.alert.info { background: var(--info-bg); border-color: var(--info-line); color: var(--info-text); }
.alert.success h1 { font-size: 1.5rem; }
.linkbox { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); }
.linkbox code { flex: 1 1 240px; word-break: break-all; font-size: .85rem; }

.appt-time { font-size: 1.4rem; margin-bottom: 1rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 16px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form label { flex: 1 1 220px; }
details.cancel { margin-top: 18px; }
details.cancel summary { cursor: pointer; color: var(--danger); font-weight: 600; }
details.cancel form { margin-top: 10px; }

.plain { list-style: none; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.tag { font-size: .75rem; border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); margin-left: 4px; }

/* admin */
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .num { display: block; font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: .875rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.schedule { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .95rem; }
.schedule th, .schedule td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.schedule th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.schedule .time { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.schedule tr.booked .time { color: var(--accent); }
.schedule tr.blocked { background: var(--bg); }
.note { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; min-width: 260px; }
.actions details { display: inline-block; }
.actions details[open] { flex-basis: 100%; }
.actions details summary { list-style: none; display: inline-block; }
.actions details summary::-webkit-details-marker { display: none; }
.actions details > form { margin-top: 6px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.grid-form .span2 { grid-column: span 2; }
.grid-form .btn { margin-top: 0; justify-self: start; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; }
.two-col .list { max-height: 420px; overflow-y: auto; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 640px) {
  h1 { font-size: 1.45rem; }
  .schedule thead { display: none; }
  .schedule tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .schedule td { display: block; border: 0; padding: 4px 14px; }
  .actions { min-width: 0; }
}

@media print {
  .topbar, .footer, .toolbar, .noprint, .admin-head form, .alert { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .stat { border-color: #ccc; }
}
