:root {
  /* The clinic's front desk: calm sea-green surfaces, coral for what needs a person. */
  --bg: #F3F6F5; --surface: #FFFFFF; --ink: #10302B; --muted: #5A6F6A; --line: #D9E3E0;
  --coral: #C24A31; --coral-ink: #FFFFFF; --coral-soft: #FBE6E0;
  --sea: #0D5C50; --sea-soft: #DDEFEA; --on-sea: #FFFFFF;
  --chat: #E7EFEB; --bubble-in: #FFFFFF; --bubble-out: #D3EEDF; --bubble-staff: #FCEFD6;
  --ok: #1D7A4C; --ok-soft: #DFF2E7; --wait: #9A6210; --wait-soft: #FAEFD9; --bad: #B93A27; --bad-soft: #FBE3DE;
  --f-display: "Reem Kufi", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --f-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1513; --surface: #12201D; --ink: #E3EDEA; --muted: #93A7A1; --line: #22342F;
    --coral: #EE7A5F; --coral-ink: #1A0D09; --coral-soft: #3A2019;
    --sea: #5CC3AB; --sea-soft: #17332C; --on-sea: #0B1513;
    --chat: #0E1A17; --bubble-in: #1A2B27; --bubble-out: #1D4338; --bubble-staff: #3A3018;
    --ok: #5FCB95; --ok-soft: #14301F; --wait: #E2B65E; --wait-soft: #2F2611; --bad: #FF8B74; --bad-soft: #3A1B16;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.35; }
h1 { font-family: var(--f-display); font-size: 26px; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; margin-top: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); margin: 0; }
.ok { color: var(--ok); }
.wrap { max-width: 1200px; margin: 0 auto; padding-inline: max(16px, env(safe-area-inset-left, 0px)); }

.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.mark { width: 36px; height: 36px; border-radius: 11px 11px 11px 3px; background: #0A1714; color: #D6B77A; border: 1px solid #D6B77A; display: grid; place-items: center; font-family: var(--f-display); font-weight: 700; font-size: 20px; padding-bottom: 3px; flex: none; }
.mark.big { width: 64px; height: 64px; font-size: 36px; border-radius: 18px 18px 18px 5px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { font-family: var(--f-display); font-size: 22px; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12.5px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-width: 0; }
.auth-card { width: min(420px, 100%); display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13.5px; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 12px; color: var(--ink); width: 100%; min-width: 0; }
textarea { resize: vertical; }
.btn { border: 1px solid var(--sea); color: var(--sea); background: transparent; border-radius: 10px; padding: 8px 16px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--sea-soft); }
.btn.primary { background: var(--sea); color: var(--on-sea); }
.btn.primary:hover { filter: brightness(1.08); background: var(--sea); }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px max(16px, env(safe-area-inset-left, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-actions select { width: auto; max-width: 260px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px max(16px, env(safe-area-inset-left, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; cursor: pointer; color: var(--muted); white-space: nowrap; font-weight: 500; }
.tabs button[aria-current="page"] { background: var(--sea-soft); color: var(--sea); }
.badge { background: var(--coral); color: var(--coral-ink); border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 600; }
main { padding-block: 18px 48px; }
.tab { display: grid; gap: 16px; }
#banners { display: grid; gap: 8px; padding-top: 12px; }
#banners:empty { display: none; }
.banner { background: var(--wait-soft); color: var(--wait); border-radius: 12px; padding: 10px 14px; font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.kpi span { display: block; font-size: 12.5px; color: var(--muted); }
.kpi b { display: block; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

.list { display: grid; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; padding-top: 0; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }
.item .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.empty-state { margin: 0; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; display: inline-block; }
.pill.booked { color: var(--wait); background: var(--wait-soft); }
.pill.confirmed, .pill.completed { color: var(--ok); background: var(--ok-soft); }
.pill.cancelled, .pill.no_show { color: var(--muted); background: var(--bg); }
.pill.urgent, .pill.error, .pill.low_review { color: var(--bad); background: var(--bad-soft); }
.pill.handoff, .pill.media { color: var(--coral); background: var(--coral-soft); }
.pill.human { color: var(--coral); background: var(--coral-soft); }
.status-select { width: auto; padding: 4px 8px; font-size: 13px; }

.chats { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .chats { grid-template-columns: minmax(0, 1fr); } }
.chat-list { padding: 6px; max-height: 75vh; overflow-y: auto; }
.chat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; padding: 10px; border-radius: 10px; cursor: pointer; border: 0; background: transparent; text-align: start; width: 100%; }
.chat-row:hover, .chat-row[aria-current="true"] { background: var(--sea-soft); }
.chat-row .sub { grid-column: 1 / -1; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-height: 60vh; padding: 0; overflow: hidden; }
.thread-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.msgs { flex: 1; overflow-y: auto; max-height: 60vh; padding: 14px; background: var(--chat); display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 80%; padding: 7px 11px 3px; border-radius: 14px; white-space: pre-line; overflow-wrap: anywhere; font-size: 14.5px; }
.msg.in { align-self: flex-start; background: var(--bubble-in); }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg.staff { background: var(--bubble-staff); }
.msg time { display: block; font-size: 11px; color: var(--muted); text-align: end; }
.compose { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.compose input { flex: 1; }

.form { display: grid; gap: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.toggles { display: grid; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14.5px; }
.check input { width: auto; }
.hours { display: grid; gap: 8px; }
.hours-row { display: grid; grid-template-columns: 90px auto repeat(2, minmax(0, 120px)) auto repeat(2, minmax(0, 120px)); gap: 8px; align-items: center; }
@media (max-width: 700px) { .hours-row { grid-template-columns: 80px auto minmax(0, 1fr) minmax(0, 1fr); } .hours-row .second { grid-column: 3 / -1; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.inline { display: flex; align-items: center; gap: 8px; }
.inline input { width: auto; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: start; color: var(--muted); font-weight: 500; padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td input { padding: 6px 8px; }
.table td input.narrow { width: 70px; }
.day-group h3 { margin: 14px 0 4px; }

.sim { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .sim { grid-template-columns: minmax(0, 1fr); } }
.sim-phone { padding: 0; overflow: hidden; display: flex; flex-direction: column; height: 70vh; min-height: 480px; }
.sim-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sim-head input { width: 130px; padding: 4px 8px; }
.sim-log { flex: 1; overflow-y: auto; padding: 12px; background: var(--chat); display: flex; flex-direction: column; gap: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.choices:empty { display: none; }
.choices button { border: 1px solid var(--sea); color: var(--sea); background: transparent; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13.5px; }
.sim-compose { display: flex; gap: 8px; padding: 10px 12px; }
.sim-compose input { flex: 1; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; }

.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); inset-inline-start: 16px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20; max-width: calc(100% - 32px); }

.card.setup { display: grid; gap: 8px; border-color: var(--line); }
.card.setup h2 { margin: 0; }
.card.setup p { margin: 0; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.setup-actions a.btn { text-decoration: none; }
.card.setup.ended { border-color: var(--bad); background: var(--bad-soft); }
.pill.trial { color: var(--wait); background: var(--wait-soft); }
.pill.expired { color: var(--bad); background: var(--bad-soft); }
.plan-cell { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.forgot { color: var(--sea); font-size: 13.5px; justify-self: center; }
.reset-link { display: flex; gap: 8px; align-items: center; margin-top: 6px; grid-column: 1 / -1; }
.reset-link input { direction: ltr; font-size: 12.5px; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 20px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin: 0; font-family: var(--f-display); }
