/* TheraFlow — clean clinical UI */
:root {
  --primary: #0e7490;
  --primary-ink: #ffffff;
  --primary-soft: #e6f3f7;
  --accent: #0d9488;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --ink: #1e293b;
  --ink-2: #64748b;
  --ink-3: #94a3b8;
  --line: #e2e8f0;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  --sidebar-w: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14.5px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
}
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }
p.sub { color: var(--ink-2); margin: 0 0 18px; }

/* ---------- app shell ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 auto; background: var(--surface);
  border-right: 1px solid var(--line); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; }
.brand-logo { padding: 6px 8px 18px; }
.brand-logo svg { width: 100%; height: auto; display: block; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary);
  color: var(--primary-ink); display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.brand .name { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.brand .tag { font-size: 11px; color: var(--ink-3); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--ink-2); cursor: pointer; font-weight: 500; border: none; background: none;
  font-size: 14px; text-align: left; width: 100%;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { font-size: 11px; color: var(--ink-3); padding: 8px 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 26px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40;
}
.searchwrap { position: relative; flex: 0 1 340px; }
.searchwrap input {
  width: 100%; padding: 8px 12px 8px 34px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); font-size: 14px;
}
.searchwrap .icon { position: absolute; left: 10px; top: 8px; color: var(--ink-3); }
.search-results {
  position: absolute; top: 40px; left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 60;
  max-height: 300px; overflow-y: auto;
}
.search-results div { padding: 9px 14px; cursor: pointer; }
.search-results div:hover { background: var(--primary-soft); }
.topbar .grow { flex: 1; }
.prax { display: flex; align-items: center; gap: 10px; }
.logo-box {
  height: 48px; width: 140px; display: flex; align-items: center; justify-content: flex-end;
}
.logo-box img { max-height: 48px; max-width: 140px; object-fit: contain; }
.pname { font-weight: 700; font-size: 15px; color: #0f172a; white-space: nowrap; letter-spacing: -.01em; }
.float-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); margin: 18px 2px 7px;
}
/* in-app how-to guide (Support tab) */
.guide details { border-bottom: 1px solid var(--line); }
.guide details:last-of-type { border-bottom: 0; }
.guide summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 12px;
  padding: 13px 4px; font-weight: 600; color: var(--ink); font-size: 14.5px;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "+"; color: var(--primary); font-size: 19px; font-weight: 400; margin-left: auto; }
.guide summary .badge { margin-left: 0 !important; }  /* badge sits by the title; the +/– keeps the right edge */
.guide details[open] summary::after { content: "–"; }
.guide .g-body { padding: 0 4px 16px; font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.guide .g-body ol, .guide .g-body ul { margin: 6px 0 10px 20px; display: grid; gap: 5px; }
.guide .g-body p { margin: 4px 0 8px; }
.guide .g-body .tip {
  background: var(--bg); border-left: 3px solid var(--primary); border-radius: 0 8px 8px 0;
  padding: 8px 12px; margin: 8px 0 2px; font-size: 13px;
}
.sms-chip {
  display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 12.5px; color: var(--ink-2);
  white-space: nowrap;
}
.sms-chip strong { font-size: 13.5px; color: var(--ink); }
.sms-chip .plus {
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
}
.sms-chip:hover .plus { background: var(--primary); color: var(--primary-ink); }
.sms-chip.low strong { color: var(--danger); }
.sms-bundle { display: flex; flex-direction: column; gap: 2px; padding: 12px 22px; align-items: center; }
.userchip { position: relative; }
.userchip > button {
  display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); background: var(--surface);
  padding: 6px 12px 6px 6px; border-radius: 999px; cursor: pointer; font-size: 13.5px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 600; font-size: 12.5px;
}
.userchip .menu {
  position: absolute; right: 0; top: 46px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); min-width: 190px; z-index: 70; overflow: hidden;
}
.userchip .menu button { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: none; cursor: pointer; font-size: 13.5px; }
.userchip .menu button:hover { background: var(--bg); }
.role-pill { font-size: 11px; color: var(--ink-2); }

.view { padding: 24px 26px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }
.view.wide { max-width: 1600px; }

