:root {
  --accent: #2c4a6b;
  --accent-light: #e8edf2;
  --warning: #8a5a12;
  --warning-light: #fbf1e0;
  --danger: #ae2e26;
  --danger-light: #fbeceb;
  --border: rgba(40, 32, 10, 0.1);
  --border-strong: rgba(40, 32, 10, 0.18);
  --surface-0: #faf9f6;
  --surface-1: #ffffff;
  --surface-2: #f3f1ea;
  --text-primary: #14171c;
  --text-secondary: #746f62;
  --text-muted: #a39d8e;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 18, 0.05);
  --shadow-md: 0 12px 32px rgba(20, 20, 18, 0.1), 0 2px 6px rgba(20, 20, 18, 0.05);
  --font-serif: Georgia, "Times New Roman", serif;
}
* {
  box-sizing: border-box;
}
html {
  /* Sin esto, Safari/Chrome de iOS a veces infla el tamaño de fuente por su
     cuenta (su heurística de "auto text zoom") en layouts con position:fixed
     + flex como #login-screen -- el texto crece y se corta contra el borde
     de la pantalla mientras los botones se quedan con su tamaño/posición
     real, así que el tap no cae donde se ve el botón. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
  /* 100vh en Safari/Chrome de celular incluye el espacio detrás de la
       barra de direcciones -- el contenido de más abajo (el composer del
       chat) quedaba tapado por esa barra sin que hubiera scroll para
       alcanzarlo (overflow:hidden). 100dvh sí resta ese espacio; el 100vh
       de arriba queda como respaldo para navegadores viejos sin soporte. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--surface-0);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
#login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.brand-corner {
  position: fixed;
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 101;
  opacity: 0.8;
  pointer-events: none;
}
.brand-corner img {
  width: 14px;
  height: 14px;
  max-width: 14px;
  max-height: 14px;
  object-fit: contain;
  display: block;
  flex: none;
}
.brand-corner span {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0;
  color: var(--text-secondary);
  white-space: nowrap;
}
#login-card h1 {
  font-family: var(--font-serif);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}
#login-card p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 34px;
  line-height: 1.6;
}
#login-invite-note {
  font-size: 12.5px;
  color: var(--accent);
  margin: -20px 0 24px;
}
.field-underline {
  text-align: left;
  margin-bottom: 26px;
  position: relative;
}
.field-underline label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.field-underline input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px;
  padding: 6px 0 12px;
  outline: none;
}
.field-underline input::placeholder {
  color: var(--text-muted);
}
.field-underline .rule {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 1px;
  width: 0;
  background: var(--accent);
  transition: width 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.field-underline input:focus ~ .rule,
.field-underline.filled .rule {
  width: 100%;
}
.btn {
  height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0 16px;
  color: var(--text-primary);
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.05s;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.btn:active {
  transform: scale(0.98);
}
#login-request-btn,
#login-verify-btn {
  width: 100%;
  border: none;
  background: var(--text-primary);
  color: #fff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 15px;
  border-radius: 2px;
  cursor: pointer;
  transition:
    background 0.18s ease,
    transform 0.12s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#login-request-btn:hover,
#login-verify-btn:hover {
  background: var(--accent);
}
#login-request-btn:active,
#login-verify-btn:active {
  transform: scale(0.98);
}
#login-request-btn:disabled,
#login-verify-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}
#login-error,
#login-code-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 14px;
  min-height: 14px;
  text-align: left;
}
.login-link-btn {
  background: none;
  border: none;
  padding: 0;
  margin-top: 18px;
  width: auto;
  height: auto;
  display: block;
  font-size: 12.5px;
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font-family: inherit;
}
.login-link-btn:hover {
  color: var(--text-primary);
  background: none;
}
#login-code {
  font-family: var(--font-serif);
  font-size: 30px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  text-align: center;
}

.btn-primary {
  background: var(--text-primary);
  color: #fff;
  border: none;
}
.btn-primary:hover {
  background: #000;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#onboarding-screen {
  position: fixed;
  inset: 0;
  background: var(--surface-0);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
#onboarding-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
#onboarding-header h1 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
#onboarding-header p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 20px;
  line-height: 1.5;
}
.onboarding-dots {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 28px;
}
.onboarding-dot {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  transition: background 0.2s;
}
.onboarding-dot.active {
  background: var(--accent);
}
.onboarding-dot.done {
  background: var(--accent);
  opacity: 0.5;
}
.onboarding-step h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.onboarding-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 20px;
}
.onboarding-step label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin: 14px 0 6px;
}
.onboarding-step input,
.onboarding-step textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  background: var(--surface-0);
  font-family: inherit;
}
.onboarding-step input:focus,
.onboarding-step textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-1);
}
.onboarding-step textarea {
  resize: vertical;
}
.onboarding-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}
.onboarding-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.ob-test-result {
  font-size: 12px;
  margin-top: 10px;
  min-height: 14px;
  line-height: 1.4;
}
.ob-test-result.ok {
  color: var(--accent);
}
.ob-test-result.error {
  color: var(--danger);
}
.ob-upload-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.ob-upload-box input[type="file"] {
  flex: 1;
  min-width: 180px;
  font-size: 12px;
}

#app {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#incident-banner {
  flex-shrink: 0;
  background: #fbe9e7;
  color: #8a1c10;
  border-bottom: 1px solid #f1c3bd;
  padding: 8px 20px;
  font-size: 13px;
}
#incident-banner.warning {
  background: var(--warning-light);
  color: var(--warning);
  border-bottom-color: var(--warning);
}
#incident-banner .incident-item + .incident-item {
  margin-top: 4px;
}

#topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}
#brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
#brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#brand-icon i {
  font-size: 16px;
  color: white;
}
#brand-name {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
#topbar-section-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
#account-menu {
  position: relative;
}
#avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
#avatar-btn:hover {
  border-color: var(--border-strong);
}
.account-dropdown {
  position: absolute;
  top: 40px;
  right: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px;
  min-width: 170px;
  z-index: 50;
}
.account-dropdown .account-email {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-dropdown button {
  border: none;
  width: 100%;
  text-align: left;
}

#view-perfil {
  flex-direction: row;
  background: var(--surface-0);
  overflow: hidden;
}
#perfil-sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 24px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface-1);
  overflow-y: auto;
}
.perfil-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  transition:
    background 0.12s,
    color 0.12s;
}
.perfil-nav-item i {
  font-size: 15px;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.12s,
    color 0.12s;
}
.perfil-nav-item:hover {
  background: var(--surface-2);
}
.perfil-nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}
.perfil-nav-item.active i {
  background: var(--accent);
  color: white;
}
#perfil-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  width: 100%;
  min-height: 0;
}
.perfil-section {
  display: none;
}
.perfil-section.active {
  display: block;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  align-items: start;
  max-width: 900px;
}
.settings-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings-side .settings-card {
  max-width: 100%;
  margin-bottom: 0;
}
.settings-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}
.settings-card h3 {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.settings-card .settings-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 18px;
  line-height: 1.5;
}
.settings-card label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin: 14px 0 6px;
}
.settings-card input,
.settings-card textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
  background: var(--surface-0);
  resize: vertical;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.settings-card input:focus,
.settings-card textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-1);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}
.settings-save-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}
.preview-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}
.preview-bubble {
  background: var(--accent-light);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
}
.tone-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.tone-option {
  flex: 1;
  min-width: 100px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface-1);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  transition:
    border-color 0.15s,
    color 0.15s,
    background 0.15s;
}
.tone-option:hover {
  border-color: var(--border-strong);
}
.tone-option.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.color-swatches {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
  transition:
    transform 0.1s,
    box-shadow 0.15s;
}
.color-swatch:hover {
  transform: scale(1.1);
}
.color-swatch.active {
  box-shadow:
    0 0 0 2px var(--surface-1),
    0 0 0 4px var(--accent);
}
.color-swatch-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}
.color-swatch-custom input[type="color"] {
  width: 28px;
  height: 28px;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--border);
}
.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.summary-row:last-child {
  margin-bottom: 0;
}
.summary-row .label {
  font-size: 12px;
  color: var(--text-secondary);
}
.summary-row .value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.settings-msg {
  font-size: 12px;
  min-height: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}
.settings-msg.success {
  color: #16a34a;
}
.settings-msg.error {
  color: var(--danger);
}
.kb-doc-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.kb-doc-row:last-child {
  border-bottom: none;
}
.kb-doc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.kb-doc-name {
  font-size: 13px;
  font-weight: 500;
  word-break: break-word;
}
.kb-doc-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.kb-doc-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.kb-doc-view {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
}
.kb-doc-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
}
.kb-doc-content {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-0);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  max-height: 260px;
  overflow-y: auto;
}
.kb-chunk {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  white-space: pre-wrap;
  line-height: 1.5;
}
.kb-chunk:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.kb-chunk-index {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}

#agent-control-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-shrink: 0;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px var(--accent-light);
}
.status-dot.paused {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-light);
}
#agent-toggle-text {
  flex: 1;
}
#agent-toggle-label {
  font-size: 13px;
  font-weight: 600;
}
#agent-toggle-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.switch {
  width: 44px;
  height: 26px;
  border-radius: 13px;
  border: 1px solid var(--border);
  position: relative;
  padding: 0;
  cursor: pointer;
  background: var(--surface-2);
  transition:
    background 0.2s,
    border-color 0.2s;
  flex-shrink: 0;
}
.switch.active {
  background: var(--accent);
  border-color: var(--accent);
}
.switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: left 0.2s;
  box-shadow: var(--shadow-sm);
}
.switch.active .knob {
  left: 20px;
}

#metrics {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-shrink: 0;
}
.metric-strip {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.metric-cell {
  flex: 1;
  min-width: 110px;
  padding: 10px 16px;
  border-right: 1px solid var(--border);
}
.metric-cell:last-child {
  border-right: none;
}
.metric-cell .lbl {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.metric-cell .lbl i {
  font-size: 12px;
}
.metric-cell .val {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.01em;
}
.metric-card {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 110px;
  flex: 1;
}
.metric-card .label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.metric-card .value {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.01em;
}
.metrics-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.usage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 4px;
}
.usage-grid .metric-card {
  min-width: 0;
}
.settings-card h3.with-icon {
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-card h3.with-icon i {
  font-size: 16px;
  color: var(--accent);
}
.usage-row-list {
  margin-top: 4px;
}
.usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.usage-row:last-child {
  border-bottom: none;
}
.usage-row .k {
  font-size: 12px;
  color: var(--text-secondary);
}
.usage-row .v {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}
.usage-row .v.accent {
  color: var(--accent);
}
.usage-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 18px;
}
.usage-filters label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}
.usage-filters select {
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  padding: 0 10px;
  font-size: 13px;
  color: var(--text-primary);
}

#view-analitica {
  overflow-y: auto;
  padding: 20px;
  display: block;
}
.report-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  max-width: 900px;
}
.report-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.report-kpi {
  padding: 14px 18px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.report-kpi:last-child {
  border-right: none;
}
.report-kpi .lbl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.report-kpi .val {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.01em;
}
.report-section {
  padding: 18px;
  border-bottom: 1px solid var(--border);
}
.report-section:last-child {
  border-bottom: none;
}
.report-section h3 {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 4px;
}
.report-split {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
}
.report-split > div {
  flex: 1;
  min-width: 240px;
}
.report-footer {
  display: flex;
  flex-wrap: wrap;
}
.report-footer-item {
  flex: 1;
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-right: 1px solid var(--border);
}
.report-footer-item:last-child {
  border-right: none;
}
.report-footer-item i {
  font-size: 18px;
  color: var(--accent);
  flex-shrink: 0;
}
.report-footer-item .val {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
}
.report-footer-item .lbl {
  font-size: 11px;
  color: var(--text-secondary);
}
.funnel-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.funnel-bar-label {
  font-size: 12px;
  color: var(--text-secondary);
  width: 110px;
  flex-shrink: 0;
}
.funnel-bar-track {
  flex: 1;
  height: 10px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}
.funnel-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
}
/* Umbrales de consumo del plan (cláusula 4.9: aviso al 80% y al 100%) */
.funnel-bar-fill.warn {
  background: var(--warning);
}
.funnel-bar-fill.crit {
  background: var(--danger);
}
.funnel-bar-count {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  width: 30px;
  text-align: right;
  flex-shrink: 0;
}
.area-chart-wrap {
  margin-top: 14px;
}
.area-chart-wrap svg {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}
.area-chart-wrap .grid-line {
  stroke: var(--border);
  stroke-width: 1;
}
.area-chart-wrap .axis-label {
  font-size: 10px;
  fill: var(--text-muted);
}
.area-chart-wrap .day-label {
  font-size: 10px;
  fill: var(--text-muted);
  text-anchor: middle;
}
.area-chart-wrap .value-label {
  font-size: 10px;
  fill: var(--text-secondary);
  font-weight: 600;
  text-anchor: middle;
}
.area-chart-wrap .chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.area-chart-wrap .chart-dot {
  fill: var(--accent);
}
.area-chart-empty {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 14px;
  background: var(--surface-0);
  border-radius: var(--radius);
}

#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#sidebar {
  width: 300px;
  border-right: 1px solid var(--border);
  background: var(--surface-1);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#search-box {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
#search-input {
  width: 100%;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0 12px;
  font-size: 13px;
  background: var(--surface-0);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-1);
}
#filter-chips {
  display: flex;
  gap: 6px;
  padding: 0 12px 12px;
  flex-wrap: wrap;
}
.filter-chip {
  font-size: 11px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s;
}
.filter-chip:hover {
  background: var(--surface-2);
}
.filter-chip.active {
  background: var(--text-primary);
  color: white;
  border-color: var(--text-primary);
}
.filter-chip .count {
  font-weight: 700;
}
.filter-chip i {
  font-size: 13px;
}
.filter-chip.pending:not(.active) {
  border-color: var(--warning);
  color: var(--warning);
  background: var(--warning-light);
}
.filter-chip.unread:not(.active) {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-light);
}
.conv-unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}
#conv-list {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  border-left: 2px solid transparent;
  transition: background 0.12s;
}
.conv-item:hover {
  background: var(--surface-2);
}
.conv-item.active {
  background: var(--accent-light);
  border-left-color: var(--accent);
}
.conv-item.pending_handoff {
  border-left-color: var(--warning);
  background: var(--warning-light);
}
.conv-item.pending_handoff.active {
  background: var(--accent-light);
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.conv-info {
  flex: 1;
  min-width: 0;
}
.conv-name-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.conv-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.conv-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.conv-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-block;
  margin-top: 6px;
}
.badge.bot_active {
  background: var(--accent-light);
  color: var(--accent);
}
.badge.pending_handoff {
  background: var(--warning-light);
  color: var(--warning);
}
.badge.human_active {
  background: #eaf1fb;
  color: #1a5aa8;
}
.badge.is-client {
  background: #e6f4ea;
  color: #1e7e34;
}
.waiting-tag {
  font-size: 10px;
  font-weight: 600;
  color: var(--warning);
  margin-top: 6px;
}

