/* =====================================================================
   PhysioScribe AI — design system
   Medical palette: white / blue / grey / light-green. Light + dark.
   ===================================================================== */

:root {
    --bg:            #f4f7fb;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --border:        #e6ecf3;
    --text:          #0f2137;
    --text-soft:     #5b6b7f;
    --text-faint:    #93a2b4;
    --brand:         #1a66db;
    --brand-600:     #1651b1;
    --brand-soft:    #eaf2ff;
    --mint:          #22b892;
    --mint-soft:     #e5f7f1;
    --amber:         #e9a23b;
    --amber-soft:    #fdf3e1;
    --danger:        #e5484d;
    --danger-soft:   #fdecec;
    --shadow-sm:     0 1px 2px rgba(16,33,55,.06), 0 1px 3px rgba(16,33,55,.05);
    --shadow-md:     0 6px 20px rgba(16,33,55,.08);
    --shadow-lg:     0 18px 48px rgba(16,33,55,.14);
    --radius:        18px;
    --radius-sm:     12px;
    --sidebar-w:     264px;
    --topbar-h:      70px;
    --ease:          cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
    --bg:            #0b1220;
    --surface:       #121c2e;
    --surface-2:     #0f1826;
    --border:        #223148;
    --text:          #e8eef7;
    --text-soft:     #9fb0c6;
    --text-faint:    #6c7f98;
    --brand:         #4a92ff;
    --brand-600:     #2f83f5;
    --brand-soft:    #16283f;
    --mint:          #38d0a5;
    --mint-soft:     #12312a;
    --amber-soft:    #33290f;
    --danger-soft:   #3a1618;
    --shadow-md:     0 6px 20px rgba(0,0,0,.4);
    --shadow-lg:     0 18px 48px rgba(0,0,0,.55);
    --shadow-sm:     0 1px 2px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    transition: background .3s var(--ease), color .3s var(--ease);
}
.d-none { display: none !important; }
h1,h2,h3,h4,h5,h6 { font-family: 'Plus Jakarta Sans','Inter',sans-serif; color: var(--text); }
a { text-decoration: none; color: inherit; }
/* Keep our theme colours winning over Bootstrap's heading/body variables */
:root { --bs-heading-color: var(--text); --bs-body-color: var(--text); }

/* =====================================================================
   PRELOADER (full-page splash until the app is ready)
   ===================================================================== */
