@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fa;
  --chat-bg: #ebf2f1;
  --border: #e1e8ec;
  --border-strong: #cdd7dd;
  --text: #0f1f24;
  --text-secondary: #485c63;
  --muted: #687c84;
  --primary: #0d6e66;
  --primary-hover: #095750;
  --primary-soft: #e6f4f2;
  --primary-border: #bce3dd;
  --danger: #c81e1e;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --shadow-sm: 0 1px 2px rgba(15, 31, 36, 0.05);
  --shadow: 0 2px 10px rgba(15, 31, 36, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 31, 36, 0.16);
  --radius: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  line-height: 1.45;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.89rem;
}

/* Inline SVG Icon sizing */
.ic {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.ic-sm {
  width: 15px;
  height: 15px;
}

.ic-lg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Login */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #eef6f5 0%, #f5f7f9 60%, #edf2f5 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-brand-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.login-brand-img {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(13, 110, 102, 0.22);
}

.login-brand-pill {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.42rem;
  letter-spacing: -0.02em;
}

.login-form {
  margin-top: 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form label {
  font-weight: 600;
  font-size: 0.88rem;
}

/* Form controls */
input[type="text"],
input[type="password"],
input[type="tel"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 102, 0.12);
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field .search-ic {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}

.search-field input {
  padding-left: 38px;
  background: var(--surface-soft);
}

.search-field input:focus {
  background: var(--surface);
}

.info-box {
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  color: #0b4a44;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
}

.info-box.warn {
  margin-top: 10px;
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: #92400e;
}

.meta-health-card.health-red .info-box.warn {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.error-text {
  color: var(--danger);
  font-size: 0.87rem;
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, opacity 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(13, 110, 102, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: #eaeff2;
  color: var(--text);
}

.btn-danger-outline {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger-border);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-sm {
  padding: 7px 12px;
  min-height: 38px;
  font-size: 0.84rem;
}

.btn-lg {
  padding: 12px 18px;
  min-height: 46px;
  font-size: 0.95rem;
}

.btn-full {
  width: 100%;
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: #edf2f4;
  color: var(--text);
}

.icon-btn.is-active {
  color: var(--primary);
  background: var(--primary-soft);
}

.icon-btn.is-pinned {
  color: #d97706;
  background: #fef3c7;
}

.push-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16a34a;
  border: 2px solid var(--surface);
}

/* App Shell & Topbar */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  z-index: 15;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo-img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 0.76rem;
  color: var(--muted);
}

.topnav {
  display: flex;
  gap: 4px;
  background: var(--surface-soft);
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--border);
}

.nav-tab {
  background: transparent;
  border: none;
  padding: 7px 14px;
  min-height: 36px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.nav-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 1px 7px;
  border-radius: 999px;
  line-height: 1.4;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 11px;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: var(--warn-border);
}

.status-pill.neutral {
  background: #edf2f4;
  color: var(--muted);
}

.offline-banner {
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-border);
  color: #92400e;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Inbox Layout */
.tab-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inbox-toolbar {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.filter-pills-wrap {
  position: relative;
  min-width: 0;
  flex: 1;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-right: 18px;
}

.filter-pills::-webkit-scrollbar {
  display: none;
}

.pill-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 13px;
  min-height: 38px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pill-count {
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: #edf2f4;
  color: var(--muted);
}

.pill-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pill-btn.active .pill-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.pill-urgent.has-items:not(.active) {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.pill-urgent.has-items:not(.active) .pill-count {
  background: var(--danger);
  color: #fff;
}

.inbox-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  padding: 0 18px 18px;
  min-height: 0;
}

.conv-list-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-y: auto;
  max-height: calc(100dvh - 134px);
}

.conv-search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.conv-search-wrap .search-field {
  flex: 1;
  min-width: 0;
}

.inbox-refresh-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  flex-shrink: 0;
}

