/* Desk app additions on top of the approved design system (desk.css). */
[hidden] { display: none !important; }

a.chan, a.row, a.chip, a.source-chip, a.attach, a.kb-row { text-decoration: none; color: inherit; }
.chan.disabled { cursor: default; }
.rail .foot form { margin: 0; }

.convo-wrap { display: flex; min-width: 0; min-height: 0; }
.convo-wrap .conversation { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.convo-body { flex: 1; min-height: 0; overflow-y: auto; }
.back-link { display: none; font-size: 28px; line-height: 1; color: var(--teal); text-decoration: none; padding: 0 10px 0 0; }

.btext { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .meta { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
img.photo { display: block; max-width: min(260px, 100%); max-height: 320px; border-radius: 8px; margin-bottom: 6px; background: var(--navy-softer); }
img.sticker { display: block; width: 120px; height: auto; }
audio.voice { width: 250px; max-width: 100%; display: block; margin-bottom: 4px; }
video.video { max-width: min(300px, 100%); border-radius: 8px; display: block; margin-bottom: 6px; }
.media-pending { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.ticks.failed { color: var(--red); font-weight: 600; }

.badge-emergency, .badge-urgent, .badge-archived {
  font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-right: 6px;
}
.badge-emergency { background: var(--red); color: #fff; }
.badge-urgent { background: var(--gold-soft); color: #7a5f12; }
.badge-archived { background: var(--navy-softer); color: var(--muted); }
.list-empty { padding: 28px 18px; }
.big-empty { margin: auto; padding: 40px; text-align: center; color: var(--muted); }

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 16px; }
.reply-row textarea {
  width: 100%; min-height: 76px; max-height: 40vh; resize: vertical; font: inherit; line-height: 1.5;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 10px 12px; background: #fff; color: var(--text);
}
.reply-row textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; border-color: var(--teal); }
.reply-row textarea:disabled { background: var(--navy-softer); }
.composer-bar { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.draft-shell { margin-bottom: 10px; }
.draft-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.draft-model { margin-left: auto; color: var(--faint); font-size: 11px; }
.draft-none { margin-bottom: 10px; }
.draft-failed { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.staff-note { font-size: 12.5px; background: var(--navy-softer); border-radius: var(--radius-sm); padding: 7px 10px; margin-top: 8px; }
.urg { font-weight: 700; }
.urg-emergency { color: #fff; background: var(--red); padding: 0 6px; border-radius: 4px; }
.urgency-banner, .send-error { margin-bottom: 10px; }
.medical-flag { margin-bottom: 10px; }

.note-status { font-size: 11.5px; color: var(--faint); margin-top: 4px; min-height: 16px; }

/* Sign in */
.page-signin .signin { min-height: 100vh; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; text-align: left; }
.login-input { font: inherit; font-size: 15px; padding: 11px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.login-input.code { font-size: 24px; letter-spacing: 6px; text-align: center; }
.login-btn { justify-content: center; padding: 11px; }
.login-help { font-size: 13px; color: var(--muted); margin: 0; }
.login-alt { font-size: 12.5px; color: var(--teal); text-align: center; }

/* Knowledge */
.kb-app .workspace { overflow-y: auto; height: 100vh; }
.kb-main { padding: 22px 32px 60px; grid-column: 2 / span 2; }
.kb-top { margin-bottom: 14px; }
.kb-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.kb-head h1 { font-size: 22px; color: var(--navy); margin: 4px 0; }
.kb-chips { margin-bottom: 10px; }
.kb-search { max-width: 520px; margin: 0 0 16px; }
.kb-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 6px; }
.kb-row { display: grid; grid-template-columns: 46px 1fr 120px 170px; gap: 12px; align-items: center; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); margin-bottom: 6px; }
.kb-row:hover { border-color: var(--teal); }
.kb-ref { color: var(--faint); }
.kb-status { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; justify-self: start; }
.st-approved { background: var(--teal-soft); color: var(--teal-dark); }
.st-draft { background: var(--gold-soft); color: #7a5f12; }
.st-needs_review { background: var(--red-soft); color: var(--red); }
.st-archived { background: var(--navy-softer); color: var(--muted); }
.kb-who { font-size: 12px; text-align: right; }
.kb-form { max-width: 820px; }
.kb-form .form-field { margin-bottom: 14px; }
.kb-form input, .kb-form textarea, .kb-form select { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; }
.kb-form textarea { resize: vertical; line-height: 1.5; }
.kb-example { white-space: pre-wrap; background: var(--navy-softer); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.kb-actions { display: flex; gap: 10px; }
.saved-note { background: var(--teal-soft); color: var(--teal-dark); padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; max-width: 820px; }
.tb-result { max-width: 820px; margin-top: 18px; }



/* Email thread (from the approved inbox-email design) */
.email-message { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 12px; overflow: hidden; }
.email-msg-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--navy-softer); }
.email-msg-head .msg-who { font-weight: 650; color: var(--navy); font-size: 13.5px; }
.email-msg-head .msg-from { font-size: 12px; color: var(--muted); }
.email-msg-head .msg-date { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.email-message .email-body { padding: 14px 18px; }
.thread-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.thread-toolbar .t-title { flex: 1; }
.email-message.from-clinic { border-left: 3px solid var(--teal); }
.t-subject { font-size: 17px; font-weight: 650; color: var(--navy); }
.email-thread { padding: 4px 4px 12px; }
.full-email { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.full-email summary { cursor: pointer; color: var(--teal); }
.email-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.folder-tabs { margin-bottom: 8px; }
.folder-tabs .subtab { text-decoration: none; color: inherit; }

/* Fit the conversation to the screen: the chat scrolls, the composer never pushes
   the reply box off the bottom. */
.app > * { min-height: 0; }
.convo-wrap { height: 100vh; }
.convo-wrap .conversation { height: 100%; }
.convo-head { flex-shrink: 0; }
.draft-actions { margin-top: 8px; }

/* List: the unread dot sits under the time, not on it; filters fit one line. */
.row .dot { top: 38px; right: 18px; }
.list-pane .chips { flex-wrap: nowrap; }
.list-pane .chip { padding: 3px 9px; font-size: 12.5px; white-space: nowrap; }

/* Edited and deleted WhatsApp messages */
.edited { font-style: italic; color: var(--faint); cursor: help; }
.deleted-note { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.btext.deleted { color: var(--faint); text-decoration: line-through; }


/* Conversation layout: chat | drag | AI draft panel. Reply box and contact strip
   sit under the chat; both borders can be dragged (sizes remembered per browser). */
.convo-wrap { display: flex; height: 100vh; min-width: 0; }
.composer { flex-shrink: 0; padding: 8px 16px 10px; }
.reply-row textarea { height: var(--reply-h, 96px); min-height: 48px; max-height: 60vh; resize: none; }
.composer-bar { margin-top: 6px; }

.split-h { flex-shrink: 0; height: 7px; cursor: row-resize; background: var(--line); position: relative; }
.split-h::after { content: ''; position: absolute; left: 50%; top: 2px; width: 44px; height: 3px; margin-left: -22px; border-radius: 3px; background: var(--line-strong); }
.split-v { flex-shrink: 0; width: 7px; cursor: col-resize; background: var(--line); position: relative; }
.split-v::after { content: ''; position: absolute; top: 50%; left: 2px; height: 44px; width: 3px; margin-top: -22px; border-radius: 3px; background: var(--line-strong); }
.split-h:hover, .split-v:hover, .dragging .split-h, .dragging .split-v { background: var(--teal-soft); }
body.dragging { user-select: none; }
body.dragging-v { cursor: col-resize; }
body.dragging-h { cursor: row-resize; }

.draft-panel { width: var(--draft-w, 420px); flex-shrink: 0; background: var(--panel); overflow-y: auto; padding: 14px 16px 24px; }
.dp-head { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.draft-panel .draft-shell { border: 1px solid var(--sky); border-radius: var(--radius-lg); background: var(--sky-soft); padding: 12px 14px; position: relative; }
.draft-panel .draft-text { white-space: pre-wrap; max-height: none; overflow: visible; }
.draft-panel .medical-flag, .draft-panel .urgency-banner { margin-bottom: 10px; }

.contact-strip { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--text); }
.contact-strip .k { color: var(--faint); margin-right: 3px; }
.cs-note { flex-basis: 100%; }
.cs-note summary { cursor: pointer; color: var(--teal); font-size: 12.5px; }
.cs-note textarea { width: 100%; min-height: 56px; margin-top: 6px; font: inherit; font-size: 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 9px; resize: vertical; }


/* Channel icons and rail counts */
.rail .icon .ico, .ico { display: inline-flex; width: 20px; height: 20px; }
.ico svg { width: 100%; height: 100%; }
.rail .icon.wa { color: #25D366; }
.rail .icon.mail { color: #8EC2EE; }
.rail .icon.meta { color: #9AA6BD; }
.rail .icon.kb { background: rgba(91, 155, 213, 0.20); color: #8EC2EE; }
.rail-counts { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.rc-unreplied { background: var(--teal); color: #fff; font-size: 12px; font-weight: 700; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; }
.rc-unread { font-size: 11px; color: rgba(255, 255, 255, 0.55); white-space: nowrap; }

/* Coloured initials avatars */
.contact-avatar.av-0 { background: #E6F2F2; color: #006666; }
.contact-avatar.av-1 { background: #EAF2FA; color: #2F6EA8; }
.contact-avatar.av-2 { background: #F7F0DC; color: #8A6A10; }
.contact-avatar.av-3 { background: #F3E8F7; color: #7A3E91; }
.contact-avatar.av-4 { background: #FBEBEB; color: #A12A2A; }
.contact-avatar.av-5 { background: #E9F5E9; color: #2E7D32; }
.contact-avatar.av-6 { background: #FFF0E6; color: #B5531C; }
.contact-avatar.av-7 { background: #E8EDF5; color: #1B2A4A; }

/* Contact strip under the reply box: labelled cells on one line, note on demand */
.contact-strip { display: block; margin-top: 8px; padding: 8px 0 0; border-top: 1px solid var(--line); }
.cs-grid { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; }
.cs-cell { display: flex; flex-direction: column; justify-content: center; padding: 4px 10px; background: var(--navy-softer); border-radius: var(--radius-sm); min-width: 0; }
.cs-k { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); line-height: 1.3; }
.cs-v { font-size: 12.5px; color: var(--navy); font-weight: 600; white-space: nowrap; line-height: 1.4; }
.cs-note-btn { margin-left: auto; align-self: center; border: 1px dashed var(--line-strong); background: transparent; color: var(--teal); font: inherit; font-size: 12.5px; padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.cs-note-btn.has-note { border-style: solid; background: var(--gold-soft); color: #7a5f12; border-color: transparent; }
.cs-note { margin-top: 6px; }
.cs-note textarea { width: 100%; min-height: 56px; font: inherit; font-size: 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 9px; resize: vertical; }

/* Steering the draft with staff key points */
.steer { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-strong); }
.steer label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.steer textarea { width: 100%; font: inherit; font-size: 13px; line-height: 1.5; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; resize: vertical; min-height: 64px; }
.steer textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; }
.steer-bar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 11.5px; }
.guided-note { font-size: 12.5px; background: #fff; border: 1px solid var(--sky); border-radius: var(--radius-sm); padding: 7px 10px; margin-top: 8px; white-space: pre-wrap; }

/* Right panel: AI draft and key points scroll; reply box and Send stay at the bottom. */
.draft-panel { display: flex; flex-direction: column; padding: 0; overflow: hidden; height: 100vh; }
.dp-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 16px 16px; }
.draft-panel .composer { border-top: none; padding: 10px 16px 12px; background: var(--panel); }
.convo-wrap .conversation { height: 100vh; }
.convo-wrap .conversation .contact-strip { flex-shrink: 0; margin: 0; padding: 8px 16px 10px; background: var(--panel); border-top: 1px solid var(--line); }
.composer.drop { outline: 2px dashed var(--teal); outline-offset: -6px; background: var(--teal-softer); }

/* Attachments */
.attach-btn { cursor: pointer; }
.attach-btn.disabled { opacity: .5; pointer-events: none; }
.attachment-tray { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.att { display: grid; grid-template-columns: 34px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center; padding: 5px 6px 5px 5px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; max-width: 230px; }
.att img, .att .att-type { grid-row: 1 / span 2; width: 34px; height: 34px; border-radius: 5px; object-fit: cover; }
.att .att-type { display: inline-flex; align-items: center; justify-content: center; background: var(--navy); color: #fff; font-size: 9.5px; font-weight: 700; }
.att-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 11px; color: var(--muted); grid-column: 2; }
.att-x { grid-row: 1 / span 2; grid-column: 3; border: none; background: none; font-size: 18px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.att-error { border-color: var(--red); }
.att-error .att-size { color: var(--red); }

/* ================= Media in the chat ================= */
.vh { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.photo-block, .audio-block, .video-block { margin-bottom: 6px; }
.media-actions { display: flex; gap: 12px; font-size: 12px; margin-top: 3px; }
.media-actions a { color: var(--teal); text-decoration: none; font-weight: 600; }
.doc-block { display: grid; grid-template-columns: 38px 1fr; gap: 4px 10px; align-items: center; max-width: 320px; }
.doc-block .doc-meta { min-width: 0; }
.doc-block .a-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.doc-actions .btn { flex: 1; justify-content: center; text-decoration: none; }
.window-row { display: flex; justify-content: center; margin: 4px 0 8px; }
.window-row:empty { display: none; }
.att-retry { grid-row: 1 / span 2; grid-column: 3; border: 1px solid var(--red); color: var(--red); background: #fff; border-radius: 6px; font-size: 11.5px; padding: 3px 7px; cursor: pointer; margin-right: 22px; }

/* ================= Shared bits for small screens ================= */
.mnav { display: none; }
.info-btn { display: none; }
.dp-head { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 14px 16px 0; text-align: left; font: inherit; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; cursor: default; }
.dp-state { color: var(--teal); letter-spacing: 0; text-transform: none; font-size: 12px; }
.dp-chev { display: none; margin-left: auto; }
.app { height: 100vh; height: 100dvh; }
.convo-wrap, .convo-wrap .conversation, .draft-panel { height: 100vh; height: 100dvh; }
.composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

/* Touch screens: no drag handles (sizes adapt), larger targets, 16px text so iOS
   does not zoom into the reply box. */
@media (pointer: coarse) {
  .split-h, .split-v { display: none; }
  .reply-row textarea, .steer textarea, .cs-note textarea, .search input, .kb-form input, .kb-form textarea, .kb-form select, .login-input { font-size: 16px; }
  .btn.small { min-height: 36px; padding-left: 12px; padding-right: 12px; }
  .chip { min-height: 32px; display: inline-flex; align-items: center; }
  .row { padding-top: 14px; padding-bottom: 14px; }
}

/* ================= Small laptops, iPad landscape: icon rail ================= */
@media (max-width: 1279px) {
  .app { grid-template-columns: 72px 320px 1fr; }
  .rail { padding-left: 8px; padding-right: 8px; }
  .rail .brand > div, .rail .chan-name, .rail .chan-sub, .rail-label, .rc-unread { display: none; }
  .rail .brand { justify-content: center; }
  .rail .chan { justify-content: center; position: relative; padding: 10px 0; }
  .rail .chan > div:nth-child(2) { display: none; }
  .rail-counts { position: absolute; top: 2px; right: 2px; }
  .rc-unreplied { min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 5px; }
  .draft-panel { --draft-w: 360px; }
}

/* ================= Tablets: AI draft folds out above the reply box ================= */
@media (max-width: 1099px) {
  .convo-wrap { flex-direction: column; }
  .convo-wrap .conversation { flex: 1 1 auto; height: auto; min-height: 0; }
  .split-v, .split-h { display: none; }
  .draft-panel { width: auto !important; height: auto; flex: 0 0 auto; border-top: 1px solid var(--line-strong); box-shadow: 0 -4px 14px rgba(27, 42, 74, .06); }
  .dp-scroll { display: none; max-height: 55dvh; padding-top: 0; }
  .draft-panel.open .dp-scroll { display: block; }
  .dp-head { padding: 10px 16px; margin: 0; cursor: pointer; background: var(--sky-soft); color: var(--navy); }
  .draft-panel.open .dp-head { background: none; }
  .dp-chev { display: inline; transition: transform .15s; }
  .draft-panel.open .dp-chev { transform: rotate(180deg); }
  .dp-scroll { padding-top: 10px; }
  .composer { padding-top: 8px; }
  .reply-row textarea { height: auto; min-height: 52px; }
  .info-btn { display: inline-flex; }
  .conversation .contact-strip { display: none; }
  .conversation.show-info .contact-strip { display: block; }
}

/* ================= Phones and iPad portrait: one screen at a time ================= */
@media (max-width: 859px) {
  .app { grid-template-columns: 1fr !important; }
  .rail { display: none; }
  .app.has-convo .list-pane { display: none; }
  .app:not(.has-convo):not(.kb-app) .convo-wrap { display: none; }
  .back-link { display: inline-block; padding: 4px 12px 4px 0; }
  .mnav { display: flex; align-items: center; gap: 2px; background: var(--navy); padding: calc(4px + env(safe-area-inset-top)) 6px 4px; position: sticky; top: 0; z-index: 20; }
  .mnav > a { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; color: rgba(255, 255, 255, .62); text-decoration: none; font-size: 10.5px; font-weight: 600; letter-spacing: .01em; padding: 7px 0 6px; border-radius: 10px; }
  .mnav > a.on { color: #fff; background: rgba(255, 255, 255, .10); }
  .mnav .mn-ico { position: relative; display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; }
  .mnav .mn-ico .ico { width: 21px; height: 21px; }
  .mnav .desk-ai-nav { width: 22px; height: 22px; }
  .mnav .mn-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mnav .mn-n { position: absolute; top: -6px; left: 13px; background: var(--teal); color: #fff; font-size: 9.5px; font-weight: 700; line-height: 1; border-radius: 999px; min-width: 16px; height: 16px; padding: 0 4px; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--navy); }
  .list-pane { height: 100dvh; }
  .pane-head { padding-top: 10px; }
  .list-pane .chips { overflow-x: auto; scrollbar-width: none; }
  .convo-head { padding: calc(8px + env(safe-area-inset-top)) 10px 8px; gap: 6px; }
  .convo-head .h-name { font-size: 15px; }
  .convo-head .h-sub { font-size: 11.5px; }
  .h-actions { gap: 4px; flex-wrap: nowrap; }
  .h-actions .btn { padding: 4px 8px; font-size: 12px; }
  .h-actions [data-action="mark-replied"] { display: none; }
  .convo-body { padding: 10px 8px; }
  .bubble { max-width: 86vw; }
  img.photo { max-width: min(240px, 70vw); }
  .email-message { padding: 10px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .composer-bar .send-hint { display: none; }
  .cs-cell { padding: 3px 8px; }
  .kb-app .app, .app.kb-app { grid-template-columns: 1fr !important; }
  .kb-main { grid-column: 1; padding: 0 0 40px; }
  .kb-main > *:not(.mnav) { margin-left: 14px; margin-right: 14px; }
  .kb-main .mnav { margin: 0 0 12px; }
  .kb-row { grid-template-columns: 40px 1fr; }
  .kb-row .kb-status, .kb-row .kb-who { grid-column: 2; text-align: left; }
  .kb-head { flex-direction: column; }
}

/* ================= Email thread, Gmail style ================= */
.email-thread.gm { max-width: 860px; margin: 0 auto; padding: 4px 2px 12px; }
.gm-subject { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; padding: 6px 4px 14px; }
.gm-subject h2 { margin: 0; font-size: 19px; font-weight: 600; color: var(--navy); line-height: 1.3; overflow-wrap: anywhere; }
.gm-count { font-size: 12px; color: var(--faint); }
.gm-label { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 4px; background: var(--navy-softer); color: var(--muted); }
.gm-label.in { background: var(--teal-soft); color: var(--teal-dark); }

.gm-msg { background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(27, 42, 74, .04); overflow: hidden; }
.gm-msg.ours { background: #F2F8F8; border-color: #CFE5E5; border-left: 4px solid var(--teal); }
.gm-head { list-style: none; display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: start; padding: 12px 16px; cursor: pointer; }
.gm-head::-webkit-details-marker { display: none; }
.gm-head:hover { background: rgba(27, 42, 74, .025); }
.gm-avatar { width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; }
.gm-avatar.ours { background: var(--teal); color: #fff; }
.gm-who { min-width: 0; display: flex; flex-direction: column; }
.gm-name { font-weight: 650; color: var(--navy); font-size: 14px; overflow-wrap: anywhere; }
.gm-badge { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 600; color: var(--teal-dark); background: var(--teal-soft); padding: 1px 7px; border-radius: 999px; vertical-align: 1px; }
.gm-addr { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-preview { display: none; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.gm-msg:not([open]) .gm-preview { display: block; }
.gm-msg:not([open]) .gm-addr { display: none; }
.gm-date { font-size: 12px; color: var(--muted); white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.gm-body { padding: 0 18px 16px 66px; }
.gm-body > .btext { font-size: 14px; line-height: 1.65; color: #222; overflow-wrap: anywhere; }
.gm-quote { margin-top: 10px; }
.gm-quote > summary { list-style: none; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 16px; border-radius: 8px; background: var(--navy-softer); color: var(--muted); font-size: 12px; line-height: 1; cursor: pointer; letter-spacing: 1px; }
.gm-quote > summary::-webkit-details-marker { display: none; }
.gm-quote > .btext { margin-top: 8px; padding-left: 12px; border-left: 3px solid var(--line-strong); color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

.em-atts { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.em-atts-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.em-atts-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.em-att { width: 168px; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: #fff; }
.em-att-prev { display: flex; align-items: center; justify-content: center; height: 104px; background: var(--navy-softer); overflow: hidden; text-decoration: none; }
.em-att-prev img { width: 100%; height: 100%; object-fit: cover; }
.em-att-prev.doc span { font-weight: 800; font-size: 13px; color: #fff; background: var(--navy); padding: 8px 10px; border-radius: 6px; }
.em-att-prev.doc span.pdf { background: var(--red); }
.em-att-name { font-size: 12px; font-weight: 600; padding: 6px 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.em-att-actions { display: flex; gap: 10px; padding: 3px 8px 7px; font-size: 12px; align-items: center; }
.em-att-actions a { color: var(--teal); font-weight: 600; text-decoration: none; }
.em-att-actions span { margin-left: auto; color: var(--faint); font-size: 11px; }

/* ================= Layout switches ================= */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: var(--navy-softer); color: var(--navy); border-color: var(--line); }
.icon-btn .ico { width: 18px; height: 18px; }
.convo-head .h-main { min-width: 0; flex: 1; }
.convo-head .h-name, .convo-head .h-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Hide the conversation list: the conversation takes its width. */
.app.list-hidden { grid-template-columns: 232px 1fr; }
.app.list-hidden .list-pane { display: none; }

/* Draft and reply below the conversation, at full width (same as the tablet layout). */
.app.dock-bottom .convo-wrap { flex-direction: column; }
.app.dock-bottom .convo-wrap .conversation { flex: 1 1 auto; height: auto; min-height: 0; }
.app.dock-bottom .split-v, .app.dock-bottom .split-h { display: none; }
.app.dock-bottom .draft-panel { width: auto !important; height: auto; flex: 0 0 auto; border-top: 1px solid var(--line-strong); box-shadow: 0 -4px 14px rgba(27, 42, 74, .06); }
.app.dock-bottom .dp-scroll { display: none; max-height: 45dvh; }
.app.dock-bottom .draft-panel.open .dp-scroll { display: block; }
.app.dock-bottom .dp-head { padding: 10px 16px; margin: 0; cursor: pointer; background: var(--sky-soft); color: var(--navy); }
.app.dock-bottom .draft-panel.open .dp-head { background: none; }
.app.dock-bottom .dp-chev { display: inline; }
.app.dock-bottom .reply-row textarea { height: auto; min-height: 56px; }
.app.dock-bottom .composer { max-width: none; }

@media (max-width: 1279px) {
  .app.list-hidden { grid-template-columns: 72px 1fr; }
}
@media (max-width: 1099px) {
  .layout-btn[data-action="toggle-dock"] { display: none; }
}
@media (max-width: 859px) {
  .layout-btn { display: none; }
  .gm-head { grid-template-columns: 32px 1fr; padding: 10px 12px; }
  .gm-avatar { width: 32px; height: 32px; font-size: 13px; }
  .gm-date { grid-column: 2; font-size: 11px; }
  .gm-body { padding: 0 12px 12px 12px; }
  .em-att { width: calc(50% - 5px); }
}

/* The reply box: the one place a message leaves the clinic. A soft ocean blue
   (blue with green in it, not bright) sets it apart from the AI draft above it. */
:root { --ocean: #2F7F8F; --ocean-soft: #E6F2F4; --ocean-line: #9CCBD4; }
.reply-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ocean); margin-bottom: 5px; }
.rl-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ocean); }
.rl-hint { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--muted); font-size: 11.5px; }
.reply-row textarea { background: var(--ocean-soft); border: 1.5px solid var(--ocean-line); color: #1d3a40; }
.reply-row textarea::placeholder { color: #6E9AA3; }
.reply-row textarea:focus { background: #F1F8FA; border-color: var(--ocean); outline: 3px solid rgba(47, 127, 143, .18); outline-offset: 0; }
.reply-row textarea:disabled { background: var(--navy-softer); border-color: var(--line); }
#send.btn.primary { background: var(--ocean); border-color: var(--ocean); }
#send.btn.primary:hover { background: #276C79; }
@media (max-width: 859px) { .rl-hint { display: none; } }

/* The reply area, inverted: a deep ocean panel against the white workspace, so
   attention goes to where messages are written and sent. Everything inside
   (label, box, Attach, tray, errors, Send) is styled for the dark background. */
:root { --ocean-deep: #1D4E59; --ocean-deeper: #163F48; --ocean-glow: #7FD1DE; }
.convo-wrap .composer {
  background: linear-gradient(180deg, var(--ocean-deep), var(--ocean-deeper));
  color: #E8F4F6;
  border-top: 0;
  box-shadow: 0 -6px 18px rgba(22, 63, 72, .18);
}
.convo-wrap .draft-panel .composer { border-radius: 14px 14px 0 0; background: linear-gradient(180deg, var(--ocean-deep), var(--ocean-deeper)); }
.composer .reply-label { color: #fff; }
.composer .rl-dot { background: var(--ocean-glow); box-shadow: 0 0 0 3px rgba(127, 209, 222, .25); }
.composer .rl-hint, .composer .send-hint { color: rgba(232, 244, 246, .7); }
.composer .reply-row textarea {
  background: #F4FAFB; border: 1.5px solid transparent; color: #12343B;
}
.composer .reply-row textarea::placeholder { color: #6B8F96; }
.composer .reply-row textarea:focus { background: #fff; border-color: var(--ocean-glow); outline: 3px solid rgba(127, 209, 222, .35); outline-offset: 0; }
.composer .reply-row textarea:disabled { background: rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .6); }
.composer .reply-row textarea:disabled::placeholder { color: rgba(255, 255, 255, .6); }
.composer .attach-btn { background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .35); color: #fff; }
.composer .attach-btn:hover { background: rgba(255, 255, 255, .16); border-color: #fff; }
.composer #send.btn.primary { background: #fff; border-color: #fff; color: var(--ocean-deeper); font-weight: 700; }
.composer #send.btn.primary:hover { background: var(--ocean-glow); border-color: var(--ocean-glow); }
.composer #send.btn.primary:disabled { background: rgba(255, 255, 255, .25); border-color: transparent; color: rgba(255, 255, 255, .7); }
.composer .send-error { background: #FDECEC; color: #8A1C1C; border: 0; }
.composer .att { background: rgba(255, 255, 255, .95); border-color: transparent; }
.composer.drop { outline-color: var(--ocean-glow); background: var(--ocean-deeper); }
.draft-panel .split-h { background: transparent; }
.draft-panel .split-h::after { background: var(--line-strong); }

/* ================= Ask Desk ================= */
.rail .icon.ask, .ask-spark { color: #F2D27A; }
.rail .icon.ask { background: rgba(197, 160, 48, .18); font-size: 17px; }
.ask-ico { font-size: 18px; line-height: 20px; color: #F2D27A; }
.ask-app .ask-main { grid-column: 2 / span 2; height: 100vh; height: 100dvh; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.ask-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 900px; margin: 0 auto; padding: 18px 20px 14px; }
.ask-head h1 { margin: 0; font-size: 21px; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.ask-head p { margin: 4px 0 10px; font-size: 13px; }
.ask-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 2px 12px; }
.ask-empty { display: flex; align-items: center; justify-content: center; min-height: 100%; }
.ask-examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 640px; }
.ask-example { border: 1px solid var(--line-strong); background: #fff; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; color: var(--navy); cursor: pointer; }
.ask-example:hover { border-color: var(--teal); color: var(--teal-dark); }
.ask-msg { display: flex; flex-direction: column; margin-bottom: 14px; }
.ask-msg.me { align-items: flex-end; }
.ask-msg.ai { align-items: flex-start; }
.ask-bubble { max-width: min(720px, 92%); padding: 10px 14px; border-radius: 14px; line-height: 1.6; font-size: 14px; overflow-wrap: anywhere; }
.ask-msg.me .ask-bubble { background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.ask-msg.ai .ask-bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; color: var(--text); }
.ask-msg.error .ask-bubble { background: var(--red-soft); border-color: transparent; color: #8A1C1C; }
.ask-meta { font-size: 11px; color: var(--faint); margin-top: 4px; padding: 0 4px; }
.ask-ref { color: var(--teal-dark); font-weight: 600; text-decoration: none; background: var(--teal-soft); padding: 1px 7px; border-radius: 6px; white-space: nowrap; }
.ask-ref:hover { background: var(--teal); color: #fff; }
.ask-img { display: inline-block; margin: 6px 6px 2px 0; vertical-align: top; }
.ask-img img { width: 150px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.ask-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-radius: 14px; background: linear-gradient(180deg, var(--ocean-deep, #1D4E59), var(--ocean-deeper, #163F48)); margin-bottom: env(safe-area-inset-bottom); }
.ask-form textarea { flex: 1; resize: none; border: 0; border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 14px; line-height: 1.5; background: #F4FAFB; color: #12343B; max-height: 160px; }
.ask-form textarea:focus { outline: 2px solid #7FD1DE; }
.ask-form .btn.primary { background: #fff; border-color: #fff; color: #163F48; font-weight: 700; }
@media (max-width: 1279px) { .ask-app .ask-main { grid-column: 2; } }
@media (max-width: 859px) {
  .ask-app .ask-main { grid-column: 1; }
  .ask-wrap { padding: 12px 12px 10px; }
  .ask-head p { display: none; }
  .ask-form textarea { font-size: 16px; }
}

/* Change cards (Ask Desk proposing Knowledge / clinic-fact updates) */
.change-card { margin-top: 10px; border: 1px solid var(--gold); background: #FFFCF3; border-radius: 12px; padding: 12px 14px; }
.change-card.cc-applied { border-color: var(--teal); background: var(--teal-softer); }
.change-card.cc-cancelled, .change-card.cc-reverted { border-color: var(--line-strong); background: var(--navy-softer); }
.cc-head { font-weight: 700; color: var(--navy); margin-bottom: 8px; }
.cc-row { border-top: 1px dashed var(--line-strong); padding: 8px 0; }
.cc-label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px; }
.cc-before, .cc-after { font-size: 13px; line-height: 1.55; padding: 6px 9px; border-radius: 7px; margin-bottom: 4px; white-space: normal; overflow-wrap: anywhere; }
.cc-before { background: #FDF1F1; color: #5a2a2a; }
.cc-after { background: #EEF8EF; color: #1f4d26; }
.cc-tag { display: inline-block; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin-right: 7px; opacity: .7; }
.cc-before del { background: #F6C9C9; text-decoration: line-through; }
.cc-after ins { background: #BFE5C5; text-decoration: none; font-weight: 600; }
.cc-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.cc-note { font-size: 11.5px; color: var(--muted); }
.cc-done { margin-top: 8px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cc-done.error, .cc-error { color: var(--red); font-size: 13px; }

/* Knowledge > History */
.hist { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 8px; max-width: 900px; }
.hist > summary { list-style: none; cursor: pointer; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.hist > summary::-webkit-details-marker { display: none; }
.hist-status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--navy-softer); color: var(--muted); }
.hist-status.st-applied { background: var(--teal-soft); color: var(--teal-dark); }
.hist-status.st-pending { background: var(--gold-soft); color: #7a5f12; }
.hist-sum { font-weight: 650; color: var(--navy); }
.hist > summary .faint { flex-basis: 100%; font-size: 12px; }
.hist-change { padding: 8px 14px; border-top: 1px dashed var(--line); }
.hist-label { font-size: 11.5px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.hist-before, .hist-after { white-space: pre-wrap; font-size: 12.5px; padding: 6px 9px; border-radius: 6px; margin-bottom: 4px; }
.hist-before { background: #FDF1F1; text-decoration: line-through; color: #7a3a3a; }
.hist-after { background: #EEF8EF; }
.hist-undo { padding: 6px 14px 12px; }
.cc-more > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--teal-dark); padding: 8px 0; border-top: 1px dashed var(--line-strong); }

/* Audit log (admins only) */
.audit .audit-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 4px 0 14px; max-width: 1000px; }
.audit-stats > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; }
.audit-stats b { font-size: 20px; color: var(--navy); }
.audit-stats span { font-size: 11.5px; color: var(--muted); }
.audit-stats .warn { border-color: var(--gold); background: #FFFCF3; }
.audit-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.audit-filter select, .audit-filter input { font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; }
.audit-table { width: 100%; max-width: 1200px; border-collapse: collapse; background: var(--panel); font-size: 12.5px; }
.audit-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line-strong); }
.audit-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.audit-table tr.warn td { background: #FFF6E5; }
.audit-table pre { white-space: pre-wrap; font-size: 11.5px; margin: 6px 0 0; max-width: 520px; }
.audit-table .nowrap { white-space: nowrap; }
.audit-tools { display: flex; flex-direction: column; gap: 3px; }
.audit-tools code { font-size: 11.5px; background: var(--navy-softer); padding: 3px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.hist-status.st-failed { background: var(--red-soft); color: var(--red); }
.audit-staff { margin-top: 18px; max-width: 900px; }
.audit-staff summary { cursor: pointer; font-weight: 600; color: var(--navy); margin-bottom: 8px; }
.ask-form { flex-direction: column; align-items: stretch; }
.ask-row { display: flex; gap: 8px; align-items: flex-end; }
.ask-attach { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .35); color: #fff; cursor: pointer; flex-shrink: 0; font-size: 17px; }
.ask-attach:hover { background: rgba(255, 255, 255, .12); }
.ask-tray { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ask-tray .att { background: rgba(255, 255, 255, .95); border-color: transparent; }
.ask-form.drop { outline: 2px dashed #7FD1DE; outline-offset: 3px; }
.ask-sent { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.ask-sent-img { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .4); }
.ask-sent-doc { font-size: 12px; background: rgba(255, 255, 255, .15); padding: 3px 8px; border-radius: 6px; }

/* Ask Desk: saved chats */
.ask-layout { flex: 1; min-height: 0; display: flex; }
.ask-side { width: 260px; flex-shrink: 0; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; padding: 14px 10px; min-height: 0; }
.ask-new { justify-content: center; margin-bottom: 12px; text-decoration: none; }
.ask-side-label { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 0 6px 6px; }
.ask-threads { flex: 1; overflow-y: auto; }
.ask-side-empty { font-size: 12.5px; padding: 6px; }
.ask-thread-row { display: flex; align-items: center; border-radius: 8px; }
.ask-thread-row a { flex: 1; min-width: 0; text-decoration: none; color: var(--text); padding: 7px 8px; display: flex; flex-direction: column; }
.ask-thread-row:hover { background: var(--navy-softer); }
.ask-thread-row.on { background: var(--teal-soft); }
.at-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--navy); }
.at-meta { font-size: 11px; color: var(--faint); }
.at-hide { border: 0; background: none; color: var(--faint); font-size: 16px; cursor: pointer; padding: 4px 8px; visibility: hidden; }
.ask-thread-row:hover .at-hide, .ask-thread-row.on .at-hide { visibility: visible; }
.ask-side-toggle { display: none; margin-bottom: 6px; }
.ask-layout .ask-wrap { max-width: 900px; }
a.ask-sent-doc { color: inherit; text-decoration: none; }
@media (max-width: 1279px) { .ask-side { width: 220px; } }
@media (max-width: 859px) {
  .ask-side { display: none; position: fixed; inset: 0 30% 0 0; z-index: 20; box-shadow: 8px 0 24px rgba(0, 0, 0, .18); }
  .ask-layout.side-open .ask-side { display: flex; }
  .ask-side-toggle { display: inline-flex; }
  .at-hide { visibility: visible; }
}
.loc-suggest { margin-top: 8px; background: #EAF6EE; border-color: #9BCFAA; color: #1f5a2e; }

/* Clinic facts: grouped slots */
.facts-form { max-width: 860px; }
.fact-group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 4px; margin-bottom: 14px; }
.fact-group h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fact-row label { text-transform: capitalize; }
.fact-open { font-size: 11.5px; color: var(--teal); text-transform: none; margin-left: 6px; text-decoration: none; }
.fact-input { display: flex; gap: 8px; align-items: flex-start; }
.fact-input input, .fact-input textarea { flex: 1; }
.fact-remove { color: var(--faint); visibility: hidden; flex-shrink: 0; }
.fact-row:hover .fact-remove, .fact-row:focus-within .fact-remove { visibility: visible; }
.fact-new { background: var(--navy-softer); border-style: dashed; }
@media (pointer: coarse) { .fact-remove { visibility: visible; } }

/* Shared Desk assistant identity. */
.desk-ai-avatar { width: 32px; height: 32px; object-fit: cover; border-radius: 50%; flex-shrink: 0; }
.rail .icon.ask { background: transparent; }
.desk-ai-nav { width: 24px; height: 24px; }
.desk-ai-heading { width: 44px; height: 44px; }
.ask-empty { flex-direction: column; gap: 22px; }
.desk-ai-welcome { width: 112px; height: 112px; }
.ask-author { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--navy); }
.ask-author .desk-ai-avatar { width: 28px; height: 28px; }

/* Phone top bar: account menu */
.mn-menu { position: relative; flex: 0 0 auto; margin-left: 4px; }
.mn-menu summary { list-style: none; cursor: pointer; padding: 4px; border-radius: 999px; }
.mn-menu summary::-webkit-details-marker { display: none; }
.mn-me { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 999px; background: rgba(255, 255, 255, .14); color: #fff; font-size: 13px; font-weight: 700; }
.mn-menu[open] .mn-me { background: #fff; color: var(--navy); }
.mn-sheet { position: absolute; right: 0; top: calc(100% + 8px); width: 220px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-md), 0 0 0 1px rgba(16, 32, 64, .06); padding: 6px; display: flex; flex-direction: column; }
.mn-sheet form { margin: 0; }
.mn-who { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line, #E6EAF0); margin-bottom: 4px; }
.mn-who b { font-size: 14px; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mn-who span { font-size: 12px; color: #6B7A90; }
.mn-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; border-radius: 9px; background: none; font: inherit; font-size: 14px; color: var(--navy); text-decoration: none; text-align: left; cursor: pointer; }
.mn-item:hover, .mn-item:active { background: #F1F4F8; }
.mn-item .ico { width: 18px; height: 18px; color: #6B7A90; }
.mn-item.off { color: #6B7A90; }
.mn-out { color: #B4232A; }
.mn-out .ico { color: #B4232A; }
.mn-item.spinning .ico { animation: desk-spin .6s linear infinite; }
.unlock-bar { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50; background: var(--navy); color: #fff; border: 0; border-radius: 999px; padding: 10px 16px; font: inherit; font-size: 13px; box-shadow: var(--shadow-md); cursor: pointer; }

/* ================= Sidebar footer: actions row + user card ================= */
.rail .foot { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.foot-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bell-btn, .refresh-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 0;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12); color: #fff;
  border-radius: 9px; padding: 7px 8px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.bell-btn:hover, .refresh-btn:hover { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .25); }
.bell-btn.off { color: rgba(255, 255, 255, .5); }
.rf-ico { display: inline-block; font-size: 14px; line-height: 1; }
.spinning .rf-ico { animation: desk-spin .6s linear infinite; }
@keyframes desk-spin { to { transform: rotate(360deg); } }
.user-card { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; background: rgba(255, 255, 255, .04); }
.uc-avatar { width: 34px; height: 34px; font-size: 14px; text-decoration: none; }
.uc-text { min-width: 0; }
.uc-text .who { font-size: 13px; font-weight: 650; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uc-text .role { font-size: 11.5px; color: #9FB0CE; }
.uc-text .audit-link { color: #9FB0CE; text-decoration: none; }
.uc-text .audit-link:hover, .uc-text .audit-link.on { color: #fff; text-decoration: underline; }
.uc-out { margin: 0; }
.signout-ico { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; border: 0; background: none; color: #9FB0CE; cursor: pointer; }
.signout-ico:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.signout-ico .ico { width: 17px; height: 17px; }

/* Icon rail (small laptops, tablets): everything stacks as icons */
@media (max-width: 1279px) {
  .foot-actions { grid-template-columns: 1fr; }
  .bell-btn .bell-label, .refresh-btn .rf-label, .uc-text { display: none; }
  .bell-btn, .refresh-btn { padding: 8px 0; }
  .user-card { grid-template-columns: 1fr; justify-items: center; gap: 6px; padding: 6px 0; background: none; }
}
.uc-text .role { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Translate a patient message (English or Thai), then switch back to the original. */
.tr-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 5px; font-size: 11.5px; }
.tr-btn { border: 0; background: none; padding: 2px 0; font: inherit; font-weight: 600; color: var(--teal); cursor: pointer; }
.tr-btn:hover { text-decoration: underline; }
.tr-note { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.tr-note .spinner { width: 11px; height: 11px; border-width: 2px; }
.btext.translated { border-left: 3px solid var(--teal); padding-left: 8px; }
@media (pointer: coarse) { .tr-btn { padding: 6px 0; } }

/* Files: every file in the conversation, as a side drawer (bottom sheet on phones). */
.files-btn { display: inline-flex; align-items: center; gap: 5px; }
.files-btn .ico { width: 15px; height: 15px; }
.files-sheet { position: fixed; inset: 0; z-index: 40; display: none; }
.files-sheet.open { display: block; }
.fs-backdrop { position: absolute; inset: 0; background: rgba(15, 25, 45, .35); }
.fs-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--panel, #fff); display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0, 0, 0, .15); }
.fs-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--navy); }
.fs-body { overflow-y: auto; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
.fs-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 8px; }
.fs-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.fs-photo { display: flex; flex-direction: column; gap: 3px; }
.fs-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.fs-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.fs-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.fs-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--navy); }
.fs-name span { font-size: 11.5px; color: var(--muted); }
.fs-save, .fs-open { color: var(--teal); font-weight: 600; font-size: 13px; text-decoration: none; padding: 4px 0; }
.fs-photo .fs-save { font-size: 12px; text-align: center; }
.fs-empty { padding: 20px 0; }
.desk-toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.desk-toast[hidden] { display: none; }
@media (max-width: 859px) {
  .files-btn .files-label { display: none; }
  .fs-panel { top: auto; left: 0; width: 100%; max-height: 82dvh; border-radius: 16px 16px 0 0; }
  .fs-save, .fs-open { padding: 8px 0; }
}

/* WhatsApp templates: shown in the reply area once the 24-hour window has closed. */
.composer [hidden] { display: none !important; }
.tpl-loading, .tpl-done { font-size: 13px; color: rgba(232, 244, 246, .8); margin: 4px 0 2px; }
.tpl-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tpl-chip, .tpl-lang { border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .08); color: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 12.5px; cursor: pointer; }
.tpl-chip.on, .tpl-lang.on { background: #fff; color: var(--ocean-deeper); border-color: #fff; font-weight: 700; }
.tpl-langs { display: flex; gap: 6px; margin-bottom: 8px; }
.tpl-fields { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.tpl-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600; color: rgba(232, 244, 246, .8); flex: 1 1 140px; }
.tpl-fields input { border: 0; border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 14px; background: #F4FAFB; color: #12343B; }
.tpl-fields input:focus { outline: 3px solid rgba(127, 209, 222, .45); }
.tpl-preview { background: #F4FAFB; color: #12343B; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; line-height: 1.5; margin-bottom: 8px; max-height: 30dvh; overflow-y: auto; }
.tpl-blank { background: #FFF3C4; color: #7A5A00; border-radius: 4px; padding: 0 4px; }
.tpl-qr { margin-top: 6px; text-align: center; color: var(--teal-dark, #1F6F6F); font-weight: 600; border-top: 1px solid var(--line, #E3E7EE); padding-top: 6px; font-size: 13px; }
.tpl-bar { display: flex; align-items: center; gap: 10px; }
.tpl-status { flex: 1; font-size: 12px; color: rgba(232, 244, 246, .8); }
.composer #tpl-send { background: #fff; border-color: #fff; color: var(--ocean-deeper); font-weight: 700; }
.composer #tpl-send:disabled { background: rgba(255, 255, 255, .25); border-color: transparent; color: rgba(255, 255, 255, .7); }
.tpl-panel .failed-banner { margin-top: 8px; background: #FDECEC; color: #8A1C1C; border: 0; }
.window.soon { background: #FFF4E0; border-color: #F0C36D; color: #7A4B00; }
.window.soon .pill { background: #E39A1B; }
@media (pointer: coarse) { .tpl-fields input { font-size: 16px; } .tpl-chip, .tpl-lang { padding: 8px 14px; } }

/* New email (compose) */
.compose-btn { margin-left: auto; text-decoration: none; }
.list-pane .pane-title { display: flex; align-items: center; gap: 8px; }
.compose { display: flex; flex-direction: column; gap: 12px; padding: 18px 22px 24px; overflow-y: auto; max-width: 860px; width: 100%; }
.compose label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.compose label .faint { text-transform: none; letter-spacing: 0; font-weight: 500; }
.compose input, .compose textarea { font: inherit; font-size: 14px; color: var(--ink, #1d2a3a); text-transform: none; letter-spacing: 0; font-weight: 400; border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 11px; background: #fff; }
.compose textarea { resize: vertical; min-height: 220px; line-height: 1.55; }
.compose input:focus, .compose textarea:focus { outline: 3px solid rgba(47, 127, 143, .18); border-color: var(--ocean, #2F7F8F); }
.compose-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.compose-bar .spacer { flex: 1; }
.compose .failed-banner { background: #FDECEC; color: #8A1C1C; border: 0; }
@media (pointer: coarse) { .compose input, .compose textarea { font-size: 16px; } }
@media (max-width: 859px) { .compose { padding: 12px 12px 20px; } }
.compose .compose-bar .attach-btn { flex-direction: row; text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 600; color: var(--navy); }
.compose-ai { background: var(--sky-soft, #EEF5FA); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.compose .compose-ai > label { color: var(--navy); }
.compose-ai textarea { min-height: 70px; }
.compose-ai-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.compose-ai-bar select { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 7px; background: #fff; }
.compose-ai-bar .spacer { flex: 1; }
.compose-ai-out { font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.cai-warn { background: #FFF4E0; color: #7A4B00; border-radius: 7px; padding: 6px 9px; font-weight: 600; }
.cai-note { color: var(--muted); }
.cai-src a { color: var(--teal-dark, #1F6F6F); }
@media (pointer: coarse) { .compose-ai-bar select { font-size: 16px; } }

/* Delivery failures: impossible to miss */
.delivery-failed { margin: 8px auto 4px; max-width: 640px; background: #FDECEC; color: #8A1C1C; border: 1px solid #F3B7B7; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.failed-alerts { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; left: auto; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 24px)); }
.failed-alert { background: #fff; border: 2px solid #D93636; border-radius: 12px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #5a1a1a; }
.failed-alert b { color: #B42020; }
.failed-alert div { display: flex; gap: 14px; align-items: center; margin-top: 4px; }
.failed-alert a { color: var(--teal-dark, #1F6F6F); font-weight: 700; }
.failed-alert button { border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; padding: 4px 0; }

/* Patient number under the name in the list: quiet, aligned digits, easy to compare with WhatsApp */
.row .r-num { font-size: 12px; line-height: 1.35; color: var(--muted); margin: 1px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-num-user { font-style: italic; letter-spacing: 0; }
.row.active .r-num { color: inherit; opacity: .8; }
.convo-head .num { font-variant-numeric: tabular-nums; letter-spacing: .02em; }

/* ---------- Hotline pilot ---------- */
.hl-main { overflow-y: auto; }
.hl-panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 16px; max-width: 900px; }
.hl-panel h2 { font-size: 15px; color: var(--navy); margin: 0 0 8px; }
.hl-pill { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--sky-soft); color: var(--sky); border-radius: 999px; padding: 2px 9px; vertical-align: middle; }
.hl-call { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hl-engines { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 0 0 14px; font-size: 13px; }
.hl-pill.hl-engine { background: var(--line); color: var(--muted); text-transform: none; letter-spacing: 0; }
.hl-btn { display: inline-flex; align-items: center; gap: 10px; border: 0; border-radius: 999px; padding: 14px 28px; font-size: 16px; font-weight: 650; color: #fff; background: var(--teal); cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.hl-btn:hover { background: var(--teal-dark); }
.hl-btn:disabled { opacity: .6; cursor: default; }
.hl-btn.on { background: var(--red); animation: hl-pulse 2s infinite; }
@keyframes hl-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(200,60,60,.35); } 50% { box-shadow: 0 0 0 10px rgba(200,60,60,0); } }
.hl-btn-ico { font-size: 18px; }
.hl-status { font-size: 13px; color: var(--muted); text-align: center; }
.hl-booking { font-size: 13px; background: var(--sky-soft); color: var(--navy); border-radius: var(--radius-sm); padding: 8px 12px; }
.hl-transcript { width: 100%; max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.hl-transcript.static { max-height: none; }
.hl-line { font-size: 14px; line-height: 1.45; padding: 7px 11px; border-radius: 10px; max-width: 85%; background: var(--navy-softer); align-self: flex-start; }
.hl-line.caller { align-self: flex-end; background: var(--sky-soft); }
.hl-who { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.hl-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hl-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.hl-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.hl-table tr.off td { color: var(--muted); }
.hl-tag { font-size: 11.5px; background: var(--sky-soft); color: var(--navy); border-radius: 4px; padding: 1px 7px; }
.hl-tag.warn { background: #FDECEC; color: var(--red); }
.hl-linkform { display: flex; gap: 8px; margin: 10px 0; }
.hl-linkform input { flex: 1; max-width: 320px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; }
.hl-newlink { background: #F1FAF4; border: 1px solid #BFE3CB; border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin: 8px 0; }
.hl-newlink input { width: 100%; margin-top: 6px; padding: 6px 8px; font: inherit; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.hl-dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; font-size: 13.5px; margin: 0; }
.hl-dl dt { color: var(--muted); }
.hl-dl dd { margin: 0; }
.hl-handoff { border-color: #F2B8B8; background: #FFF7F7; }
.hl-err { color: var(--red); }
.hl-tools { font-size: 12.5px; padding-left: 18px; margin: 0; word-break: break-word; }
.hl-note { font-size: 12px; }
.hl-body { background: var(--sky-soft); min-height: 100vh; margin: 0; }
.hl-public { max-width: 560px; margin: 0 auto; padding: 32px 16px 48px; text-align: center; }
.hl-public h1 { color: var(--navy); font-size: 24px; margin: 12px 0 8px; }
.hl-public .hl-call { background: #fff; border-radius: 16px; padding: 22px 16px; margin-top: 18px; box-shadow: 0 6px 24px rgba(27,42,74,.08); }
.hl-public .hl-line { text-align: left; }
.hl-logo { height: 56px; }
.hl-foot { margin-top: 20px; font-size: 12px; }
.hl-booking.warn { background: #FDECEC; color: var(--red); }

/* Saved call history */
.hl-tabs { display: flex; gap: 6px; margin: 0 0 20px; border-bottom: 1px solid var(--line); max-width: 900px; }
.hl-tabs a { padding: 11px 15px; text-decoration: none; color: var(--muted); font-weight: 650; border-bottom: 3px solid transparent; }
.hl-tabs a[aria-current] { color: var(--teal-dark); border-bottom-color: var(--teal); }
.hl-history-intro, .hl-section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.hl-history-intro p { margin: 0; font-size: 13px; }
.hl-history-intro .btn { flex-shrink: 0; }
.hl-section-head { margin-bottom: 12px; font-size: 13px; }
.hl-section-head p, .hl-section-head h2 { margin: 0; }
.hl-search { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding-bottom: 20px; }
.hl-search label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 650; color: var(--muted); }
.hl-search-query { flex: 1 1 300px; }
.hl-search input, .hl-search select { min-height: 40px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; padding: 8px 10px; font: inherit; font-size: 13px; color: var(--ink); }
.hl-search input { width: 100%; min-width: 0; }
.hl-search .btn { min-height: 40px; }
.hl-cards { display: flex; flex-direction: column; gap: 12px; }
.hl-card { border: 1px solid var(--line); border-radius: 10px; padding: 16px; overflow-wrap: anywhere; }
.hl-card:hover { border-color: var(--teal); }
.hl-card-top { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.hl-ref { font-size: 16px; font-weight: 750; color: var(--teal-dark); }
.hl-card-name { margin-top: 10px; font-size: 14px; font-weight: 650; }
.hl-card-name .muted { font-weight: 400; }
.hl-card-purpose { font-size: 14px; line-height: 1.55; margin: 7px 0 12px; }
.hl-card-bottom { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.hl-card-bottom a { font-weight: 650; }
.hl-card .hl-note { margin-top: 7px; }
.hl-pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 20px; font-size: 13px; }
.hl-empty { padding: 32px 12px; text-align: center; color: var(--muted); }
.hl-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; margin: 18px 0; }
.hl-summary > div:nth-child(n+4) { grid-column: 1 / -1; }
.hl-summary dt { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.hl-summary dd { margin: 0; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.hl-sources { display: inline-flex; gap: 5px; margin-left: 8px; font-size: 12px; }
.hl-line:target { outline: 2px solid var(--teal); outline-offset: 3px; }
.hl-line { overflow-wrap: anywhere; scroll-margin-top: 20px; }
.hl-review-link:not([hidden]) { display: block; text-align: center; margin-top: 16px; font-weight: 650; }
@media (max-width: 600px) {
  .hl-history-intro { align-items: start; flex-direction: column; }
  .hl-panel { padding: 14px; }
  .hl-card { padding: 12px; }
  .hl-search-query { flex-basis: 100%; }
  .hl-search label:not(.hl-search-query) { flex: 1; min-width: 120px; }
  .hl-summary { grid-template-columns: 1fr; }
  .hl-summary > div { grid-column: 1 !important; }
  .hl-line { max-width: 95%; }
  .hl-section-head { align-items: start; flex-wrap: wrap; }
}
