:root {
  --app: #071012;
  --panel: #0d171a;
  --panel-2: #122024;
  --panel-3: #1b2c31;
  --chat: #081214;
  --line: #263b40;
  --ink: #f3f7f7;
  --muted: #8fa3a8;
  --green: #28d6a3;
  --green-dark: #0d6c5c;
  --support: #8b7cff;
  --support-soft: #25214d;
}

body.crm-page {
  background:
    radial-gradient(circle at 14% 8%, #123a35 0, transparent 28%),
    radial-gradient(circle at 92% 92%, #27204f 0, transparent 24%),
    var(--app);
}

.app-bar {
  height: 72px;
  padding: 0 24px;
  border-bottom-color: #ffffff12;
  background: #0d171ae8;
  box-shadow: 0 12px 30px #00000024;
  backdrop-filter: blur(18px);
}

.app-brand img {
  width: 40px;
  height: 40px;
  padding: 3px;
  border: 1px solid #ffffff1a;
  background: #ffffff0d;
  box-shadow: 0 8px 20px #0006;
}

.app-brand strong {
  font-size: 15px;
  letter-spacing: .02em;
}

.app-version {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-left: 5px;
  padding: 1px 6px;
  border: 1px solid #28d6a352;
  border-radius: 999px;
  background: #12372f;
  color: #8df0d2;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .04em;
  vertical-align: 1px;
}

.app-brand span {
  margin-top: 2px;
  color: #86a6a5;
  letter-spacing: .04em;
}

.web-user {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid #ffffff12;
  border-radius: 999px;
  background: #ffffff08;
  color: #c8d6d7;
  font-size: 11px;
  font-weight: 700;
}

.connection-state,
.labels-button {
  border-radius: 999px;
}

.connection-state.connected {
  border-color: #28d6a34d;
  background: #12372f;
  color: #c8fff0;
}

.system-status-trigger {
  appearance: none;
  cursor: pointer;
  transition: border-color .16s, background .16s, box-shadow .16s;
}

.system-status-trigger:hover {
  border-color: #28d6a375;
  box-shadow: 0 0 0 3px #28d6a312;
}

.system-status-trigger > svg {
  width: 14px;
  height: 14px;
  opacity: .7;
}

.system-status-trigger.bridge-warning {
  border-color: #f0a43a75;
  background: #352715;
  color: #ffe2ac;
}

.system-status-dialog {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #020809b8;
  backdrop-filter: blur(7px);
}

.system-status-panel {
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 18px;
  border: 1px solid #ffffff17;
  border-radius: 14px;
  background: #0d171a;
  box-shadow: 0 28px 80px #0009;
}

.system-status-panel > header,
.system-status-panel > footer,
.system-line-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.system-status-panel > header > div {
  display: grid;
  gap: 3px;
}

.system-status-panel > header small {
  color: var(--green);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.system-status-panel > header strong {
  font-size: 20px;
}

.system-status-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 12px 14px;
  border: 1px solid #ffffff12;
  border-radius: 10px;
  background: #ffffff08;
}

.system-status-summary > div {
  display: grid;
  gap: 3px;
}

.system-status-summary strong { font-size: 14px; }
.system-status-summary small { color: var(--muted); }

.system-status-light {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border-radius: 50%;
  background: #94a3b8;
  box-shadow: 0 0 0 4px #94a3b81c;
}

.system-status-summary.online .system-status-light,
.system-line-card.online .system-status-light { background: #22c55e; box-shadow: 0 0 0 4px #22c55e1f; }
.system-status-summary.partial .system-status-light,
.system-line-card.warning .system-status-light { background: #f59e0b; box-shadow: 0 0 0 4px #f59e0b1f; }
.system-status-summary.offline .system-status-light,
.system-line-card.offline .system-status-light { background: #ef4444; box-shadow: 0 0 0 4px #ef44441f; }

.system-status-versions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.system-status-metric {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid #ffffff0d;
  border-radius: 8px;
  background: #ffffff06;
}

.system-status-metric small {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.system-status-metric strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-status-metric.good strong { color: #7ce7bd; }
.system-status-metric.bad strong { color: #ffc36c; }
.system-status-metric.tunnel-user { grid-column: 1 / -1; }

.system-status-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.system-line-card {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid #ffffff12;
  border-left: 3px solid #94a3b8;
  border-radius: 10px;
  background: #101d20;
}

.system-line-card.online { border-left-color: #22c55e; }
.system-line-card.warning { border-left-color: #f59e0b; }
.system-line-card.offline { border-left-color: #ef4444; }
.system-line-card header > div { display: flex; align-items: center; gap: 8px; }
.system-line-card header > b { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.system-line-card.online header > b { color: #7ce7bd; }
.system-line-card.warning header > b { color: #ffc36c; }
.system-line-card.offline header > b { color: #ff8c97; }
.system-line-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }

.system-line-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.system-line-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 10px;
}

.system-line-detail .warning { color: #ffc36c; }
.system-status-panel > footer { color: var(--muted); font-size: 10px; }
.system-status-panel > footer .primary { min-height: 34px; display: inline-flex; align-items: center; gap: 7px; }
.system-status-panel > footer .primary svg { width: 15px; height: 15px; }
.system-status-panel > footer .primary.loading svg { animation: download-spin .75s linear infinite; }

[data-theme="light"] .system-status-dialog { background: #dfe8e9b8; }
[data-theme="light"] .system-status-panel { border-color: #d7e0e2; background: #ffffff; box-shadow: 0 28px 80px #31505a38; }
[data-theme="light"] .system-status-summary { border-color: #dce5e6; background: #f5f8f8; }
[data-theme="light"] .system-status-metric { border-color: #dfe7e8; background: #f7f9f9; }
[data-theme="light"] .system-line-card { border-top-color: #dce5e6; border-right-color: #dce5e6; border-bottom-color: #dce5e6; background: #ffffff; }
[data-theme="light"] .system-status-metric.good strong { color: #08775d; }
[data-theme="light"] .system-status-metric.bad strong { color: #a85a00; }
[data-theme="light"] .system-status-trigger.bridge-warning { border-color: #e5a33e; background: #fff8ea; color: #865112; }

@media (max-width: 760px) {
  .system-status-dialog { padding: 8px; }
  .system-status-panel { max-height: calc(100vh - 16px); padding: 13px; }
  .system-status-versions,
  .system-status-lines { grid-template-columns: 1fr; }
}

.crm-workspace {
  height: calc(100vh - 72px);
  grid-template-columns: minmax(350px, 420px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

body:has(.connection-banner:not(.hidden)) .crm-workspace {
  height: calc(100vh - 110px);
}

.conversation-pane,
.chat-pane {
  overflow: hidden;
  border: 1px solid #ffffff12;
  border-radius: 16px;
  background: #0d171af2;
  box-shadow: 0 18px 42px #00000038;
}

.conversation-pane {
  grid-template-rows: 62px 54px 156px minmax(0, 1fr) 36px;
}

.sidebar-title {
  padding: 0 18px;
  border-bottom: 1px solid #ffffff0b;
}

.sidebar-title > div {
  display: grid;
  gap: 2px;
}

.sidebar-title small {
  color: var(--green);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.sidebar-title strong {
  font-size: 20px;
  letter-spacing: -.02em;
}

.sidebar-title > span {
  background: #ffffff0d;
  color: #d8e4e5;
}

.conversation-search input {
  border: 1px solid #ffffff0c;
  border-radius: 11px;
  background: #ffffff09;
  transition: border-color .18s, background .18s, box-shadow .18s;
}

.conversation-search input:focus {
  border-color: #28d6a36b;
  background: #102125;
  box-shadow: 0 0 0 4px #28d6a312;
}

.status-filters button {
  border-radius: 9px;
}

.main-filters {
  gap: 5px;
}

.main-filters button {
  padding-inline: 8px;
  font-size: 10px;
}

.main-filters .support-filter {
  border-color: #8b7cff38;
  color: #c9c2ff;
}

.main-filters .support-filter svg {
  width: 14px;
  height: 14px;
}

.main-filters .support-filter.active {
  border-color: #8b7cff;
  background: var(--support-soft);
  color: #eeeaff;
  box-shadow: inset 0 0 0 1px #8b7cff33, 0 5px 16px #17103855;
}

.conversation-row {
  margin: 4px 7px;
  width: calc(100% - 14px);
  border: 1px solid transparent;
  border-radius: 11px;
  transition: background .15s, border-color .15s, transform .15s;
}

.conversation-row:hover {
  border-color: #ffffff0e;
  background: #ffffff08;
  transform: translateY(-1px);
}

.conversation-row.selected {
  border-color: #28d6a33d;
  background: linear-gradient(90deg, #143a33, #17272b);
  box-shadow: inset 3px 0 0 var(--green), 0 8px 18px #0003;
}

.conversation-row.has-support {
  box-shadow: inset 3px 0 0 var(--support);
}

.conversation-row.support-pending {
  box-shadow: inset 3px 0 0 #d8a649;
}

.conversation-row.support-failed {
  box-shadow: inset 3px 0 0 #f15c6d;
}

.conversation-avatar,
.customer-avatar {
  background: linear-gradient(145deg, #1d5f52, #243452);
  box-shadow: inset 0 0 0 1px #ffffff12;
}

.support-label {
  width: max-content;
  min-height: 17px;
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border: 1px solid #8b7cff73;
  border-radius: 4px;
  background: var(--support-soft);
  color: #d8d3ff !important;
  font-size: 8px !important;
  font-weight: 850;
  letter-spacing: .05em;
  line-height: 14px;
  text-transform: uppercase;
}

.support-sync-label {
  min-height: 17px;
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 8px !important;
  font-weight: 800;
  line-height: 14px;
  text-transform: uppercase;
}

.support-sync-label.pending {
  border: 1px solid #d8a64973;
  background: #3a2b13;
  color: #ffe0a2 !important;
}

.support-sync-label.failed {
  border: 1px solid #f15c6d73;
  background: #3b2026;
  color: #ffc1c9 !important;
}

.support-toggle {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid #8b7cff5c;
  border-radius: 9px;
  background: #8b7cff14;
  color: #d8d3ff;
  font-weight: 750;
  white-space: nowrap;
}

.support-toggle:hover:not(:disabled) {
  border-color: #a79cff;
  background: #8b7cff28;
}

.support-toggle.active {
  border-color: #38c9997a;
  background: #103c33;
  color: #bff4df;
}

.support-toggle.pending {
  border-color: #d8a64978;
  background: #3a2b13;
  color: #ffe0a2;
}

.support-toggle.failed {
  border-color: #f15c6d8c;
  background: #3b2026;
  color: #ffc1c9;
}

.support-toggle svg {
  width: 16px;
  height: 16px;
}

.chat-context-menu #supportMenuItem > svg {
  color: #b6adff;
}

.chat-header {
  grid-template-columns: 42px minmax(0, 1fr) auto auto auto 150px;
  border-bottom-color: #ffffff10;
  background: #122024f2;
}

.messages {
  background:
    radial-gradient(circle at 82% 15%, #15332e66 0, transparent 30%),
    linear-gradient(#081214e8, #081214f5);
}

.message-bubble {
  border-radius: 12px;
  box-shadow: 0 6px 18px #0004;
}

.message-row.outbound .message-bubble {
  background: linear-gradient(145deg, #0c7562, #0b5d51);
}

.composer {
  border-top-color: #ffffff10;
  background: #101d20f2;
}

.composer textarea {
  border: 1px solid #ffffff0c;
  border-radius: 12px;
  background: #ffffff09;
}

.spellcheck-button {
  color: #8fa3a8;
}

.spellcheck-button:hover:not(:disabled) {
  color: #8df0d2;
}

.spellcheck-button.correcting {
  color: #8df0d2;
  background: #12372f;
}

.spellcheck-button.correcting svg {
  animation: download-spin .75s linear infinite;
}

.send-button {
  box-shadow: 0 8px 20px #00a88438;
}

.empty-icon {
  border: 1px solid #28d6a329;
  background: linear-gradient(145deg, #17332e, #1d2640);
  box-shadow: 0 18px 40px #0005;
}

.login-box {
  border-color: #ffffff17;
  border-radius: 18px;
  background: #10191ced;
  box-shadow: 0 30px 80px #0008;
}

.single-login-shell {
  width: min(440px, 100%);
}

.single-login-card {
  width: 100%;
}

.single-login-card h1 {
  margin: 5px 0 8px;
  color: #f2f7f6;
  font-size: 22px;
}

.production-connect-icon img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 50%;
}

.production-session-form {
  margin-left: auto;
}

.production-session-button {
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid #36d5a558;
  border-radius: 999px;
  background: #0c2d27;
  color: #8ff1d4;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.production-connect-backdrop {
  position: fixed;
  z-index: 5000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #030a0cd9;
  backdrop-filter: blur(14px);
}

.production-connect-card {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid #ffffff17;
  border-radius: 20px;
  background: linear-gradient(145deg, #142326, #0d1719);
  box-shadow: 0 30px 90px #000b;
}

.production-connect-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid #28d6a349;
  border-radius: 15px;
  background: #0b392f;
  color: #71e8c4;
}

.production-connect-icon svg {
  width: 25px;
  height: 25px;
}

.production-connect-card small {
  color: #64dcb9;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.production-connect-card h2 {
  margin: 5px 0 8px;
  color: #f2f7f6;
  font-size: 22px;
}

.production-connect-card p {
  margin: 0;
  color: #a8b8b5;
  font-size: 12px;
  line-height: 1.55;
}

.production-connect-card label {
  display: grid;
  gap: 6px;
  color: #cad6d4;
  font-size: 11px;
  font-weight: 700;
}

.production-connect-card input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #ffffff17;
  border-radius: 10px;
  outline: 0;
  background: #ffffff08;
  color: #f5faf9;
}

.production-connect-card input:focus {
  border-color: #3dd8aa8c;
  box-shadow: 0 0 0 3px #28d6a312;
}

.production-connect-card > button {
  min-height: 43px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #16a780, #08715f);
  color: white;
  font-weight: 850;
  box-shadow: 0 12px 26px #00a8842c;
}

@media (max-width: 1000px) {
  .crm-workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .support-toggle span {
    display: none;
  }

  .support-toggle {
    width: 36px;
    justify-content: center;
    padding: 0;
  }

  .chat-header {
    grid-template-columns: 40px minmax(0, 1fr) auto auto 126px;
  }
}

@media (max-width: 760px) {
  .app-bar {
    height: 60px;
    padding-inline: 10px;
  }

  .crm-workspace {
    height: calc(100vh - 60px);
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }

  body:has(.connection-banner:not(.hidden)) .crm-workspace {
    height: calc(100vh - 98px);
  }

  .conversation-pane,
  .chat-pane {
    border: 0;
    border-radius: 0;
  }

  .main-filters button {
    font-size: 9px;
  }

  .chat-header {
    grid-template-columns: 38px 40px minmax(0, 1fr) auto auto;
  }
}

/* CRM 1.4: roles, themes and a lighter support workspace. */
.web-user {
  display: grid;
  justify-items: end;
  gap: 1px;
  padding: 5px 12px;
  line-height: 1.1;
}

.web-user > span {
  color: var(--ink);
  font-size: 11px;
}

.web-user > strong {
  color: var(--green);
  font-size: 8px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #ffffff17;
  border-radius: 50%;
  background: #ffffff09;
  color: var(--ink);
}

.theme-toggle:hover {
  border-color: #28d6a36b;
  background: #28d6a312;
}

.theme-toggle span {
  position: absolute;
  font-size: 20px;
  line-height: 1;
  transition: opacity .18s, transform .18s;
}

.theme-toggle .theme-sun {
  opacity: 0;
  transform: rotate(-35deg) scale(.65);
}

.theme-toggle .theme-moon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

[data-theme="light"] .theme-toggle .theme-sun {
  opacity: 1;
  transform: rotate(0) scale(1);
}

[data-theme="light"] .theme-toggle .theme-moon {
  opacity: 0;
  transform: rotate(35deg) scale(.65);
}

.chat-header {
  grid-template-columns: 42px minmax(0, 1fr) auto auto;
}

.conversation-row {
  contain: layout paint style;
  content-visibility: visible;
}

.support-role-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  color: #c9c2ff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.support-role-heading svg {
  width: 15px;
  height: 15px;
}

.support-line-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.support-line-filters button {
  min-height: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 10px;
}

.support-line-filters button small {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

body[data-role="soporte"] .conversation-pane {
  grid-template-rows: 62px 54px 132px minmax(0, 1fr) 36px;
}

body[data-role="soporte"] .status-filters {
  display: grid;
  grid-template-rows: 38px 18px 38px;
  gap: 6px;
  padding: 8px 12px;
}

.support-view-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.support-view-filters button {
  min-height: 38px;
}

.support-view-filters .support-filter.active {
  border-color: #d84a55;
  background: #481f25;
  color: #ffabb2;
}

body[data-role="soporte"] .conversation-row.has-support {
  box-shadow: none;
}

.document-card .icon-button.downloading svg {
  animation: download-spin .75s linear infinite;
}

.document-card .icon-button.downloading {
  color: var(--green);
  opacity: 1;
}

@keyframes download-spin {
  to { transform: rotate(360deg); }
}

[data-theme="light"] {
  color-scheme: light;
  --app: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --panel-3: #f0f2f5;
  --chat: #ffffff;
  --line: #d9e1e4;
  --ink: #111b21;
  --muted: #667781;
  --green: #00a884;
  --green-dark: #d9fdd3;
  --incoming: #ffffff;
  --danger: #c83f51;
  --support: #6957dd;
  --support-soft: #eeeaff;
}

[data-theme="light"] body.crm-page {
  background: var(--app);
}

[data-theme="light"] .app-bar {
  border-bottom-color: #cfdadc;
  background: #ffffffea;
  box-shadow: 0 8px 26px #37525b14;
}

[data-theme="light"] .app-brand img,
[data-theme="light"] .web-user,
[data-theme="light"] .theme-toggle {
  border-color: #d8e1e3;
  background: #ffffff;
  box-shadow: none;
}

[data-theme="light"] .app-brand span,
[data-theme="light"] .web-user {
  color: #63777b;
}

[data-theme="light"] .conversation-pane,
[data-theme="light"] .chat-pane {
  border-color: #d8e1e3;
  background: #ffffff;
  box-shadow: 0 8px 24px #36535d12;
}

[data-theme="light"] .sidebar-title,
[data-theme="light"] .chat-header,
[data-theme="light"] .composer,
[data-theme="light"] .template-panel,
[data-theme="light"] .attachment-preview,
[data-theme="light"] .recording-preview {
  border-color: #dbe4e6;
  background: #ffffff;
  box-shadow: none;
}

[data-theme="light"] .conversation-search input,
[data-theme="light"] .composer textarea,
[data-theme="light"] .template-row select,
[data-theme="light"] .template-variables input {
  border-color: #d7e0e2;
  background: #eef3f4;
  color: var(--ink);
}

[data-theme="light"] .status-filters button {
  border-color: #d8e1e3;
  background: #f5f8f8;
  color: #586b70;
}

[data-theme="light"] .status-filters button:hover,
[data-theme="light"] .status-filters button.active {
  border-color: #69bdaa;
  background: #dff4ed;
  color: #126c5a;
}

[data-theme="light"] .main-filters .support-filter.active {
  border-color: #8575e5;
  background: #eeeaff;
  color: #5142b6;
}

[data-theme="light"] .conversation-row:hover {
  border-color: #dbe4e6;
  background: #f3f7f7;
}

[data-theme="light"] .conversation-row.selected {
  border-color: #8acdbd;
  background: linear-gradient(90deg, #dff5ee, #eff8f5);
  box-shadow: inset 3px 0 0 var(--green);
}

[data-theme="light"] .messages {
  background: #f7f9f8;
}

[data-theme="light"] .message-bubble {
  border-color: #d5dfe1;
  background: #ffffff;
  box-shadow: 0 5px 16px #37525b14;
}

[data-theme="light"] .message-row.inbound .message-bubble::before {
  border-color: #d5dfe1;
  background: #ffffff;
}

[data-theme="light"] .message-row.outbound .message-bubble {
  border-color: #aadcca;
  background: #d8f5eb;
}

[data-theme="light"] .message-row.outbound .message-bubble::after {
  border-color: #aadcca;
  background: #d8f5eb;
}

[data-theme="light"] .message-author strong,
[data-theme="light"] .message-row.inbound .message-author strong {
  color: #217b69;
}

[data-theme="light"] .message-author span,
[data-theme="light"] .message-row.outbound .message-author span,
[data-theme="light"] .message-meta {
  color: #63777b;
}

[data-theme="light"] .message-day span,
[data-theme="light"] .conversation-time-group {
  border-color: #d5dfe1;
  background: #f8fafaf2;
  color: #66787c;
  box-shadow: 0 2px 6px #37525b12;
}

[data-theme="light"] .support-toggle.active {
  border-color: #78cbb5;
  background: #dff5ee;
  color: #126c5a;
}

/* Date separators belong in the message flow. Sticky separators overlap when
   several dates are rendered close together. */
.message-day {
  position: relative;
  top: auto;
  z-index: 1;
  width: 100%;
  min-height: 26px;
  clear: both;
  isolation: isolate;
}

/* Icons inherit a deliberate foreground in both themes instead of retaining
   a color from a previously active theme. */
:root:not([data-theme="light"]) .icon-button:not(.danger),
:root:not([data-theme="light"]) .theme-toggle,
:root:not([data-theme="light"]) .chat-context-menu button > svg {
  color: #dce7e9;
}

[data-theme="light"] .icon-button:not(.danger),
[data-theme="light"] .theme-toggle,
[data-theme="light"] .chat-context-menu button > svg {
  color: #3b4a4f;
}

[data-theme="light"] .labels-button {
  border-color: #d7e0e2;
  background: #ffffff;
  color: #334247;
}

[data-theme="light"] .labels-button:hover {
  border-color: #9fb0b5;
  background: #f5f7f8;
}

[data-theme="light"] .labels-button svg,
[data-theme="light"] .document-card > svg,
[data-theme="light"] .attachment-kind {
  color: #087c69;
}

[data-theme="light"] .send-button {
  background: #00a884;
  color: #ffffff;
}

[data-theme="light"] .send-button:hover:not(:disabled) {
  background: #008f72;
}

[data-theme="light"] .support-label {
  border-color: #8d7cf0;
  background: #f0edff;
  color: #5b48c8 !important;
}

[data-theme="light"] .support-role-heading {
  color: #5b48c8;
}

[data-theme="light"] .conversation-preview.outbound {
  color: #16856f;
}

[data-theme="light"] .service-window.open {
  border-color: #72c8b1;
  background: #e7f7f2;
  color: #087c69;
}

[data-theme="light"] .conversation-time-group {
  border-color: #e1e6e8;
  background: #f7f9fa;
  color: #54656b;
}

/* CRM 1.5: flat WhatsApp-like workspace and unambiguous channel colors. */
.app-bar {
  height: 64px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: none;
  backdrop-filter: none;
}

.crm-workspace {
  height: calc(100vh - 64px);
  grid-template-columns: minmax(350px, 420px) minmax(0, 1fr);
  gap: 0;
  padding: 0;
}

body:has(.connection-banner:not(.hidden)) .crm-workspace {
  height: calc(100vh - 102px);
}

.conversation-pane,
.chat-pane {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.conversation-pane {
  border-right: 1px solid var(--line);
}

.conversation-row {
  width: 100%;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  transition: background-color .1s ease;
}

.conversation-row:hover {
  border-color: var(--line);
  transform: none;
}

.conversation-row.selected,
.conversation-row.has-support,
.conversation-row.support-pending,
.conversation-row.support-failed {
  box-shadow: none;
}

.message-bubble,
[data-theme="light"] .message-bubble {
  box-shadow: 0 1px 1px #00000018;
}

.message-row.outbound .message-bubble {
  background: var(--green-dark);
}

.status-filters button,
.support-line-filters button {
  border-radius: 6px;
  box-shadow: none !important;
}

.support-label {
  border-color: #e0525d;
  background: #4a2026;
  color: #ff9ca5 !important;
}

.line-badge.line-1 {
  border-color: #13966b;
  background: #123c30;
  color: #8ff0cb !important;
}

.line-badge.line-2 {
  border-color: #3d82e3;
  background: #172f56;
  color: #a9ccff !important;
}

.main-filters .support-filter.active,
.support-view-filters .support-filter.active {
  border-color: #d84a55;
  background: #481f25;
  color: #ffabb2;
}

.support-role-heading {
  color: var(--muted);
}

[data-theme="light"] body.crm-page,
[data-theme="light"] .conversation-pane,
[data-theme="light"] .chat-pane,
[data-theme="light"] .app-bar,
[data-theme="light"] .sidebar-title,
[data-theme="light"] .chat-header,
[data-theme="light"] .composer {
  background: #ffffff;
}

[data-theme="light"] .messages {
  background: #f5f7f6;
}

[data-theme="light"] .conversation-row:hover {
  background: #f5f6f6;
}

[data-theme="light"] .conversation-row.selected {
  border-color: var(--line);
  background: #f0f2f5;
}

[data-theme="light"] .conversation-avatar,
[data-theme="light"] .customer-avatar {
  background: #dfe5e7;
  color: #54656b;
  box-shadow: none;
}

[data-theme="light"] .support-label {
  border-color: #e0525d;
  background: #ffe3e5;
  color: #b4232b !important;
}

[data-theme="light"] .line-badge.line-1 {
  border-color: #23a873;
  background: #dcf8e9;
  color: #087a52 !important;
}

[data-theme="light"] .line-badge.line-2 {
  border-color: #5b96e8;
  background: #e1edff;
  color: #1d5eb8 !important;
}

[data-theme="light"] .main-filters .support-filter.active,
[data-theme="light"] .support-view-filters .support-filter.active {
  border-color: #e0525d;
  background: #ffe3e5;
  color: #b4232b;
}

[data-theme="light"] .icon-button:not(.danger),
[data-theme="light"] .theme-toggle,
[data-theme="light"] .conversation-search svg,
[data-theme="light"] .filter-heading svg,
[data-theme="light"] .support-role-heading svg,
[data-theme="light"] .chat-context-menu button > svg {
  color: #54656b;
}

[data-theme="light"] .empty-icon {
  border-color: #d9e1e4;
  background: #f0f2f5;
  color: #54656b;
  box-shadow: none;
}

[data-theme="light"] .status-filters button {
  border-color: #d9e1e4;
  background: #ffffff;
  color: #3b4a4f;
}

[data-theme="light"] .status-filters button:hover,
[data-theme="light"] .status-filters button.active:not(.support-filter) {
  border-color: #7acbb7;
  background: #e7f7f2;
  color: #087c69;
}

/* Message deletion through the authenticated WhatsApp bridge. */
.message-context-menu .context-menu-title {
  display: block;
  padding: 4px 14px 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.message-context-menu button.danger,
.message-context-menu button.danger > svg {
  color: var(--danger) !important;
}

.message-delete-state {
  margin-right: auto;
  font-size: 9px;
  font-weight: 650;
}

.message-delete-state.pending {
  color: #d7b85a;
}

.message-delete-state.failed {
  color: var(--danger);
}

.message-row.delete-pending .message-bubble {
  opacity: .76;
}

.message-row.delete-failed .message-bubble {
  outline: 1px solid color-mix(in srgb, var(--danger) 70%, transparent);
}

.deleted-message-copy {
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 760px) {
  .app-brand {
    flex: 0 0 auto;
  }

  .app-brand > div {
    display: none;
  }

  .web-user > span { display: none; }
  .web-user { padding-inline: 8px; }
  .theme-toggle { width: 34px; height: 34px; flex-basis: 34px; }
  .chat-header { grid-template-columns: 38px 40px minmax(0, 1fr) auto auto; }
}

/* CRM 1.5.1: local avatars, brain pattern and clear light-mode status pills. */
.messages {
  background-color: #0b141a;
  background-image: url("./assets/brain-pattern-dark.svg");
  background-repeat: repeat;
  background-size: 144px 144px;
}

[data-theme="light"] .messages {
  background-color: #f3f1ec;
  background-image: url("./assets/brain-pattern-light.svg");
}

.conversation-avatar.avatar-image,
.customer-avatar.avatar-image {
  overflow: hidden;
  padding: 0;
  background: var(--panel-3);
  color: transparent;
  box-shadow: none;
}

.avatar-image > img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
}

.production-session-button {
  height: 34px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

[data-theme="light"] .connection-state.connected {
  border-color: #9ed9ca;
  background: #e7f7f2;
  color: #087c69;
}

[data-theme="light"] .connection-state.connected span {
  background: #00a884;
}

[data-theme="light"] .production-session-button {
  border-color: #9ed9ca;
  background: #e7f7f2;
  color: #087c69;
  box-shadow: none;
}

[data-theme="light"] .conversation-avatar.avatar-image,
[data-theme="light"] .customer-avatar.avatar-image {
  background: #eef2f3;
}

/* CRM 1.5.2: compact WhatsApp-style voice messages. */
.media-shell.voice-shell {
  width: min(360px, 68vw);
  min-width: 290px;
  max-width: 100%;
  overflow: visible;
  border-radius: 12px;
  background: transparent;
}

.voice-player {
  min-height: 62px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border: 1px solid #ffffff0d;
  border-radius: 12px;
  background: #ffffff09;
}

.voice-play,
.voice-speed {
  border: 0;
  color: inherit;
}

.voice-play {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  background: var(--green);
  color: #05251d;
  box-shadow: none;
}

.voice-play:hover:not(:disabled) {
  background: #20c7a2;
}

.voice-play-icon {
  display: block;
  margin-left: 2px;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

.voice-player.playing .voice-play-icon {
  margin-left: 0;
  font-size: 14px;
  letter-spacing: -3px;
}

.voice-content {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.voice-track {
  height: 30px;
  position: relative;
  display: flex;
  align-items: center;
}

.voice-waveform {
  width: 100%;
  height: 24px;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  color: #91a3a8;
  pointer-events: none;
}

.voice-waveform i {
  width: 2px;
  min-width: 2px;
  border-radius: 2px;
  background: currentColor;
}

.voice-waveform .h2 { height: 5px; }
.voice-waveform .h3 { height: 8px; }
.voice-waveform .h4 { height: 11px; }
.voice-waveform .h5 { height: 14px; }
.voice-waveform .h6 { height: 18px; }
.voice-waveform .h7 { height: 22px; }

.voice-track progress {
  width: 100%;
  height: 3px;
  position: absolute;
  left: 0;
  bottom: 0;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  appearance: none;
}

.voice-track progress::-webkit-progress-bar {
  background: #ffffff24;
}

.voice-track progress::-webkit-progress-value {
  border-radius: 3px;
  background: var(--green);
}

.voice-track progress::-moz-progress-bar {
  border-radius: 3px;
  background: var(--green);
}

.voice-seek {
  width: 100%;
  height: 30px;
  position: absolute;
  inset: 0;
  margin: 0;
  cursor: pointer;
  opacity: 0;
}

.voice-seek:focus-visible {
  opacity: .12;
}

.voice-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
}

.voice-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-time {
  color: inherit;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.voice-speed {
  width: 34px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 14px;
  background: #ffffff0d;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.voice-speed:hover:not(:disabled) {
  background: #ffffff18;
  color: var(--ink);
}

.voice-audio {
  display: none;
}

.voice-error {
  border-color: #f15c6d66;
}

.voice-error .voice-waveform,
.voice-error .voice-info {
  color: #f58b97;
}

.message-row.outbound .voice-player {
  border-color: #a7dfd01f;
  background: #ffffff0b;
}

.message-row.outbound .voice-waveform {
  color: #a8d8cd;
}

[data-theme="light"] .voice-player {
  border-color: #dce3e5;
  background: #f6f8f8;
}

[data-theme="light"] .message-row.outbound .voice-player {
  border-color: #a9dacb;
  background: #cceee3;
}

[data-theme="light"] .voice-waveform {
  color: #84969b;
}

[data-theme="light"] .message-row.outbound .voice-waveform {
  color: #4b8f7e;
}

[data-theme="light"] .voice-track progress::-webkit-progress-bar {
  background: #9aabad52;
}

[data-theme="light"] .voice-speed {
  background: #dfe7e8;
  color: #54656b;
}

[data-theme="light"] .voice-speed:hover:not(:disabled) {
  background: #d2dddf;
  color: #26373c;
}

@media (max-width: 560px) {
  .media-shell.voice-shell {
    width: min(290px, 72vw);
    min-width: 235px;
  }

  .voice-player {
    grid-template-columns: 40px minmax(0, 1fr) 32px;
    gap: 7px;
    padding-inline: 7px;
  }

  .voice-play {
    width: 38px;
    height: 38px;
  }

  .voice-waveform i:nth-child(n+21) {
    display: none;
  }
}

/* Todo "no leido" usa un unico indicador azul compartido con el programa. */
.unread-badge {
  background: #2997ff;
  color: #fff;
  box-shadow: 0 0 0 2px rgb(41 151 255 / 14%);
}

.unread-badge.manual {
  min-width: 10px;
  width: 10px;
  height: 10px;
  padding: 0;
  background: #2997ff;
  box-shadow: 0 0 0 2px rgb(41 151 255 / 14%);
  font-size: 0;
}

/* La lista conserva su posicion cuando el polling reordena conversaciones. */
.conversation-list {
  overflow-anchor: none;
  scroll-behavior: auto;
}

/* La fecha y la hora siempre identifican el dia del ultimo mensaje. */
.conversation-meta {
  min-width: 68px;
}

.conversation-meta-top {
  align-items: center;
}

.conversation-date-time {
  display: grid;
  justify-items: end;
  gap: 2px;
  line-height: 1.05;
  white-space: nowrap;
}

.conversation-day {
  color: var(--ink);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .015em;
  text-transform: uppercase;
}

.conversation-clock {
  color: var(--muted);
  font-size: 10px;
}

[data-theme="light"] .conversation-day {
  color: #34484e;
}

/* El historial conserva el mensaje visible mientras llegan actualizaciones. */
.messages {
  overflow-anchor: none;
  scroll-behavior: auto;
}

/* Control FAKE: solo se renderiza para administradores. */
.privacy-toggle {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.privacy-toggle strong {
  min-width: 20px;
  color: inherit;
  font-size: 9px;
}

.privacy-toggle:hover {
  filter: brightness(1.08);
}

.privacy-toggle.active {
  border-color: #d4a72c;
  background: #3a3017;
  color: #ffdc73;
}

[data-theme="light"] .privacy-toggle {
  border-color: #d6dce0;
  background: #f5f7f8;
  color: #667781;
}

[data-theme="light"] .privacy-toggle.active {
  border-color: #d5a000;
  background: #fff4c7;
  color: #795d00;
}

/* El menu contextual sigue el tema activo. app.css conserva los valores
   historicos oscuros, por eso esta capa final debe definir fondo y texto
   juntos para evitar texto oscuro sobre un panel oscuro en modo claro. */
.chat-context-menu {
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--ink);
}

.chat-context-menu button {
  color: var(--ink);
}

.chat-context-menu button:hover,
.chat-context-menu button:focus-visible {
  background: var(--panel-3);
}

:root:not([data-theme="light"]) .chat-context-menu {
  border-color: #34424a;
  background: #233138;
  box-shadow: 0 8px 28px #000a;
}

:root:not([data-theme="light"]) .chat-context-menu button {
  color: #e9edef;
}

:root:not([data-theme="light"]) .chat-context-menu button:hover,
:root:not([data-theme="light"]) .chat-context-menu button:focus-visible {
  background: #34424a;
}

[data-theme="light"] .chat-context-menu {
  border-color: #d8e1e3;
  background: #ffffff;
  color: #111b21;
  box-shadow: 0 10px 32px rgb(49 80 90 / 20%);
}

[data-theme="light"] .chat-context-menu button {
  color: #111b21;
}

[data-theme="light"] .chat-context-menu button:hover,
[data-theme="light"] .chat-context-menu button:focus-visible {
  background: #f0f2f5;
}

[data-theme="light"] .chat-context-menu #supportMenuItem > svg {
  color: #6758d8;
}

[data-theme="light"] .chat-context-menu #markUnreadMenuItem > svg {
  color: #54656b;
}

/* Referencia manual para chats privados. */
.service-window {
  justify-content: center;
  background: transparent;
  white-space: nowrap;
}

.service-window:not(.reference-action) {
  cursor: default;
}

.service-window.reference-action {
  border-color: #31b89a;
  background: #103c33;
  color: #d9fdd3;
  cursor: pointer;
}

.service-window.reference-action:hover,
.service-window.reference-action:focus-visible {
  border-color: #5ee5c3;
  background: #155043;
}

.reference-dialog-panel {
  width: min(480px, 100%);
}

.reference-dialog-panel form {
  padding: 18px;
}

.reference-field {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 650;
}

.reference-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #40525c;
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--ink);
}

.reference-field small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
}

.reference-dialog-panel footer {
  display: grid;
  grid-template-columns: minmax(12px, 1fr) auto auto;
  align-items: center;
  gap: 9px;
  margin-top: 18px;
}

.reference-error {
  margin: 12px 0 0;
  padding: 9px 11px;
  border: 1px solid #713641;
  border-radius: 6px;
  background: #3c2228;
  color: #ffbbc3;
}

[data-theme="light"] .service-window.reference-action {
  border-color: #00a884;
  background: #e7f8f3;
  color: #006b57;
}

[data-theme="light"] .service-window.reference-action:hover,
[data-theme="light"] .service-window.reference-action:focus-visible {
  background: #d7f3eb;
}

[data-theme="light"] .reference-field input {
  border-color: #c8d2d8;
  background: #fff;
  color: #17242b;
}

[data-theme="light"] .reference-error {
  border-color: #f2aab3;
  background: #fff1f3;
  color: #9c2534;
}

/* Chat de voz compartido con WhatsApp Brain Academy. */
.voice-team-control {
  position: relative;
  flex: 0 0 auto;
}

.voice-team-button {
  min-width: 42px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
  position: relative;
}

.voice-team-button svg {
  width: 17px;
  height: 17px;
}

.voice-team-button:disabled {
  opacity: .72;
}

.voice-team-control.connected .voice-team-button {
  border-color: #2d6f62;
  background: #17352f;
  color: #a9d9ce;
}

.voice-team-control.active .voice-team-button {
  border-color: #21c063;
  background: #0c5336;
  color: #ecfff3;
  box-shadow: 0 0 0 2px rgb(33 192 99 / 14%);
}

/* Apagado debe verse apagado incluso cuando la sala de voz sigue conectada. */
.voice-team-control.muted .voice-team-button {
  border-color: #59666b;
  background: #242c2f;
  color: #89979c;
  box-shadow: none;
}

.voice-team-control.muted .voice-team-button::after {
  content: "";
  position: absolute;
  top: 17px;
  left: 8px;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 0 0 1px var(--panel-3);
  transform: rotate(-48deg);
  transform-origin: center;
  pointer-events: none;
}

.voice-team-control.speaking .voice-team-button {
  box-shadow: 0 0 0 4px rgb(33 192 99 / 20%);
  animation: crm-voice-speaking 900ms ease-in-out infinite alternate;
}

.voice-team-count {
  min-width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 9px;
  background: rgb(255 255 255 / 13%);
  color: inherit;
  font-size: 9px;
}

.voice-team-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d9a441;
}

.voice-team-control.connected .voice-team-dot {
  background: #53bdeb;
}

.voice-team-control.active .voice-team-dot {
  background: #5ff28e;
  box-shadow: 0 0 0 3px rgb(95 242 142 / 16%);
}

.voice-team-control.muted .voice-team-dot {
  background: #7b898e;
  box-shadow: none;
}

.voice-team-control.muted .voice-team-count {
  background: rgb(137 151 156 / 12%);
  color: #89979c;
}

.voice-engine-panel {
  display: none !important;
}

.voice-team-notice {
  position: fixed;
  left: 50%;
  bottom: 78px;
  z-index: 90;
  max-width: min(520px, calc(100vw - 30px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 6px;
  background: #f1f3f4;
  color: #111b21;
  box-shadow: 0 4px 20px #0008;
  font-weight: 600;
}

@keyframes crm-voice-speaking {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}

[data-theme="light"] .voice-team-button {
  border-color: #d4dde1;
  background: #f6f8f9;
  color: #54656b;
}

[data-theme="light"] .voice-team-control.connected .voice-team-button {
  border-color: #8ecfc0;
  background: #e8f6f2;
  color: #087c69;
}

[data-theme="light"] .voice-team-control.active .voice-team-button {
  border-color: #00a884;
  background: #d9fdd3;
  color: #075e54;
}

[data-theme="light"] .voice-team-control.muted .voice-team-button {
  border-color: #c7d0d4;
  background: #edf0f1;
  color: #75858b;
  box-shadow: none;
}

[data-theme="light"] .voice-team-control.muted .voice-team-button::after {
  box-shadow: 0 0 0 1px #edf0f1;
}

[data-theme="light"] .voice-team-count {
  background: rgb(0 80 65 / 10%);
}

@media (max-width: 1120px) {
  .voice-team-button > span {
    display: none;
  }
}