#thread-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface-0);
}
#thread-header {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  background: var(--surface-1);
  flex-shrink: 0;
}
#thread-header .name {
  font-size: 13px;
  font-weight: 600;
}
#thread-header .phone {
  font-size: 12px;
  color: var(--text-secondary);
}
#thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  flex-shrink: 0;
}
#composer-input {
  flex: 1;
  height: 40px;
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 0 16px;
  font-size: 13px;
  background: var(--surface-0);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
#composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-1);
}
#composer-send-btn {
  background: var(--text-primary);
  color: white;
  border: none;
  font-weight: 500;
  border-radius: 20px;
  padding: 0 20px;
}
#composer-send-btn:hover {
  background: #000;
}
.msg-group {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}
.msg-group.inbound {
  align-self: flex-start;
  align-items: flex-start;
}
.msg-group.outbound_bot,
.msg-group.outbound_human {
  align-self: flex-end;
  align-items: flex-end;
}
.msg-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  padding: 0 2px;
}
.msg {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.inbound {
  background: var(--surface-1);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.msg.outbound_bot {
  background: var(--surface-1);
  border: 1px dashed var(--border-strong);
  color: var(--text-primary);
}
.msg.outbound_human {
  background: var(--text-primary);
  color: white;
}
.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}
.msg.outbound_human .msg-time {
  color: rgba(255, 255, 255, 0.65);
}
.rag-context-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
  margin-top: 2px;
}
.rag-context-toggle:hover {
  color: var(--text-secondary);
}
.rag-context-box {
  max-width: 320px;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  line-height: 1.4;
}
#empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}
#banner {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px;
  display: none;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