#app-preloader {
    position: fixed; inset: 0; z-index: 4000; display: grid; place-items: center;
    background:
        radial-gradient(900px 500px at 15% -10%, #dbeafe 0%, transparent 55%),
        radial-gradient(800px 500px at 110% 20%, #d8f5ec 0%, transparent 55%),
        var(--bg);
    transition: opacity .5s var(--ease), visibility .5s var(--ease);
}
[data-theme="dark"] #app-preloader {
    background:
        radial-gradient(900px 500px at 15% -10%, #12294a 0%, transparent 55%),
        radial-gradient(800px 500px at 110% 20%, #0f3630 0%, transparent 55%),
        var(--bg);
}
#app-preloader.hide { opacity: 0; visibility: hidden; }
.pl-inner { text-align: center; animation: rise .5s var(--ease) both; }
.pl-badge {
    position: relative; width: 88px; height: 88px; margin: 0 auto 22px; border-radius: 26px;
    display: grid; place-items: center; color: #fff; font-size: 36px;
    background: linear-gradient(135deg, var(--brand), var(--mint));
    box-shadow: 0 16px 40px rgba(26,102,219,.4);
    animation: plbob 1.8s var(--ease) infinite;
}
.pl-badge img { width: 56px; height: 56px; object-fit: contain; border-radius: 12px; }
.pl-ring {
    position: absolute; inset: -10px; border-radius: 32px;
    border: 3px solid transparent; border-top-color: var(--brand); border-right-color: var(--mint);
    animation: plspin 1s linear infinite;
}
@keyframes plbob { 0%,100%{ transform: translateY(0); } 50%{ transform: translateY(-10px); } }
@keyframes plspin { to { transform: rotate(360deg); } }
.pl-name { font-family: 'Plus Jakarta Sans','Inter',sans-serif; font-weight: 800; font-size: 24px; letter-spacing: -.02em; color: var(--text); }
.pl-name span { color: var(--brand); }
.pl-bar { width: 180px; height: 5px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 18px auto 12px; }
.pl-bar > span { display: block; height: 100%; width: 40%; border-radius: 4px;
    background: linear-gradient(90deg, var(--brand), var(--mint)); animation: plload 1.3s var(--ease) infinite; }
@keyframes plload { 0%{ transform: translateX(-120%); } 100%{ transform: translateX(320%); } }
.pl-tag { font-size: 13px; color: var(--text-soft); font-weight: 500; }

/* ---------- Brand ---------- */
.brand-badge img, .brand-badge.sm img { width: 74%; height: 74%; object-fit: contain; border-radius: 8px; }
.brand-badge {
    width: 54px; height: 54px; border-radius: 16px;
    display: grid; place-items: center; color: #fff; font-size: 22px;
    background: linear-gradient(135deg, var(--brand), var(--mint));
    box-shadow: 0 8px 22px rgba(26,102,219,.35);
}
.brand-badge.sm { width: 38px; height: 38px; border-radius: 11px; font-size: 16px; box-shadow: none; }

/* =====================================================================
   AUTH / LOGIN
   ===================================================================== */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    position: relative; overflow: hidden;
    background: radial-gradient(1200px 600px at 10% -10%, #dbeafe 0%, transparent 55%),
                radial-gradient(900px 500px at 110% 20%, #d8f5ec 0%, transparent 55%),
                var(--bg);
}
[data-theme="dark"] .auth-wrap {
    background: radial-gradient(1000px 600px at 10% -10%, #12294a 0%, transparent 55%),
                radial-gradient(900px 500px at 110% 20%, #0f3630 0%, transparent 55%),
                var(--bg);
}
.auth-bg span {
    position: absolute; border-radius: 50%; filter: blur(50px); opacity: .5;
    animation: float 14s var(--ease) infinite;
}
.auth-bg span:nth-child(1){ width:340px;height:340px; background:#7db6ff; top:-60px; left:-40px; }
.auth-bg span:nth-child(2){ width:300px;height:300px; background:#5fe0bd; bottom:-80px; right:-30px; animation-delay:-4s; }
.auth-bg span:nth-child(3){ width:220px;height:220px; background:#a9c8ff; top:40%; right:20%; animation-delay:-8s; }
@keyframes float { 0%,100%{transform:translateY(0) scale(1);} 50%{transform:translateY(-26px) scale(1.06);} }

.glass {
    background: rgba(255,255,255,.72);
    backdrop-filter: blur(22px) saturate(150%);
    -webkit-backdrop-filter: blur(22px) saturate(150%);
    border: 1px solid rgba(255,255,255,.6);
}
[data-theme="dark"] .glass {
    background: rgba(18,28,46,.72);
    border: 1px solid rgba(255,255,255,.08);
}
.auth-card {
    position: relative; z-index: 2; width: 100%; max-width: 420px;
    padding: 40px 36px; border-radius: 26px; box-shadow: var(--shadow-lg);
    animation: rise .6s var(--ease) both;
}
@keyframes rise { from{opacity:0; transform:translateY(18px);} to{opacity:1; transform:none;} }
.auth-title { font-size: 26px; font-weight: 800; margin: 0; letter-spacing:-.02em; }
.auth-title span { color: var(--brand); }
.auth-sub { color: var(--text-soft); margin: 6px 0 0; font-size: 14px; }
.demo-hint { text-align:center; margin: 18px 0 0; font-size: 12px; color: var(--text-faint); }

.auth-alert {
    display: flex; align-items: center; gap: 9px;
    background: var(--danger-soft); color: var(--danger);
    border: 1px solid var(--danger); border-radius: 12px;
    padding: 11px 14px; margin-bottom: 18px;
    font-size: 13.5px; font-weight: 500; line-height: 1.35;
}
.auth-alert i { flex: none; font-size: 15px; }
.auth-alert.shake { animation: shake .4s var(--ease); }
@keyframes shake {
    10%,90%{transform:translateX(-1px);} 20%,80%{transform:translateX(2px);}
    30%,50%,70%{transform:translateX(-4px);} 40%,60%{transform:translateX(4px);}
}

.field { margin-bottom: 16px; }
.field > label { display:block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text-soft); }
.input-icon { position: relative; }
.input-icon > i { position:absolute; left:14px; top:50%; transform:translateY(-50%); color: var(--text-faint); font-size: 14px; }
.input-icon input {
    width: 100%; padding: 13px 42px 13px 40px; border-radius: 12px;
    border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
    font-size: 15px; transition: border-color .2s, box-shadow .2s;
}
.input-icon input:focus { outline:none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.pw-toggle { position:absolute; right:8px; top:50%; transform:translateY(-50%); border:0; background:none; color:var(--text-faint); padding:8px; cursor:pointer; }
.remember { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--text-soft); cursor:pointer; margin:0; }
.remember input { accent-color: var(--brand); width:15px; height:15px; }
.link { color: var(--brand); font-size: 13px; font-weight: 600; }
.link:hover { text-decoration: underline; }

.theme-fab {
    position: fixed; top: 20px; right: 20px; z-index: 5;
    width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn-primary {
    display:inline-flex; align-items:center; justify-content:center; gap:8px;
    padding: 13px 20px; border:0; border-radius: 12px; cursor:pointer;
    background: linear-gradient(135deg, var(--brand), var(--brand-600));
    color:#fff; font-weight:700; font-size:15px; box-shadow: 0 8px 20px rgba(26,102,219,.3);
    transition: transform .15s var(--ease), box-shadow .2s, filter .2s;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity:.7; cursor:not-allowed; transform:none; }
.btn-ghost { background: var(--surface); border:1px solid var(--border); color: var(--text); border-radius:12px; padding:11px 16px; font-weight:600; cursor:pointer; display:inline-flex; align-items:center; gap:8px; transition:.2s; }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-soft { background: var(--brand-soft); color: var(--brand); border:0; border-radius:12px; padding:11px 16px; font-weight:600; cursor:pointer; display:inline-flex; align-items:center; gap:8px; transition:.2s; }
.btn-soft:hover { filter: brightness(.97); }
.btn-soft.is-ok { background:var(--mint-soft,#e6f8f1); color:var(--mint,#16a34a); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border:0; border-radius:12px; padding:11px 16px; font-weight:600; cursor:pointer; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

/* =====================================================================
   APP LAYOUT
   ===================================================================== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--border); display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; z-index: 40;
}
.sidebar-head { display:flex; align-items:center; gap:10px; padding: 18px 20px; border-bottom:1px solid var(--border); }
.brand-word { font-family:'Plus Jakarta Sans'; font-weight:800; font-size:17px; letter-spacing:-.02em; }
.sidebar-close { margin-left:auto; border:0; background:none; color:var(--text-soft); font-size:18px; }
.side-nav { padding: 14px 12px; display:flex; flex-direction:column; gap:4px; flex:1; overflow-y:auto; }
.nav-item {
    display:flex; align-items:center; gap:12px; padding: 11px 14px; border-radius: 12px;
    color: var(--text-soft); font-weight:600; font-size:14.5px; transition: .18s var(--ease);
}
.nav-item i { width: 20px; text-align:center; font-size:16px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-item.active i { color: var(--brand); }
.sidebar-foot { padding: 14px 18px; border-top:1px solid var(--border); }
.ai-status { display:flex; align-items:center; gap:8px; font-size:12.5px; color: var(--text-soft); font-weight:600; }
.ai-status .dot { width:8px; height:8px; border-radius:50%; background: var(--mint); box-shadow:0 0 0 3px var(--mint-soft); animation: pulse 2s infinite; }
/* The AI runs entirely on the member's own two Groq keys, so the badge tracks
   them: amber on one key (half the capacity), red with none (nothing works). */
.ai-status.is-degraded .dot { background: var(--amber); box-shadow:0 0 0 3px var(--amber-soft); }
.ai-status.is-degraded { color: var(--amber); }
.ai-status.is-off .dot { background: var(--danger); box-shadow:0 0 0 3px var(--danger-soft); animation:none; }
.ai-status.is-off { color: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.4;} }

.sidebar-scrim { display:none; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h); display:flex; align-items:center; gap:14px; padding: 0 22px;
    background: var(--surface); border-bottom:1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
.topbar-search { flex:1; max-width:520px; position:relative; }
.topbar-search i { position:absolute; left:14px; top:50%; transform:translateY(-50%); color:var(--text-faint); font-size:14px; }
.topbar-search input {
    width:100%; padding:11px 14px 11px 40px; border-radius:12px; border:1.5px solid transparent;
    background: var(--surface-2); color: var(--text); font-size:14px; transition:.2s;
}
.topbar-search input:focus { outline:none; border-color: var(--brand); background: var(--surface); box-shadow:0 0 0 4px var(--brand-soft); }
.topbar-actions { margin-left:auto; display:flex; align-items:center; gap:8px; }
.icon-btn {
    width:42px; height:42px; border-radius:12px; border:1px solid var(--border); background:var(--surface);
    color: var(--text-soft); cursor:pointer; transition:.18s; display:grid; place-items:center;
}
.icon-btn:hover { color: var(--brand); border-color: var(--brand); }

.profile-menu { position: relative; }
.profile-btn { display:flex; align-items:center; gap:10px; background:none; border:0; cursor:pointer; padding:5px 8px; border-radius:12px; }
.profile-btn:hover { background: var(--surface-2); }
.avatar { width:38px; height:38px; border-radius:11px; background:linear-gradient(135deg,var(--brand),var(--mint)); color:#fff; display:grid; place-items:center; font-weight:700; font-size:14px; }
.profile-meta { flex-direction:column; align-items:flex-start; line-height:1.15; }
.profile-meta strong { font-size:13.5px; }
.profile-meta small { font-size:11.5px; color: var(--text-faint); }
.profile-dropdown {
    position:absolute; right:0; top: calc(100% + 8px); width: 240px; background:var(--surface);
    border:1px solid var(--border); border-radius:16px; box-shadow: var(--shadow-lg); padding:8px;
    opacity:0; visibility:hidden; transform: translateY(-8px); transition:.2s var(--ease); z-index:50;
}
.profile-dropdown.open { opacity:1; visibility:visible; transform:none; }
.pd-head { padding:10px 12px; border-bottom:1px solid var(--border); margin-bottom:6px; display:flex; flex-direction:column; }
.pd-head small { color:var(--text-faint); font-size:12px; }
.profile-dropdown a, .profile-dropdown button {
    display:flex; align-items:center; gap:11px; width:100%; padding:10px 12px; border:0; background:none;
    color:var(--text); font-size:13.5px; font-weight:500; border-radius:10px; cursor:pointer; text-align:left;
}
.profile-dropdown a:hover, .profile-dropdown button:hover { background: var(--surface-2); }
.profile-dropdown .danger { color: var(--danger); }

.content { padding: 26px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* =====================================================================
   SHARED COMPONENTS
   ===================================================================== */
.page-head { display:flex; align-items:flex-end; justify-content:space-between; gap:16px; margin-bottom:22px; flex-wrap:wrap; }
.page-head h1 { font-size: 26px; font-weight:800; margin:0; letter-spacing:-.02em; }
.page-head p { margin:4px 0 0; color: var(--text-soft); font-size:14px; }

.card {
    background: var(--surface); border:1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); transition: box-shadow .25s var(--ease), transform .25s var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-pad { padding: 20px; }

.stat-grid { display:grid; grid-template-columns: repeat(4,1fr); gap:18px; margin-bottom:24px; }
.stat-card { padding:20px; display:flex; flex-direction:column; gap:14px; animation: rise .5s var(--ease) both; }
.stat-card .ic { width:46px; height:46px; border-radius:13px; display:grid; place-items:center; font-size:19px; }
.ic.blue { background:var(--brand-soft); color:var(--brand); }
.ic.mint { background:var(--mint-soft); color:var(--mint); }
.ic.amber { background:var(--amber-soft); color:var(--amber); }
.ic.red { background:var(--danger-soft); color:var(--danger); }
.stat-card .num { font-size:30px; font-weight:800; line-height:1; font-family:'Plus Jakarta Sans'; }
.stat-card .lbl { color: var(--text-soft); font-size:13.5px; font-weight:500; }

.pill { display:inline-flex; align-items:center; gap:6px; padding:4px 11px; border-radius:999px; font-size:12px; font-weight:600; }
.pill.final { background:var(--mint-soft); color:var(--mint); }
.pill.draft { background:var(--amber-soft); color:var(--amber); }
.pill.blue { background:var(--brand-soft); color:var(--brand); }
.pill.red { background:var(--danger-soft); color:var(--danger); }

.data-table { width:100%; border-collapse: collapse; }
.data-table th { text-align:left; font-size:12px; text-transform:uppercase; letter-spacing:.04em; color:var(--text-faint); padding:12px 16px; border-bottom:1px solid var(--border); font-weight:700; }
.data-table td { padding:14px 16px; border-bottom:1px solid var(--border); font-size:14px; }
.data-table tr:last-child td { border-bottom:0; }
.data-table tbody tr { transition:.15s; cursor:pointer; }
.data-table tbody tr:hover { background: var(--surface-2); }

.empty { text-align:center; padding:60px 20px; color: var(--text-faint); }
.empty i { font-size:42px; opacity:.5; margin-bottom:14px; display:block; }

/* ---------- Skeletons ---------- */
.skeleton { position:relative; overflow:hidden; background: var(--surface-2); border-radius:10px; }
.skeleton::after { content:''; position:absolute; inset:0; transform:translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.5), transparent); animation: shimmer 1.4s infinite; }
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }
.sk-line { height:14px; margin:8px 0; }

/* =====================================================================
   CONSULTATION (split screen)
   ===================================================================== */
.consult-toolbar { display:flex; gap:16px; flex-wrap:wrap; align-items:flex-end; margin-bottom:16px; }
.ct-field { display:flex; flex-direction:column; gap:6px; }
.ct-field > label { font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:var(--text-faint); }
.consult-toolbar .ct-field { min-width:240px; }
.consult-toolbar .ct-row { display:flex; gap:8px; align-items:center; }
.consult-toolbar .ct-row select { flex:1; }
.consult-toolbar .ct-row .btn-sm { white-space:nowrap; }

/* "Add Patient" button — gradient pill that aligns to the bottom of the toolbar row. */
.btn-add-patient {
    align-self:flex-end; display:inline-flex; align-items:center; gap:9px; white-space:nowrap;
    padding:9px 16px 9px 10px; border:0; border-radius:12px; cursor:pointer;
    font-size:13.5px; font-weight:700; color:#fff;
    background:linear-gradient(135deg, var(--brand), var(--mint));
    box-shadow:0 4px 14px -4px var(--brand); transition:transform .15s var(--ease), box-shadow .15s var(--ease), filter .15s var(--ease);
}
.btn-add-patient:hover { transform:translateY(-1px); box-shadow:0 7px 18px -5px var(--brand); filter:brightness(1.03); }
.btn-add-patient:active { transform:translateY(0); }
.btn-add-patient .btn-add-icon { display:grid; place-items:center; width:26px; height:26px; border-radius:8px; background:rgba(255,255,255,.22); font-size:13px; }
@media (max-width:560px){ .consult-toolbar .ct-field { min-width:100%; } .btn-add-patient { width:100%; justify-content:center; } }

/* ---------- Searchable patient combobox ---------- */
.combo { position:relative; flex:1; min-width:0; }
.combo-list {
    position:absolute; z-index:60; top:calc(100% + 6px); left:0; right:0;
    background:var(--surface); border:1px solid var(--border); border-radius:12px;
    box-shadow:var(--shadow-lg); max-height:260px; overflow-y:auto; padding:6px;
    display:none;
}
.combo-list.open { display:block; }
.combo-item { padding:9px 11px; border-radius:9px; cursor:pointer; display:flex; flex-direction:column; gap:1px; }
.combo-item:hover { background:var(--surface-2); }
.combo-item strong { font-size:14px; font-weight:600; }
.combo-item small { font-size:12px; color:var(--text-faint); }
.combo-empty { padding:12px; font-size:13px; color:var(--text-faint); text-align:center; }

/* No-match row: create the typed name as a patient on a single tick. */
.combo-add { padding:9px 11px; border-radius:9px; cursor:pointer; display:flex; align-items:center; gap:10px; }
.combo-add:hover { background:var(--mint-soft); }
.combo-add-tick {
    flex:0 0 auto; width:26px; height:26px; border-radius:50%;
    display:inline-flex; align-items:center; justify-content:center;
    background:var(--mint); color:#fff; font-size:12px;
}
.combo-add-text { font-size:13.5px; color:var(--text-soft); min-width:0; }
.combo-add-text strong { font-weight:600; color:var(--text); }

.consult-split { display:flex; gap:0; align-items:stretch; min-height: calc(100vh - var(--topbar-h) - 52px); }
.consult-panel { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); display:flex; flex-direction:column; min-width:0; box-shadow:var(--shadow-sm); }
.panel-left { flex: 1 1 50%; }
.panel-right { flex: 1 1 50%; }
.resizer { flex: 0 0 14px; cursor: col-resize; display:grid; place-items:center; }
.resizer::before { content:''; width:4px; height:46px; border-radius:4px; background:var(--border); transition:.2s; }
.resizer:hover::before { background: var(--brand); }
.panel-head { padding:16px 18px; border-bottom:1px solid var(--border); display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.panel-head h3 { margin:0; font-size:16px; font-weight:700; display:flex; align-items:center; gap:9px; }
.panel-body { padding:16px 18px; flex:1; display:flex; flex-direction:column; min-height:0; }

.rec-controls { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px; }
.rec-btn { display:inline-flex; align-items:center; gap:7px; padding:9px 13px; border-radius:11px; border:1px solid var(--border); background:var(--surface); color:var(--text); font-weight:600; font-size:13px; cursor:pointer; transition:.18s; }
.rec-btn:hover { border-color:var(--brand); color:var(--brand); }
.rec-btn.rec-live { background:var(--danger); color:#fff; border-color:var(--danger); }
.rec-btn:disabled { opacity:.45; cursor:not-allowed; }
.rec-btn.primary { background:var(--brand); color:#fff; border-color:var(--brand); }

.rec-meter { display:flex; align-items:center; gap:12px; padding:10px 14px; background:var(--surface-2); border-radius:12px; margin-bottom:14px; }
.rec-dot { width:11px; height:11px; border-radius:50%; background:var(--text-faint); }
.rec-dot.live { background:var(--danger); animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight:700; font-size:15px; }
.wave { display:flex; align-items:center; gap:3px; height:22px; }
.wave span { width:3px; background:var(--brand); border-radius:2px; height:6px; }
.rec-live-mode .wave span { animation: wv .9s ease-in-out infinite; }
.wave span:nth-child(2){animation-delay:.1s}.wave span:nth-child(3){animation-delay:.2s}.wave span:nth-child(4){animation-delay:.3s}.wave span:nth-child(5){animation-delay:.4s}
@keyframes wv { 0%,100%{height:6px;} 50%{height:20px;} }

.transcript-search-wrap { position:relative; margin-bottom:10px; }
.transcript-search-wrap .form-control-x { padding-right:96px; }
.ts-count {
    position:absolute; right:12px; top:50%; transform:translateY(-50%);
    font-size:12px; font-weight:600; color:var(--text-faint); pointer-events:none; white-space:nowrap;
}

.transcript-editor {
    flex:1; width:100%; border:1px solid var(--border); border-radius:12px; padding:14px; resize:none;
    background:var(--surface-2); color:var(--text); font-size:14px; line-height:1.7; min-height:280px;
    font-family:'Inter',sans-serif;
}
.transcript-editor:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 4px var(--brand-soft); background:var(--surface); }
.transcript-editor::selection { background:var(--brand); color:#fff; }

/* Highlight overlay: backdrop mirrors the transcript, textarea sits transparent on top. */
.ta-hl-wrap { position:relative; display:flex; flex:1; min-height:280px; }
.ta-hl-wrap > .transcript-editor { position:relative; z-index:2; flex:1; min-height:0; background:transparent; scrollbar-gutter:stable; }
.ta-hl-wrap:focus-within > .ta-hl-backdrop { background:var(--surface); }
.ta-hl-backdrop {
    position:absolute; inset:0; z-index:1; overflow:hidden; pointer-events:none;
    background:var(--surface-2); border:1px solid transparent; border-radius:12px;
    padding:14px; scrollbar-gutter:stable;
}
.ta-hl-content { font-size:14px; line-height:1.7; font-family:'Inter',sans-serif; color:transparent; white-space:pre-wrap; overflow-wrap:break-word; }
.ta-hl-content mark { background:var(--brand); color:transparent; border-radius:2px; }
.transcript-meta { display:flex; gap:16px; margin-top:10px; font-size:12.5px; color:var(--text-faint); flex-wrap:wrap; }
.transcript-meta b { color:var(--text-soft); }

/* ---------- Pipeline progress ---------- */
.pipeline { padding: 8px 0 4px; }
.pipe-step { display:flex; align-items:center; gap:12px; padding:9px 0; }
.pipe-ic { width:30px; height:30px; border-radius:9px; display:grid; place-items:center; background:var(--surface-2); color:var(--text-faint); font-size:13px; flex-shrink:0; transition:.3s; }
.pipe-step.active .pipe-ic { background:var(--brand-soft); color:var(--brand); }
.pipe-step.done .pipe-ic { background:var(--mint); color:#fff; }
.pipe-label { font-size:13.5px; font-weight:600; color:var(--text-soft); }
.pipe-step.active .pipe-label, .pipe-step.done .pipe-label { color:var(--text); }
.pipe-bar { flex:1; height:5px; border-radius:4px; background:var(--surface-2); overflow:hidden; }
.pipe-bar > span { display:block; height:100%; width:0; background:linear-gradient(90deg,var(--brand),var(--mint)); transition:width .5s var(--ease); }
/* Elapsed time and why a long run is still going — the stages above finish
   their animation in seconds, the pipeline behind them may not. */
.pipe-status { margin-top:10px; padding:10px 12px; border-radius:10px; background:var(--surface-2);
  color:var(--text-soft); font-size:12.5px; line-height:1.55; }
.pipe-status i { color:var(--brand); margin-right:6px; }

/* ---------- SOAP cards ---------- */
.transcript-card { border:1px solid var(--border); border-radius:14px; margin-bottom:14px; background:var(--surface-2); overflow:hidden; }
.transcript-card > summary { list-style:none; cursor:pointer; padding:12px 16px; font-size:14px; font-weight:700; display:flex; align-items:center; gap:9px; user-select:none; }
.transcript-card > summary::-webkit-details-marker { display:none; }
.transcript-card > summary::after { content:'\f078'; font-family:'Font Awesome 6 Free'; font-weight:900; font-size:11px; color:var(--text-faint); margin-left:auto; transition:transform .18s var(--ease); }
.transcript-card[open] > summary::after { transform:rotate(180deg); }
.transcript-card-body { padding:0 16px 14px; max-height:220px; overflow-y:auto; white-space:pre-wrap; font-size:13.5px; line-height:1.7; color:var(--text-soft); }
.transcript-card-body .muted { color:var(--text-faint); font-style:italic; }

.soap-card { border:1px solid var(--border); border-radius:14px; margin-bottom:14px; overflow:hidden; background:var(--surface); animation: rise .4s var(--ease) both; }
.soap-card-head { display:flex; align-items:center; gap:10px; padding:12px 16px; border-bottom:1px solid var(--border); background:var(--surface-2); }
.soap-tag { width:30px; height:30px; border-radius:9px; display:grid; place-items:center; color:#fff; font-weight:800; font-size:14px; }
.soap-s{background:#2f83f5}.soap-o{background:#22b892}.soap-a{background:#e9a23b}.soap-p{background:#7c5cff}
.soap-card-head h4 { margin:0; font-size:14.5px; font-weight:700; flex:1; }
.soap-card-body { padding:14px 16px; }
.soap-text { width:100%; border:0; background:none; color:var(--text); font-size:14px; line-height:1.75; resize:vertical; min-height:80px; font-family:'Inter',sans-serif; }
.soap-text:focus { outline:none; }
.soap-actions { display:flex; gap:6px; }

/* ---------- Red flags ----------
   Carried at the top of the note, and present on every note: "none identified"
   is the screening being documented, not an empty section. */
.red-flag-card { border-color:var(--danger); }
.red-flag-card .soap-card-head { background:color-mix(in srgb, var(--danger) 12%, var(--surface-2)); }
.red-flag-card.clear { border-color:var(--border); }
.red-flag-card.clear .soap-card-head { background:var(--surface-2); }
.soap-rf { background:var(--danger); }
.soap-rf-clear { background:var(--surface-3, var(--surface-2)); color:var(--text-faint); border:1px solid var(--border); }
/* list-style is explicit: the global reset strips it, and an unbulleted list of
   red flags reads as one run-on sentence. */
.rf-list { margin:0; padding-left:20px; list-style:disc; color:var(--text); font-size:14px; line-height:1.7; }
.rf-list li { margin-bottom:4px; }
.rf-list li::marker { color:var(--danger); }
.rf-note { margin:10px 0 0; font-size:12px; color:var(--text-soft); }
.rf-none { margin:0; font-size:13.5px; color:var(--text-soft); }
/* The history list marks a consultation that carries one. */
.rf-badge { display:inline-flex; align-items:center; gap:5px; padding:2px 8px; border-radius:999px;
  background:color-mix(in srgb, var(--danger) 16%, transparent); color:var(--danger);
  font-size:11.5px; font-weight:700; white-space:nowrap; }

/* Clickable patient name → opens that patient's SOAP history. */
.pt-name-cell { display:flex; align-items:center; gap:11px; cursor:pointer; border-radius:8px; padding:2px 6px; margin:-2px -6px; transition:background .15s var(--ease); }
.pt-name-cell:hover { background:var(--surface-2); }
.pt-name-cell:hover strong { color:var(--brand); text-decoration:underline; }
.mini-btn { border:1px solid var(--border); background:var(--surface); color:var(--text-soft); width:32px; height:32px; border-radius:9px; cursor:pointer; transition:.15s; position:relative; }
.mini-btn:hover { color:var(--brand); border-color:var(--brand); }
.mini-btn[disabled] { opacity:.6; cursor:default; }
/* Regenerate button carries a label, so it needs auto width. */
/* Header strip above the four SOAP cards — carries the whole-note action, so
   it sits with the note rather than in the modal footer beside Close/Save. */
.soap-toolbar { display:flex; align-items:center; gap:10px; margin:18px 0 10px; }
.soap-toolbar-label { font-size:13px; font-weight:700; color:var(--text-soft); display:inline-flex; align-items:center; gap:7px; }
.soap-toolbar-actions { margin-left:auto; display:flex; align-items:center; gap:8px; }
/* Inline confirmation. It lives in the toolbar instead of a confirm dialog
   because opening a modal from inside a modal closes the one you are in. */
.soap-confirm { display:flex; align-items:center; gap:8px; }
.soap-confirm-msg { font-size:12.5px; font-weight:600; color:var(--danger); }
@media (max-width: 620px) {
    .soap-toolbar { flex-wrap:wrap; }
    .soap-confirm { flex-wrap:wrap; }
    .soap-confirm-msg { flex:1 1 100%; }
}

/* The labelled variant. .mini-btn is a 32px icon square by default, so any
   mini button carrying text has to opt out of the fixed size or the label
   spills out of the box. */
.mini-btn[data-regen], .mini-btn[data-polish] { width:auto; height:auto; padding:6px 11px; font-size:12.5px; font-weight:600; display:inline-flex; align-items:center; gap:6px; }
/* Two labelled buttons now share the card header; keep them off the title
   without each one claiming the free space. */
.soap-card-head .mini-btn[data-polish] { margin-left:auto; }
/* Count badge on the history row's "regeneration history" button. */
.log-badge { position:absolute; top:-6px; right:-6px; min-width:16px; height:16px; padding:0 4px; border-radius:9px;
    background:var(--brand); color:#fff; font-size:10px; font-weight:700; line-height:16px; text-align:center; }

/* ---- Regeneration change log ---- */
.cl-filters { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:18px; align-items:center; }
.cl-filters .selx { width:auto; min-width:0; }
.cl-filters .selx-btn { padding:9px 12px; font-size:13px; }
.cl-daterange { grid-column:1 / -1; display:flex; align-items:center; gap:8px; min-width:0; }
.cl-field-label { font-size:12px; font-weight:600; color:var(--text-faint); flex:none; }
.cl-daterange .form-control-x { flex:1; width:auto; min-width:0; padding:9px 10px; font-size:13px; }
.cl-daterange .form-control-x:disabled { opacity:.5; cursor:not-allowed; background:var(--surface-2); }
.cl-daterange-sep { color:var(--text-faint); font-weight:600; flex:none; }
#cl-f-clear { grid-column:1 / -1; justify-self:end; }
@media (max-width:520px){ .cl-filters { grid-template-columns:1fr; } }
.changelog { display:flex; flex-direction:column; gap:14px; }
.cl-entry { border:1px solid var(--border); border-radius:12px; overflow:hidden; }
.cl-head { display:flex; align-items:center; gap:9px; flex-wrap:wrap; padding:11px 14px; background:var(--surface-2); border-bottom:1px solid var(--border); font-size:14px; }
.cl-head .soap-tag { width:24px; height:24px; font-size:12px; border-radius:7px; }
.cl-meta { color:var(--text-faint); font-size:12.5px; font-weight:500; }
.cl-diff { display:grid; grid-template-columns:1fr 1fr; gap:1px; background:var(--border); }
.cl-col { background:var(--surface); padding:12px 14px; }
.cl-label { display:inline-block; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.04em; margin-bottom:6px; padding:1px 7px; border-radius:6px; }
.cl-from .cl-label { background:var(--danger-soft); color:var(--danger); }
.cl-to .cl-label { background:var(--mint-soft,#e6f8f1); color:var(--mint,#16a34a); }
.cl-col p { margin:0; white-space:pre-wrap; font-size:13px; line-height:1.6; color:var(--text); }
@media (max-width:560px){ .cl-diff { grid-template-columns:1fr; } }

/* ---------- Review flags ---------- */
.flag-box { border-radius:12px; padding:12px 14px; margin-bottom:12px; font-size:13px; display:flex; gap:10px; }
.flag-box.warn { background:var(--amber-soft); color:#8a5b12; }
.flag-box.info { background:var(--brand-soft); color:var(--brand-600); }
.flag-box.red { background:var(--danger-soft); color:var(--danger); }
[data-theme="dark"] .flag-box.warn { color:#f0c078; }
.chip { display:inline-block; padding:3px 9px; border-radius:8px; background:var(--surface); font-size:11.5px; margin:3px 4px 0 0; border:1px solid var(--border); }

/* ---------- Confidence ---------- */
.conf-item { display:flex; align-items:center; gap:10px; padding:7px 0; font-size:13px; }
.conf-name { flex:0 0 42%; color:var(--text-soft); font-weight:500; text-transform:capitalize; }
.conf-track { flex:1; height:7px; border-radius:5px; background:var(--surface-2); overflow:hidden; }
.conf-fill { height:100%; border-radius:5px; transition:width .6s var(--ease); }
.conf-val { flex:0 0 46px; text-align:right; font-weight:700; font-size:12.5px; }

/* =====================================================================
   ANALYTICS — quota meters, model cards, usage bars
   ===================================================================== */
/* Auto-fitting variant of .stat-grid for rows that are not exactly 4 wide. */
.stat-grid.auto { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.an-cols { display:grid; grid-template-columns: 1fr 1fr; gap:18px; margin-bottom:24px; }
@media (max-width: 1000px) { .an-cols { grid-template-columns:1fr; } }

.model-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap:16px; padding:16px; }
.model-card { border:1px solid var(--border); border-radius:14px; padding:16px; background:var(--surface); }
.model-card .mc-head { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; margin-bottom:4px; }
.model-card .mc-name { font-weight:700; font-size:14px; font-family:'Plus Jakarta Sans'; word-break:break-all; }
.model-card .mc-role { color:var(--text-faint); font-size:12px; margin-bottom:14px; }

.quota { margin-bottom:12px; }
.quota-top { display:flex; justify-content:space-between; align-items:baseline; gap:8px; margin-bottom:5px; }
.quota-lbl { font-size:12px; color:var(--text-soft); font-weight:600; }
.quota-val { font-size:12.5px; font-weight:700; }
.quota-sub { font-size:11px; color:var(--text-faint); margin-top:4px; }
.quota-na  { font-size:12px; color:var(--text-faint); font-style:italic; }

.mc-stats { display:grid; grid-template-columns: repeat(3, 1fr); gap:10px; margin-top:14px;
            padding-top:13px; border-top:1px solid var(--border); }
.mc-stat .k { font-size:10.5px; text-transform:uppercase; letter-spacing:.04em; color:var(--text-faint); font-weight:700; }
.mc-stat .v { font-size:15px; font-weight:700; font-family:'Plus Jakarta Sans'; margin-top:2px; }

/* 14-day call volume */
.spark { display:flex; align-items:flex-end; gap:5px; height:130px; padding:16px 16px 0; }
.spark-col { flex:1; display:flex; flex-direction:column; justify-content:flex-end; align-items:center; gap:5px; height:100%; }
.spark-bar { width:100%; min-height:3px; border-radius:4px 4px 0 0; background:var(--brand); opacity:.85; transition:.2s; }
.spark-col:hover .spark-bar { opacity:1; }
.spark-lbl { font-size:9.5px; color:var(--text-faint); white-space:nowrap; }

.bar-row { display:flex; align-items:center; gap:11px; padding:10px 16px; }
.bar-row .br-name { flex:0 0 130px; font-size:13px; font-weight:600; text-transform:capitalize; }
.bar-row .br-val { flex:0 0 90px; text-align:right; font-size:12.5px; font-weight:700; }

/* Inline key actions ("Test this key" / "Remove") under each field in
   Settings → AI · Groq. */
.link-btn { background:none; border:0; padding:0; font-size:11.5px; font-weight:600; color:var(--danger);
    cursor:pointer; }
.link-btn:hover { text-decoration:underline; }
/* Non-destructive inline action (e.g. "Test this key") — danger red would read
   as "this will remove something". */
.link-btn.neutral { color:var(--brand); }

.stale-note { font-size:11.5px; color:var(--text-faint); padding:0 16px 14px; line-height:1.6; }
.stale-note b { color:var(--text-soft); }

.throttle-alert { display:flex; gap:11px; align-items:flex-start; margin:16px 16px 0; padding:13px 15px;
    border-radius:12px; background:var(--danger-soft); border:1px solid var(--danger);
    color:var(--text); font-size:12.5px; line-height:1.55; }
.throttle-alert > i { color:var(--danger); font-size:15px; margin-top:1px; }
.throttle-alert code { font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:11.5px; }

/* =====================================================================
   TOASTS / LOADER / MODAL
   ===================================================================== */
.toast-stack { position:fixed; top:18px; right:18px; z-index:2000; display:flex; flex-direction:column; gap:10px; max-width:360px; }
.toast {
    background:var(--surface); border:1px solid var(--border); border-left:4px solid var(--brand);
    border-radius:13px; box-shadow:var(--shadow-lg); padding:13px 15px; display:flex; gap:12px; align-items:flex-start;
    animation: toastIn .35s var(--ease);
}
.toast.success { border-left-color:var(--mint); }
.toast.error { border-left-color:var(--danger); }
.toast.warn { border-left-color:var(--amber); }
.toast .t-ic { font-size:17px; margin-top:1px; }
.toast.success .t-ic{color:var(--mint)} .toast.error .t-ic{color:var(--danger)} .toast.warn .t-ic{color:var(--amber)} .toast.info .t-ic{color:var(--brand)}
.toast .t-body { flex:1; }
.toast .t-title { font-weight:700; font-size:13.5px; }
.toast .t-msg { font-size:12.5px; color:var(--text-soft); margin-top:2px; }
.toast .t-close { border:0; background:none; color:var(--text-faint); cursor:pointer; }
@keyframes toastIn { from{opacity:0; transform:translateX(30px);} to{opacity:1;transform:none;} }
.toast.out { opacity:0; transform:translateX(30px); transition:.3s; }

.global-loader { position:fixed; inset:0; z-index:1900; display:grid; place-items:center; background:rgba(8,15,28,.5); backdrop-filter: blur(4px); }
.loader-card { background:var(--surface); border-radius:20px; padding:34px 44px; text-align:center; box-shadow:var(--shadow-lg); }
.loader-card p { margin:16px 0 0; font-weight:600; color:var(--text-soft); }
.pipeline-spinner { width:64px; height:64px; border-radius:20px; display:grid; place-items:center; margin:0 auto; font-size:26px; color:#fff;
    background:linear-gradient(135deg,var(--brand),var(--mint)); animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0) rotate(0);} 50%{transform:translateY(-8px) rotate(4deg);} }

/* ---- Searchable select (SelectX) ---- */
.selx { position:relative; display:block; width:100%; }
.selx-native { display:none !important; }
.selx-btn { display:flex; align-items:center; justify-content:space-between; gap:10px; width:100%; text-align:left; cursor:pointer; }
.selx-btn .selx-val { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.selx-btn .selx-val.muted { color:var(--text-faint); }
.selx-caret { font-size:11px; color:var(--text-faint); transition:transform .18s var(--ease); flex:none; }
.selx.open .selx-btn { border-color:var(--brand); box-shadow:0 0 0 4px var(--brand-soft); }
.selx.open .selx-caret { transform:rotate(180deg); }
.selx-menu {
    position:absolute; z-index:1600; top:calc(100% + 6px); left:0; right:0;
    background:var(--surface); border:1px solid var(--border); border-radius:12px;
    box-shadow:var(--shadow-lg); padding:8px; opacity:0; transform:translateY(-6px);
    pointer-events:none; transition:opacity .16s var(--ease), transform .16s var(--ease);
}
.selx.open .selx-menu { opacity:1; transform:none; pointer-events:auto; }
.selx-search { position:relative; margin-bottom:6px; }
.selx-search i { position:absolute; left:11px; top:50%; transform:translateY(-50%); font-size:12px; color:var(--text-faint); }
.selx-search input { width:100%; padding:9px 12px 9px 32px; border:1.5px solid var(--border); border-radius:9px;
    background:var(--surface-2); color:var(--text); font-size:13.5px; font-family:inherit; }
.selx-search input:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft); }
.selx-list { max-height:240px; overflow-y:auto; display:flex; flex-direction:column; gap:2px; }
.selx-item { padding:9px 11px; border-radius:8px; font-size:13.5px; cursor:pointer; transition:.12s; display:flex; align-items:center; gap:8px; }
.selx-item:hover { background:var(--surface-2); }
.selx-item.active { background:var(--brand-soft); color:var(--brand); font-weight:600; }
.selx-item.active::after { content:'\f00c'; font-family:'Font Awesome 6 Free'; font-weight:900; margin-left:auto; font-size:11px; }
.selx-empty { padding:12px; text-align:center; color:var(--text-faint); font-size:13px; }

.modal-scrim { position:fixed; inset:0; z-index:1500; background:rgba(8,15,28,.55); backdrop-filter:blur(4px); display:grid; place-items:center; padding:20px; }
.modal-box { background:var(--surface); border-radius:20px; box-shadow:var(--shadow-lg); width:100%; max-width:520px; animation: rise .3s var(--ease); max-height:90vh; overflow:auto; }
.modal-head { padding:18px 22px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
.modal-head h3 { margin:0; font-size:17px; font-weight:700; }
.modal-body { padding:22px; }
.modal-foot { padding:16px 22px; border-top:1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; }
.form-group { margin-bottom:15px; }
.form-group label { display:block; font-size:13px; font-weight:600; margin-bottom:6px; color:var(--text-soft); }
.req { color:var(--danger); font-weight:700; }
.form-control-x.is-invalid { border-color:var(--danger); box-shadow:0 0 0 4px var(--danger-soft); }
.field-error { color:var(--danger); font-size:12px; font-weight:500; margin-top:5px; display:flex; align-items:center; gap:5px; }
.field-error::before { content:"\f06a"; font-family:"Font Awesome 6 Free"; font-weight:900; font-size:11px; }
.form-control-x { width:100%; padding:11px 13px; border:1.5px solid var(--border); border-radius:11px; background:var(--surface); color:var(--text); font-size:14px; font-family:inherit; }
.form-control-x:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 4px var(--brand-soft); }
textarea.form-control-x { resize:vertical; min-height:90px; }
.pw-wrap { position:relative; }
.pw-wrap .form-control-x { padding-right:44px; }
.pw-wrap .pw-toggle { position:absolute; right:6px; top:50%; transform:translateY(-50%); border:0; background:none; color:var(--text-faint); padding:8px; cursor:pointer; border-radius:8px; }
.pw-wrap .pw-toggle:hover { color:var(--brand); }

/* ---------- Logo upload ---------- */
.logo-upload { display:flex; gap:16px; align-items:center; }
.logo-preview {
    width:76px; height:76px; flex-shrink:0; border-radius:16px; border:1.5px dashed var(--border);
    background:var(--surface-2); display:grid; place-items:center; color:var(--text-faint); font-size:24px; overflow:hidden;
}
.logo-preview img { width:100%; height:100%; object-fit:contain; padding:8px; }
.logo-actions { display:flex; flex-direction:column; gap:8px; align-items:flex-start; }
.logo-actions .btn-soft, .logo-actions .btn-ghost { cursor:pointer; }

/* ---------- Detail view ---------- */
.detail-grid { display:grid; grid-template-columns: 1fr 1fr; gap:12px; }
.detail-field { padding:12px 14px; background:var(--surface-2); border-radius:11px; }
.detail-field .k { font-size:11.5px; text-transform:uppercase; letter-spacing:.04em; color:var(--text-faint); font-weight:700; }
.detail-field .v { font-size:14px; margin-top:3px; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 991px) {
    .sidebar { position:fixed; left:0; top:0; transform: translateX(-100%); transition: transform .3s var(--ease); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform:none; }
    .sidebar-scrim.show { display:block; position:fixed; inset:0; background:rgba(8,15,28,.5); z-index:39; }
    .stat-grid { grid-template-columns: repeat(2,1fr); }
    .consult-split { flex-direction:column; min-height:0; }
    .resizer { display:none; }
    .panel-left, .panel-right { flex:1 1 auto; }
    .detail-grid { grid-template-columns:1fr; }
}
@media (max-width: 560px) {
    .content { padding:16px; }
    .stat-grid { grid-template-columns:1fr; }
    .topbar-search { display:none; }
    .auth-card { padding:32px 24px; }
}

/* A key whose daily budget is entirely spent */
.model-card.key-dry { border-color:var(--danger); background:var(--danger-soft); }
.model-card code { font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:11px; }

/* =====================================================================
   NOTES & REMINDERS
   Everything here is expressed in the theme variables, so the page follows
   light/dark automatically rather than needing a second set of rules.
   ===================================================================== */
.pill.grey { background:var(--surface-2); color:var(--text-faint); border:1px solid var(--border); }

/* Buttons grouped at the right of a page heading. */
.page-head-actions { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }

/* Count of waiting reminders, pinned to the right of the sidebar link. */
.nav-badge { margin-left:auto; min-width:20px; height:20px; padding:0 6px; border-radius:10px;
    background:var(--danger); color:#fff; font-size:11px; font-weight:700; line-height:20px; text-align:center; }

/* ---- Filter bar ---- */
.nt-filters { margin-bottom:16px; display:flex; flex-direction:column; gap:12px; }
.nt-filter-row { display:flex; gap:12px; align-items:flex-end; flex-wrap:wrap; }
.nt-field { display:flex; flex-direction:column; gap:5px; min-width:170px; }
.nt-field .cl-field-label { margin:0; }
.nt-grow { flex:1; min-width:220px; }
/* The search box is the topbar component reused; it needs to fill its cell. */
.nt-field .topbar-search { width:100%; }
.nt-filter-row #nt-f-clear { margin-left:auto; }

/* ---- Note cards ---- */
.nt-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(320px,1fr)); gap:14px; }
.nt-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-sm);
    padding:15px 16px; box-shadow:var(--shadow-sm); display:flex; flex-direction:column; gap:9px;
    transition:.18s var(--ease); }
.nt-card:hover { box-shadow:var(--shadow-md); }
/* An overdue reminder earns a coloured edge — the strongest signal available
   without shouting, and it survives being one card among many. */
.nt-card.is-overdue { border-color:var(--danger); box-shadow:0 0 0 3px var(--danger-soft); }
.nt-card.is-done { opacity:.62; }
.nt-card.is-done .nt-title { text-decoration:line-through; }
.nt-card-top { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.nt-card-actions { margin-left:auto; }
.nt-title { font-size:15.5px; font-weight:700; margin:0; line-height:1.35; word-break:break-word; }
.nt-body { margin:0; font-size:13px; color:var(--text-soft); line-height:1.6; white-space:pre-wrap;
    /* Long notes are clamped rather than scrolled: the card is a summary and the
       edit modal holds the full text. */
    display:-webkit-box; -webkit-line-clamp:4; -webkit-box-orient:vertical; overflow:hidden; }
.nt-meta { display:flex; align-items:center; gap:14px; flex-wrap:wrap; margin-top:auto;
    padding-top:9px; border-top:1px solid var(--border); font-size:12px; color:var(--text-faint); }
.nt-meta i { margin-right:4px; }
.nt-remind { font-weight:600; color:var(--brand); }
.nt-remind.is-overdue { color:var(--danger); }
.nt-readonly { display:inline-flex; align-items:center; color:var(--text-faint); font-size:12px; padding:0 4px; }

/* ---- Note editor ---- */
.nt-hint { font-weight:500; color:var(--text-faint); font-size:12px; }
.nt-remind-row { display:flex; gap:8px; align-items:center; }
.nt-remind-row .form-control-x { flex:1; min-width:0; }
.nt-quick { display:flex; gap:6px; flex-wrap:wrap; margin-top:8px; }

/* ---- The due-reminder alert ---- */
.rem-alert-list { display:flex; flex-direction:column; gap:12px; }
.rem-alert { display:flex; gap:13px; padding:13px 14px; border:1px solid var(--border);
    border-radius:var(--radius-sm); background:var(--surface-2); }
.rem-alert-ic { flex:none; width:38px; height:38px; border-radius:11px; display:grid; place-items:center;
    background:var(--brand-soft); color:var(--brand); font-size:15px; }
.rem-alert-ic.high   { background:var(--amber-soft);  color:var(--amber); }
.rem-alert-ic.urgent { background:var(--danger-soft); color:var(--danger); }
.rem-alert-ic.low    { background:var(--surface); color:var(--text-faint); }
.rem-alert-body { min-width:0; flex:1; }
.rem-alert-top { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.rem-alert-top strong { font-size:15px; word-break:break-word; }
.rem-alert-when { font-size:12.5px; color:var(--text-faint); margin-top:3px; font-weight:600; }
.rem-alert-text { margin:8px 0 0; font-size:13px; color:var(--text-soft); line-height:1.6; white-space:pre-wrap; }
.rem-alert-actions { display:flex; gap:6px; flex-wrap:wrap; margin-top:11px; }

@media (max-width:560px) {
    .nt-grid { grid-template-columns:1fr; }
    .nt-field, .nt-grow { min-width:0; width:100%; }
    .nt-filter-row #nt-f-clear { margin-left:0; }
}

/* =====================================================================
   AI ASSISTANT — chat over the clinic's records
   ===================================================================== */

/* The thread scrolls, the page does not: a chat that grows the document
   pushes the composer off-screen, which is exactly where it must never go.
   Hence the fixed height and min-height:0 on the flex children — without the
   latter, a flex item refuses to shrink below its content and the overflow
   never engages. */
.chat-wrap {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    height: calc(100vh - var(--topbar-h) - 132px);
    min-height: 460px;
}

/* ---------- conversation list ---------- */
.chat-side {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.chat-side-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    font-size: 13px; font-weight: 700; color: var(--text-soft);
    text-transform: uppercase; letter-spacing: .04em;
}
.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.chat-side-empty { color: var(--text-faint); font-size: 13px; padding: 18px 10px; text-align: center; margin: 0; }

.chat-item {
    display: flex; align-items: center; gap: 4px;
    border-radius: var(--radius-sm); padding: 2px;
    transition: background .15s var(--ease);
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--brand-soft); }
.chat-item-open {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px;
    background: none; border: 0; padding: 9px 8px; text-align: left; cursor: pointer;
    color: var(--text); font-size: 13.5px;
}
.chat-item-open i { color: var(--text-faint); flex-shrink: 0; }
.chat-item.active .chat-item-open i { color: var(--brand); }
.chat-item-title {
    flex: 1; min-width: 0; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-open small { display: none; }
.chat-item-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s var(--ease); }
.chat-item:hover .chat-item-actions, .chat-item.active .chat-item-actions { opacity: 1; }

/* ---------- thread ---------- */
.chat-main {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column;
    min-height: 0; overflow: hidden;
}
.chat-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 22px; scroll-behavior: smooth; }

.chat-row { display: flex; gap: 11px; margin-bottom: 18px; align-items: flex-start; }
.chat-row.user { justify-content: flex-end; }

.chat-avatar {
    width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0;
    display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff;
}
.chat-avatar.ai   { background: linear-gradient(135deg, var(--brand), var(--mint)); }
.chat-avatar.you  { background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); }
.chat-avatar.err  { background: var(--danger); }

.chat-bubble {
    position: relative;
    max-width: min(720px, 78%);
    padding: 13px 16px;
    border-radius: 16px;
    font-size: 14.5px; line-height: 1.65;
    word-wrap: break-word; overflow-wrap: anywhere;
}
.chat-user { background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.chat-ai   { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 5px; padding-right: 40px; }
.chat-err  { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); }

.chat-bubble p  { margin: 0 0 9px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h4 { font-size: 14.5px; font-weight: 700; margin: 13px 0 7px; }
.chat-bubble h4:first-child { margin-top: 0; }
/* Tailwind's preflight strips list markers globally, so a model answer that is
   mostly bullet points renders as unlabelled indented lines. Put them back. */
.chat-bubble ul { list-style: disc outside; }
.chat-bubble ol { list-style: decimal outside; }
.chat-bubble ul, .chat-bubble ol { margin: 0 0 9px; padding-left: 22px; }
.chat-bubble li { margin-bottom: 4px; }
.chat-bubble code {
    background: rgba(127,146,170,.16); padding: 1.5px 5px;
    border-radius: 5px; font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chat-bubble pre {
    background: rgba(127,146,170,.14); padding: 11px 13px; border-radius: var(--radius-sm);
    overflow-x: auto; margin: 0 0 9px;
}
.chat-bubble pre code { background: none; padding: 0; }
.chat-user code, .chat-user pre { background: rgba(255,255,255,.2); }

/* Which records the answer was built from. Worth showing: it is the
   difference between the model recalling something and having read it. */
.chat-tools {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    font-size: 11.5px; font-weight: 600; color: var(--text-faint);
    margin-bottom: 9px; padding-bottom: 9px; border-bottom: 1px dashed var(--border);
}
.chat-tools span {
    background: var(--brand-soft); color: var(--brand);
    padding: 2px 8px; border-radius: 20px; text-transform: capitalize;
}

.chat-copy {
    position: absolute; top: 8px; right: 8px;
    opacity: 0; transition: opacity .15s var(--ease);
}
.chat-row:hover .chat-copy { opacity: 1; }

/* typing indicator */
.chat-dots { display: flex; gap: 5px; padding: 4px 2px; }
.chat-dots span {
    width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
    animation: chatdot 1.3s var(--ease) infinite;
}
.chat-dots span:nth-child(2) { animation-delay: .18s; }
.chat-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes chatdot { 0%, 60%, 100% { opacity: .28; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

/* ---------- empty state ---------- */
.chat-welcome { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.chat-welcome-badge {
    width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand), var(--mint)); color: #fff; font-size: 23px; margin-bottom: 16px;
}
.chat-welcome h2 { font-family: var(--font-display, inherit); font-size: 21px; font-weight: 700; margin: 0 0 6px; }
.chat-welcome p  { color: var(--text-soft); font-size: 14px; margin: 0 0 22px; max-width: 420px; }
.chat-suggests { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; max-width: 560px; }
.chat-suggest {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft);
    border-radius: 20px; padding: 9px 15px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: all .15s var(--ease);
}
.chat-suggest:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- composer ---------- */
.chat-composer { border-top: 1px solid var(--border); padding: 14px 18px 12px; background: var(--surface); }
.chat-input-row { display: flex; align-items: flex-end; gap: 10px; }
.chat-input-row textarea {
    flex: 1; resize: none; min-height: 46px; max-height: 200px;
    border: 1.5px solid var(--border); border-radius: 14px;
    background: var(--surface); color: var(--text);
    padding: 12px 14px; font: inherit; font-size: 14.5px; line-height: 1.5;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.chat-input-row textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.chat-input-row textarea:disabled { opacity: .6; }
.chat-send {
    width: 46px; height: 46px; border-radius: 14px; border: 0; flex-shrink: 0;
    background: var(--brand); color: #fff; font-size: 15px; cursor: pointer;
    transition: background .15s var(--ease);
}
.chat-send:hover:not(:disabled) { background: var(--brand-600); }
.chat-send:disabled { opacity: .55; cursor: not-allowed; }
.chat-hint { font-size: 11.5px; color: var(--text-faint); margin: 8px 2px 0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
    /* The list becomes a horizontal strip above the thread — still reachable,
       but no longer taking a third of a narrow screen. */
    .chat-wrap { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-h) - 118px); }
    .chat-side { max-height: 148px; }
    .chat-list { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; }
    .chat-item { flex: 0 0 190px; }
    .chat-item-actions { opacity: 1; }
}
@media (max-width: 640px) {
    .chat-bubble { max-width: 88%; }
    .chat-thread { padding: 16px 13px; }
    .chat-suggests { flex-direction: column; }
}

/* ---------- assistant links & write badge ---------- */
.chat-link {
    color: var(--brand); font-weight: 600; text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
    word-break: break-word;
}
.chat-link:hover { color: var(--brand-600); border-bottom-color: var(--brand-600); }
.chat-link i { font-size: 10px; margin-right: 5px; opacity: .75; }
.chat-user .chat-link { color: #fff; border-bottom-color: rgba(255,255,255,.5); }

/* A write is flagged amber, not blue: the user should be able to tell at a
   glance that this turn changed their records rather than only read them. */
.chat-tools.wrote { color: var(--amber); border-bottom-style: solid; }
.chat-tools.wrote span { background: var(--amber-soft); color: var(--amber); }

/* ---------- destructive-action gate ---------- */
.chat-confirm {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap;
    margin: 4px 0 18px 45px;
    padding: 13px 16px;
    background: var(--danger-soft);
    border: 1px solid var(--danger);
    border-radius: 14px;
}
.chat-confirm-text { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--danger); min-width: 0; }
.chat-confirm-text strong { font-weight: 700; }
.chat-confirm-actions { display: flex; gap: 8px; flex-shrink: 0; }
.chat-confirm-actions button { padding: 7px 16px; font-size: 13px; border-radius: 10px; }
@media (max-width: 640px) {
    .chat-confirm { margin-left: 0; }
    .chat-confirm-actions { width: 100%; justify-content: flex-end; }
}
