:root {
  color-scheme: light;

  --bg: #f3f4f8;
  --panel: #ffffff;
  --panel-subtle: #f6f7fb;
  --panel-raised: #ffffff;

  --ink: #1a1d24;
  --ink-soft: #454a54;
  --muted: #6b7280;
  --muted-light: #9aa1ad;

  --line: rgba(20, 24, 38, 0.08);
  --line-subtle: rgba(20, 24, 38, 0.05);
  --line-strong: rgba(20, 24, 38, 0.14);

  --brand: #4f6dff;
  --brand-hover: #3c57e6;
  --brand-dark: #2c3fb0;
  --brand-soft: #eef1ff;
  --brand-soft-strong: #dde4ff;

  --inbound: #ffffff;
  --outbound-from: #5b7bff;
  --outbound-to: #4f6dff;
  --outbound-ink: #ffffff;

  --call: #f1f2f6;
  --reaction: #fdf1fb;
  --reaction-line: #f3c9ec;
  --accent: #c45fdc;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --bubble-radius: 18px;
  --bubble-tail: 5px;

  --shadow-sm: 0 1px 2px rgba(20, 24, 38, 0.06), 0 1px 1px rgba(20, 24, 38, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 24, 38, 0.08), 0 2px 6px rgba(20, 24, 38, 0.05);
  --shadow-lg: 0 16px 48px rgba(20, 24, 38, 0.16), 0 4px 12px rgba(20, 24, 38, 0.08);

  --avatar-ink: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0e1015;
  --panel: #16181f;
  --panel-subtle: #1c1f28;
  --panel-raised: #20232d;

  --ink: #f1f2f6;
  --ink-soft: #c7cad3;
  --muted: #8b919e;
  --muted-light: #5c6270;

  --line: rgba(255, 255, 255, 0.08);
  --line-subtle: rgba(255, 255, 255, 0.05);
  --line-strong: rgba(255, 255, 255, 0.14);

  --brand: #6e87ff;
  --brand-hover: #8298ff;
  --brand-dark: #c2cdff;
  --brand-soft: rgba(110, 135, 255, 0.16);
  --brand-soft-strong: rgba(110, 135, 255, 0.28);

  --inbound: #20232d;
  --outbound-from: #6e87ff;
  --outbound-to: #5468e0;
  --outbound-ink: #ffffff;

  --call: #1c1f28;
  --reaction: #2a1f2c;
  --reaction-line: #4a2f4d;
  --accent: #e29bf0;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 1px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.36), 0 2px 6px rgba(0, 0, 0, 0.24);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 220ms ease, color 220ms ease;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* Subtle scrollbars */
.conversation-list,
.thread-scroller {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.conversation-list::-webkit-scrollbar,
.thread-scroller::-webkit-scrollbar {
  width: 8px;
}

.conversation-list::-webkit-scrollbar-thumb,
.thread-scroller::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  padding: 12px;
  gap: 12px;
  transition: grid-template-columns 200ms ease;
}

.app-shell.call-insights-open {
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr) minmax(320px, 440px);
}

.sidebar,
.thread-panel {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: background-color 220ms ease, box-shadow 220ms ease;
}

.sidebar {
  display: flex;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
  background: var(--panel);
  overflow: hidden;
}

.sidebar-header,
.thread-header,
.thread-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header {
  justify-content: space-between;
  min-height: 76px;
  padding: 18px 18px 14px;
}

.header-actions {
  /* Action buttons are added dynamically (theme, new, phone + admin tools,
     security, sign out), so the count grows past the sidebar width. A fixed
     5-column grid lays them out as a clean 5-per-row block
     that wraps deterministically instead of clipping the last one — the sidebar
     is overflow:hidden, so an un-wrapped row would hide e.g. Sign out. */
  display: grid;
  grid-template-columns: repeat(5, 38px);
  gap: 6px;
  justify-content: end;
  align-content: center;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted-light);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.icon-button,
.toolbar-button {
  display: inline-grid;
  place-items: center;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--panel-subtle);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease,
    box-shadow 140ms ease, transform 80ms ease;
}