#tabs {
  display: flex;
  gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-shrink: 0;
}
.tab {
  background: none;
  border: none;
  padding: 14px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}
.tab:hover {
  color: var(--text-primary);
}
.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}
.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: 6px 2px;
  color: var(--text-muted);
  cursor: pointer;
}
.mobile-nav-item i {
  font-size: 20px;
}
.mobile-nav-item span {
  font-size: 10px;
  font-weight: 500;
}
.mobile-nav-item.active {
  color: var(--accent);
}
.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.placeholder-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 40px;
  gap: 6px;
}
.placeholder-view strong {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.btn-accent {
  background: var(--text-primary);
  color: white;
  border: none;
  font-weight: 500;
}
.btn-accent:hover {
  background: #000;
}

#directorio-toolbar,
#cal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  background: var(--surface-1);
}
#client-search-input {
  width: 260px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0 12px;
  font-size: 13px;
  background: var(--surface-0);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
#client-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-1);
}
#client-table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  background: var(--surface-1);
}
#client-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#client-table th {
  text-align: left;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
#client-table td {
  padding: 14px 8px;
  border-bottom: 1px solid var(--border);
}
#client-table tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}
#client-table tbody tr:hover {
  background: var(--surface-0);
}

#prospectos-toolbar {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface-1);
}
#prospect-table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  background: var(--surface-1);
}
#prospect-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#prospect-table th {
  text-align: left;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
