/* Appointment Booking — CareClinic practice management. Namespaced .ap */
* { box-sizing: border-box; }
body { margin: 0; }
.ap {
    --bg: #f1f6f6; --panel: #ffffff; --line: #e2ecec; --ink: #0f2b2b; --muted: #5b7d7d;
    --brand: #0d9488; --brand-ink: #0f766e; --accent: #f59e0b;
    --ok: #16a34a; --warn: #f59e0b; --danger: #ef4444; --info: #2563eb;
    --shadow: 0 12px 32px -18px rgba(13,148,136,.35);
    min-height: calc(100vh - 44px);
    font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
    background: radial-gradient(1000px 420px at 88% -10%, rgba(13,148,136,.08), transparent), var(--bg);
    color: var(--ink);
}
.ap-btn { border: 0; cursor: pointer; border-radius: .6rem; padding: .6rem 1rem; font: 600 .88rem inherit; background: var(--brand); color: #fff; transition: transform .1s, background .15s; white-space: nowrap; }
.ap-btn:hover { transform: translateY(-1px); }
.ap-btn.ghost { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.ap-btn.ghost:hover { border-color: var(--brand); color: var(--brand-ink); }
.ap-btn.sm { padding: .4rem .7rem; font-size: .8rem; }
.ap-btn.danger { background: var(--danger); }
.ap-h2 { margin: 0 0 1.2rem; font-size: 1.3rem; }

/* Topbar */
.ap-topbar { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.5rem; background: var(--panel); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; flex-wrap: wrap; }
.ap-brand { display: flex; align-items: center; gap: .6rem; }
.ap-logo { background: var(--brand); color: #fff; width: 2rem; height: 2rem; border-radius: .55rem; display: grid; place-items: center; font-size: 1.2rem; font-weight: 800; }
.ap-brand b { display: block; font-size: 1.05rem; }
.ap-brand small { color: var(--muted); font-size: .72rem; }
.ap-nav { display: flex; gap: .25rem; margin: 0 auto; flex-wrap: wrap; }
.ap-navbtn { border: 0; background: transparent; color: var(--muted); padding: .5rem .8rem; border-radius: .6rem; font: 600 .85rem inherit; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.ap-navbtn:hover { color: var(--ink); background: #ecf5f5; }
.ap-navbtn.active { background: var(--brand); color: #fff; }
.ap-badge { background: rgba(0,0,0,.12); border-radius: 999px; padding: 0 .4rem; font-size: .7rem; min-width: 1.1rem; text-align: center; }
.ap-navbtn.active .ap-badge { background: rgba(255,255,255,.25); }
.ap-top-actions { display: flex; align-items: center; gap: .6rem; }
.ap-live-dot { color: var(--ok); font-size: .72rem; font-weight: 800; letter-spacing: .1em; display: inline-flex; align-items: center; gap: .4rem; }
.ap-live-dot::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); animation: appulse 1.3s infinite; }
@keyframes appulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.ap-view { max-width: 1360px; margin: 0 auto; padding: 1.5rem; }
.ap-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 1.3rem; box-shadow: var(--shadow); }
.ap-card h3 { margin: 0 0 1rem; font-size: .95rem; }

/* BOOK */
.ap-book-grid { display: grid; grid-template-columns: 240px 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 860px) { .ap-book-grid { grid-template-columns: 1fr; } }
.ap-filters { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 1.2rem; box-shadow: var(--shadow); position: sticky; top: 76px; }
@media (max-width: 860px) { .ap-filters { position: static; } }
.ap-filters h3 { margin: 0 0 .8rem; font-size: .9rem; }
.ap-filters input[type=text] { width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: .6rem; background: #f8fbfb; margin-bottom: .8rem; }
.ap-spec-list { display: flex; flex-direction: column; gap: .15rem; margin-bottom: .8rem; }
.ap-spec { border: 0; background: transparent; text-align: left; padding: .45rem .6rem; border-radius: .5rem; font: 600 .82rem inherit; color: var(--muted); cursor: pointer; }
.ap-spec:hover { background: #ecf5f5; color: var(--ink); }
.ap-spec.active { background: #ccfbf1; color: var(--brand-ink); }
.ap-check { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--muted); }
.ap-check input { accent-color: var(--brand); }

.ap-doclist { display: flex; flex-direction: column; gap: 1rem; }
.ap-doc { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 1.3rem; box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr auto; gap: 1.2rem; align-items: start; }
@media (max-width: 640px) { .ap-doc { grid-template-columns: 1fr; } }
.ap-doc-av { width: 3.6rem; height: 3.6rem; border-radius: 1rem; display: grid; place-items: center; font-size: 1.9rem; color: #fff; }
.ap-doc-info h4 { margin: 0 0 .15rem; font-size: 1.05rem; }
.ap-doc-info .quals { color: var(--muted); font-size: .8rem; }
.ap-doc-info .meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin: .5rem 0; font-size: .8rem; color: var(--muted); }
.ap-doc-info .meta b { color: var(--ink); }
.ap-doc-info .rating { color: var(--accent); font-weight: 700; }
.ap-doc-info .bio { font-size: .84rem; color: var(--muted); line-height: 1.5; }
.ap-doc-info .langs { margin-top: .5rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.ap-doc-info .langs span { font-size: .7rem; background: #ecf5f5; color: var(--muted); border-radius: 999px; padding: .1rem .5rem; }
.ap-doc-cta { text-align: right; }
.ap-doc-cta .fee { font-weight: 800; font-size: 1.1rem; }
.ap-doc-cta .fee small { display: block; color: var(--muted); font-size: .7rem; font-weight: 400; }
.ap-doc-cta .next { color: var(--ok); font-size: .78rem; font-weight: 600; margin: .4rem 0; }
.ap-tele-tag { display: inline-block; font-size: .68rem; background: #dbeafe; color: var(--info); border-radius: 999px; padding: .1rem .5rem; font-weight: 700; margin-top: .3rem; }

/* Booking modal */
.ap-modal-overlay { position: fixed; inset: 0; background: rgba(6,42,42,.55); display: flex; align-items: center; justify-content: center; z-index: 120; padding: 1rem; }
.ap-modal-overlay[hidden] { display: none; }
.ap-modal-card { background: var(--panel); border-radius: 1.2rem; padding: 1.6rem; width: min(34rem, 100%); max-height: 90vh; overflow: auto; position: relative; box-shadow: var(--shadow); }
.ap-modal-close { position: absolute; top: 1rem; right: 1.2rem; border: 0; background: transparent; font-size: 1.5rem; cursor: pointer; color: #94a3b8; }
.ap-modal-card h3 { margin: 0 0 .3rem; }
.ap-modal-card .sub { color: var(--muted); font-size: .85rem; margin: 0 0 1.2rem; }
.ap-step-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--brand-ink); font-weight: 800; margin: 1.2rem 0 .6rem; }
.ap-days { display: flex; gap: .4rem; flex-wrap: wrap; }
.ap-day { border: 1.5px solid var(--line); background: #f8fbfb; border-radius: .6rem; padding: .5rem .7rem; text-align: center; cursor: pointer; min-width: 3.4rem; }
.ap-day.sel { border-color: var(--brand); background: var(--brand); color: #fff; }
.ap-day small { display: block; font-size: .66rem; opacity: .8; }
.ap-day b { font-size: 1.05rem; }
.ap-slot-group { margin-top: .8rem; }
.ap-slot-group .sg-label { font-size: .74rem; color: var(--muted); margin-bottom: .4rem; }
.ap-slots { display: flex; gap: .4rem; flex-wrap: wrap; }
.ap-slot { border: 1.5px solid var(--line); background: var(--panel); border-radius: .5rem; padding: .45rem .7rem; cursor: pointer; font: 600 .82rem inherit; font-variant-numeric: tabular-nums; }
.ap-slot:hover { border-color: var(--brand); }
.ap-slot.sel { border-color: var(--brand); background: var(--brand); color: #fff; }
.ap-slot.taken { opacity: .35; text-decoration: line-through; cursor: not-allowed; }
.ap-field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; font-size: .78rem; color: var(--muted); font-weight: 600; }
.ap-field span { text-transform: uppercase; font-size: .66rem; letter-spacing: .03em; }
.ap-field input, .ap-field select, .ap-field textarea { font: 400 .9rem inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: .55rem; background: #f8fbfb; color: var(--ink); }
.ap-field-row { display: flex; gap: .6rem; }
.ap-field-row .ap-field { flex: 1; }
.ap-mode-toggle { display: flex; gap: .4rem; }
.ap-mode-toggle button { flex: 1; border: 1.5px solid var(--line); background: #f8fbfb; border-radius: .6rem; padding: .55rem; font: 600 .82rem inherit; cursor: pointer; color: var(--muted); }
.ap-mode-toggle button.sel { border-color: var(--brand); background: #ccfbf1; color: var(--brand-ink); }
.ap-summary { background: #f8fbfb; border: 1px solid var(--line); border-radius: .7rem; padding: .9rem 1rem; font-size: .85rem; margin: 1rem 0; }
.ap-summary .r { display: flex; justify-content: space-between; padding: .15rem 0; }
.ap-summary .r b { }

/* Confirmation / WhatsApp */
.ap-confirm { text-align: center; padding: .5rem 0; }
.ap-confirm .check { width: 3.5rem; height: 3.5rem; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; font-size: 1.6rem; margin: 0 auto 1rem; animation: appop .4s ease; }
@keyframes appop { from { transform: scale(0); } }
.ap-wa { background: #075e54; border-radius: .9rem; overflow: hidden; margin: 1.2rem 0 .5rem; text-align: left; }
.ap-wa-top { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; color: #fff; font-size: .82rem; }
.ap-wa-top .a { width: 1.9rem; height: 1.9rem; border-radius: 50%; background: #128c7e; display: grid; place-items: center; }
.ap-wa-body { background: #e5ddd5; padding: .9rem; display: flex; flex-direction: column; gap: .5rem; }
.ap-wa-msg { background: var(--panel); align-self: flex-start; border-radius: .7rem; border-top-left-radius: .2rem; padding: .55rem .7rem; font-size: .82rem; max-width: 90%; box-shadow: 0 1px 1px rgba(0,0,0,.1); line-height: 1.45; }
.ap-wa-msg.link { color: var(--brand-ink); font-weight: 700; }

/* APPOINTMENTS */
.ap-appt-list { display: flex; flex-direction: column; gap: 1rem; }
.ap-appt { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 1rem; padding: 1.2rem; box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; }
@media (max-width: 640px) { .ap-appt { grid-template-columns: 1fr; } }
.ap-appt.past { border-left-color: var(--muted); opacity: .8; }
.ap-appt.cancelled { border-left-color: var(--danger); }
.ap-appt-av { width: 3rem; height: 3rem; border-radius: .8rem; display: grid; place-items: center; font-size: 1.5rem; color: #fff; }
.ap-appt-info b { display: block; }
.ap-appt-info .l { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.ap-appt-info .tag { display: inline-block; font-size: .68rem; padding: .1rem .5rem; border-radius: 999px; margin-top: .4rem; font-weight: 700; }
.ap-appt-info .tag.up { background: #ccfbf1; color: var(--brand-ink); }
.ap-appt-info .tag.past { background: #e2e8f0; color: var(--muted); }
.ap-appt-info .tag.cancelled { background: #fee2e2; color: var(--danger); }
.ap-appt-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.ap-empty { text-align: center; color: var(--muted); padding: 3rem 1rem; border: 1px dashed var(--line); border-radius: 1rem; }

/* QUEUE */
.ap-queue-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.2rem; }
.ap-queue-head h2 { margin: 0; }
.ap-queue-stats { display: flex; gap: 1.5rem; }
.ap-queue-stats .s b { font-size: 1.3rem; font-weight: 800; display: block; }
.ap-queue-stats .s small { color: var(--muted); font-size: .72rem; }
.ap-queue-lanes { display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem; }
@media (max-width: 1000px) { .ap-queue-lanes { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 560px) { .ap-queue-lanes { grid-template-columns: 1fr; } }
.ap-qlane { background: var(--panel); border: 1px solid var(--line); border-radius: .9rem; padding: .7rem; min-height: 340px; box-shadow: var(--shadow); }
.ap-qlane h3 { margin: 0 0 .7rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: flex; justify-content: space-between; }
.ap-qlane[data-lane="checked-in"] h3 { color: var(--warn); }
.ap-qlane[data-lane="in-consult"] h3 { color: var(--brand-ink); }
.ap-qlane[data-lane="done"] h3 { color: var(--ok); }
.ap-qlane-body { display: flex; flex-direction: column; gap: .5rem; }
.ap-qcard { background: #f8fbfb; border: 1px solid var(--line); border-radius: .7rem; padding: .65rem .7rem; animation: apin .25s ease; }
@keyframes apin { from { opacity: 0; transform: translateY(-6px); } }
.ap-qcard .qh { display: flex; justify-content: space-between; align-items: center; margin-bottom: .3rem; }
.ap-qcard .token { background: var(--brand); color: #fff; border-radius: .4rem; padding: .05rem .4rem; font-size: .72rem; font-weight: 800; }
.ap-qcard .wait { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ap-qcard .wait.long { color: var(--danger); font-weight: 700; }
.ap-qcard b { font-size: .9rem; }
.ap-qcard .meta { font-size: .74rem; color: var(--muted); margin: .15rem 0 .5rem; }
.ap-qcard .adv { width: 100%; border: 0; border-radius: .5rem; padding: .4rem; font: 700 .74rem inherit; cursor: pointer; background: #ecf5f5; color: var(--brand-ink); }
.ap-qcard .adv:hover { background: var(--brand); color: #fff; }

/* SCHEDULE */
.ap-sched-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.2rem; }
.ap-sched-head h2 { margin: 0; }
.ap-sched-controls { display: flex; align-items: center; gap: .8rem; }
.ap-sched-controls select { font: inherit; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--panel); }
.ap-sched-date { color: var(--muted); font-size: .85rem; }
.ap-sched-grid { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 1rem; box-shadow: var(--shadow); }
.ap-sched-row { display: grid; grid-template-columns: 64px 1fr; gap: .5rem; align-items: stretch; min-height: 2.6rem; }
.ap-sched-time { font-size: .74rem; color: var(--muted); padding-top: .3rem; font-variant-numeric: tabular-nums; }
.ap-sched-cell { border-top: 1px dashed var(--line); padding: .25rem 0; }
.ap-sched-appt { background: #ccfbf1; border-left: 3px solid var(--brand); border-radius: .4rem; padding: .35rem .6rem; font-size: .8rem; }
.ap-sched-appt.lunch { background: #f1f5f9; border-left-color: #cbd5e1; color: var(--muted); text-align: center; }
.ap-sched-appt.free { background: transparent; border: 1px dashed var(--line); color: var(--muted); text-align: center; cursor: pointer; }
.ap-sched-appt.free:hover { border-color: var(--brand); color: var(--brand-ink); }
.ap-sched-appt b { display: block; }
.ap-sched-appt small { color: var(--muted); }

/* INSIGHTS */
.ap-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.ap-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 1.2rem; box-shadow: var(--shadow); }
.ap-kpi b { font-size: 1.8rem; font-weight: 800; display: block; }
.ap-kpi small { color: var(--muted); font-size: .78rem; }
.ap-kpi .delta { color: var(--ok); font-size: .74rem; font-weight: 600; }
.ap-insights-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.5rem; }
@media (max-width: 860px) { .ap-insights-grid { grid-template-columns: 1fr; } }
.ap-card-wide { grid-column: 1 / -1; }
#ap-weekchart { width: 100%; height: 200px; }
#ap-donut { width: 130px; height: 130px; display: block; margin: 0 auto; }
.ap-donut-legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; justify-content: center; font-size: .76rem; color: var(--muted); margin-top: .6rem; }
.ap-donut-legend span { display: inline-flex; align-items: center; gap: .3rem; }
.ap-donut-legend i { width: .7rem; height: .7rem; border-radius: 3px; }
.ap-util-row { display: flex; align-items: center; gap: .8rem; padding: .5rem 0; border-bottom: 1px dashed var(--line); }
.ap-util-row:last-child { border-bottom: 0; }
.ap-util-row .av { width: 2rem; height: 2rem; border-radius: .5rem; display: grid; place-items: center; font-size: 1rem; color: #fff; }
.ap-util-row .nm { flex: 1; font-size: .85rem; }
.ap-util-row .bar { flex: 2; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.ap-util-row .bar i { display: block; height: 100%; background: var(--brand); }
.ap-util-row .pct { font-size: .8rem; color: var(--muted); min-width: 3rem; text-align: right; }

/* Toast */
.ap-toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: #0f2b2b; color: #fff; padding: .7rem 1.1rem; border-radius: .7rem; font-size: .88rem; z-index: 200; box-shadow: 0 15px 40px -12px rgba(0,0,0,.4); max-width: 90vw; }
.ap-toast[hidden] { display: none; }