.icon-button {
  width: 38px;
  font-size: 1.35rem;
  font-weight: 700;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button input {
  display: none;
}

.toolbar-button {
  min-width: 72px;
  padding: 0 14px;
  font-size: 0.8125rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
}

.toolbar-button:hover,
.icon-button:hover {
  background: var(--line-subtle);
  color: var(--ink);
}

.toolbar-button:active,
.icon-button:active {
  transform: scale(0.96);
}

.icon-button.is-active {
  background: var(--accent, #2563eb);
  color: #fff;
}

.conversation-row:hover {
  background: var(--panel-subtle);
}

/* Theme toggle icon swap */
#themeToggle .icon-sun {
  display: none;
}

#themeToggle .icon-moon {
  display: block;
}

:root[data-theme="dark"] #themeToggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] #themeToggle .icon-moon {
  display: none;
}

.search-wrap {
  padding: 4px 14px 12px;
}

/* Inbox status filter tabs (All / Unread / Unreplied / Read / Replied / Error).
   Horizontally scrollable so they never wrap or overflow the sidebar. */
.inbox-filters {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  padding: 0 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.inbox-filters::-webkit-scrollbar {
  display: none;
}

.inbox-filter {
  flex: 0 0 auto;
  padding: 5px 12px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.inbox-filter:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.inbox-filter.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

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

.search-icon {
  position: absolute;
  left: 14px;
  width: 16px;
  height: 16px;
  color: var(--muted-light);
  pointer-events: none;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--panel-subtle);
  color: var(--ink);
  outline: none;
  font-size: 0.875rem;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input,
textarea {
  padding: 0 14px;
}

.search-field input {
  padding-left: 38px;
}

textarea {
  min-height: 38px;
  max-height: 160px;
  padding: 9px 14px;
  resize: none;
  line-height: 1.4;
  border-radius: var(--radius-lg);
}

select {
  width: 140px;
  padding: 0 36px 0 14px;
  border-radius: var(--radius-pill);
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 50%,
    calc(100% - 11px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.icon-button:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.conversation-list {
  overflow-y: auto;
  padding: 4px 10px 10px;
  background: var(--panel);
}

.conversation-row {
  position: relative;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  min-height: 78px;
  margin: 0;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 80ms ease;
}

.conversation-row:active {
  transform: scale(0.99);
}

.conversation-row.active {
  background: var(--brand-soft);
}

.conversation-row.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 18px;
  bottom: 18px;
  width: 4px;
  border-radius: var(--radius-pill);
  background: var(--brand);
}

.conversation-row:has(.unread-badge:not([hidden])) .conversation-name {
  color: var(--ink);
  font-weight: 800;
}

.avatar,
.mini-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--avatar-ink);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.avatar {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

.mini-avatar {
  width: 46px;
  height: 46px;
  font-size: 0.84rem;
}

.conversation-main {
  min-width: 0;
}

.conversation-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

/* Leading status dot, mirroring Weave's per-row read status. Hidden for
   already-handled (replied + read) rows; colored for the states that need
   attention so the inbox is scannable at a glance. */
.status-dot {
  display: none;
  flex: 0 0 auto;
  align-self: center;
  width: 8px;
  height: 8px;
  margin-right: 2px;
  border-radius: 50%;
}

.conversation-row[data-readstatus="unread"] .status-dot {
  display: block;
  background: var(--brand);
}

.conversation-row[data-readstatus="unreplied"] .status-dot {
  display: block;
  background: #f59e0b;
}

.conversation-row[data-error="true"] .status-dot {
  display: block;
  background: #dc2626;
}

/* Unreplied rows (a patient is waiting) get a slightly emphasized name even
   when already read, so they don't blend in with handled conversations. */
.conversation-row[data-readstatus="unreplied"] .conversation-name {
  color: var(--ink);
  font-weight: 800;
}

.conversation-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-date,
.conversation-phone,
.conversation-preview,
.meta-line,
.message-meta {
  color: var(--muted);
  font-size: 0.8125rem;
}

.conversation-date {
  flex: 0 0 auto;
  font-size: 0.75rem;
}

.conversation-preview {
  display: -webkit-box;
  margin-top: 4px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.35;
}

.conversation-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.unread-badge {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.thread-panel {
  display: flex;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
  background: var(--panel-subtle);
  overflow: hidden;
}

.thread-header {
  justify-content: space-between;
  min-height: 76px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-subtle);
}

/* Back-to-inbox button: only relevant on small screens (master/detail). */
.thread-back {
  display: none;
  flex: none;
}

.identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
}

.identity-copy {
  min-width: 0;
}

.identity-copy h2 {
  overflow: hidden;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.thread-actions {
  display: flex;
  flex: 0 1 auto;
  gap: 8px;
  /* Same guard as .header-actions: thread action buttons (call, transfer, hold,
     etc.) must wrap rather than overflow a narrow thread header. */
  flex-wrap: wrap;
  justify-content: flex-end;
}

.thread-tools {
  padding: 10px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-subtle);
}

.thread-tools input {
  background: var(--panel-subtle);
}

.thread-scroller {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 24px;
  background: var(--panel-subtle);
}

.composer {
  flex: 0 0 auto;
  background: var(--panel);
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line-subtle);
}

.patient-info-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.patient-info-panel span {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 28px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: var(--panel-subtle);
}

.patient-info-panel strong {
  color: var(--ink);
}

.composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-lg);
  background: var(--panel-subtle);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.composer-bar:focus-within {
  border-color: var(--brand);
  background: var(--panel);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.composer-bar textarea {
  flex: 1;
  min-height: 40px;
  max-height: 160px;
  padding: 9px 6px;
  border: none;
  background: transparent;
  border-radius: 0;
}

.composer-bar textarea:focus {
  border: none;
  box-shadow: none;
}

.composer-icon-button,
.send-button {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, transform 80ms ease, opacity 140ms ease;
}

.composer-icon-button {
  background: transparent;
  color: var(--muted);
}

.composer-icon-button:hover {
  background: var(--line-subtle);
  color: var(--ink);
}

.composer-icon-button svg,
.send-button svg {
  width: 19px;
  height: 19px;
}

.composer-icon-button input {
  display: none;
}

.send-button {
  background: var(--brand);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.send-button:hover {
  background: var(--brand-hover);
}

.send-button:active {
  transform: scale(0.92);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.attachment-chip {
  display: inline-flex;
  max-width: 260px;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 700;
  font-size: 0.875rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-chip button {
  display: inline-grid;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(79, 109, 255, 0.16);
  color: var(--brand-dark);
  cursor: pointer;
  font-weight: 700;
}

.attachment-chip-image {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.message-list {
  display: flex;
  flex-direction: column;
  max-width: 920px;
  min-height: 100%;
  margin: 0 auto;
}

.thread-empty-note {
  align-self: center;
  margin: auto 0;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.date-divider {
  align-self: center;
  margin: 18px 0 10px;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.load-more-row {
  align-self: center;
  margin: 4px 0 14px;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.message-row {
  display: flex;
  width: 100%;
  margin-top: 12px;
  animation: message-in 220ms ease both;
}

.message-row:first-child,
.date-divider + .message-row {
  margin-top: 0;
}

.message-row.merge-prev {
  margin-top: 2px;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-row.outbound {
  justify-content: flex-end;
}

.message-card {
  max-width: min(640px, 76%);
}

.bubble {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: var(--bubble-radius);
  padding: 10px 14px;
  background: var(--inbound);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-size: 0.925rem;
  line-height: 1.45;
}

.message-row.inbound .bubble {
  border-bottom-left-radius: var(--bubble-tail);
}

.message-row.inbound.merge-next .bubble {
  border-bottom-left-radius: var(--bubble-radius);
}

.message-row.outbound .bubble {
  border-bottom-right-radius: var(--bubble-tail);
}

.message-row.outbound.merge-next .bubble {
  border-bottom-right-radius: var(--bubble-radius);
}

.bubble.attachment-only {
  padding: 4px;
  background: transparent;
  box-shadow: none;
  border-radius: var(--radius-md);
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.message-image-link {
  display: block;
  overflow: hidden;
  max-width: min(320px, 100%);
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.message-image {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
}

.message-attachment {
  display: inline-flex;
  max-width: 220px;
  min-height: 28px;
  align-items: center;
  padding: 4px 10px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outbound .bubble {
  background: linear-gradient(135deg, var(--outbound-from), var(--outbound-to));
  color: var(--outbound-ink);
}

.outbound .message-attachment {
  background: rgba(255, 255, 255, 0.16);
  color: var(--outbound-ink);
}

.reaction .bubble {
  background: var(--reaction);
  box-shadow: var(--shadow-sm);
}

.call .bubble {
  background: var(--call);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.bubble.call-bubble {
  padding: 10px 12px;
  cursor: pointer;
  transition: background-color 150ms ease, box-shadow 150ms ease;
}

.bubble.call-bubble:hover,
.bubble.call-bubble:focus-visible {
  background: var(--brand-soft);
  outline: none;
}

.call-bubble-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
}

.call-icon {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.call-icon.phone-missed {
  color: #e0473e;
  background: rgba(224, 71, 62, 0.12);
}

.call-icon.voicemail {
  color: var(--accent);
  background: rgba(196, 95, 220, 0.12);
}

.call-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.call-label {
  font-size: 0.9rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-sub {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.call-play-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--panel);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
  transition: background-color 150ms ease, color 150ms ease, transform 120ms ease;
}

.call-play-icon svg {
  width: 13px;
  height: 13px;
  margin-left: 1px; /* optically center the triangle */
  fill: currentColor;
  stroke: none;
}

.bubble.call-bubble:hover .call-play-icon,
.bubble.call-bubble:focus-visible .call-play-icon {
  background: var(--brand);
  color: #fff;
  transform: scale(1.06);
}

.message-meta {
  display: flex;
  gap: 7px;
  margin: 5px 4px 0;
  font-size: 0.75rem;
}

.message-row.merge-next .message-meta {
  display: none;
}

.outbound .message-meta {
  justify-content: flex-end;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: 100%;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 56px;
  height: 56px;
  color: var(--muted-light);
}

.empty-state strong {
  color: var(--ink);
  font-size: 1.05rem;
}

.hidden {
  display: none;
}

[hidden] {
  display: none !important;
}

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background: rgba(10, 12, 20, 0.4);
  backdrop-filter: blur(2px);
}

.dialog-panel {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header {
  padding-bottom: 4px;
}

.dialog-header h2 {
  font-size: 1.125rem;
  font-weight: 800;
}

.field-label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 0.8125rem;
  font-weight: 700;
}

.dialog-actions {
  justify-content: flex-end;
  padding-top: 2px;
}

.dialog-actions .send-button {
  width: auto;
  height: 38px;
  padding: 0 18px;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 700;
}

/* --- Call Insights side panel --- */
.call-insights-panel {
  display: flex;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: panel-in 200ms ease both;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.ci-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-subtle);
}

.ci-header h3 {
  font-size: 1.05rem;
  font-weight: 800;
}

.ci-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
  background: var(--panel-subtle);
}

.ci-contact {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ci-contact-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ci-phone {
  font-size: 1rem;
  font-weight: 800;
}

.ci-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.ci-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.ci-play-button {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.ci-play-button:hover {
  background: var(--brand-hover);
}

.ci-scrubber {
  flex: 1;
  accent-color: var(--brand);
}

.ci-time {
  min-width: 72px;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.ci-no-audio {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.ci-section h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ci-transcript {
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  font-size: 0.875rem;
  line-height: 1.5;
}

.ci-transcript .ci-empty {
  padding: 6px 0;
  color: var(--muted);
  text-align: center;
}

.ci-transcript .ci-empty .ci-sub {
  margin-top: 4px;
  font-size: 0.78rem;
}

.ci-details-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 12px;
  list-style: none;
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.ci-details-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.875rem;
}

.ci-detail-label {
  color: var(--muted);
  font-weight: 700;
}

.ci-detail-value {
  font-weight: 700;
  text-align: right;
}

/* Medium widths: three columns (list + thread + insights) crush the thread
   to a sliver. When Call Insights is open here, hide the conversation list
   and give the thread + insights the full width side by side; the list
   returns when the panel is closed. Below 820px the panel goes fullscreen
   instead (next block). */
@media (max-width: 1100px) {
  .app-shell.call-insights-open {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  }

  .app-shell.call-insights-open .sidebar {
    display: none;
  }
}

@media (max-width: 820px) {
  /* Master/detail: show one view at a time. The inbox list fills the screen;
     opening a conversation (.conversation-open, set in app.js) swaps to the
     thread full-screen with a back button. No more stacked top/bottom split. */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    padding: 8px;
    gap: 8px;
  }

  .app-shell .thread-panel {
    display: none;
  }

  .app-shell.conversation-open .sidebar {
    display: none;
  }

  .app-shell.conversation-open .thread-panel {
    display: flex;
  }

  .thread-back {
    display: inline-flex;
  }

  /* The avatar is redundant on the full-screen conversation (it's shown in the
     inbox list) and crowds the header — drop it so the name has room. */
  .thread-header .avatar {
    display: none;
  }

  .sidebar,
  .thread-panel {
    border-radius: var(--radius-md);
  }

  .thread-header {
    min-height: 76px;
    padding: 12px 14px;
  }

  .thread-tools {
    padding: 10px 14px;
  }

  .thread-scroller {
    padding: 14px;
  }

  .message-card {
    max-width: 88%;
  }

  .composer {
    padding: 10px;
  }

  .app-shell.call-insights-open {
    grid-template-columns: 1fr;
  }

  .call-insights-panel {
    position: fixed;
    inset: 0;
    z-index: 30;
    border-radius: 0;
  }
}

@keyframes telephony-pop-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Telephony: call dock (see telephony-service/frontend-integration) ---
   One row per in-progress call (ringing/dialing/active/held), so multiple
   receptionists can each pick up a different call, and a single
   receptionist can hold one call to switch to another. */
.telephony-call-dock {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 280px;
}

.telephony-call-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel, #fff);
  color: var(--ink, var(--text, #1a1a1a));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--line, var(--border, rgba(0, 0, 0, 0.08)));
  animation: telephony-pop-in 0.2s ease-out;
  transition: border-color 220ms ease, background-color 220ms ease, opacity 220ms ease,
    box-shadow 220ms ease;
}

.telephony-call-row--ringing {
  border-color: #16a34a;
  animation: telephony-pop-in 0.2s ease-out, telephony-ring-pulse 1.7s ease-in-out 0.2s infinite;
}

.telephony-call-row--updating {
  animation: none;
}

.telephony-call-row--updating.telephony-call-row--ringing {
  animation: telephony-ring-pulse 1.7s ease-in-out infinite;
}

.telephony-call-row--ringing .telephony-call-row__status {
  color: #16a34a;
}

@keyframes telephony-ring-pulse {
  0%,
  100% {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18), 0 0 0 0 rgba(22, 163, 74, 0);
  }
  50% {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18), 0 0 0 4px rgba(22, 163, 74, 0.2);
  }
}

/* On hold: a calm "paused" treatment (amber accent + faint tint) rather than
   a dimmed/disabled look, so it's clearly an intentional state. */
.telephony-call-row--held {
  border-color: #f59e0b;
  background: linear-gradient(0deg, rgba(245, 158, 11, 0.08), rgba(245, 158, 11, 0.08)),
    var(--panel, #fff);
}

.telephony-call-row--held .telephony-call-row__status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #f59e0b;
}

.telephony-call-row__held-time {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

/* Gentle blink next to "On hold" signals the hold music is live. */
.telephony-call-row--held .telephony-call-row__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: telephony-hold-blink 1.3s ease-in-out infinite;
}

@keyframes telephony-hold-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

.telephony-call-row__main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.telephony-call-row__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.telephony-call-row__phone {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.telephony-call-row__status {
  font-size: 12px;
  color: var(--brand, var(--accent, #2563eb));
  font-weight: 600;
}

.telephony-call-row__number {
  font-size: 12px;
  opacity: 0.7;
}

.telephony-call-row__timer {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-soft, #6b7280);
  white-space: nowrap;
}

.telephony-call-row__actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.telephony-call-row__actions button {
  width: 100%;
  border: 1px solid var(--line-strong, rgba(0, 0, 0, 0.14));
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--panel-subtle, rgba(0, 0, 0, 0.06));
  color: var(--ink, #1a1a1a);
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease,
    transform 80ms ease, filter 140ms ease;
}

/* A lone action (e.g. "Cancel" while dialing) spans the full width. */
.telephony-call-row__actions button:only-child {
  grid-column: 1 / -1;
}

.telephony-call-row__actions button:hover {
  border-color: transparent;
  background: var(--line-subtle, rgba(0, 0, 0, 0.05));
  color: var(--ink, #1a1a1a);
}

.telephony-call-row__actions button:active {
  transform: scale(0.95);
}

.telephony-call-row__actions button[data-action="answer"] {
  border-color: transparent;
  background: #16a34a;
  color: #fff;
}

.telephony-call-row__actions button[data-action="reject"],
.telephony-call-row__actions button[data-action="hangup"] {
  border-color: transparent;
  background: #dc2626;
  color: #fff;
}

.telephony-call-row__actions button[data-action="answer"]:hover,
.telephony-call-row__actions button[data-action="reject"]:hover,
.telephony-call-row__actions button[data-action="hangup"]:hover {
  filter: brightness(1.08);
  color: #fff;
}

/* --- Telephony: error toast --- */
.telephony-error-toast {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 1000;
  max-width: 320px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #dc2626;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  animation: telephony-pop-in 0.2s ease-out;
}

/* --- Login page --- */
.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(380px, 100%);
  padding: 28px;
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}

.login-head h1 {
  margin-top: 2px;
  font-size: 1.5rem;
}

.login-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.login-card .field-label input {
  margin-top: 2px;
}

.login-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 700;
}

.login-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.login-submit {
  width: 100%;
  height: 42px;
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  font-weight: 700;
}

.login-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
  font-size: 0.85rem;
}

.login-error.is-info {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.login-link-button {
  justify-self: center;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.password-reset-panel {
  display: grid;
  gap: 12px;
  padding-top: 2px;
  border-top: 1px solid var(--line-subtle);
}

.login-reset-actions {
  display: flex;
  justify-content: flex-end;
}

/* --- Admin modal (manage users / audit log) --- */
.admin-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 12, 20, 0.45);
  backdrop-filter: blur(2px);
  animation: telephony-pop-in 0.15s ease-out;
}

.admin-modal {
  display: flex;
  flex-direction: column;
  width: min(820px, 100%);
  max-height: 86vh;
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.admin-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-subtle);
}

.admin-modal__head h2 {
  font-size: 1.1rem;
  font-weight: 800;
}

.admin-modal__body {
  padding: 18px 20px;
  overflow-y: auto;
}

.admin-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.admin-error {
  margin: 8px 0 0;
  color: #dc2626;
  font-size: 0.82rem;
}

.admin-success {
  margin: 8px 0 0;
  color: #16a34a;
  font-size: 0.82rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-table th,
.admin-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: middle;
}

.admin-table th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-audit td {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.admin-tag {
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.68rem;
  font-weight: 700;
}

.admin-row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-row-actions button {
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--panel-subtle);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.admin-row-actions button:hover {
  background: var(--line-subtle);
}

.admin-add-user {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line-subtle);
}

.admin-add-user h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 800;
}

.admin-add-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.admin-add-grid input[type="text"],
.admin-add-grid input[type="email"],
.admin-add-grid input[type="password"],
.admin-add-grid input:not([type]) {
  border: 1px solid var(--line-strong);
}

.admin-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
}

.admin-check input {
  width: auto;
  min-height: 0;
}

.admin-submit {
  width: auto;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-pill);
  font-weight: 700;
}

.mfa-secret {
  display: block;
  width: 100%;
  margin: 10px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-md);
  background: var(--panel-subtle);
  color: var(--ink);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

@media (max-width: 560px) {
  .admin-add-grid {
    grid-template-columns: 1fr;
  }
}

/* --- Telephony: directed-transfer extension picker --- */
.telephony-transfer-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  padding: 6px;
  border-radius: 12px;
  background: var(--panel-subtle, rgba(0, 0, 0, 0.06));
  border: 1px solid var(--line, rgba(0, 0, 0, 0.08));
  font-size: 12px;
  color: var(--muted, #6b7280);
  animation: telephony-pop-in 0.15s ease-out;
}

.telephony-transfer-item {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.telephony-transfer-target {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  background: transparent;
  color: var(--ink, #1a1a1a);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.telephony-transfer-target:hover:not(:disabled) {
  background: var(--brand-soft, rgba(79, 109, 255, 0.12));
  color: var(--brand-dark, var(--brand, #4f6dff));
}

.telephony-transfer-target:disabled,
.telephony-transfer-warm:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.telephony-transfer-presence {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #9ca3af;
  box-shadow: 0 0 0 2px rgba(156, 163, 175, 0.16);
  flex: 0 0 auto;
}

.telephony-transfer-item.is-ready .telephony-transfer-presence {
  background: #16a34a;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.18);
}

.telephony-transfer-item.is-busy .telephony-transfer-presence {
  background: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.telephony-transfer-item.is-held .telephony-transfer-presence {
  background: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.telephony-transfer-status {
  margin-left: auto;
  color: #b45309;
  font-size: 11px;
  font-weight: 700;
}

.telephony-transfer-item.is-held .telephony-transfer-status {
  color: #1d4ed8;
}

.telephony-transfer-warm {
  flex: 0 0 auto;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted, #6b7280);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.telephony-transfer-warm:hover:not(:disabled) {
  background: var(--line-subtle, rgba(0, 0, 0, 0.05));
  color: var(--ink, #1a1a1a);
}

/* A call mid warm-transfer gets an amber accent (like hold). */
.telephony-call-row:has(.telephony-call-row__actions [data-action="wt-complete"]) {
  border-color: #f59e0b;
}

.telephony-call-row__actions button[data-action="wt-complete"] {
  border-color: transparent;
  background: #16a34a;
  color: #fff;
}

/* --- Call Insights: labeled real-time transcript --- */
.ci-transcript-line {
  display: grid;
  grid-template-columns: minmax(72px, auto) 1fr;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.ci-transcript-line + .ci-transcript-line {
  border-top: 1px solid var(--line-subtle);
}

.ci-transcript-who {
  font-weight: 800;
  font-size: 0.78rem;
  white-space: nowrap;
}

.ci-transcript-line--patient .ci-transcript-who {
  color: var(--accent);
}

.ci-transcript-line--staff .ci-transcript-who {
  color: var(--brand);
}

.ci-transcript-text {
  color: var(--ink);
}

/* Karaoke transcript sync: dim every line, then light up the one being spoken
   as the recording plays. Lines are click-to-seek. */
.ci-transcript--karaoke .ci-transcript-line {
  opacity: 0.45;
  border-radius: 8px;
  padding: 5px 8px;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.ci-transcript-line.is-seekable {
  cursor: pointer;
}

.ci-transcript--karaoke .ci-transcript-line.is-seekable:hover {
  opacity: 0.75;
  background-color: var(--brand-soft);
}

.ci-transcript--karaoke .ci-transcript-line.is-active {
  opacity: 1;
  background-color: var(--brand-soft);
}

/* The dim/active state replaces the divider lines for a cleaner karaoke look. */
.ci-transcript--karaoke .ci-transcript-line + .ci-transcript-line {
  border-top: none;
}

/* Lifecycle events (hold/resume/transfer) — a centered system note in the
   call timeline, visually distinct from speaker lines. */
.ci-transcript-event {
  margin: 8px 0;
  padding: 4px 10px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.ci-transcript-event::before {
  content: "•  ";
  opacity: 0.5;
}