#prospect-table td {
  padding: 14px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
#prospect-table td.interest-cell {
  max-width: 220px;
}
.prospect-interest-input {
  width: 100%;
  font-size: 13px;
  padding: 6px 8px;
  border: 0.5px solid var(--border, #ddd);
  border-radius: 6px;
  background: var(--surface-1, #fff);
}
.interest-original {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#prospect-table td.urgency-cell {
  max-width: 140px;
}
.prospect-urgency-select {
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 8px;
  border: 0.5px solid var(--border, #ddd);
  border-radius: 6px;
  background: var(--surface-1, #fff);
  color: var(--text-secondary);
}
.prospect-urgency-select.urgency-alta {
  color: var(--danger);
  background: var(--danger-light);
  border-color: transparent;
}
.prospect-urgency-select.urgency-media {
  color: var(--warning);
  background: var(--warning-light);
  border-color: transparent;
}
.prospect-urgency-select.urgency-baja {
  color: var(--text-secondary);
  background: var(--surface-2);
  border-color: transparent;
}
.prospect-actions,
.client-actions {
  display: flex;
  gap: 6px;
}

.tipo-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-block;
}
.tipo-badge.auto {
  background: #eaf1fb;
  color: #1a5aa8;
}
.tipo-badge.gmm {
  background: var(--accent-light);
  color: var(--accent);
}
.tipo-badge.vida {
  background: #fbeaf1;
  color: #a13d63;
}
.tipo-badge.hogar {
  background: var(--warning-light);
  color: var(--warning);
}
.tipo-badge.pyme {
  background: #eeecfb;
  color: #4c3fa8;
}
.tipo-badge.otro {
  background: var(--surface-2);
  color: var(--text-secondary);
}

.client-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
}
.client-name-cell {
  display: flex;
  align-items: center;
}
.expiry-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-block;
  background: var(--warning-light);
  color: var(--warning);
}
.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn.danger {
  color: var(--danger);
}
.icon-btn.danger:hover {
  background: var(--danger-light);
}
.add-column-th {
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}
.add-column-th:hover {
  text-decoration: underline;
}
.col-del-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}
.col-del-btn:hover {
  color: var(--danger);
  background: var(--danger-light);
}
.add-field-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.add-field-link:hover {
  text-decoration: underline;
}
.add-field-link i {
  font-size: 12px;
}

