/* DentalCare UI. No build step: plain CSS with design tokens. */
:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e3e8ef;
    --text: #172133;
    --muted: #667085;
    --primary: #0e9384;
    --primary-dark: #0b7568;
    --primary-soft: #e7f6f4;
    --danger: #d92d20;
    --danger-soft: #fef3f2;
    --success: #067647;
    --success-soft: #ecfdf3;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; font-weight: 700; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: .9rem; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a, .nav .soon { padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav .soon { color: var(--muted); cursor: default; }
.nav .soon small { font-size: .7rem; background: var(--bg); padding: 1px 7px; border-radius: 99px; }
.nav-section { margin: 16px 12px 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidebar-footer { border-top: 1px solid var(--border); padding: 14px 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-footer .who strong { display: block; font-size: .9rem; }
.sidebar-footer .who span { font-size: .78rem; color: var(--muted); }

.main { padding: 28px 36px 48px; max-width: 1180px; width: 100%; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-header p { margin: 4px 0 0; }
.back { display: inline-block; margin-bottom: 6px; font-size: .9rem; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 2fr 1fr; }

.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 6px 11px; font-size: .85rem; }
.btn-lg { padding: 14px 22px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert ul { margin: 0; padding-left: 18px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Tables ---------- */
.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 12px 18px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.table td { padding: 13px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table .name { font-weight: 600; color: var(--text); }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 16px; }

.empty { text-align: center; padding: 48px 20px; }
.empty p { margin: 6px 0 18px; }

/* ---------- Forms ---------- */
.form { max-width: 720px; }
.field { margin-bottom: 18px; }
.field > label, .field-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], input[type=time], input[type=search], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; font: inherit; color: var(--text); background: #fff; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.is-invalid { border-color: var(--danger) !important; }
.field-error { color: var(--danger); font-size: .83rem; margin: 5px 0 0; }
.form-footer { display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 18px; margin-top: 6px; }

/* Big tap-friendly choice buttons: "select, don't type". */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label { position: relative; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span { display: inline-block; padding: 9px 18px; border: 1px solid var(--border); border-radius: 99px; cursor: pointer; font-weight: 500; background: #fff; transition: all .15s; }
.choices span:hover { border-color: var(--primary); }
.choices input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.choices input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }

.toggle { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; }
.toggle input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); }

.search { margin-bottom: 16px; }
.search input { max-width: 420px; padding: 11px 14px; }

/* ---------- Detail view ---------- */
.details { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 24px; margin: 0; }
.details dt { color: var(--muted); font-size: .82rem; }
.details dd { margin: 2px 0 0; font-weight: 500; }
.placeholder { border-style: dashed; background: transparent; box-shadow: none; text-align: center; color: var(--muted); }

/* ---------- Working hours ---------- */
.hours td { padding: 10px 14px; }
.hours input[type=time] { width: 120px; padding: 7px 9px; }
.hours tr.off .times { opacity: .35; }

/* ---------- Examination ---------- */
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.exam-item { display: block; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; margin-top: 8px; color: var(--text); }
.exam-item:hover { border-color: var(--primary); text-decoration: none; background: #fafbfc; }
.exam-date { font-size: .78rem; color: var(--muted); }
.exam-title { font-weight: 600; }

.exam-form .step { margin-bottom: 18px; }
.exam-form .card + .card { margin-top: 0; }
.step-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.step-head h2 { margin: 0; }
.step-head p { margin: 2px 0 0; }
.step-no { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: .85rem; }
.exam-summary h2 .step-no { width: 24px; height: 24px; font-size: .78rem; margin-right: 6px; vertical-align: 2px; }
.field.other { margin: 16px 0 0; }

.picker-tools { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.picker-tools input[type=search] { max-width: 460px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter { border: 1px solid var(--border); background: #fff; border-radius: 99px; padding: 5px 12px; font: inherit; font-size: .83rem; cursor: pointer; color: var(--muted); }
.filter:hover { border-color: var(--primary); color: var(--text); }
.filter.active { background: var(--text); border-color: var(--text); color: #fff; }
.complaint-list { }   /* no inner scroll box: the page itself scrolls */

.option-group + .option-group { margin-top: 14px; }
.option-group-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 7px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { position: relative; }
.chip[hidden] { display: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 7px 13px; border: 1px solid var(--border); border-radius: 99px; background: #fff; cursor: pointer; font-size: .9rem; transition: all .12s; }
.chip span:hover { border-color: var(--primary); }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip input:checked + span::before { content: "✓ "; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }

/* Tests stay hidden until a diagnosis is chosen (or typed under "Other diagnosis"). */
.exam-form:not(:has(input[name="diagnosisIds"]:checked)):not(:has(#otherDiagnosis:not(:placeholder-shown))) .tests-body { display: none; }
.exam-form:has(input[name="diagnosisIds"]:checked) .tests-hint,
.exam-form:has(#otherDiagnosis:not(:placeholder-shown)) .tests-hint { display: none; }

.teeth-chart { display: flex; flex-direction: column; align-items: center; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.arch { display: flex; }
.arch.lower { border-top: 2px solid var(--border); padding-top: 6px; }
.arch-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.quadrant { display: flex; gap: 4px; padding: 0 8px; }
.quadrant.right { border-right: 2px solid var(--border); }
.tooth { position: relative; }
.tooth input { position: absolute; opacity: 0; pointer-events: none; }
.tooth span { display: grid; place-items: center; width: 38px; height: 42px; border: 1px solid var(--border); border-radius: 10px 10px 14px 14px; background: #fff; cursor: pointer; font-size: .85rem; font-weight: 600; transition: all .12s; }
.tooth span:hover { border-color: var(--primary); }
.tooth input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.tooth input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }
.primary-teeth { margin-top: 14px; }
.primary-teeth summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-bottom: 10px; }

.plan-settings { display: grid; grid-template-columns: auto 180px 140px; gap: 16px; align-items: end; }
.planner:has(input[name="treatmentMonths"][value=""]:checked) .plan-settings { display: none; }
.plan-summary { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin: 4px 0 12px; }
.plan-card { border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.plan-table td, .plan-table th { padding: 9px 14px; }
.plan-table .plan-date { font-weight: 600; margin-right: 6px; }
.plan-table input[type=datetime-local] { padding: 6px 8px; font-size: .85rem; width: 210px; }
.plan-table tr.row-error td { background: var(--danger-soft); }
.plan-table .field-error { margin: 2px 0 0; }

.sticky-footer { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; margin: 0; z-index: 5; }

.exam-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.exam-summary .card + .card { margin-top: 0; }
.exam-summary section:last-child { grid-column: 1 / -1; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 5px 11px; border-radius: 99px; background: var(--primary-soft); color: var(--primary-dark); font-size: .88rem; font-weight: 500; }
.tag-other { background: var(--bg); color: var(--text); border: 1px dashed var(--border); }
.tag-tooth { background: var(--text); color: #fff; font-weight: 700; }
.findings { margin-top: 12px; }
.findings p { margin: 2px 0 0; }

/* ---------- Calendar ---------- */
.main-wide { max-width: 1400px; }
.cal-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.dentist-switch select { width: auto; padding: 8px 10px; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tabs a { padding: 7px 14px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--primary); color: #fff; }

.cal-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.legend { display: flex; gap: 14px; font-size: .85rem; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 3px; }
.dot.booked { background: var(--primary); }
.dot.free { background: #fff; border: 1.5px dashed #33b38a; }
.dot.break { background: repeating-linear-gradient(45deg, #eef1f5, #eef1f5 3px, #fff 3px, #fff 6px); border: 1px solid var(--border); }

.cal-card { padding: 0; overflow-x: auto; }
.cal-grid { --row-h: 18px; display: grid; grid-template-columns: 64px repeat(7, minmax(120px, 1fr)); min-width: 920px; }
.cal-corner, .cal-day-head { position: sticky; top: 0; background: #fafbfc; border-bottom: 1px solid var(--border); z-index: 2; }
.cal-day-head { padding: 10px 10px 8px; border-left: 1px solid var(--border); }
.cal-day-head .dow { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.cal-day-head .dom { font-weight: 700; font-size: 1.05rem; }
.cal-day-head .counts { font-size: .75rem; color: var(--muted); }
.cal-day-head.today .dom { color: var(--primary); }
.cal-hours { display: grid; padding-top: 4px; }
.cal-hour { font-size: .72rem; color: var(--muted); text-align: right; padding-right: 8px; border-top: 1px solid var(--border); padding-top: 2px; }
.cal-day { display: grid; grid-template-columns: 1fr; border-left: 1px solid var(--border); padding: 4px 4px 8px; gap: 0;
    background-image: linear-gradient(var(--border) 1px, transparent 1px); background-size: 100% calc(var(--row-h) * 4); background-position: 0 4px; }
.cal-day.today { background-color: #f6fbfa; }
.cal-day.closed { background-color: #f7f8fa; }
.cal-block { grid-column: 1; margin: 1px 2px; border-radius: 7px; padding: 2px 7px; font-size: .75rem; overflow: hidden; line-height: 1.3; }
.cal-block.booked { background: var(--primary); color: #fff; display: flex; flex-direction: column; justify-content: center; z-index: 1; }
.cal-block.booked:hover { background: var(--primary-dark); text-decoration: none; }
.cal-block.booked strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-block.booked span { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-block.free { border: 1.5px dashed #33b38a; background: #f1fbf6; color: #1d7a57; display: flex; align-items: center; }
.cal-block.break { background: repeating-linear-gradient(45deg, #eef1f5, #eef1f5 4px, #f8f9fb 4px, #f8f9fb 8px); color: var(--muted); display: flex; align-items: center; justify-content: center; }

.month-grid { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 700px; }
.month-grid th { padding: 10px; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--border); }
.month-grid td { border: 1px solid var(--border); height: 96px; vertical-align: top; padding: 0; }
.month-grid td.out { background: #fafbfc; }
.month-grid td.out .month-day { opacity: .45; }
.month-grid td.closed { background: #f7f8fa; }
.month-grid td.today .dom { background: var(--primary); color: #fff; border-radius: 99px; padding: 0 8px; }
.month-day { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px; height: 100%; color: var(--text); }
.month-day:hover { background: var(--primary-soft); text-decoration: none; }
.month-day .dom { font-weight: 700; }
.pill { font-size: .72rem; padding: 1px 8px; border-radius: 99px; font-weight: 600; }
.pill.booked { background: var(--primary); color: #fff; }
.pill.free { background: #e8f8f0; color: #1d7a57; }
.pill.closed { color: var(--muted); }

/* Booking from a free slot, days off, appointment status */
.cal-block.free { text-decoration: none; justify-content: space-between; gap: 4px; }
.cal-block.free .plus { display: none; font-weight: 700; }
.cal-block.free:hover { background: #33b38a; color: #fff; border-style: solid; text-decoration: none; }
.cal-block.free:hover .plus { display: inline; }
.cal-block.booked.done { background: #475467; }
.cal-block.booked.noshow { background: var(--danger); }
.cal-block.off { background: #fff4e5; border: 1px solid #f5c37a; color: #8a5300; display: flex; align-items: center; justify-content: center; text-align: center; }
.cal-day.off { background-color: #fff8ee; }
.dot.off { background: #fff4e5; border: 1px solid #f5c37a; }
.close-day { font-size: .72rem; }
.closed-reason { color: #8a5300 !important; font-weight: 600; }
.pill.off { background: #fff4e5; color: #8a5300; }
.month-grid td.off { background: #fff8ee; }

.alert-warning { background: #fff8ee; color: #8a5300; border: 1px solid #f5c37a; }
.alert-warning a { color: #8a5300; text-decoration: underline; }
.alert p { margin: 0; }

.patient-results { margin-top: 10px; min-height: 40px; }
.off-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); }
form:has(input[name="wholeDay"]:checked) .part-day { display: none; }

.reschedule { display: flex; gap: 10px; flex-wrap: wrap; }
.reschedule input { max-width: 260px; }
.status-actions { display: flex; flex-direction: column; gap: 8px; }
.status-badge { font-size: .9rem; padding: 6px 14px; }
.status-scheduled { background: var(--primary-soft); color: var(--primary-dark); }
.status-confirmed { background: var(--success-soft); color: var(--success); }
.status-completed { background: #eaecf0; color: #344054; }
.status-cancelled, .status-no_show { background: var(--danger-soft); color: var(--danger); }

/* Multiple visits: step-6 options, next-sitting picker, course progress */
.planner .multi-settings { display: none; margin-top: 4px; }
.planner:has(input[name="treatmentMonths"][value="0"]:checked) .multi-settings { display: block; }
.planner:has(input[name="treatmentMonths"][value="0"]:checked) .plan-settings,
.planner:has(input[name="treatmentMonths"][value="0"]:checked) #schedule-preview { display: none; }
.multi-settings:not(:has(input[name="sittings"]:checked)) .next-sitting,
.multi-settings:has(input[name="sittings"][value="1"]:checked) .next-sitting { display: none; }
.next-sitting { border-top: 1px solid var(--border); padding-top: 14px; }
.sub-title { font-size: 1rem; margin: 0 0 4px; }
.sitting-picker { margin-top: 10px; }
.free-times { margin: 6px 0 4px; }
.time-chips .chip span { min-width: 84px; text-align: center; }
.inner-card { margin-top: 14px; box-shadow: none; background: #fafbfc; }

.course-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.progress { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; margin-bottom: 12px; }
.progress span { display: block; height: 100%; border-radius: 99px; background: var(--primary); transition: width .4s ease; }
.sittings { list-style: none; margin: 0; padding: 0; }
.sittings li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.sittings .s-no { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem;
    border: 2px solid var(--border); color: var(--muted); background: #fff; }
.sittings li.done .s-no { background: var(--primary); border-color: var(--primary); color: #fff; }
.sittings li.booked .s-no { border-color: var(--primary); color: var(--primary); }
.sittings li.missed .s-no { border-color: var(--danger); color: var(--danger); }
.sittings .s-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sittings .s-status { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.course-actions { margin-top: 14px; }

.range-switch { display: flex; gap: 6px; align-items: center; margin-bottom: 14px; }
.day-group + .day-group { margin-top: 14px; }
.day-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 1rem; }
.appt-row { display: grid; grid-template-columns: 170px 1fr auto; gap: 14px; align-items: center; padding: 11px 0; border-top: 1px solid var(--border); }
.appt-row.compact { grid-template-columns: 80px 1fr; padding: 8px 0; }
.appt-time { font-weight: 700; color: var(--primary-dark); }
.appt-meta { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--primary-soft), var(--bg) 55%); }
.auth .card { width: 100%; max-width: 400px; padding: 32px; }
.auth .brand { padding: 0 0 22px; }

/* Elements that exist only for the phone layout. Hidden on desktop. */
.mobile-only { display: none; }

/* =====================================================================
   PHONE / SMALL TABLET (≤ 900px). Everything below applies only here;
   the desktop layout above is untouched.
   ===================================================================== */
@media (max-width: 900px) {
    :root { --tabbar-h: 64px; }

    /* ---- App shell: compact top bar + bottom tab bar ---- */
    .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center;
        padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar > .nav, .sidebar-footer { display: none; }
    .brand { padding: 0; }
    .brand-mark { width: 32px; height: 32px; }
    .main { padding: 16px 14px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom)); }

    .mobile-only { display: block; }
    .tabbar.mobile-only { display: flex; }
    .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border);
        box-shadow: 0 -2px 10px rgba(16, 24, 40, .05); }
    .tabbar > a, .tab-more > summary { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; font-size: .7rem; font-weight: 600; color: var(--muted); list-style: none; cursor: pointer; text-decoration: none; }
    .tabbar > a:hover { text-decoration: none; }
    .tab-more { flex: 1; display: flex; }
    .tab-more > summary::-webkit-details-marker { display: none; }
    .tab-icon { font-size: 1.35rem; line-height: 1; }
    .tabbar > a.active, .tab-more.active > summary, .tab-more[open] > summary { color: var(--primary); }
    .tab-add { color: var(--primary) !important; }
    .tab-add .tab-icon { width: 46px; height: 46px; margin-top: -20px; border-radius: 50%; background: var(--primary); color: #fff;
        display: grid; place-items: center; font-size: 1.7rem; box-shadow: 0 4px 12px rgba(14, 147, 132, .35); }
    .more-sheet { position: fixed; left: 10px; right: 10px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
        display: flex; flex-direction: column; padding: 8px; background: var(--surface); border: 1px solid var(--border);
        border-radius: 16px; box-shadow: 0 12px 32px rgba(16, 24, 40, .18); }
    .more-who { display: flex; flex-direction: column; padding: 10px 14px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
    .more-sheet a, .more-logout { display: block; width: 100%; padding: 13px 14px; border: 0; border-radius: 10px; background: none;
        font: inherit; font-size: 1rem; font-weight: 500; color: var(--text); text-align: left; text-decoration: none; }
    .more-sheet a:active, .more-logout:active { background: var(--bg); }
    .more-logout { color: var(--danger); cursor: pointer; }

    /* ---- General sizing: bigger tap targets, no iPhone zoom on focus ---- */
    h1 { font-size: 1.35rem; }
    .page-header { align-items: stretch; margin-bottom: 16px; }
    .page-header > .btn { width: 100%; }
    .page-header .actions { width: 100%; }
    .page-header .actions .btn { flex: 1; }
    .card { padding: 16px; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }
    input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], input[type=time],
    input[type=search], input[type=datetime-local], select, textarea { font-size: 16px; }
    .search input { max-width: none; }
    .form-footer { flex-direction: column-reverse; }
    .form-footer .btn { width: 100%; }
    .sticky-footer { flex-direction: row; }
    .sticky-footer .btn { width: auto; flex: 1; }
    .grid-2, .row, .details, .exam-summary, .plan-settings { grid-template-columns: 1fr; }

    input[type=datetime-local] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
        font: inherit; font-size: 16px; color: var(--text); background: #fff; }
    .grid > .card + .card { margin-top: 0; }
    .table-card { padding: 0; }
    .card > .table:not(.stack-mobile) td { padding: 10px 6px; white-space: nowrap; }

    /* Dashboard: keep the three numbers side by side */
    .grid-3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .card.stat { padding: 12px; }
    .stat .label { font-size: .7rem; line-height: 1.25; }
    .stat .value { font-size: 1.5rem; }

    /* ---- Tables become cards ---- */
    .table-card:has(.stack-mobile) { background: transparent; border: 0; box-shadow: none; overflow: visible; }
    .plan-card { border: 0; }
    .stack-mobile thead { display: none; }
    .stack-mobile, .stack-mobile tbody, .stack-mobile tr { display: block; width: 100%; }
    .stack-mobile tr { position: relative; margin-bottom: 10px; padding: 12px 14px; background: var(--surface);
        border: 1px solid var(--border); border-radius: 12px; }
    .stack-mobile tbody tr:hover { background: var(--surface); }
    .stack-mobile td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; }
    .stack-mobile td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 500; }
    .stack-mobile td:has(input:not([type=checkbox]):not([type=hidden])) { flex-direction: column; align-items: stretch; gap: 4px; }
    .stack-mobile td.cell-title { font-size: 1.05rem; padding: 0 40px 6px 0; }
    .stack-mobile td.cell-seq { position: absolute; top: 12px; right: 14px; padding: 0; }
    .stack-mobile td.cell-actions { padding-top: 10px; }
    .stack-mobile td.cell-actions .actions { justify-content: flex-start !important; width: 100%; }
    .stack-mobile tr.row-error { background: var(--danger-soft); border-color: #f5b5ae; }
    .stack-mobile tr.row-error td { background: transparent; }
    .plan-table input[type=datetime-local] { width: 100%; }
    .hours input[type=time] { width: 100%; }
    .hours.stack-mobile tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
    .hours.stack-mobile td.cell-title, .hours.stack-mobile td[data-label="Open"] { grid-column: 1 / -1; }

    /* ---- Examination ---- */
    .chip span { padding: 9px 14px; font-size: .95rem; }
    .choices span { padding: 10px 16px; }
    .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
    .filter { white-space: nowrap; padding: 7px 13px; }
    .sticky-footer { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 10px 0; }
    .arch { flex-direction: column; align-items: center; gap: 10px; }
    .arch.lower { padding-top: 10px; }
    .quadrant { flex-wrap: wrap; justify-content: center; gap: 3px; padding: 0; }
    .quadrant.right { border-right: 0; }
    .quadrant::before { flex-basis: 100%; text-align: center; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
    .arch:not(.lower) .quadrant.right::before { content: "Upper right"; }
    .arch:not(.lower) .quadrant.left::before { content: "Upper left"; }
    .arch.lower .quadrant.right::before { content: "Lower right"; }
    .arch.lower .quadrant.left::before { content: "Lower left"; }
    .tooth span { width: 35px; height: 40px; font-size: .8rem; }

    /* ---- Appointment list rows ---- */
    .appt-row { grid-template-columns: 1fr; gap: 4px; }
    .appt-meta { justify-content: flex-start; }
    .reschedule input { max-width: none; }
    .reschedule .btn { width: 100%; }

    /* ---- Calendar: toolbar, one-day agenda instead of the week grid ---- */
    .cal-controls { width: 100%; }
    .dentist-switch, .dentist-switch select { width: 100%; }
    .tabs { width: 100%; overflow-x: auto; }
    .tabs a { flex: 1; text-align: center; white-space: nowrap; padding: 9px 10px; }
    .cal-nav { flex-direction: column; align-items: stretch; }
    .cal-nav .actions .btn { flex: 1; }
    .cal-nav > strong { text-align: center; }
    .cal-nav .legend { justify-content: center; flex-wrap: wrap; }
    .cal-card:has(.cal-grid) { display: none; }

    .day-agenda .agenda-radio { display: none; }
    .day-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; position: sticky;
        top: 53px; z-index: 5; background: var(--bg); padding: 4px 0; }
    .day-strip label { display: flex; flex-direction: column; align-items: center; padding: 7px 0; border-radius: 12px; cursor: pointer;
        background: var(--surface); border: 1px solid var(--border); }
    .day-strip .dow { font-size: .66rem; font-weight: 600; text-transform: uppercase; color: var(--muted); }
    .day-strip .dom { font-size: 1.05rem; font-weight: 700; }
    .day-strip .mini { font-size: .6rem; color: #1d7a57; white-space: nowrap; }
    .day-strip label.closed .mini { color: var(--muted); }
    .day-strip label.today .dom { color: var(--primary); }
    #agenda-0:checked ~ .day-strip label[for="agenda-0"], #agenda-1:checked ~ .day-strip label[for="agenda-1"],
    #agenda-2:checked ~ .day-strip label[for="agenda-2"], #agenda-3:checked ~ .day-strip label[for="agenda-3"],
    #agenda-4:checked ~ .day-strip label[for="agenda-4"], #agenda-5:checked ~ .day-strip label[for="agenda-5"],
    #agenda-6:checked ~ .day-strip label[for="agenda-6"] { background: var(--primary); border-color: var(--primary); }
    #agenda-0:checked ~ .day-strip label[for="agenda-0"] span, #agenda-1:checked ~ .day-strip label[for="agenda-1"] span,
    #agenda-2:checked ~ .day-strip label[for="agenda-2"] span, #agenda-3:checked ~ .day-strip label[for="agenda-3"] span,
    #agenda-4:checked ~ .day-strip label[for="agenda-4"] span, #agenda-5:checked ~ .day-strip label[for="agenda-5"] span,
    #agenda-6:checked ~ .day-strip label[for="agenda-6"] span { color: #fff; }
    .agenda-day { display: none; }
    #agenda-0:checked ~ .agenda-day[data-day="0"], #agenda-1:checked ~ .agenda-day[data-day="1"],
    #agenda-2:checked ~ .agenda-day[data-day="2"], #agenda-3:checked ~ .agenda-day[data-day="3"],
    #agenda-4:checked ~ .agenda-day[data-day="4"], #agenda-5:checked ~ .agenda-day[data-day="5"],
    #agenda-6:checked ~ .agenda-day[data-day="6"] { display: block; }
    .agenda-head { display: flex; flex-direction: column; margin-bottom: 12px; }
    .agenda-item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 12px; margin-bottom: 8px;
        border-radius: 12px; color: var(--text); text-decoration: none; }
    .agenda-item:hover { text-decoration: none; }
    .agenda-item .a-time { flex: none; width: 74px; font-size: .85rem; font-weight: 700; }
    .agenda-item .a-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
    .agenda-item .a-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .agenda-item .a-go { font-size: 1.4rem; color: var(--muted); }
    .agenda-item.booked { background: var(--primary-soft); border-left: 4px solid var(--primary); }
    .agenda-item.free { background: #f1fbf6; border: 1.5px dashed #33b38a; color: #1d7a57; }
    .agenda-item.free:active { background: #33b38a; color: #fff; }
    .agenda-item .a-book { font-weight: 700; }
    .agenda-item.break { min-height: 0; padding: 7px 12px; color: var(--muted);
        background: repeating-linear-gradient(45deg, #eef1f5, #eef1f5 4px, #f8f9fb 4px, #f8f9fb 8px); }
    .agenda-item.off { background: #fff4e5; color: #8a5300; }

    /* Month: compact cells with coloured dots */
    .cal-card:has(.month-grid) { overflow: visible; }
    .month-grid { min-width: 0; }
    .month-grid th { padding: 6px 0; font-size: .65rem; }
    .month-grid td { height: 56px; }
    .month-day { flex-direction: row; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 3px; padding: 6px 2px; }
    .month-day .dom { flex-basis: 100%; text-align: center; font-size: .9rem; }
    .month-grid td.today .dom { flex-basis: auto; }
    .pill { font-size: 0; width: 8px; height: 8px; padding: 0; border-radius: 50%; }
    .pill.free { background: #33b38a; }
    .pill.off { background: #f5a524; }
    .pill.closed { background: #d0d5dd; }
}

/* Priority labels: green (low), yellow (medium), red (high) */
.prio-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; vertical-align: 1px; margin-right: 4px; }
.prio-dot.prio-lg { width: 14px; height: 14px; vertical-align: 3px; }
.prio-dot.prio-GREEN { background: #22c55e; }
.prio-dot.prio-YELLOW { background: #eab308; }
.prio-dot.prio-RED { background: #ef4444; }
.cal-block.booked.prio-GREEN { box-shadow: inset 4px 0 0 #22c55e; }
.cal-block.booked.prio-YELLOW { box-shadow: inset 4px 0 0 #eab308; }
.cal-block.booked.prio-RED { box-shadow: inset 4px 0 0 #ef4444; }
.agenda-item.booked.prio-GREEN { border-left-color: #22c55e; }
.agenda-item.booked.prio-YELLOW { border-left-color: #eab308; }
.agenda-item.booked.prio-RED { border-left-color: #ef4444; }
.prio-picker { display: flex; gap: 8px; margin-bottom: 8px; }
.prio-picker form { flex: 1; }
.prio-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px; border-radius: 10px;
    border: 1.5px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.prio-btn.selected.prio-GREEN { border-color: #22c55e; background: rgba(34, 197, 94, .12); }
.prio-btn.selected.prio-YELLOW { border-color: #eab308; background: rgba(234, 179, 8, .14); }
.prio-btn.selected.prio-RED { border-color: #ef4444; background: rgba(239, 68, 68, .12); }
.sittings .prio-dot { margin: 0; }
/* Calendar appointment box: name and time centred; the priority dot stays on the left. */
.cal-block.booked { align-items: stretch; text-align: center; }
.cal-block.booked strong { position: relative; display: block; padding: 0 12px; }
.cal-block.booked strong .prio-dot.on-fill { position: absolute; left: 0; top: 50%; transform: translateY(-50%); margin: 0; }
.prio-dot.on-fill { width: 9px; height: 9px; box-shadow: 0 0 0 1.5px #fff; margin-right: 5px; vertical-align: 0; }

/* Date / time picker (flatpickr) in DentDesk colours, light and dark */
.flatpickr-input[readonly] { cursor: pointer; background: var(--surface); }
[data-theme="dark"] .flatpickr-input[readonly] { background: var(--input-bg); }
.flatpickr-calendar { font-family: var(--font); border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
    box-shadow: 0 12px 32px rgba(16, 24, 40, .16); }
.flatpickr-calendar.arrowTop::before, .flatpickr-calendar.arrowTop::after,
.flatpickr-calendar.arrowBottom::before, .flatpickr-calendar.arrowBottom::after { display: none; }
.flatpickr-months .flatpickr-month, .flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year, span.flatpickr-weekday,
.flatpickr-months .flatpickr-prev-month, .flatpickr-months .flatpickr-next-month { color: var(--text); fill: var(--text); background: transparent; }
.flatpickr-current-month { font-size: 1rem; font-weight: 600; }
span.flatpickr-weekday { color: var(--muted); font-weight: 600; font-size: .75rem; }
.flatpickr-day { color: var(--text); border-radius: 10px; }
.flatpickr-day:hover, .flatpickr-day:focus { background: var(--primary-soft); border-color: transparent; }
.flatpickr-day.today { border-color: var(--primary); }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.flatpickr-day.flatpickr-disabled, .flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay { color: var(--muted); opacity: .45; }
.flatpickr-time { border-top: 1px solid var(--border) !important; }
.flatpickr-time input, .flatpickr-time .flatpickr-am-pm, .flatpickr-time .flatpickr-time-separator { color: var(--text); background: transparent; }
.flatpickr-time input:hover, .flatpickr-time .flatpickr-am-pm:hover,
.flatpickr-time input:focus, .flatpickr-time .flatpickr-am-pm:focus { background: var(--primary-soft); }
.flatpickr-calendar.hasTime.noCalendar { width: 220px; }
.numInputWrapper span.arrowUp::after { border-bottom-color: var(--muted); }
.numInputWrapper span.arrowDown::after { border-top-color: var(--muted); }

/* Appointments moved out of a closed day */
.moved-card { margin-bottom: 18px; }
.moved-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--border); }

/* Patient messages */
.msg-item { padding: 10px 0; border-top: 1px solid var(--border); }
.msg-item:first-of-type { border-top: 0; }
.msg-item p { margin: 6px 0 0; }
.msg-cell { max-width: 420px; white-space: normal; }

/* =====================================================================
   LOGO
   ===================================================================== */
img.brand-mark { display: block; object-fit: cover; background: none; box-shadow: 0 1px 3px rgba(16, 24, 40, .15); }
.login-logo { display: block; width: 132px; height: 132px; margin: 0 auto 14px; border-radius: 28px; object-fit: cover;
    box-shadow: 0 8px 24px rgba(14, 147, 132, .25); }
.auth .login-brand { justify-content: center; text-align: center; padding-bottom: 18px; }
.auth h1, .auth .card > p.muted { text-align: center; }

/* =====================================================================
   THEME TOGGLE (top right)
   ===================================================================== */
.theme-toggle { position: fixed; top: 14px; right: 18px; z-index: 40; width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center; cursor: pointer; font-size: 1.1rem; line-height: 1;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
    transition: transform .15s, background .15s; }
.theme-toggle:hover { transform: rotate(-15deg); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
/* Room for the toggle above the page title on desktop. */
.main { padding-top: 60px; }
@media (max-width: 900px) {
    .theme-toggle { top: 10px; right: 12px; width: 34px; height: 34px; }
    .main { padding-top: 16px; }
}

/* =====================================================================
   DARK THEME: active only when <html data-theme="dark">.
   The light theme above is not modified; this block only overrides it.
   ===================================================================== */
[data-theme="dark"] {
    color-scheme: dark;   /* dark native date/time pickers and scrollbars */
    --bg: #0b0d10;
    --surface: #14181d;
    --surface-2: #1b2027;
    --input-bg: #0f1216;
    --border: #262c35;
    --text: #e6eaef;
    --muted: #8d97a5;
    --primary: #12a594;
    --primary-dark: #0e9384;
    --primary-soft: rgba(18, 165, 148, .16);
    --primary-text: #5eead4;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .12);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, .12);
    --free: #6ee7b7;
    --free-soft: rgba(51, 179, 138, .12);
    --free-border: rgba(51, 179, 138, .55);
    --off: #fbbf24;
    --off-soft: rgba(245, 165, 36, .12);
    --off-border: rgba(245, 165, 36, .45);
    --stripe-a: #1a1f26;
    --stripe-b: #14181e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .35);
}

/* Surfaces that were hard-coded white / off-white */
[data-theme="dark"] .table th,
[data-theme="dark"] .cal-corner, [data-theme="dark"] .cal-day-head,
[data-theme="dark"] .month-grid th,
[data-theme="dark"] .month-grid td.out,
[data-theme="dark"] .inner-card { background: var(--surface-2); }
[data-theme="dark"] .table tbody tr:hover,
[data-theme="dark"] .exam-item:hover { background: var(--surface-2); }
[data-theme="dark"] input[type=text], [data-theme="dark"] input[type=email], [data-theme="dark"] input[type=password],
[data-theme="dark"] input[type=tel], [data-theme="dark"] input[type=date], [data-theme="dark"] input[type=time],
[data-theme="dark"] input[type=search], [data-theme="dark"] input[type=datetime-local],
[data-theme="dark"] select, [data-theme="dark"] textarea { background: var(--input-bg); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .choices span, [data-theme="dark"] .filter, [data-theme="dark"] .chip span,
[data-theme="dark"] .tooth span, [data-theme="dark"] .sittings .s-no { background: var(--surface-2); color: var(--text); }
[data-theme="dark"] .filter { color: var(--muted); }

/* Text on light-on-dark fills */
[data-theme="dark"] .filter.active, [data-theme="dark"] .tag-tooth { background: var(--text); border-color: var(--text); color: var(--bg); }
[data-theme="dark"] .badge-primary, [data-theme="dark"] .tag, [data-theme="dark"] .nav a.active,
[data-theme="dark"] .status-scheduled, [data-theme="dark"] .appt-time { color: var(--primary-text); }
[data-theme="dark"] .tag-other { color: var(--text); }
[data-theme="dark"] .btn-primary, [data-theme="dark"] .cal-block.booked, [data-theme="dark"] .tabs a.active { color: #fff; }
[data-theme="dark"] .status-completed { background: #2a2f37; color: #cbd5e1; }

/* Calendar: today, closed, free slots, break, days off */
[data-theme="dark"] .cal-day.today { background-color: rgba(18, 165, 148, .06); }
[data-theme="dark"] .cal-day.closed, [data-theme="dark"] .month-grid td.closed { background-color: #101317; }
[data-theme="dark"] .cal-block.free, [data-theme="dark"] .agenda-item.free { background: var(--free-soft); border-color: var(--free-border); color: var(--free); }
[data-theme="dark"] .cal-block.free:hover { background: #33b38a; color: #fff; }
[data-theme="dark"] .dot.free { background: transparent; border-color: var(--free-border); }
[data-theme="dark"] .pill.free { background: var(--free-soft); color: var(--free); }
[data-theme="dark"] .cal-block.break, [data-theme="dark"] .agenda-item.break, [data-theme="dark"] .dot.break {
    background: repeating-linear-gradient(45deg, var(--stripe-a), var(--stripe-a) 4px, var(--stripe-b) 4px, var(--stripe-b) 8px); }
[data-theme="dark"] .cal-block.off, [data-theme="dark"] .agenda-item.off, [data-theme="dark"] .pill.off,
[data-theme="dark"] .dot.off, [data-theme="dark"] .alert-warning { background: var(--off-soft); border-color: var(--off-border); color: var(--off); }
[data-theme="dark"] .cal-day.off, [data-theme="dark"] .month-grid td.off { background-color: rgba(245, 165, 36, .06); }
[data-theme="dark"] .closed-reason, [data-theme="dark"] .alert-warning a { color: var(--off) !important; }
[data-theme="dark"] .placeholder { border-color: var(--border); }

/* Login background */
[data-theme="dark"] .auth { background: linear-gradient(160deg, rgba(18, 165, 148, .14), var(--bg) 55%); }

@media (max-width: 900px) {
    [data-theme="dark"] .day-strip .mini { color: var(--free); }
    [data-theme="dark"] .tabbar { box-shadow: 0 -2px 12px rgba(0, 0, 0, .5); }
    [data-theme="dark"] .more-sheet { box-shadow: 0 12px 32px rgba(0, 0, 0, .6); }
    [data-theme="dark"] .pill.free { background: #33b38a; }
    [data-theme="dark"] .pill.off { background: #f5a524; }
    [data-theme="dark"] .pill.closed { background: #4b5563; }
    [data-theme="dark"] .stack-mobile tr.row-error { border-color: rgba(248, 113, 113, .4); }
}

/* =====================================================================
   PHONE APP SHELL (≤ 900px): app top bar, transitions, toasts, loading bar,
   install banner, quick actions, tappable cards. Desktop is not affected.
   ===================================================================== */
.m-progress { display: none; }

@media (max-width: 900px) {
    /* Feel like an app, not a web page */
    html { -webkit-text-size-adjust: 100%; }
    body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
    .tabbar, .m-topbar, .quick-actions, .day-strip, .tabs, .btn, .chip, .choices, .tooth { -webkit-user-select: none; user-select: none; }
    a, button, .chip span, .choices span, .tooth span { touch-action: manipulation; }

    /* Smooth fade between pages (Chrome / Android, Safari 18+) */
    @view-transition { navigation: auto; }
    ::view-transition-old(root) { animation: 120ms ease-out both vt-fade-out; }
    ::view-transition-new(root) { animation: 180ms ease-out both vt-fade-in; }

    /* Top app bar: logo on main screens, back arrow on inner screens; title fades in on scroll */
    .sidebar { padding-top: calc(10px + env(safe-area-inset-top)); min-height: calc(54px + env(safe-area-inset-top));
        gap: 6px; flex-wrap: nowrap; background: var(--surface); }
    /* No backdrop-filter/transform on .sidebar: it would trap the fixed tab bar and sheets inside it. */
    .theme-toggle { top: calc(10px + env(safe-area-inset-top)); }
    .m-topbar.mobile-only { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; padding-right: 44px; }
    .m-back { display: none; width: 36px; height: 36px; margin-left: -6px; border-radius: 50%; place-items: center;
        font-size: 2rem; line-height: 1; color: var(--primary); text-decoration: none; }
    .m-back:active { background: var(--primary-soft); }
    .is-subpage .m-back { display: grid; }
    .is-subpage .sidebar .brand { display: none; }
    .m-title { font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s; }
    .m-topbar.scrolled .m-title { opacity: 1; transform: none; }
    .sidebar:has(.m-topbar.scrolled) .brand > div { display: none; }
    .page-header .back { display: none; }        /* replaced by the back arrow in the top bar */
    .page-header h1 { font-size: 1.6rem; letter-spacing: -.02em; }

    /* Tap feedback */
    .btn:active, .tabbar > a:active, .quick-actions a:active, .stack-mobile.tap-cards tr:active,
    .exam-item:active, .appt-row:active, .agenda-item:active { transform: scale(.97); }
    .btn, .tabbar > a, .quick-actions a, .stack-mobile tr, .exam-item, .agenda-item { transition: transform .12s ease; }

    /* Whole patient card is tappable */
    .stack-mobile.tap-cards tr { cursor: pointer; }
    .stack-mobile.tap-cards td.cell-title a.name::after { content: ""; position: absolute; inset: 0; border-radius: 12px; }
    .stack-mobile.tap-cards tr::after { content: "›"; position: absolute; right: 14px; top: 10px; font-size: 1.4rem; color: var(--muted); }

    /* Home: quick action tiles */
    .quick-actions.mobile-only { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: -4px 0 14px; }
    .quick-actions a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 14px;
        background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .74rem; font-weight: 600;
        text-decoration: none; text-align: center; }
    .qa-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem;
        background: var(--primary-soft); color: var(--primary); }
    .dashboard-add { display: none; }

    /* Form buttons always reachable above the tab bar */
    .form > .form-footer, form.card > .form-footer { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        background: var(--surface); margin: 16px -16px -16px; padding: 12px 16px; border-top: 1px solid var(--border);
        border-radius: 0 0 12px 12px; z-index: 4; flex-direction: row; }
    .form > .form-footer .btn, form.card > .form-footer .btn { flex: 1; }

    /* Success messages as toasts */
    .toast { position: fixed; left: 12px; right: 12px; top: calc(62px + env(safe-area-inset-top)); z-index: 60; margin: 0;
        box-shadow: 0 10px 30px rgba(16, 24, 40, .18); animation: toast-in .25s ease-out both; }
    .toast.toast-hide { animation: toast-out .4s ease-in both; }

    /* Thin loading bar at the top while the next page opens */
    .m-progress { display: block; position: fixed; top: env(safe-area-inset-top); left: 0; height: 3px; width: 0; z-index: 70;
        background: var(--primary); opacity: 0; pointer-events: none; }
    .m-progress.loading { opacity: 1; animation: progress 8s cubic-bezier(.1, .7, .2, 1) forwards; }

    /* Install banner */
    .install-banner.mobile-only { display: flex; align-items: center; gap: 10px; position: fixed; left: 10px; right: 10px; z-index: 35;
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); padding: 10px 12px; border-radius: 16px;
        background: var(--surface); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(16, 24, 40, .18); }
    .install-banner[hidden] { display: none !important; }
    .install-banner img { border-radius: 10px; flex: none; }
    .install-text { flex: 1; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
    .install-close { border: 0; background: none; font-size: 1.4rem; color: var(--muted); padding: 0 4px; }

    /* Bottom tab bar respects the iPhone home indicator */
    .tabbar { padding-bottom: env(safe-area-inset-bottom); }

    /* Login: full-screen app welcome */
    .auth { align-items: stretch; padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom)); }
    .auth .card { max-width: none; border: 0; box-shadow: none; background: transparent; padding: 24px 6px; display: flex;
        flex-direction: column; justify-content: center; }
    .auth .login-logo { width: 112px; height: 112px; }
    .auth .btn-lg { min-height: 52px; font-size: 1.05rem; }
}

@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-12px); } }
@keyframes progress { 0% { width: 0; } 30% { width: 55%; } 100% { width: 92%; } }
@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root), ::view-transition-new(root), .toast, .m-progress.loading { animation: none !important; }
}

/* =====================================================================
   PHONE: examination as a step-by-step form (see js/examination.js)
   ===================================================================== */
.wizard-head, .wizard-nav { display: none; }

@media (max-width: 900px) {
    .exam-wizard > section.step { display: none; margin-bottom: 0; }
    .exam-wizard > section.step.active { display: block; animation: wizard-in .22s ease-out both; }
    .exam-wizard .sticky-footer { display: none; }          /* replaced by Back / Next */
    .exam-wizard .complaint-list { max-height: none; }      /* the step has the whole screen */

    .exam-wizard .wizard-head { display: block; position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 6;
        margin: -16px -14px 14px; padding: 10px 14px 12px; background: var(--bg); border-bottom: 1px solid var(--border); }
    .wizard-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
    .wizard-count { font-weight: 700; font-size: .95rem; }
    .wizard-skip { font-size: .85rem; white-space: nowrap; }
    .wizard-bar { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
    .wizard-bar span { display: block; height: 100%; border-radius: 99px; background: var(--primary); transition: width .3s ease; }
    .wizard-dots { display: flex; justify-content: space-between; gap: 6px; margin-top: 10px; }
    .wizard-dots button { flex: 1; height: 30px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
        color: var(--muted); font: inherit; font-size: .8rem; font-weight: 700; }
    .wizard-dots button.done { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
    .wizard-dots button.current { background: var(--primary); border-color: var(--primary); color: #fff; }

    .exam-wizard .wizard-nav { display: flex; gap: 10px; position: fixed; z-index: 25; left: 0; right: 0;
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 10px 14px;
        background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 14px rgba(16, 24, 40, .06); }
    .exam-wizard { padding-bottom: 76px; }   /* room for the fixed Back / Next bar */
    .wizard-nav .btn { flex: 1; min-height: 50px; font-size: 1rem; }
    .wizard-nav [data-next] { flex: 2; }
    .wizard-msg { margin-top: 12px; font-weight: 600; }
}

@keyframes wizard-in { from { opacity: 0; transform: translateX(14px); } }

/* PHONE: examination "focus mode" (less on screen) */
@media (max-width: 900px) {
    .exam-focus .tabbar, .exam-focus .install-banner { display: none !important; }
    .exam-focus .main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
    .exam-focus .main > .page-header { display: none; }                 /* big title: shown in the compact header instead */

    .exam-wizard .wizard-head { top: calc(54px + env(safe-area-inset-top)); margin: -16px -14px 12px; padding: 10px 14px 0;
        border-bottom: 0; }
    .wizard-top { margin-bottom: 8px; align-items: center; }
    .wizard-label { display: flex; flex-direction: column; min-width: 0; }
    .wizard-count { font-size: 1.05rem; font-weight: 700; }
    .wizard-patient { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .wizard-bar { height: 4px; margin: 0 -14px; border-radius: 0; }
    .wizard-bar span { border-radius: 0; }

    /* Steps without card chrome or repeated headings */
    .exam-wizard > section.step { background: transparent; border: 0; box-shadow: none; padding: 4px 0 0; }
    .exam-wizard > section.step > .step-head { margin-bottom: 10px; }
    .exam-wizard > section.step > .step-head .step-no,
    .exam-wizard > section.step > .step-head h2 { display: none; }
    .exam-wizard > section.step > .step-head p { margin: 0; }

    /* Denser, lighter controls */
    .exam-wizard .chip span { padding: 7px 11px; font-size: .86rem; }
    .exam-wizard .chips { gap: 6px; }
    .exam-wizard .option-group-title { font-size: .7rem; margin-bottom: 6px; }
    .exam-wizard .option-group + .option-group { margin-top: 12px; }
    .exam-wizard .filter { padding: 5px 11px; font-size: .8rem; }
    .exam-wizard .field > label, .exam-wizard .field-label { font-size: .85rem; }
    .exam-wizard .choices span { padding: 8px 13px; font-size: .9rem; }

    .exam-wizard .wizard-nav { bottom: 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* Public legal pages (privacy policy, terms, data deletion) */
.legal { max-width: 760px; margin: 0 auto; padding: 32px 20px 48px; line-height: 1.65; }
.legal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.legal-head img { border-radius: 12px; }
.legal-head div { display: flex; flex-direction: column; line-height: 1.2; }
.legal h1 { font-size: 1.9rem; margin-bottom: 4px; }
.legal h2 { font-size: 1.15rem; margin: 26px 0 8px; }
.legal ul, .legal ol { padding-left: 22px; }
.legal li { margin-bottom: 6px; }
.legal-foot { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Remove patient */
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 18px;
    padding: 16px 20px; border: 1px solid var(--danger-soft); border-radius: var(--radius); background: var(--surface); }
.danger-zone p { margin: 2px 0 0; }
.file-input { width: 100%; padding: 10px; border: 1px dashed var(--border); border-radius: 9px; background: var(--bg); }

/* Page loading indicator (all screen sizes): thin bar at the top + spinner if it takes a moment */
.m-progress { display: block; position: fixed; top: env(safe-area-inset-top); left: 0; height: 3px; width: 0; z-index: 70;
    background: var(--primary); opacity: 0; pointer-events: none; }
.m-progress.loading { opacity: 1; animation: progress 8s cubic-bezier(.1, .7, .2, 1) forwards; }
@keyframes progress { 0% { width: 0; } 30% { width: 55%; } 100% { width: 92%; } }
.page-loader { position: fixed; inset: 0; z-index: 69; display: none; place-items: center; background: rgba(15, 23, 42, .28); }
.page-loader.show { display: grid; }   /* no fade-in: animations may not run while the browser leaves the page */
.page-loader-box { display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 140px; padding: 22px 28px;
    border-radius: 16px; background: var(--surface); box-shadow: 0 12px 40px rgba(0, 0, 0, .18); }
.page-loader-spin { width: 38px; height: 38px; border-radius: 50%; border: 3.5px solid var(--primary-soft);
    border-top-color: var(--primary); animation: spin .7s linear infinite; }
.page-loader-text { font-weight: 600; font-size: .9rem; color: var(--text); }
[data-theme="dark"] .page-loader { background: rgba(0, 0, 0, .5); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Ongoing patient (examination step 6) + prescriptions & reports */
.ongoing-visits .next-visit { margin-top: 14px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { text-align: center; font-size: 1.15rem; font-weight: 700; max-width: 90px; }
.stepper .btn { width: 46px; height: 46px; padding: 0; font-size: 1.3rem; }
.ongoing-summary { font-weight: 600; color: var(--primary-dark) !important; }

.documents-card { margin-top: 18px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.doc { position: relative; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.doc-thumb { display: grid; place-items: center; height: 120px; background: var(--bg); }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-pdf { font-weight: 800; color: var(--danger); font-size: 1.3rem; letter-spacing: .05em; }
.doc-meta { display: flex; flex-direction: column; padding: 8px 10px; min-width: 0; }
.doc-name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc form { position: absolute; top: 6px; right: 6px; }
.doc-remove { width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 1rem;
    line-height: 1; cursor: pointer; }
.doc-upload { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.doc-pick { position: relative; overflow: hidden; cursor: pointer; }
.doc-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
@media (max-width: 900px) {
    .doc-grid { grid-template-columns: repeat(2, 1fr); }
    .doc-upload .btn { flex: 1; }
}

/* Dashboard: patients who cancelled on WhatsApp (rebook) */
.rebook-alerts { margin-bottom: 18px; border-color: var(--danger-soft); }
.rebook-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 0; border-top: 1px solid var(--border); }
.rebook-main { display: flex; flex-direction: column; min-width: 0; }
.rebook-row .actions { display: flex; gap: 8px; }

/* Message switches: clinic-wide (Admin → Messages) and per patient */
.msg-switch { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.msg-switch p { margin: 2px 0 0; }
.msg-switch.is-on { border-left: 4px solid var(--success, #16a34a); }
.msg-switch.is-off { border-left: 4px solid var(--danger); }
.msg-toggle { display: flex; align-items: center; gap: 8px; }

/* Patients list: Select → tick several → Remove */
.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.bulk-form:not(.selecting) .bulk-only { display: none !important; }
.bulk-all { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; }
.table th.cell-select, .table td.cell-select { width: 36px; }
.cell-select input, .bulk-all input { width: 20px; height: 20px; accent-color: var(--primary); }
@media (max-width: 900px) {
    /* checkbox sits above the "tap whole card" link */
    .stack-mobile td.cell-select { position: absolute; right: 38px; top: 10px; z-index: 2; width: auto; padding: 0; }
    .stack-mobile td.cell-select::before { content: none; }
}

/* ---------- Working hours (day cards, switches, time dropdowns) ---------- */
.hours-form { max-width: 820px; }
.hours-tools { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.hours-day { display: grid; grid-template-columns: 200px 1fr; gap: 14px 20px; align-items: center; padding: 16px 20px; margin-bottom: 10px; }
.hours-day-head { display: flex; flex-direction: column; gap: 8px; }
.hours-day-name { font-size: 1.05rem; }
.hours-body { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: flex-end; }
.hours-range { display: flex; flex-direction: column; gap: 6px; }
.time-pair { display: flex; align-items: center; gap: 8px; }
.time-select { min-width: 118px; padding: 10px 12px; font-size: .95rem; font-weight: 600; border: 1px solid var(--border);
    border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; }
.time-select:disabled { opacity: .4; cursor: default; }
.hours-break.no-break .time-pair { opacity: .4; }
.hours-closed-note { display: none; margin: 0; }
.hours-day.closed { background: var(--bg); }
.hours-day.closed .hours-range { display: none; }
.hours-day.closed .hours-closed-note { display: block; }
.hours-day.closed .hours-day-name { color: var(--muted); }

/* On/off switch (big tap target) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 50px; height: 30px; flex: none; border-radius: 999px; background: var(--border);
    transition: background .15s ease; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s ease; }
.switch input:checked ~ .switch-track { background: var(--primary); }
.switch input:checked ~ .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible ~ .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch-label { font-weight: 600; font-size: .9rem; }
.switch-sm .switch-track { width: 40px; height: 24px; }
.switch-sm .switch-track::after { width: 18px; height: 18px; }
.switch-sm input:checked ~ .switch-track::after { transform: translateX(16px); }

@media (max-width: 900px) {
    .hours-tools { justify-content: stretch; }
    .hours-tools .btn { width: 100%; }
    .hours-day { grid-template-columns: 1fr; padding: 14px 16px; }
    .hours-day-head { flex-direction: row; justify-content: space-between; align-items: center; }
    .hours-body { flex-direction: column; align-items: stretch; }
    .time-pair .time-select { flex: 1; min-width: 0; }
}

/* Patient's page from the reminder links (/r/<code>, /c/<code>): phone-first, no app chrome */
.patient-page { background: var(--bg); min-height: 100vh; }
.patient-wrap { max-width: 460px; margin: 0 auto; padding: 24px 16px 40px; }
.patient-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; font-size: 1.1rem; }
.patient-brand img { border-radius: 10px; }
.patient-card { margin-bottom: 14px; }
.patient-card h1, .patient-card h2 { margin-top: 0; }
.patient-card p { margin: 4px 0; }
.patient-when { display: flex; flex-direction: column; gap: 2px; margin: 12px 0; padding: 12px 14px; border-radius: 12px;
    background: var(--primary-soft); }
.patient-when strong { font-size: 1.15rem; }
.patient-card .alert { margin: 12px 0 0; }
.slot-btn { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.patient-alt { display: inline-block; margin-top: 12px; font-size: .9rem; }
.patient-request { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.patient-request textarea, .patient-request input[type=date] { width: 100%; padding: 12px; font-size: 1rem; border: 1px solid var(--border);
    border-radius: 10px; background: var(--surface); color: var(--text); }

/* Dashboard: what patients did from their "Change time" page */
.patient-requests { margin-bottom: 18px; border-color: var(--primary-soft); }
.preq-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 0; border-top: 1px solid var(--border); }
.preq-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.preq-main .badge { align-self: flex-start; }
.preq-reason { font-style: italic; color: var(--muted); }
.preq-row .actions { display: flex; gap: 8px; }

/* ---------- Reschedules: menu badge, tasks, dashboard "Needs your attention", live pop-ups ---------- */
.nav-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 6px;
    border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; line-height: 1; }
.nav-badge[hidden] { display: none; }
.tab-more summary { position: relative; }
.tab-badge { position: absolute; top: 2px; right: 50%; margin: 0 -22px 0 0; min-width: 18px; height: 18px; font-size: .68rem; }
.tab-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 4px;
    border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; }
.tabs { margin-bottom: 16px; }

.task-card { display: block; position: relative; margin-bottom: 12px; color: var(--text); text-decoration: none;
    border-left: 4px solid var(--danger); transition: box-shadow .15s ease; }
.task-card:hover { text-decoration: none; box-shadow: 0 4px 16px rgba(0, 0, 0, .08); }
.task-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.task-head strong { font-size: 1.05rem; }
.task-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.task-reason { margin: 8px 0 0; font-style: italic; color: var(--muted); }
.task-open { position: absolute; right: 16px; bottom: 14px; font-weight: 600; color: var(--primary); font-size: .9rem; }
.task-detail { margin-bottom: 14px; }
.task-picker { margin-bottom: 14px; }
.task-picker .sitting-picker .row > .field:nth-child(2) { display: none; }   /* length = the appointment's own length */
.task-picker > .btn { margin-top: 14px; }
.task-keep { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.task-keep p { margin: 2px 0 0; }

.attention { margin-bottom: 18px; border-left: 4px solid var(--danger); }
.attention-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border);
    color: var(--text); text-decoration: none; }
.attention-row:hover { text-decoration: none; }
.attention-row:hover .attention-go { color: var(--primary); }
.attention-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%;
    background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.attention-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.attention-main .task-reason { margin: 0; }
.attention-go { font-size: 1.4rem; color: var(--muted); }
.stat-link { color: var(--text); text-decoration: none; }
.stat-link:hover { text-decoration: none; box-shadow: 0 4px 16px rgba(0, 0, 0, .08); }
.stat-alert { border-left: 4px solid var(--danger); }
.stat-alert .value { color: var(--danger); }

.live-toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.live-toast { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface);
    color: var(--text); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0, 0, 0, .18); text-decoration: none;
    animation: toast-in .2s ease-out; }
.live-toast:hover { text-decoration: none; }
.live-toast-text { flex: 1; font-weight: 600; font-size: .92rem; }
.live-toast-close { border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (max-width: 900px) {
    .live-toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; }
    .task-open { position: static; display: block; margin-top: 8px; }
}

/* Cards side by side in a grid: no stacking margin (the grid gap spaces them) */
.grid > .card + .card { margin-top: 0; }
.patient-when.is-off { background: var(--bg); color: var(--muted); }
.patient-when.is-cancelled strong { text-decoration: line-through; }

/* Ongoing patient, step 6: the visits left as a monthly list (hidden when no visits are left) */
.ongoing-monthly { margin-top: 6px; }
.ongoing-monthly[hidden] { display: none; }

/* − [ 3 ] + stepper: one joined control styled like the other fields (same border, radius, height, focus ring) */
.stepper { display: inline-flex; align-items: stretch; gap: 0; height: 44px; border: 1px solid var(--border); border-radius: 9px;
    overflow: hidden; background: #fff; transition: border-color .15s, box-shadow .15s; }
.stepper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.stepper .btn { width: 44px; height: auto; padding: 0; border: 0; border-radius: 0; background: var(--bg); color: var(--text);
    font-size: 1.2rem; font-weight: 600; box-shadow: none; }
.stepper .btn:hover { background: var(--primary-soft); color: var(--primary); }
.stepper input { width: 64px; max-width: none; padding: 0 6px; border: 0; border-left: 1px solid var(--border);
    border-right: 1px solid var(--border); border-radius: 0; background: transparent; color: var(--text);
    font: inherit; font-size: 1rem; font-weight: 600; text-align: center; -moz-appearance: textfield; appearance: textfield; }
.stepper input:focus { outline: none; box-shadow: none; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
[data-theme="dark"] .stepper { background: var(--input-bg); }
[data-theme="dark"] .stepper .btn { background: var(--surface-2); }
/* ---------- Login page (trial look): split screen, self-drawing tooth, rotating lines, floating teeth ---------- */
.auth-split { position: relative; overflow: hidden; display: grid; grid-template-columns: 1.1fr 1fr; align-items: center; min-height: 100vh; color: #fff;
    background: radial-gradient(900px 600px at 15% 10%, #19b8a5, transparent 60%),
                radial-gradient(900px 700px at 95% 95%, #0b5f8a, transparent 60%), #0e8a7c; }
.auth-hero { position: relative; z-index: 1; display: grid; place-items: center; padding: 48px; }
.hero-teeth { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.float-tooth { position: absolute; top: 0; left: 0; will-change: transform; }
.float-tooth svg { width: 100%; height: 100%; display: block; fill: #fff; }
.hero-content { position: relative; z-index: 1; max-width: 420px; text-align: center; }
.hero-tooth { display: block; margin: 0 auto 18px; overflow: visible; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .18)); }
.tooth-line { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 220; stroke-dashoffset: 220; animation: tooth-draw 2.2s ease forwards .3s; }
.tooth-fill { fill: #fff; opacity: 0; animation: tooth-fill .8s ease forwards 2.3s; }
.tooth-smile { fill: none; stroke: #0e8a7c; stroke-width: 2.4; stroke-linecap: round;
    stroke-dasharray: 20; stroke-dashoffset: 20; animation: tooth-draw .6s ease forwards 2.9s; }
.sparkles path { fill: #fff3b0; opacity: 0; transform-box: fill-box; transform-origin: center;
    animation: sparkle 2.4s ease-in-out infinite 3.2s; }
.sparkles path:nth-child(2) { animation-delay: 3.8s; }
.sparkles path:nth-child(3) { animation-delay: 4.4s; }
@keyframes tooth-draw { to { stroke-dashoffset: 0; } }
@keyframes tooth-fill { to { opacity: 1; } }
@keyframes sparkle { 0%, 100% { opacity: 0; transform: scale(.4) rotate(0deg); } 50% { opacity: 1; transform: scale(1.2) rotate(45deg); } }
.hero-title { margin: 0; font-size: 2.4rem; letter-spacing: -.02em; color: #fff; }
.hero-sub { margin: 6px 0 22px; opacity: .9; font-size: 1.05rem; }
.hero-lines { display: grid; margin: 0; padding: 0; list-style: none; }   /* all lines share one cell: height = the longest */
.hero-lines li { grid-area: 1 / 1; font-weight: 600; opacity: 0; transform: translateY(10px);
    transition: opacity .5s ease, transform .5s ease; }
.hero-lines li.active { opacity: 1; transform: none; }

.auth-side { position: relative; z-index: 1; display: grid; place-items: center; padding: 32px; perspective: 1200px; }
.login-card { width: 100%; max-width: 420px; color: var(--text); border: 1px solid rgba(255, 255, 255, .5); border-radius: 22px;
    background: rgba(255, 255, 255, .94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .25s ease-out;
    box-shadow: 0 40px 90px rgba(4, 40, 48, .45), 0 0 0 1px rgba(255, 255, 255, .15); animation: card-in .6s cubic-bezier(.2, .8, .2, 1) both; }
[data-theme="dark"] .login-card { background: rgba(20, 24, 29, .92); border-color: rgba(255, 255, 255, .08); }
.login-card .login-brand { justify-content: center; text-align: left; padding: 0 0 18px; }
.login-card h1, .login-card > p.muted { text-align: center; }
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(.97); } }

@media (max-width: 900px) {
    .auth-split { grid-template-columns: 1fr; grid-template-rows: auto 1fr; align-items: start; }
    .auth-hero { padding: 28px 20px 26px; }
    .hero-tooth { width: 84px; height: 84px; margin-bottom: 8px; }
    .hero-title { font-size: 1.7rem; }
    .hero-sub { margin-bottom: 12px; font-size: .95rem; }
    .hero-lines { font-size: .9rem; }
    .auth-side { padding: 18px 14px 28px; align-items: start; }
    .login-card { box-shadow: 0 20px 50px rgba(4, 40, 48, .35); }
}
/* ---------- App-wide look (light): dashboard teal banner + a very faint drifting tooth pattern behind every page ---------- */
/* Dashboard banner: CSS-only animation (no script), same colours as the login page */
.dash-hero { position: relative; overflow: hidden; align-items: center; gap: 18px; margin-bottom: 22px; padding: 26px 28px;
    border-radius: 20px; color: #fff; isolation: isolate;
    background: radial-gradient(700px 300px at 10% 0%, #19b8a5, transparent 60%),
                radial-gradient(600px 300px at 100% 100%, #0b5f8a, transparent 60%), #0e8a7c;
    box-shadow: 0 18px 40px rgba(14, 138, 124, .25); }
.dash-hero h1 { color: #fff; margin: 0; }
.dash-hero p { margin: 4px 0 0; color: rgba(255, 255, 255, .85); }
.dash-hero-text { position: relative; z-index: 1; flex: 1; min-width: 0; }
.dash-hero-btn { position: relative; z-index: 1; background: #fff; color: #0e8a7c; border-color: #fff; font-weight: 700; }
.dash-hero-btn:hover { background: #f0fdfa; color: #0b6f64; }
.dash-hero-tooth { position: relative; z-index: 1; flex: none; overflow: visible; animation: hero-tooth-float 5s ease-in-out infinite;
    filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .18)); }
.dash-hero-tooth .tooth-body { fill: #fff; }
.dash-hero-tooth .tooth-mouth { fill: none; stroke: #0e8a7c; stroke-width: 2.6; stroke-linecap: round; }
.dash-hero-tooth .tooth-spark { fill: #fff3b0; transform-box: fill-box; transform-origin: center; animation: sparkle 2.6s ease-in-out infinite; }
@keyframes hero-tooth-float { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-6px) rotate(4deg); } }
.dash-hero-teeth { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.dash-hero-teeth span { position: absolute; bottom: -40px; width: 22px; height: 22px; opacity: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath fill='%23ffffff' d='M32 7C22 3 10 7 10 21c0 10 4 17 6 29 1 6 6 8 8 2 2-8 4-12 8-12s6 4 8 12c2 6 7 4 8-2 2-12 6-19 6-29C54 7 42 3 32 7z'/%3E%3C/svg%3E") center / contain no-repeat; animation: hero-bubble 11s linear infinite; will-change: transform, opacity; }
.dash-hero-teeth span:nth-child(1) { left: 6%;  width: 16px; height: 16px; animation-duration: 12s; }
.dash-hero-teeth span:nth-child(2) { left: 18%; width: 26px; height: 26px; animation-duration: 15s; animation-delay: -4s; }
.dash-hero-teeth span:nth-child(3) { left: 31%; width: 14px; height: 14px; animation-duration: 10s; animation-delay: -7s; }
.dash-hero-teeth span:nth-child(4) { left: 44%; width: 22px; height: 22px; animation-duration: 14s; animation-delay: -2s; }
.dash-hero-teeth span:nth-child(5) { left: 57%; width: 18px; height: 18px; animation-duration: 11s; animation-delay: -9s; }
.dash-hero-teeth span:nth-child(6) { left: 69%; width: 28px; height: 28px; animation-duration: 16s; animation-delay: -5s; }
.dash-hero-teeth span:nth-child(7) { left: 81%; width: 15px; height: 15px; animation-duration: 12s; animation-delay: -1s; }
.dash-hero-teeth span:nth-child(8) { left: 92%; width: 20px; height: 20px; animation-duration: 13s; animation-delay: -6s; }
@keyframes hero-bubble {
    0% { transform: translate(0, 0) rotate(-10deg); opacity: 0; }
    15% { opacity: .28; }
    85% { opacity: .2; }
    100% { transform: translate(14px, -220px) rotate(14deg); opacity: 0; }
}
@media (max-width: 900px) {
    .dash-hero { padding: 18px; border-radius: 16px; margin-bottom: 14px; }
    .dash-hero-tooth { width: 46px; height: 46px; }
    .dash-hero h1 { font-size: 1.35rem; }
}

/* Every logged-in page: a very faint tooth pattern drifting slowly behind the content (GPU transform, no script) */
body:has(.app)::before { content: ""; position: fixed; inset: -160px; z-index: -1; pointer-events: none; opacity: .2;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='%2312a594'%3E%3Cpath transform='translate(18 20) scale(.42) rotate(-12 32 32)' d='M32 7C22 3 10 7 10 21c0 10 4 17 6 29 1 6 6 8 8 2 2-8 4-12 8-12s6 4 8 12c2 6 7 4 8-2 2-12 6-19 6-29C54 7 42 3 32 7z'/%3E%3Cpath transform='translate(100 92) scale(.3) rotate(14 32 32)' d='M32 7C22 3 10 7 10 21c0 10 4 17 6 29 1 6 6 8 8 2 2-8 4-12 8-12s6 4 8 12c2 6 7 4 8-2 2-12 6-19 6-29C54 7 42 3 32 7z'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 160px 160px repeat; animation: bg-drift 90s linear infinite; will-change: transform; }
[data-theme="dark"] body:has(.app)::before { opacity: .1; filter: brightness(2.2); }
@keyframes bg-drift { to { transform: translate(160px, 160px); } }

/* ---------- Left menu (desktop): teal like the login & dashboard banner, faint drifting teeth, icons, glowing active item ---------- */
.nav-ico { display: inline-grid; place-items: center; width: 22px; flex: none; font-size: 1rem; opacity: .9; }
.nav a, .nav .soon { justify-content: flex-start; gap: 10px; }
.nav .nav-badge, .nav .soon small { margin-left: auto; }
@media (min-width: 901px) {
    /* No transform / backdrop-filter on .sidebar itself (it would trap its fixed children); the teeth move on ::before. */
    .sidebar { position: sticky; overflow: hidden; color: #fff; border-right: 0; isolation: isolate;
        background: radial-gradient(500px 400px at 0% 0%, #19b8a5, transparent 60%),
                    radial-gradient(500px 500px at 100% 100%, #0b5f8a, transparent 65%), #0e8a7c; }
    .sidebar::before { content: ""; position: absolute; inset: -160px 0 0 0; z-index: -1; pointer-events: none; opacity: .12;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='160' viewBox='0 0 120 160'%3E%3Cg fill='%23ffffff'%3E%3Cpath transform='translate(10 14) scale(.36) rotate(-12 32 32)' d='M32 7C22 3 10 7 10 21c0 10 4 17 6 29 1 6 6 8 8 2 2-8 4-12 8-12s6 4 8 12c2 6 7 4 8-2 2-12 6-19 6-29C54 7 42 3 32 7z'/%3E%3Cpath transform='translate(70 96) scale(.26) rotate(16 32 32)' d='M32 7C22 3 10 7 10 21c0 10 4 17 6 29 1 6 6 8 8 2 2-8 4-12 8-12s6 4 8 12c2 6 7 4 8-2 2-12 6-19 6-29C54 7 42 3 32 7z'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 120px 160px repeat; animation: side-drift 40s linear infinite; }
    @keyframes side-drift { to { transform: translateY(160px); } }
    .sidebar .brand { color: #fff; }
    .sidebar .brand small { color: rgba(255, 255, 255, .75); }
    .sidebar .brand-mark { box-shadow: 0 6px 16px rgba(0, 0, 0, .2); }
    .sidebar .nav a { color: rgba(255, 255, 255, .88); transition: background .15s, transform .15s, color .15s; }
    .sidebar .nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; transform: translateX(3px); }
    .sidebar .nav a.active { background: #fff; color: #0b6f64; font-weight: 700;
        box-shadow: 0 8px 22px rgba(0, 0, 0, .18), 0 0 0 4px rgba(255, 255, 255, .12); }
    .sidebar .nav a.active .nav-ico { opacity: 1; }
    .sidebar .nav .soon { color: rgba(255, 255, 255, .5); }
    .sidebar .nav .soon small { background: rgba(255, 255, 255, .15); color: rgba(255, 255, 255, .8); }
    .sidebar .nav-section { color: rgba(255, 255, 255, .6); }
    .sidebar .sidebar-footer { border-top-color: rgba(255, 255, 255, .18); }
    .sidebar .sidebar-footer .who strong { color: #fff; }
    .sidebar .sidebar-footer .who span { color: rgba(255, 255, 255, .7); }
    .sidebar .sidebar-footer .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .3); }
    .sidebar .sidebar-footer .btn-ghost:hover { background: rgba(255, 255, 255, .12); }
    .sidebar .nav-badge { background: #ff5a5f; box-shadow: 0 0 0 2px rgba(255, 255, 255, .25); }
    [data-theme="dark"] .sidebar { background: radial-gradient(500px 400px at 0% 0%, #0f6f63, transparent 60%),
                                               radial-gradient(500px 500px at 100% 100%, #0a3d57, transparent 65%), #0b3f3a; }
    [data-theme="dark"] .sidebar .nav a.active { background: rgba(255, 255, 255, .92); color: #0b6f64; }
}

/* ---------- Plan my day ---------- */
.plan-day-date { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.plan-day-date input[type=date] { width: auto; }
.plan-day-modes { margin-bottom: 18px; align-items: start; }
.plan-day-list { display: flex; flex-direction: column; gap: 4px; margin: 10px 0 14px; max-height: none; }
.plan-day-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 10px; cursor: pointer; background: var(--surface); }
.plan-day-item:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.plan-day-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.plan-day-item.is-fixed { opacity: .6; cursor: default; }
.plan-day-time { font-weight: 700; min-width: 70px; }
.plan-day-name { flex: 1; min-width: 0; }
.plan-day-preview { border-left: 4px solid var(--primary); }
.plan-day-result { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plan-day-result li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.plan-day-confirm { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.plan-day-modes input[type=number] { width: 100%; max-width: 160px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
    font: inherit; color: var(--text); background: var(--surface); }
.plan-day-modes input[type=number]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Working hours: gap between appointments */
.hours-gap { display: flex; justify-content: space-between; align-items: center; gap: 14px 24px; flex-wrap: wrap; margin-bottom: 12px; }
.hours-gap p { margin: 2px 0 0; }

/* ---------- Install app page (/install): step cards with drawn phone pictures ---------- */
.install-page .tabs { margin: 6px 0 12px; }
.install-state { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.install-state[hidden], .install-desktop[hidden] { display: none; }
.install-steps { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.install-steps > li.card { margin: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; }
.install-steps svg { width: 150px; max-width: 70%; height: auto; display: block; }
.install-steps .step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
    background: var(--primary); color: #fff; font-weight: 700; font-size: .8rem; margin-right: 6px; }
.install-steps p { margin: 4px 0 0; }
.ph-frame { fill: var(--text); }
.ph-screen { fill: var(--surface); }
.ph-brand { fill: var(--primary); }
.ph-line { fill: var(--border); }
.ph-card { fill: var(--primary-soft); }
.ph-bar { fill: var(--bg); }
.ph-pill, .ph-row { fill: var(--border); }
.ph-sheet { fill: var(--surface); stroke: var(--border); }
.ph-dim { fill: rgba(0, 0, 0, .35); }
.ph-home { fill: #3b5bdb; }
.ph-app { fill: rgba(255, 255, 255, .55); }
.ph-dot { fill: var(--text); }
.ph-stroke { fill: none; stroke: var(--primary); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.ph-text { fill: var(--text); font-size: 7.5px; font-family: var(--font); }
.ph-tiny { fill: var(--muted); font-size: 5.5px; font-family: var(--font); }
.ph-light { fill: #fff; }
.ph-link { fill: #0a84ff; font-size: 7.5px; font-family: var(--font); }
.ph-bold { font-weight: 700; }
.ph-icon { fill: var(--primary); font-size: 10px; font-family: var(--font); }
.install-steps .hl { fill: none; stroke: #f59e0b; stroke-width: 2.5; animation: hl-pulse 1.6s ease-in-out infinite; }
@keyframes hl-pulse { 0%, 100% { stroke-opacity: 1; } 50% { stroke-opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .install-steps .hl { animation: none; } }
.ph-small { font-size: 6px; }
@media (max-width: 600px) {
    .install-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .install-steps > li.card { padding: 12px 10px; }
    .install-steps svg { max-width: 100%; width: 120px; }
    .install-steps strong { font-size: .9rem; }
}

/* "Keep me logged in" checkbox on the login card */
.remember-me { display: flex; align-items: center; gap: 8px; margin: 2px 0 14px; font-size: .92rem; cursor: pointer; }
.remember-me input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