.inbox-refresh-btn.spinning svg {
  animation: spin360 0.7s linear infinite;
}

@keyframes spin360 {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.conv-list {
  display: flex;
  flex-direction: column;
}

.conv-item {
  padding: 13px 14px;
  border-bottom: 1px solid #f0f4f6;
  cursor: pointer;
  transition: background 0.12s;
  text-align: left;
  background: transparent;
  border-left: 3px solid transparent;
  border-right: none;
  border-top: none;
  width: 100%;
  font-family: inherit;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.conv-item:hover {
  background: var(--surface-soft);
}

.conv-item.active {
  background: var(--primary-soft);
  border-left-color: var(--primary);
}

.conv-item.is-urgent {
  border-left-color: var(--danger);
  background: #fffafa;
}

.conv-item.is-urgent.active {
  background: #fee2e2;
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.88rem;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.av-0 { background: #ccfbf1; color: #0f766e; }
.av-1 { background: #e0f2fe; color: #0369a1; }
.av-2 { background: #ede9fe; color: #6d28d9; }
.av-3 { background: #fef3c7; color: #b45309; }
.av-4 { background: #fce7f3; color: #be185d; }

.avatar-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--primary);
}

.avatar-dot.urgent {
  background: var(--danger);
}

.conv-item-body {
  flex: 1;
  min-width: 0;
}

.conv-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.conv-name {
  font-weight: 600;
  font-size: 0.94rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.conv-item.is-pending .conv-name {
  font-weight: 700;
}

.pin-star {
  color: #d97706;
  font-size: 0.82rem;
}

.conv-time {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.conv-preview {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  margin-bottom: 6px;
}

.conv-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #edf2f4;
  color: var(--text-secondary);
  white-space: nowrap;
}

.tag-pending { background: var(--warn-soft); color: var(--warn); }
.tag-replied { background: var(--ok-soft); color: var(--ok); }
.tag-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); }
.tag-primary { background: var(--primary-soft); color: var(--primary); }
.tag-clinical { background: #ede9fe; color: #5b21b6; }
.tag-neutral { background: #edf2f4; color: var(--muted); }
.tag-simulator { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.tag-sla-urgent { background: #dc2626; color: #ffffff; font-weight: 700; }
.tag-sla-warn { background: #ffedd5; color: #9a3412; border: 1px solid #fdba74; font-weight: 700; }

/* Conversation Detail */
.conv-detail-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 134px);
  overflow: hidden;
}

.empty-state {
  margin: auto;
  text-align: center;
  padding: 40px 24px;
  max-width: 380px;
}

.empty-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.conv-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.conv-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface);
  flex-shrink: 0;
}

.conv-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.conv-patient-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  padding: 4px 6px;
  border: none;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.conv-patient-trigger:hover {
  background: var(--surface-soft);
}

.conv-header-info {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.conv-header h2 {
  margin: 0 0 2px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.77rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow: hidden;
}

#detail-phone {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#detail-window-badge {
  flex-shrink: 0;
}

.conv-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.chat-offline-strip {
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-border);
  color: #92400e;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
}

.chat-note-strip {
  width: 100%;
  border: none;
  border-bottom: 1px solid #e5e0f8;
  background: #f6f4ff;
  color: #3b267d;
  padding: 7px 14px;
  text-align: left;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.chat-note-strip:hover {
  background: #eeebff;
}

/* Messages Stream */
.messages-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(rgba(13, 110, 102, 0.07) 1px, transparent 1px);
  background-size: 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.date-sep {
  align-self: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  margin: 6px 0;
  box-shadow: var(--shadow-sm);
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.msg-row.in {
  align-self: flex-start;
}

.msg-row.out {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.93rem;
  line-height: 1.44;
  box-shadow: 0 1px 2px rgba(15, 31, 36, 0.06);
}

.msg-row.in .msg-bubble {
  background: var(--surface);
  border: 1px solid rgba(15, 31, 36, 0.06);
  border-top-left-radius: 4px;
}

.msg-row.out .msg-bubble {
  background: #d8f3ee;
  border: 1px solid #b8e4dc;
  color: #0b3a35;
  border-top-right-radius: 4px;
}

.msg-time {
  margin-top: 3px;
  padding: 0 4px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.msg-media {
  margin-bottom: 6px;
}

.msg-img {
  max-width: 240px;
  max-height: 240px;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
  border: 1px solid rgba(15, 31, 36, 0.08);
  object-fit: cover;
}

.msg-audio {
  width: 240px;
  max-width: 100%;
  height: 36px;
}

.msg-doc-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
}

.msg-doc-btn {
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}

.msg-doc-btn:hover {
  border-color: var(--primary);
  background: #ffffff;
}

.msg-doc-ext {
  padding: 4px 7px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.msg-doc-info {
  min-width: 0;
  flex: 1;
}

.msg-doc-name {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-doc-sub {
  font-size: 0.74rem;
  color: var(--muted);
}

.msg-transcript {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 0.84rem;
  color: var(--text-secondary);
  font-style: italic;
}

.msg-reply-quote {
  margin-bottom: 6px;
  padding: 5px 8px;
  border-left: 3px solid var(--primary);
  background: rgba(13, 110, 102, 0.08);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.msg-reaction-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: -6px;
  margin-left: 8px;
  padding: 2px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.86rem;
  box-shadow: var(--shadow-sm);
  align-self: flex-start;
}

.msg-row.out .msg-reaction-pill {
  align-self: flex-end;
  margin-left: 0;
  margin-right: 8px;
}

.msg-video {
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  display: block;
  background: #000;
}

.msg-sticker {
  max-width: 140px;
  max-height: 140px;
  display: block;
}

.msg-location-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.84rem;
  text-decoration: underline;
}

.msg-delivery-err {
  color: var(--danger);
  font-size: 0.76rem;
  margin-top: 2px;
  padding: 0 4px;
}

.tick-sent,
.tick-delivered {
  color: var(--muted);
  font-weight: 700;
}

.tick-read {
  color: #0284c7;
  font-weight: 700;
}

.tick-failed {
  color: var(--danger);
  font-weight: 700;
}

/* Composer & AI Draft Card */
.draft-card {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  max-height: 58dvh;
  overflow-y: auto;
}

.draft-card.compact-mode {
  gap: 6px;
  padding: 8px 12px;
}

.ai-draft-panel {
  background: #f5fbfa;
  border: 1px solid var(--primary-border);
  border-radius: 12px;
  padding: 6px 10px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-draft-panel.is-collapsed {
  padding-bottom: 6px;
  gap: 0;
}

.ai-draft-panel.is-collapsed .ai-panel-body {
  display: none;
}

.ai-draft-panel.is-collapsed .ai-chevron {
  transform: rotate(-90deg);
}

.draft-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.ai-panel-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 2px 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--text);
}

.ai-chevron {
  color: var(--muted);
  transition: transform 0.16s ease;
  flex-shrink: 0;
}

.ai-panel-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ai-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.draft-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.draft-title {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.ai-feedback-group {
  display: inline-flex;
  gap: 6px;
}

.feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 11px;
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.feedback-discard:hover {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.feedback-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.feedback-btn.rated-good {
  background: var(--ok-soft);
  border-color: #86efac;
  color: var(--ok);
}

.feedback-btn.rated-bad {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.doctor-note {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.84rem;
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  color: #7c2d12;
}

.doctor-note.urgent {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
  font-weight: 600;
}

.fallback-note {
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  background: #eef2f4;
  color: var(--muted);
}

.quick-replies {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.quick-chip {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  min-height: 36px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.quick-chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

#draft-textarea {
  min-height: 50px;
  max-height: 200px;
  resize: vertical;
  line-height: 1.44;
}

#draft-textarea:disabled {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: not-allowed;
}

.tweak-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tweak-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tweak-chip {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
}

.tweak-input-row,
.tweak-row {
  display: flex;
  gap: 8px;
}

.tweak-input-row input,
.tweak-row input {
  flex: 1;
}

.attached-file-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  color: #0b4a44;
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
}

.draft-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.draft-actions-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.tool-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.tool-btn.is-listening {
  border-color: #dc2626;
  background: #fef2f2;
  color: #dc2626;
  animation: micPulse 1.3s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.34); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.voice-dictate-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
}

.voice-dictate-bar #voice-dictate-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #dc2626;
  flex-shrink: 0;
  animation: micPulse 1.2s ease-in-out infinite;
}

.send-cta {
  min-height: 44px;
  padding: 9px 16px;
  white-space: nowrap;
}

@media (max-width: 400px) {
  .send-cta {
    padding: 9px 11px;
    font-size: 0.84rem;
  }
}

.outside-24h-panel {
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.84rem;
}

.outside-24h-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.outside-24h-row select,
.outside-24h-row input {
  flex: 1;
  min-width: 170px;
}

/* Sub-tabs & Pages */
.page-container {
  max-width: 1040px;
  width: 100%;
  margin: 18px auto;
  padding: 0 18px 40px;
}

.subtab-bar {
  display: inline-flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.subtab-btn {
  border: none;
  background: transparent;
  padding: 9px 16px;
  min-height: 38px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.subtab-btn.active {
  background: var(--primary);
  color: #fff;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-header h2,
.card h3,
.card h4 {
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.card-header-simple,
.card-header-stack {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.prices-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

/* Stats & AI Memory */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-tile {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}

.stat-value-sm {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
  margin-bottom: 3px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.storage-meta-line {
  font-size: 0.82rem;
  margin-top: 4px;
}

.triage-toggle-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.triage-toggle-label {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
}

.triage-toggle-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.triage-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.88rem;
}

.triage-toggle-text .muted {
  font-size: 0.8rem;
  line-height: 1.4;
}

.memory-list,
.backup-list,
.templates-status-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-item,
.backup-item,
.tpl-status-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.memory-item-body {
  flex: 1;
  min-width: 0;
  font-size: 0.87rem;
}

.memory-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.memory-snippet {
  margin: 3px 0;
  color: var(--text-secondary);
  font-size: 0.84rem;
}

.backup-actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* Quick Replies Editor & Price Table */
.quick-replies-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.qr-editor-row {
  display: grid;
  grid-template-columns: 220px 1fr 44px;
  gap: 8px;
  align-items: start;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.prices-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.price-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.price-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.price-group-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  min-height: 48px;
  background: var(--surface-soft);
  cursor: pointer;
  user-select: none;
}

.price-group-summary::-webkit-details-marker {
  display: none;
}

.price-group-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.price-group-title {
  font-weight: 700;
  font-size: 0.93rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price-group-count {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}

.price-group-chevron,
.collapsible-chevron {
  color: var(--muted);
  transition: transform 0.16s ease;
  flex-shrink: 0;
}

.price-group[open] .price-group-chevron,
.settings-collapsible[open] .collapsible-chevron {
  transform: rotate(180deg);
}

.price-group-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.price-item-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(130px, 1fr) minmax(140px, 1fr) 40px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid #e7eff2;
}

.price-field-label {
  display: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 3px;
}

.price-field-wrap {
  min-width: 0;
}

.price-field-wrap input {
  width: 100%;
}

.price-del-wrap {
  display: flex;
  justify-content: flex-end;
}

.price-group-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.floating-save-bar {
  position: sticky;
  bottom: 14px;
  margin-top: 18px;
  padding: 11px 16px;
  background: #102127;
  color: #ffffff;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(15, 31, 36, 0.28);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 32;
}

.floating-save-text {
  font-size: 0.88rem;
  font-weight: 600;
}

.floating-save-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.floating-save-bar .btn-ghost {
  color: rgba(255, 255, 255, 0.84);
}

.floating-save-bar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

/* Collapsible Advanced Technical Settings */
.settings-collapsible {
  padding: 0;
  overflow: hidden;
}

.settings-collapsible-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  cursor: pointer;
  user-select: none;
}

.settings-collapsible-summary::-webkit-details-marker {
  display: none;
}

.settings-collapsible-summary h3 {
  margin: 0 0 4px;
}

.settings-advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.advanced-subcard {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.advanced-subcard h4 {
  margin: 0;
}

.advanced-save-row {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  justify-content: flex-end;
}

.sim-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Settings Grid */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.full-span {
  grid-column: 1 / -1;
}

.copy-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  margin-bottom: 10px;
}

.copy-label {
  font-size: 0.76rem;
  color: var(--muted);
}

.copy-box code {
  font-size: 0.82rem;
  word-break: break-all;
}

.pin-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.pin-row .form-group {
  flex: 1;
  min-width: 210px;
}

.pin-input-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pin-input-wrap input {
  flex: 1;
}

.security-controls-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.security-controls-row .form-group {
  flex: 1;
  min-width: 240px;
}

.security-logout-all-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-card-sm {
  max-width: 420px;
}

/* Modals & Sheets */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 31, 36, 0.48);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 10px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-close-btn {
  min-width: 40px;
  min-height: 40px;
  font-size: 1.05rem;
}

.patient-quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tags-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-pick-chip {
  padding: 8px 13px;
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
}

.tag-pick-chip.selected {
  background: #ede9fe;
  border-color: #c4b5fd;
  color: #5b21b6;
}

.patient-danger-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.preset-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 16px;
}

.preset-btn {
  text-align: left;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.preset-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.contact-picker-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 10px 0 12px;
  flex-wrap: wrap;
}

.contact-picker-bar #pick-phone-contact-btn {
  flex: 1;
  min-height: 44px;
}

.contact-picker-bar #import-vcf-btn {
  min-height: 44px;
}

.contact-picker-hint {
  font-size: 0.83rem;
  margin: -4px 0 10px;
}

.contact-multi-phones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

.contact-phone-chip {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  min-height: 38px;
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.contact-phone-chip.active,
.contact-phone-chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

#existing-24h-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Full-screen Image Lightbox */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 19, 0.94);
  z-index: 80;
  display: flex;
  flex-direction: column;
}

.lightbox-topbar {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff;
}

.lightbox-caption {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lightbox-close {
  color: #fff !important;
}

.lightbox-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: auto;
}

.lightbox-body img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.pdf-preview-body {
  flex: 1;
  min-height: 0;
  padding: 0 10px 8px;
  display: flex;
}

.pdf-preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 10px;
  background: #ffffff;
}

.pdf-preview-status {
  padding: 10px 16px;
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.88rem;
}

.pdf-preview-hint {
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  text-align: center;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #102127;
  color: #fff;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
  z-index: 90;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.toast-action-btn {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  padding: 5px 11px;
  min-height: 34px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.toast-action-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.toast.error {
  background: var(--danger);
}

.mobile-only {
  display: none;
}

/* Mobile Bottom Nav (hidden on desktop; enabled inside @media (max-width: 860px)) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: none;
  grid-template-columns: repeat(4, 1fr);
  padding: 4px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 25;
}

.bottom-nav-btn {
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 6px 2px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-family: inherit;
  font-size: 0.69rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.bottom-nav-btn.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.bottom-nav-btn .badge {
  position: absolute;
  top: 4px;
  right: 16%;
}

/* Analytics Dashboard & Live Meta Health */
.analytics-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.analytics-header h2 {
  margin: 0 0 3px;
  font-size: 1.32rem;
}

.analytics-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.period-pills {
  display: inline-flex;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.period-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  min-height: 36px;
  border-radius: 7px;
  cursor: pointer;
}

.period-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.meta-health-card {
  margin-bottom: 14px;
  border-left: 4px solid var(--border);
}

.meta-health-card.health-green {
  border-left-color: #16a34a;
}

.meta-health-card.health-yellow {
  border-left-color: #d97706;
}

.meta-health-card.health-red {
  border-left-color: #dc2626;
}

.meta-health-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.meta-health-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.meta-health-title-row h3 {
  margin: 0;
  font-size: 1.02rem;
}

.meta-health-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.analytics-kpi-grid {
  margin-bottom: 14px;
}

.stat-sub {
  font-size: 0.75rem;
  margin-top: 3px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.analytics-grid > .card {
  min-width: 0;
  overflow: hidden;
}

.analytics-full-span {
  grid-column: 1 / -1;
}

.analytics-mini-div {
  margin: 14px 0;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.bar-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
}

.bar-row-label {
  font-weight: 600;
  color: var(--text);
}

.bar-row-val {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-track {
  width: 100%;
  height: 9px;
  background: var(--surface-soft);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.25s ease;
}

.bar-fill.fill-danger { background: #dc2626; }
.bar-fill.fill-warn { background: #d97706; }
.bar-fill.fill-purple { background: #7c3aed; }
.bar-fill.fill-green { background: #16a34a; }
.bar-fill.fill-muted { background: #64748b; }

.daily-legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 3px;
}

.legend-dot.in { background: var(--primary); }
.legend-dot.out { background: #7cc4bc; }

.daily-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 150px;
  padding-top: 22px;
  margin-top: 10px;
  overflow-x: auto;
}

.daily-col {
  flex: 1;
  min-width: 28px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.daily-bars {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
}

.daily-bar {
  width: 10px;
  max-width: 44%;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  position: relative;
}

.daily-bar.in { background: var(--primary); }
.daily-bar.out { background: #7cc4bc; }
.daily-bar.zero { background: var(--border); height: 2px !important; opacity: 0.55; }

.daily-count {
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.daily-date {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}

.ai-rate-box {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
}

.ai-rate-big {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.ai-rate-desc {
  font-size: 0.83rem;
  color: var(--text-secondary);
}

/* Responsive Mobile */
@media (max-width: 860px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: inline-flex;
  }

  .bottom-nav.mobile-only {
    display: grid;
  }

  .topbar {
    min-height: calc(56px + env(safe-area-inset-top));
    height: auto;
    padding: env(safe-area-inset-top) 12px 0;
    gap: 8px;
  }

  .brand-title {
    font-size: 0.98rem;
  }

  .status-pill {
    padding: 6px 11px;
    min-height: 38px;
    font-size: 0.78rem;
  }

  .icon-btn,
  .tool-btn,
  .feedback-btn,
  .pill-btn,
  .subtab-btn {
    min-height: 44px;
  }

  .icon-btn,
  .tool-btn {
    min-width: 44px;
  }

  textarea {
    resize: none;
  }

  .tab-panel {
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .inbox-toolbar {
    padding: 8px 12px 6px;
    flex-direction: row;
    align-items: center;
    gap: 0;
  }

  .filter-pills-wrap::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 28px;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(243, 246, 248, 0) 0%, var(--bg) 92%);
  }

  .new-msg-trigger {
    position: fixed;
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    min-height: 56px;
    padding: 0;
    border-radius: 50%;
    z-index: 30;
    box-shadow: 0 6px 20px rgba(13, 110, 102, 0.36);
  }

  .new-msg-trigger .new-msg-label {
    display: none;
  }

  .new-msg-trigger .ic {
    width: 24px;
    height: 24px;
    stroke-width: 2.2;
  }

  .conv-item.active {
    background: transparent;
    border-left-color: transparent;
  }

  .conv-item.is-urgent.active {
    background: #fffafa;
    border-left-color: var(--danger);
  }

  .inbox-grid {
    grid-template-columns: 1fr;
    padding: 0 12px 12px;
  }

  .conv-list-pane {
    max-height: none;
    padding-bottom: 72px;
  }

  .inbox-grid:not(.mobile-detail-open) .conv-detail-pane {
    display: none;
  }

  .inbox-grid.mobile-detail-open .conv-list-pane {
    display: none;
  }

  /* Native Full-Screen Mobile Chat */
  .app-shell.mobile-chat-open .topbar,
  .app-shell.mobile-chat-open .bottom-nav,
  .app-shell.mobile-chat-open .inbox-toolbar,
  .app-shell.mobile-chat-open .offline-banner {
    display: none !important;
  }

  .app-shell.mobile-chat-open #tab-inbox {
    padding-bottom: 0;
  }

  .app-shell.mobile-chat-open .conv-detail-pane {
    position: fixed;
    inset: 0;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    z-index: 40;
  }

  .conv-header {
    padding: calc(6px + env(safe-area-inset-top)) 6px 6px 4px;
    gap: 4px;
  }

  .conv-patient-trigger {
    gap: 8px;
    padding: 4px;
  }

  .conv-header .avatar {
    width: 34px;
    height: 34px;
    font-size: 0.78rem;
  }

  .conv-header-actions {
    gap: 0;
  }

  #mobile-back-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 6px;
  }

  .patient-quick-actions .btn {
    min-height: 44px;
  }

  .draft-card {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
    max-height: 68dvh;
  }

  .draft-card .doctor-note {
    max-height: none;
    overflow-y: visible;
    font-size: 0.85rem;
    line-height: 1.42;
  }

  #draft-textarea {
    max-height: 165px;
    resize: none;
    flex-shrink: 0;
  }

  @media (max-height: 580px) {
    .draft-card {
      max-height: 62dvh;
    }

    #draft-textarea {
      max-height: 120px;
    }
  }

  .modal-card .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .modal-card .modal-actions .btn {
    width: 100%;
    min-height: 46px;
  }

  .app-shell.mobile-chat-open ~ .toast {
    top: calc(64px + env(safe-area-inset-top));
    bottom: auto;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-container {
    margin: 12px auto;
    padding: 0 12px 24px;
  }

  .card {
    padding: 15px;
  }

  .subtab-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .settings-grid,
  .analytics-grid,
  .form-grid,
  .preset-buttons {
    grid-template-columns: 1fr;
  }

  .analytics-controls {
    width: 100%;
    justify-content: space-between;
  }

  .daily-col {
    min-width: 21px;
  }

  .daily-bar {
    width: 7px;
  }

  .daily-date {
    font-size: 0.62rem;
  }

  .period-btn {
    min-height: 40px;
  }

  .tweak-row,
  .tweak-input-row,
  .copy-box,
  .card-header-stack,
  .backup-actions-row,
  .security-controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .security-logout-all-wrap {
    width: 100%;
  }

  .copy-box .btn,
  .card-header-stack .btn,
  .backup-actions-row .btn,
  .btn-full-mobile {
    width: 100%;
    min-height: 44px;
  }

  .floating-save-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(70px + env(safe-area-inset-bottom));
    margin-top: 0;
    padding: 10px 12px;
    border-radius: 14px;
    z-index: 32;
  }

  .settings-collapsible-summary {
    padding: 15px;
  }

  .settings-advanced-grid {
    grid-template-columns: 1fr;
    padding: 14px 15px 15px;
  }

  .sim-card-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .prices-header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    padding: 18px 16px 0;
  }

  .modal-card .modal-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    margin: 14px -16px 0;
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
    z-index: 4;
  }

  #patient-info-form .modal-actions {
    position: static;
    margin: 12px 0 0;
    padding: 10px 0 0;
    border-top: none;
  }

  .backup-item {
    flex-direction: column;
    align-items: stretch;
  }

  .backup-item .memory-item-body strong {
    overflow-wrap: anywhere;
  }

  .backup-item-actions {
    width: 100%;
  }

  .backup-item-actions .btn {
    flex: 1;
    min-height: 44px;
  }

  .modal-card .patient-danger-actions {
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    text-align: center;
  }

  .qr-editor-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .draft-actions {
    gap: 6px;
  }

  .draft-actions-left {
    gap: 3px;
  }

  .tool-btn {
    min-width: 38px;
    padding: 6px;
  }

  .send-cta {
    padding: 9px 10px;
    font-size: 0.82rem;
    gap: 5px;
  }
}

/* Mobile Price Items -> Stacked Cards inside Category Accordions */
@media (max-width: 720px) {
  .price-item-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 12px;
  }

  .price-field-label {
    display: block;
  }

  .remove-price-btn {
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    background: var(--surface);
  }
}

/* Patient Media Gallery inside Karton */
.patient-media-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.patient-media-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.patient-media-header h4 {
  margin: 0;
  font-size: 0.96rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.patient-media-header .muted {
  font-size: 0.8rem;
}

.patient-media-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}

.media-gallery-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.14s, transform 0.12s;
}

.media-gallery-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.media-gallery-thumb {
  width: 100%;
  height: 92px;
  background: #e6eff1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.media-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-gallery-ext {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.media-gallery-meta {
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.media-gallery-name {
  font-size: 0.8rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-gallery-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.backup-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.restore-filename {
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 10px;
  word-break: break-all;
}

.restore-preview-box {
  margin-bottom: 12px;
  line-height: 1.5;
}

.restore-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.restore-options .checkbox-row {
  margin-top: 4px;
  align-items: flex-start;
}

.restore-safety-note {
  margin-bottom: 12px;
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: #0b4a44;
}

/* Printable Medical Transcript (PDF / Print via @media print) */
.print-export-sheet {
  display: none;
}

@page {
  size: A4;
  margin: 14mm;
}

@media print {
  body {
    background: #ffffff !important;
    color: #111827 !important;
  }

  #login-screen,
  #app-shell,
  .modal-backdrop,
  .lightbox-backdrop,
  .toast {
    display: none !important;
  }

  .print-export-sheet {
    display: block !important;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #111827;
    font-size: 11pt;
    line-height: 1.45;
  }

  .print-clinic-header {
    border-bottom: 2px solid #0d6e66;
    padding-bottom: 10px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
  }

  .print-clinic-title {
    font-size: 15pt;
    font-weight: 700;
    color: #0d6e66;
    margin: 0 0 3px;
  }

  .print-clinic-sub {
    font-size: 9pt;
    color: #4b5563;
  }

  .print-meta-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 14px;
    font-size: 9.8pt;
  }

  .print-meta-row {
    margin-bottom: 4px;
  }

  .print-section-title {
    font-size: 11pt;
    font-weight: 700;
    color: #0d6e66;
    margin: 14px 0 8px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 3px;
  }

  .print-date-sep {
    font-size: 9pt;
    font-weight: 700;
    color: #475569;
    margin: 12px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .print-msg {
    border-left: 3px solid #cbd5e1;
    padding: 5px 10px;
    margin-bottom: 7px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-msg.out {
    border-left-color: #0d6e66;
    background: #f4faf9;
  }

  .print-msg-head {
    font-size: 8.8pt;
    font-weight: 700;
    color: #334155;
    margin-bottom: 2px;
  }

  .print-msg-text {
    white-space: pre-wrap;
    word-break: break-word;
  }

  .print-msg-media {
    font-size: 8.8pt;
    color: #0d6e66;
    font-weight: 600;
    margin-bottom: 2px;
  }

  .print-footer {
    margin-top: 18px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
    font-size: 8.5pt;
    color: #64748b;
  }
}