#cal-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface-1);
}
#cal-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  font-weight: 600;
}
.cal-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 28px;
  height: 28px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}
.cal-nav-btn:hover {
  background: var(--surface-2);
}
#cal-grid-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--surface-0);
}
#cal-daylabels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
#cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  min-height: 76px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  font-size: 11px;
  cursor: pointer;
  transition:
    box-shadow 0.12s,
    border-color 0.12s;
}
.cal-cell:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border-strong);
}
.cal-cell.empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
  box-shadow: none;
}
.cal-cell.empty:hover {
  box-shadow: none;
  border-color: transparent;
}
.cal-cell.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.cal-cell .day-num {
  font-weight: 600;
  margin-bottom: 3px;
}
.cal-cell.today .day-num {
  color: var(--accent);
}
.cal-cell .appt-chip {
  font-size: 9.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-light);
  border-radius: 4px;
  padding: 1px 4px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-view-btn {
  background: none;
  border: none;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  border-right: 1px solid var(--border);
}
.cal-view-btn:last-child {
  border-right: none;
}
.cal-view-btn:hover {
  background: var(--surface-2);
}
.cal-view-btn.active {
  background: var(--surface-2);
  color: var(--text-primary);
}

#cal-week-wrap {
  display: flex;
  flex-direction: column;
}
.cal-week-headerrow {
  display: flex;
  position: sticky;
  top: 0;
  background: var(--surface-0);
  z-index: 1;
}
.cal-week-gutter {
  width: 48px;
  flex-shrink: 0;
}
.cal-week-daylabel {
  flex: 1;
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-bottom: 8px;
}
.cal-week-daylabel span {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: none;
  margin-top: 2px;
}
.cal-week-daylabel.today span {
  color: var(--accent);
}
.cal-week-body {
  display: flex;
}
.cal-week-gutter-col {
  width: 48px;
  flex-shrink: 0;
}
.cal-hour-label {
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
  padding-right: 6px;
  box-sizing: border-box;
  transform: translateY(-6px);
}
.cal-week-cols {
  display: flex;
  flex: 1;
}
.cal-week-daycol {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--border) 0,
    var(--border) 1px,
    transparent 1px,
    transparent var(--cal-rowh, 48px)
  );
  cursor: pointer;
}
.cal-week-daycol.today {
  background-color: var(--accent-light);
}
.cal-week-event {
  position: absolute;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 10.5px;
  font-weight: 500;
  overflow: hidden;
  box-sizing: border-box;
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.3;
}
.cal-week-event:hover {
  border-color: var(--accent);
}
.cal-week-event.conflict {
  background: var(--danger-light, #fde2e2);
  color: var(--danger, #c0392b);
}
.cal-week-event-time {
  display: block;
  font-weight: 600;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 18, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 360px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}
.modal label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin: 12px 0 6px;
}
.modal input,
.modal select,
.modal textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
  background: var(--surface-0);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.modal input:focus,
.modal select:focus,
.modal textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-1);
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 22px;
  align-items: center;
}