/* ---------- generic ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.mt { margin-top: 16px; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.right { text-align: right; }

button.btn, a.btn {
  display: inline-flex; align-items: center; gap: 7px; border-radius: 9px; padding: 8px 15px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none;
}
.btn:hover { filter: brightness(.985); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); border-color: #f3c7c7; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: none; color: var(--primary); }
.btn:disabled { opacity: .5; cursor: default; }

label.f { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
label.f span { display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.checkline { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; font-weight: 400; color: var(--ink); }
.checkline input { width: auto; margin-top: 3px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--primary-soft); }

.badge { display: inline-block; padding: 2.5px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.confirmed { background: #e0f2fe; color: #0369a1; }
.badge.completed { background: #d1fae5; color: #047857; }
.badge.no_show { background: #fee2e2; color: #b91c1c; }
.badge.cancelled { background: #f1f5f9; color: #64748b; }
.badge.paid { background: #d1fae5; color: #047857; }
.badge.unpaid { background: #fef3c7; color: #b45309; }
.badge.claim_pending { background: #ede9fe; color: #6d28d9; }
.badge.neutral { background: #f1f5f9; color: #475569; }
.badge.sent { background: #d1fae5; color: #047857; }
.badge.simulated { background: #fef3c7; color: #b45309; }
.badge.failed { background: #fee2e2; color: #b91c1c; }
.badge.draft { background: #f1f5f9; color: #475569; }

.tag { display: inline-block; background: var(--primary-soft); color: var(--primary); border-radius: 6px; padding: 2px 8px; font-size: 12px; margin: 2px 4px 2px 0; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 12.5px; color: var(--ink-2); }

.empty { text-align: center; color: var(--ink-3); padding: 34px 10px; font-size: 13.5px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.cal-title { font-size: 17px; font-weight: 650; min-width: 175px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 14px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--primary); color: var(--primary-ink); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin: 8px 0 14px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--line); gap: 1px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.month-grid .dow { background: var(--surface); padding: 8px 10px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; color: var(--ink-3); letter-spacing: .05em; }
.mcell { background: var(--surface); min-height: 132px; padding: 7px 8px; cursor: pointer; position: relative; }
.mcell:hover { background: var(--primary-soft); }
.mcell.other { background: #fafbfc; color: var(--ink-3); }
.mcell .dnum { font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.mcell.today .dnum { background: var(--primary); color: var(--primary-ink); width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.chip { font-size: 11.5px; border-radius: 5px; padding: 2px 7px; margin-bottom: 3px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-line { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); z-index: 4; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -1px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.chip.cancelled { opacity: .45; text-decoration: line-through; }
.mcell .more { font-size: 11px; color: var(--primary); font-weight: 600; }

.week-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--surface); }
.week-grid { display: grid; grid-template-columns: 52px repeat(7, minmax(120px, 1fr)); min-width: 900px; }
.wg-head { padding: 9px 8px; font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); text-align: center; position: sticky; top: 0; background: var(--surface); z-index: 5; }
.wg-head .d { color: var(--ink-3); font-weight: 500; }
.wg-head.today { color: var(--primary); }
.wg-time { font-size: 10.5px; color: var(--ink-3); text-align: right; padding: 2px 6px 0 0; border-top: 1px solid var(--line); }
.wg-col { position: relative; border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.wg-slot { height: 24px; border-bottom: 1px dashed #eef2f6; }
.wg-slot:nth-child(2n) { border-bottom: 1px solid var(--line); }
.wg-evt {
  position: absolute; left: 3px; right: 3px; border-radius: 7px; color: #fff; padding: 3px 7px;
  font-size: 11.5px; overflow: hidden; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.15); z-index: 3;
}
.wg-evt strong { display: block; font-size: 11.5px; }
.wg-evt.cancelled { opacity: .4; text-decoration: line-through; }
.wg-evt.dragging { opacity: .6; cursor: grabbing; z-index: 20; }

.day-list .grp { margin-bottom: 14px; }
.day-list .grp h3 { display: flex; align-items: center; gap: 8px; }
.booking-row { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 7px; background: var(--surface); }
.booking-row .time { font-weight: 700; font-size: 13px; min-width: 92px; }
.booking-row .who { flex: 1; min-width: 0; }
.booking-row .who .t { font-size: 12px; color: var(--ink-2); }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100; display: grid; place-items: center; padding: 20px; overflow: auto; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; padding: 22px 24px; }
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1020px; min-height: 92vh; max-height: 96vh; display: flex; flex-direction: column; }
.modal.xwide .inv-doc { flex: 1; }
.modal.xxwide { max-width: 1380px; }  /* recurring template: full-size invoice + settings card side by side */
.modal.xxwide .actions { position: sticky; bottom: -22px; background: var(--surface); padding: 12px 0; margin-bottom: -22px; border-top: 1px solid var(--line); z-index: 5; }
/* document-style invoice editor */
.inv-doc { border: 1px solid var(--line); border-radius: 10px; padding: 26px 30px; background: #fff; }
.inv-doc input, .inv-doc textarea { border-color: transparent; background: transparent; padding: 3px 6px; }
.inv-doc input:hover, .inv-doc textarea:hover { border-color: var(--line); background: #fbfcfd; }
.inv-doc input:focus, .inv-doc textarea:focus { border-color: var(--primary); background: #fff; }
.inv-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.inv-title { font-size: 19px; font-weight: 750; letter-spacing: .02em; }
.inv-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 13px; font-size: 12.5px; flex: 1; }
.inv-box h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); }
.inv-lines td { vertical-align: middle; }
.inv-icd-row td { border-bottom: 1px solid var(--line); padding: 2px 10px 9px; background: #fafcfd; }
.inv-icd-row .searchwrap input { font-size: 12px; padding: 4px 8px; border: 1px dashed var(--line); background: #fff; max-width: 300px; }
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.session-banner {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 250;
  background: var(--surface); border: 1px solid var(--primary); border-left: 5px solid var(--primary);
  border-radius: 11px; box-shadow: var(--shadow); padding: 10px 16px; font-size: 13.5px;
  display: flex; align-items: center; gap: 6px; max-width: 92vw;
}
.toast { background: var(--ink); color: #fff; border-radius: 10px; padding: 11px 16px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 360px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  position: relative; overflow: hidden;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(63,184,178,.10), transparent 60%),
    radial-gradient(800px 520px at 105% 110%, rgba(15,28,51,.07), transparent 60%),
    linear-gradient(160deg, #f3fafa, #f8fafc 55%, #f1f5fa); }
.auth-bgmark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; user-select: none; }
.auth-bgmark svg { width: min(1050px, 135vw); height: auto; opacity: .045; transform: rotate(-7deg) translateY(-4%); }
.auth-card { width: 100%; max-width: 420px; position: relative; }
.auth-card .card { padding: 28px; }
.auth-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }

/* ---------- charts ---------- */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.bar-row .lbl { width: 150px; flex: 0 0 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .track { flex: 1; background: var(--bg); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 6px; }
.bar-row .val { width: 90px; text-align: right; font-weight: 600; font-size: 12.5px; }

/* ---------- settings tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 14px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- messages ---------- */
.threads { border-right: 1px solid var(--line); overflow: auto; min-height: 0; }
.thread-item { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.thread-item:hover, .thread-item.on { background: var(--primary-soft); }
.thread-item .avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.thread-item .tmeta { flex: 1; min-width: 0; }
.thread-item .tmeta .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* WhatsApp-style chat pane */
.chat-pane { display: flex; flex-direction: column; min-height: 0; }
.chat-pane.wa .msgs { background: #e4ddd4; }
.chat-pane.sms .msgs { background: #eef2f6; }
.msgs { display: flex; flex-direction: column; gap: 4px; padding: 16px; overflow: auto; min-height: 0; flex: 1; }
.bubble { max-width: 72%; padding: 7px 10px 5px; border-radius: 9px; font-size: 13.5px;
  box-shadow: 0 1px 1px rgba(15,23,42,.12); position: relative; white-space: pre-wrap; }
.chat-pane.wa .bubble.out { align-self: flex-end; background: #d9fdd3; color: #111b21; border-top-right-radius: 2px; }
.chat-pane.wa .bubble.in { align-self: flex-start; background: #fff; color: #111b21; border-top-left-radius: 2px; }
.chat-pane.sms .bubble.out { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-top-right-radius: 2px; }
.chat-pane.sms .bubble.in { align-self: flex-start; background: #fff; border-top-left-radius: 2px; }
.bubble .meta { font-size: 10.5px; opacity: .6; margin-top: 2px; text-align: right; }
.bubble .tick { display: inline-block; margin-left: 2px; }
.day-sep { align-self: center; background: rgba(255,255,255,.85); color: #54656f; font-size: 11px;
  padding: 3px 10px; border-radius: 7px; margin: 8px 0 4px; box-shadow: 0 1px 1px rgba(15,23,42,.08); }
.chat-compose { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); align-items: center; background: var(--surface); }
.chat-compose input { flex: 1; border-radius: 20px; padding: 10px 16px; }
.chat-compose .send-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--primary);
  color: var(--primary-ink); font-size: 17px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.chat-compose .send-btn:disabled { opacity: .45; cursor: default; }

/* ---------- responsive ---------- */
#burger { display: none; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; cursor: pointer; }
@media (max-width: 960px) {
  .forms-grid { grid-template-columns: 1fr !important; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 90; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  #burger { display: block; }
  .cols-3, .cols-4 { grid-template-columns: 1fr 1fr; }
  .view { padding: 16px 14px 60px; }
}
@media (max-width: 640px) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .searchwrap { flex-basis: 160px; }
  .prax { display: none; }
  .sms-chip .plus { display: none; }  /* keep the balance visible, drop the label */
}