/* --- Responsivo (tablet / celular) --- */
#mobile-bottom-nav {
  display: none;
}
#back-to-list-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}
#tabs {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  white-space: nowrap;
  flex-shrink: 0;
}
#client-table-wrap,
#cal-grid-wrap,
#prospect-table-wrap {
  overflow-x: auto;
}

@media (max-width: 860px) {
  #sidebar {
    width: 260px;
  }
}

@media (max-width: 1000px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  #main {
    position: relative;
  }
  #thread-panel {
    display: none;
  }
  #main.mobile-thread-active #sidebar {
    display: none;
  }
  #main.mobile-thread-active #thread-panel {
    display: flex;
  }
  #back-to-list-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #sidebar {
    width: 100%;
  }
  #directorio-toolbar,
  #cal-toolbar {
    flex-wrap: wrap;
  }
  #client-search-input {
    width: 100%;
  }
  #cal-nav {
    width: 100%;
    justify-content: space-between;
  }
  #client-table {
    min-width: 700px;
  }
  #prospect-table {
    min-width: 740px;
  }
  #cal-daylabels,
  #cal-grid {
    min-width: 480px;
  }
  .settings-card {
    max-width: 100%;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
  #view-perfil {
    flex-direction: column;
  }
  #perfil-sidebar {
    width: 100%;
    display: flex;
    gap: 6px;
    padding: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .perfil-nav-item {
    width: auto;
    white-space: nowrap;
    flex-shrink: 0;
  }
  #perfil-content {
    padding: 20px 16px;
  }
  #onboarding-card {
    padding: 24px 20px;
  }

  /* Nav inferior de pulgar en vez del menú de tabs de arriba -- ver
       #mobile-bottom-nav más abajo y showTab() en el JS, que mantiene
       ambos en sync. padding-bottom en #app dado por env(safe-area-inset-bottom)
       para no quedar debajo de la barra de gestos de iOS. */
  #tabs {
    display: none;
  }

  /* La franja de métricas (Conversaciones/Nuevas hoy/etc.) usa
       flex-wrap con border-right entre celdas -- a 390px de ancho no caben
       las 5 celdas de min-width:110px, así que envuelven a una segunda
       fila con los bordes verticales originales, dejando costuras
       chuecas ("todo movido"). En vez de envolver, se vuelve una tira
       horizontal deslizable (mismo patrón que #tabs arriba). */
  .metric-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .metric-cell {
    min-width: 128px;
    flex: 0 0 auto;
  }

  #cal-metrics {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .metric-card {
    flex-shrink: 0;
  }
  #app {
    padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  }
  #mobile-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 8px rgba(20, 20, 18, 0.06);
  }
  body.mobile-thread-open #mobile-bottom-nav {
    display: none;
  }
  body.mobile-thread-open #app {
    padding-bottom: 0;
  }
}

@media (max-width: 480px) {
  #topbar,
  #agent-control-bar,
  #metrics,
  #directorio-toolbar,
  #cal-toolbar,
  #cal-metrics,
  #tabs {
    padding-left: 14px;
    padding-right: 14px;
  }
  #topbar-section-label {
    display: none;
  }
  #agent-toggle-desc {
    display: none;
  }
  .modal {
    width: 92vw;
    padding: 20px;
  }
}
