/* ============================================================
   Zonna Flow Design System — Inter + blue palette
   ============================================================ */

:root {
  /* Superficie */
  --bg: #f8faff;
  --bg-soft: #ffffff;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --panel-3: #f1f5f9;

  /* Bordes */
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  /* Texto */
  --text: #0f172a;
  --muted: #475569;
  --soft: #94a3b8;

  /* Color primario: azul profundo */
  --primary: #1e40af;
  --primary-2: #1e3a8a;
  --primary-light: #eff6ff;
  --primary-mid: #dbeafe;

  /* Semánticos */
  --success: #059669;
  --success-dim: rgba(5, 150, 105, 0.12);
  --danger: #dc2626;
  --danger-dim: rgba(220, 38, 38, 0.1);
  --warning: #d97706;
  --warning-dim: rgba(217, 119, 6, 0.12);
  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.12);

  /* Layout */
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.1), 0 4px 8px rgba(15, 23, 42, 0.06);

  /* Tipografía */
  --ff: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --ff-display: "Space Grotesk", "Inter", ui-sans-serif, system-ui, sans-serif;
  --ff-mono: "DM Mono", ui-monospace, monospace;
  --ff-cond: "Space Grotesk", "Inter", sans-serif;

  /* Aliases legacy (compatibilidad con código existente) */
  --paper: var(--bg);
  --paper2: var(--bg-soft);
  --paper3: var(--panel-3);
  --ink: var(--text);
  --ink2: #1e293b;
  --ink3: var(--muted);
  --ink4: var(--soft);
  --rule: var(--line);
  --rule2: var(--line-strong);
  --press: var(--primary);
  --press-dim: var(--primary-light);
  --green: var(--success);
  --green-dim: var(--success-dim);
  --amber: var(--warning);
  --amber-dim: var(--warning-dim);
  --blue: #1e40af;
  --blue-dim: rgba(30, 64, 175, 0.1);

  font-family: var(--ff);
  font-size: 13px;
}

/* ============================================================
   Reset & base
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff);
  font-size: 13px;
  line-height: 1.5;
  animation: zfFadeIn 0.2s ease both;
}

body[data-route="landing"],
body[data-route="login"] {
  background: #ffffff;
}

@keyframes zfFadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: var(--ff-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

h2 {
  font-family: var(--ff-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

h3 {
  font-family: var(--ff-display);
  font-size: 13px;
  font-weight: 600;
}

/* ============================================================
   Typography utilities
   ============================================================ */

.eyebrow {
  color: var(--muted);
  font-family: var(--ff-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 0;
}

/* ============================================================
   Page routing
   ============================================================ */

.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: block;
}

body[data-route='landing'] .page-landing,
body[data-route='login'] .page-login,
body[data-route='app'] .page-app {
  display: block;
}

body[data-route='landing'] .page-login,
body[data-route='landing'] .page-app,
body[data-route='login'] .page-landing,
body[data-route='login'] .page-app,
body[data-route='app'] .page-landing,
body[data-route='app'] .page-login {
  display: none;
}

/* ============================================================
   Buttons
   ============================================================ */

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--ff);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
  box-shadow: 0 2px 8px rgba(8, 145, 178, 0.3);
}

.button.secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
}

.button.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.button.ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ============================================================
   App shell layout
   ============================================================ */

.shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 200px minmax(0, 1fr);
}

.page-app .shell {
  grid-template-columns: 200px minmax(0, 1fr);
  min-height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  width: 200px;
  min-width: 200px;
  background: linear-gradient(180deg, #0f172a 0%, #131d33 100%);
  border-right: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-app {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  text-decoration: none;
  border-bottom: 1px solid #1e293b;
  margin-bottom: 8px;
}

.brand-mark {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  object-fit: contain;
}

/* El logotipo ya incluye el nombre: nunca lleva texto "Zonna Flow" al lado. */
.brand-logo {
  display: block;
  height: 34px;
  width: auto;
  flex-shrink: 0;
}

/* El isotipo tiene versión clara y oscura; se elige según el fondo del sidebar. */
.brand-mark-on-light {
  display: none;
}

/* Fallback si se usara como texto en lugar de <img> */
div.brand-mark {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0891b2 0%, #6366f1 100%);
  color: #ffffff;
  font-family: var(--ff);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.brand strong {
  font-family: var(--ff-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.4px;
}

.brand span {
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-top: 1px;
}

/* Sidebar oscura: marca y textos en claro */
.sidebar .brand strong {
  color: #f1f5f9;
}

.sidebar .brand span,
.sidebar-panel p:last-child {
  color: #94a3b8;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 4px 0;
}

.nav-group-label {
  padding: 12px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #64748b;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 16px);
  margin: 1px 8px;
  padding: 7px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #cbd5e1;
  font-family: var(--ff);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.nav-item[hidden],
.nav-group-label[hidden],
#console-switch-link[hidden],
.sidebar-console-switch[hidden] {
  display: none;
}

.nav-item:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #ffffff;
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(8, 145, 178, 0.25), rgba(99, 102, 241, 0.25));
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--primary);
}

.nav-item i {
  font-size: 15px;
  opacity: 0.7;
}

.nav-item.active i {
  opacity: 1;
  color: #22d3ee;
}

.sidebar-console-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  width: calc(100% - 24px);
  margin: 0 12px 8px;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(8, 145, 178, 0.14);
  color: #e0f2fe;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.sidebar-console-switch:hover {
  background: rgba(34, 211, 238, 0.2);
  color: #ffffff;
}

.sidebar-panel {
  margin: auto 14px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-3);
  padding: 10px;
}

.console-mode-card {
  margin: 0 12px 8px;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
}

.console-mode-card strong {
  display: block;
  margin-top: 4px;
  color: #ffffff;
  font-family: var(--ff-display);
  font-size: 14px;
}

.console-mode-card span {
  display: block;
  margin-top: 4px;
  color: #aebbd0;
  font-size: 12px;
  line-height: 1.45;
}

.sidebar-panel p:last-child {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ============================================================
   Main content area
   ============================================================ */

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 24px 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 0 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  margin-bottom: 20px;
}

.topbar-copy {
  display: grid;
  gap: 4px;
}

.topbar-copy h1 {
  font-family: var(--ff-display);
  font-size: 20px;
  font-weight: 700;
  margin: 4px 0 0;
  letter-spacing: -0.4px;
}

.topbar-copy-text {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
  max-width: 760px;
  line-height: 1.5;
}

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

.tenant-context-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -6px 0 18px;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius);
  background: #f8fafc;
  color: #334155;
}

.tenant-context-bar[hidden] {
  display: none;
}

.tenant-context-bar.is-operating {
  border-color: #99f6e4;
  background: #ecfdf5;
}

.tenant-context-bar strong,
.tenant-context-bar span {
  display: block;
}

.tenant-context-bar strong {
  margin-top: 2px;
  color: #0f172a;
}

.tenant-context-bar span {
  margin-top: 3px;
  color: #64748b;
  font-size: 12px;
}

.tenant-context-select {
  display: grid;
  gap: 4px;
  min-width: min(320px, 100%);
  color: #475569;
  font-size: 12px;
  font-weight: 600;
}

.tenant-context-select select {
  min-height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 0 10px;
  color: #0f172a;
}

/* Impersonation banner (ADR-046 Fase 3) */
.tenant-context-bar.is-impersonating {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #78350f;
}

.tenant-context-bar.is-impersonating .impersonation-copy {
  flex: 1;
}

.tenant-context-bar.is-impersonating .impersonation-copy strong {
  display: block;
  color: #78350f;
}

.tenant-context-bar.is-impersonating .impersonation-copy span {
  display: block;
  margin-top: 2px;
  color: #92400e;
  font-size: 12px;
}

.impersonation-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f59e0b;
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}

/* ============================================================
   Auth
   ============================================================ */

.auth-status {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 12px;
}

.auth-panel {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  margin-bottom: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.auth-panel.active {
  display: flex;
}

#auth-panel {
  display: none;
}

#auth-panel.active {
  display: flex;
}

/* ============================================================
   Metrics
   ============================================================ */

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.metric strong {
  display: block;
  margin-bottom: 5px;
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
  color: var(--text);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.metric small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
  text-transform: uppercase;
}

/* ============================================================
   Views
   ============================================================ */

.view {
  display: none;
}

.view.active {
  display: block;
  animation: zfFadeIn 0.18s ease both;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 18px;
  align-items: start;
}

/* View tabs (Runtime y otras vistas con sub-secciones) */
.view-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.view-tab {
  appearance: none;
  border: none;
  background: transparent;
  padding: 9px 16px;
  margin-bottom: -1px;
  font-family: var(--ff-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
}

.view-tab:hover {
  color: var(--text);
}

.view-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tabpanel[hidden] {
  display: none;
}

/* ============================================================
   Conversaciones (bandeja + transcript)
   ============================================================ */

.conversations-layout {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  height: calc(100vh - 150px);
}

.conversations-list-panel,
.conversations-detail-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.conversations-search {
  width: 160px;
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

#conversations-list {
  overflow-y: auto;
  flex: 1;
}

.conv-filters {
  display: flex;
  gap: 6px;
  padding: 0 14px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.conv-filter {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.conv-filter span {
  color: var(--soft);
  margin-left: 4px;
}

.conv-filter.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-2);
}

.conv-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  transition: background 0.12s;
}

.conv-row:hover {
  background: var(--panel-3);
}

.conv-row.active {
  background: var(--primary-light);
  box-shadow: inset 3px 0 0 var(--primary);
}

.conv-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.conv-row-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-row-time {
  font-size: 11px;
  color: var(--soft);
  flex-shrink: 0;
}

.conv-row-preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.conv-row-meta .conv-agent {
  font-size: 10px;
  padding: 1px 7px;
}

.conv-channel {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--soft);
}

.conv-tenant {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 7px;
  border-radius: 20px;
  margin-left: auto;
}

.conv-mode {
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
}

.conv-mode-manual {
  background: var(--warning-dim);
  color: var(--warning);
}

.conv-mode-bot {
  background: var(--success-dim);
  color: var(--success);
}

.conv-row-owner {
  color: var(--soft);
  font-size: 11px;
  margin-top: 2px;
}

.conversations-detail-panel {
  padding: 0;
  overflow: hidden;
}

#conversations-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.conv-placeholder {
  display: grid;
  gap: 6px;
  place-items: center;
  align-content: center;
  height: 100%;
  min-height: 200px;
  padding: 40px;
  color: var(--soft);
  font-size: 13px;
  text-align: center;
}

.conv-placeholder strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.conv-placeholder span {
  max-width: 280px;
  color: var(--muted);
  line-height: 1.45;
}

.conv-detail-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.conv-detail-actions select {
  min-width: 160px;
}

.conv-workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
}

.conv-chat-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.conv-context {
  overflow-y: auto;
  padding: 14px;
  background: #f8fafc;
}

.conv-context-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px;
}

.conv-context-card + .conv-context-card {
  margin-top: 10px;
}

.conv-context-card strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
}

.conv-context-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.conv-context-card.is-ok {
  border-color: rgba(22, 163, 74, 0.28);
  background: #f0fdf4;
}

.conv-context-card.is-warning {
  border-color: rgba(217, 119, 6, 0.28);
  background: #fffbeb;
}

.conv-context-card textarea {
  width: 100%;
  min-height: 78px;
  margin-top: 8px;
  resize: vertical;
}

.conv-context-card #conv-add-note {
  width: 100%;
  margin-top: 8px;
}

.conv-internal-notes {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.conv-internal-note {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.conv-internal-note strong,
.conv-internal-note span {
  display: inline;
  margin: 0;
}

.conv-internal-note p {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.conv-context-mode.manual {
  color: var(--warning);
}

.conv-context-mode.bot {
  color: var(--success);
}

.conv-context-actions {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.conv-reply {
  display: grid;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
}

.conv-reply-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.conv-reply textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: vertical;
}

.conv-quick-replies {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.conv-quick-reply {
  flex: 0 0 auto;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.conv-quick-reply:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.conv-detail-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.conv-detail-sub code {
  font-family: var(--ff-mono);
  font-size: 11px;
}

.conv-detail-contact {
  margin-top: 4px;
  font-size: 13px;
}

.conv-phone {
  color: var(--success);
  font-weight: 600;
  text-decoration: none;
}

.conv-phone:hover {
  text-decoration: underline;
}

.conv-row-phone {
  font-size: 11px;
  font-family: var(--ff-mono);
  color: var(--muted);
}

.conv-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(8, 145, 178, 0.02), transparent 120px);
}

.conv-bubble {
  max-width: 70%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
}

.conv-bubble-meta {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  opacity: 0.7;
  margin-bottom: 3px;
}

.conv-bubble-body {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Mensaje del usuario (entrante) — izquierda, claro */
.conv-bubble-in {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

/* Respuesta del agente (saliente) — derecha, color marca */
.conv-bubble-out {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  border-bottom-right-radius: 4px;
  color: #ffffff;
}

.conv-bubble-out .conv-bubble-meta {
  opacity: 0.85;
}

.conv-tools {
  border-top: 1px solid var(--line);
  padding: 12px 20px;
}

.conv-tools-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ============================================================
   Panels and cards
   ============================================================ */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.wizard-panel {
  overflow: hidden;
}

.wizard-panel,
.side-summary {
  background: var(--panel);
}

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

.panel-head h2 {
  margin: 0;
}

.panel-head.compact {
  border-bottom: 0;
  padding: 0;
}

.google-login {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.google-login[hidden] {
  display: none;
}

.google-login-sep {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.google-login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.panel-lead,
.login-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* ============================================================
   Stepper / Builder
   ============================================================ */

.stepper {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0;
  overflow-x: auto;
}

.step {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-bottom: 2px solid transparent;
  border-right: 1px solid var(--line);
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
  background: var(--panel-2);
  min-height: 56px;
  text-align: left;
}

.step:last-child {
  border-right: 0;
}

.step.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
  background: var(--primary-light);
}

.step small,
.step .step-number {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.6;
  margin-bottom: 3px;
}

.step span,
.step .step-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-top: 2px;
}

.wizard-body {
  padding: 18px;
}

.section-intro {
  margin-bottom: 16px;
}

.section-intro p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.wizard-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
}

.side-summary {
  position: sticky;
  top: 18px;
}

.summary-block {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.summary-block:last-child {
  border-bottom: 0;
}

.summary-block p,
.empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ============================================================
   Form fields
   ============================================================ */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

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

.field label,
.field > span,
.login-form .field span {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.field input,
.field select,
.field textarea,
.note-box input,
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  font-family: var(--ff);
  font-size: 13px;
  padding: 8px 12px;
  width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
  outline: none;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.note-box input:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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

.option {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  cursor: pointer;
  padding: 13px;
  text-align: left;
}

.option:hover {
  border-color: var(--line-strong);
}

.option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option strong {
  display: block;
  font-size: 13px;
}

.option span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.mode-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.credential-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 12px;
  padding: 14px;
}

.credential-card h3 {
  margin-bottom: 10px;
}

.form-card {
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.note-box {
  display: grid;
  gap: 6px;
}

.note-box input {
  min-width: 180px;
}

.agent-instruction-grid {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

/* ============================================================
   Login form
   ============================================================ */

.login-form {
  display: grid;
  gap: 14px;
}

.auth-form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ============================================================
   Status badges
   ============================================================ */

.status {
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 20px;
  font-family: var(--ff-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 2px 8px;
  text-transform: uppercase;
}

.status.active,
.status.ACTIVE,
.status.published,
.status.completed,
.status.ready {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.2);
}

.status.revoked,
.status.REVOKED,
.status.archived,
.status.ARCHIVED,
.status.superseded,
.status.closed {
  background: #f1f5f9;
  color: var(--muted);
  border-color: var(--line);
}

.status.pending,
.status.PENDING,
.status.requires_credentials {
  background: var(--warning-dim);
  color: var(--warning);
  border-color: rgba(217, 119, 6, 0.2);
}

.status.waiting_human {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.2);
}

/* ============================================================
   Pills / tags
   ============================================================ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--panel-3);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* ============================================================
   Tables
   ============================================================ */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table.compact {
  font-size: 12px;
}

.table th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  background: var(--panel-3);
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: var(--primary-light);
}

/* ============================================================
   Kanban
   ============================================================ */

.kanban {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.kanban-column {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 10px;
}

.kanban-column h3 {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  text-transform: capitalize;
}

.kanban-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  margin-bottom: 8px;
  padding: 9px;
}

.kanban-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

/* ============================================================
   Publication checklist
   ============================================================ */

.publication-checklist {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.publication-check {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 12px;
}

.publication-check.ok {
  border-color: rgba(5, 150, 105, 0.3);
  background: var(--success-dim);
}

.publication-check.pending {
  border-color: rgba(217, 119, 6, 0.3);
  background: var(--warning-dim);
}

.publication-check strong {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
}

.publication-check span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

/* ============================================================
   Code blocks
   ============================================================ */

.code {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  font-family: var(--ff-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.run-result {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.next-step {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.next-step strong {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
}
.automation-flow-number {
  display: inline-block;
  margin-right: 7px;
  color: var(--primary);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.next-step p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.next-step input,
.next-step textarea {
  width: 100%;
  margin-bottom: 8px;
}

.next-step textarea {
  min-height: 70px;
}

.marketplace-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.automation-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.automation-option-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.automation-option-row input {
  flex: 1;
}

.automation-option-row select {
  flex: 1;
}

.automation-detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.automation-detail-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.automation-detail-step {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.automation-detail-step-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}

.automation-detail-message {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.automation-detail-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.automation-detail-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.automation-detail-option-label {
  font-weight: 600;
  color: var(--text);
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
}

.automation-detail-option-arrow {
  color: var(--soft);
}

.automation-detail-option-target {
  color: var(--muted);
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  border-radius: var(--radius);
  background: #0f172a;
  color: #ffffff;
  opacity: 0;
  padding: 12px 14px;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  font-size: 13px;
  line-height: 1.45;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.brand-auth,
.brand-app {
  min-width: 0;
}

.status-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  padding: 18px;
}

.status-card-main h2 {
  margin: 10px 0 8px;
  font-size: 18px;
}

.status-card-main p:last-child,
.status-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

.auth-points {
  display: grid;
  gap: 14px;
}

.auth-points > div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  padding: 18px;
  box-shadow: var(--shadow);
}

.auth-points strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  margin: 8px 0 8px;
}

.auth-points span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

/* ============================================================
   Auth / Login page
   ============================================================ */

.auth-shell {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(340px, 0.7fr);
  gap: 32px;
  align-items: center;
  min-height: 100vh;
  margin: 0 auto;
  max-width: 1200px;
  padding: 28px 24px;
}

.brand-auth {
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.brand-auth span {
  font-size: 13px;
  margin-top: 0;
}

.auth-intro {
  display: grid;
  gap: 20px;
}

.auth-copy {
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  max-width: 560px;
}

.auth-points {
  grid-template-columns: 1fr;
}

.auth-panel.login-panel {
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
  padding: 22px;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1100px) {
  .auth-shell,
  .page-app .shell,
  .shell,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
  }

  .side-summary {
    position: static;
  }
}

@media (max-width: 760px) {
  .auth-shell {
    padding: 16px;
  }

  .metrics,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .auth-panel,
  .wizard-footer {
    flex-direction: column;
  }

  .auth-form-actions {
    width: 100%;
  }

  .auth-form-actions .button,
  .auth-form-actions a {
    width: 100%;
    justify-content: center;
  }

  .main {
    padding: 16px;
  }

  .metrics,
  .form-grid,
  .option-grid,
  .mode-row,
  .stepper,
  .kanban {
    grid-template-columns: 1fr;
  }

  .step {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

/* ============================================================
   2026-07 UI polish layer
   ============================================================ */

:root {
  --bg: #f6f8fb;
  --panel-3: #f3f6fa;
  --line: #dbe4ef;
  --line-strong: #c6d3e1;
  --text: #111827;
  --muted: #526173;
  --soft: #8794a5;
  --primary: #1d4ed8;
  --primary-2: #1e3a8a;
  --primary-light: #eaf2ff;
  --primary-mid: #bfd7ff;
  --accent: #0891b2;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 10px 28px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 18px 42px rgba(15, 23, 42, 0.10);
}

body[data-route='app'] {
  background:
    linear-gradient(180deg, #f9fbfe 0%, var(--bg) 240px),
    repeating-linear-gradient(90deg, rgba(29, 78, 216, 0.025) 0, rgba(29, 78, 216, 0.025) 1px, transparent 1px, transparent 64px);
}

body[data-route='landing'],
body[data-route='login'] {
  background:
    linear-gradient(180deg, #ffffff 0%, #f7fbff 48%, #f2f6fb 100%),
    repeating-linear-gradient(90deg, rgba(15, 23, 42, 0.018) 0, rgba(15, 23, 42, 0.018) 1px, transparent 1px, transparent 72px);
}

.button {
  min-height: 36px;
  border-radius: 7px;
  font-weight: 650;
}

.button.primary {
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.18);
}

.button.primary:hover {
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.22);
}

.button.ghost,
.button.secondary {
  background: rgba(255, 255, 255, 0.88);
}

.shell,
.page-app .shell {
  grid-template-columns: 224px minmax(0, 1fr);
}

.sidebar {
  width: 224px;
  min-width: 224px;
  background:
    linear-gradient(180deg, #0b1220 0%, #111827 52%, #0f172a 100%);
  border-right: 1px solid rgba(148, 163, 184, 0.2);
}

.brand-app {
  padding: 18px 16px 16px;
  border-bottom-color: rgba(148, 163, 184, 0.18);
}

.brand-app strong {
  font-size: 18px;
}

.brand-app span {
  max-width: 148px;
  line-height: 1.25;
}

.nav {
  gap: 2px;
  padding: 8px 0 12px;
}

.nav-item {
  width: calc(100% - 18px);
  min-height: 34px;
  margin: 1px 9px;
  padding: 8px 12px;
  border: 1px solid transparent;
  color: #aebbd0;
}

.nav-item:hover {
  border-color: rgba(148, 163, 184, 0.18);
  background: rgba(255, 255, 255, 0.07);
}

.nav-item.active {
  border-color: rgba(56, 189, 248, 0.22);
  background: rgba(14, 165, 233, 0.16);
  box-shadow: inset 3px 0 0 #22d3ee;
}

.sidebar-panel {
  border-color: rgba(148, 163, 184, 0.18);
  background: rgba(255, 255, 255, 0.06);
  margin: auto 12px 12px;
  padding: 12px;
}

.sidebar-panel .eyebrow {
  color: #67e8f9;
}

.main {
  padding: 22px 28px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 6;
  margin: -22px -28px 22px;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(203, 213, 225, 0.76);
  background: rgba(246, 248, 251, 0.92);
  backdrop-filter: blur(12px);
}

.topbar-copy h1 {
  font-size: 23px;
}

.topbar-copy-text {
  max-width: 820px;
}

.topbar-actions {
  justify-content: flex-end;
}

.auth-status {
  border-color: var(--line-strong);
  color: var(--text);
  font-weight: 600;
}

.metrics {
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.metric {
  position: relative;
  min-height: 84px;
  overflow: hidden;
  padding: 14px;
}

.metric::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.metric strong {
  font-family: var(--ff-display);
  font-size: 28px;
  letter-spacing: -0.6px;
}

.panel,
.metric,
.kanban-column,
.kanban-card,
.option,
.credential-card,
.publication-check,
.next-step,
.auth-points > div,
.status-card,
.auth-panel.login-panel {
  border-color: rgba(198, 211, 225, 0.95);
  box-shadow: var(--shadow);
}

.panel {
  border-radius: 10px;
}

.panel-head {
  background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.panel-head h2 {
  font-size: 16px;
}

.workspace-grid {
  gap: 20px;
}

.stepper {
  background: #ffffff;
}

.step {
  min-width: 126px;
  padding: 13px 16px;
}

.step.active {
  background: #eef6ff;
}

.wizard-body {
  padding: 22px;
}

.wizard-footer {
  padding: 16px 22px;
  background: #fbfdff;
}

.field input,
.field select,
.field textarea,
.note-box input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  min-height: 38px;
  border-radius: 7px;
}

.field textarea {
  min-height: 108px;
}

.option,
.credential-card,
.publication-check,
.next-step {
  background: #ffffff;
}

.option.selected,
.publication-check.ok {
  box-shadow: inset 0 0 0 1px rgba(29, 78, 216, 0.18);
}

.table th {
  background: #f6f9fd;
}

.table td {
  background: rgba(255, 255, 255, 0.72);
}

.table tr:hover td {
  background: #eef6ff;
}

.view-tabs {
  gap: 8px;
  border-bottom: 0;
  margin-bottom: 14px;
}

.view-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  margin-bottom: 0;
  padding: 8px 14px;
}

.view-tab.active {
  border-color: var(--primary-mid);
  background: var(--primary-light);
}

.conversations-layout {
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
}

.conversations-list-panel .panel-head {
  align-items: flex-start;
  flex-direction: column;
}

.conversations-search {
  width: 100%;
}

.conv-row {
  padding: 13px 16px;
}

.conv-row.active {
  background: #eef6ff;
}

.conv-thread {
  background:
    linear-gradient(180deg, rgba(8, 145, 178, 0.035), transparent 180px),
    #fbfdff;
}

.conv-bubble {
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.kanban {
  gap: 14px;
}

.kanban-column {
  background: #f8fafc;
}

.kanban-card {
  background: #ffffff;
}

.auth-points > div {
  transition: border-color 0.14s, transform 0.14s, box-shadow 0.14s;
}

.auth-points > div:hover {
  border-color: var(--primary-mid);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.auth-shell {
  max-width: 1120px;
}

.brand-auth .brand-logo {
  height: 52px;
}

.auth-copy {
  font-size: 18px;
}

.auth-panel.login-panel {
  padding: 28px;
}

.toast {
  z-index: 40;
  box-shadow: var(--shadow-md);
}

@media (max-width: 1100px) {
  .shell,
  .page-app .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    position: static;
    height: auto;
  }

  .nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
  }

  .nav-item {
    width: auto;
    flex: 0 0 auto;
    margin: 0;
  }

  .sidebar-panel {
    display: none;
  }

  .topbar {
    position: static;
    margin: 0 0 18px;
    padding: 0 0 16px;
    background: transparent;
    backdrop-filter: none;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .conversations-layout {
    height: auto;
    grid-template-columns: 1fr;
  }

  .conversations-list-panel,
  .conversations-detail-panel {
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 14px;
  }

  .topbar {
    gap: 14px;
  }

  .topbar-actions,
  .topbar-actions .button,
  .auth-status {
    width: 100%;
  }

  .topbar-actions .button,
  .auth-status {
    justify-content: center;
  }

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

  .workspace-grid {
    gap: 14px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .metrics,
  .publication-checklist {
    grid-template-columns: 1fr;
  }

  .conv-bubble {
    max-width: 88%;
  }
}

/* ============================================================
   Console mode split
   ============================================================ */

body[data-console-mode='tenant'] {
  --bg: #f7f9fb;
  --primary: #0f766e;
  --primary-2: #115e59;
  --primary-light: #ecfdf5;
  --accent: #2563eb;
}

body[data-console-mode='tenant'] .sidebar {
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
}

body[data-console-mode='tenant'] .brand-app,
body[data-console-mode='tenant'] .sidebar .brand strong,
body[data-console-mode='tenant'] .sidebar .brand span {
  color: var(--text);
}

/* Sidebar tenant en claro: el isotipo pasa a su versión oscura. */
body[data-console-mode='tenant'] .brand-mark-on-dark {
  display: none;
}

body[data-console-mode='tenant'] .brand-mark-on-light {
  display: block;
}

body[data-console-mode='tenant'] .brand-app {
  border-bottom-color: #e5e7eb;
}

body[data-console-mode='tenant'] .nav-group-label {
  color: #64748b;
}

body[data-console-mode='tenant'] .nav-item {
  color: #334155;
}

body[data-console-mode='tenant'] .nav-item:hover {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #0f172a;
}

body[data-console-mode='tenant'] .nav-item.active {
  background: #ecfdf5;
  border-color: #bbf7d0;
  box-shadow: inset 3px 0 0 #0f766e;
  color: #064e3b;
}

body[data-console-mode='tenant'] .sidebar-console-switch {
  background: #0f766e;
  border-color: #0f766e;
  color: #ffffff;
}

body[data-console-mode='tenant'] .sidebar-console-switch:hover {
  background: #115e59;
  border-color: #115e59;
}

body[data-console-mode='tenant'] .console-mode-card,
body[data-console-mode='tenant'] .sidebar-panel {
  background: #f8fafc;
  border-color: #e2e8f0;
}

body[data-console-mode='tenant'] .console-mode-card strong,
body[data-console-mode='tenant'] .console-mode-card span,
body[data-console-mode='tenant'] .sidebar-panel p:last-child {
  color: #334155;
}

body[data-console-mode='tenant'] .console-mode-card .eyebrow,
body[data-console-mode='tenant'] .sidebar-panel .eyebrow {
  color: #0f766e;
}

body[data-console-mode='tenant'] .topbar {
  background: rgba(248, 250, 252, 0.94);
}

body[data-console-mode='admin'] .topbar {
  background: rgba(15, 23, 42, 0.94);
  border-bottom-color: rgba(148, 163, 184, 0.28);
}

body[data-console-mode='admin'] .topbar h1,
body[data-console-mode='admin'] #page-context {
  color: #f8fafc;
}

body[data-console-mode='admin'] .topbar-copy-text {
  color: #cbd5e1;
}

.help-manual {
  padding: 16px;
}

.help-manual-hero {
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.09), rgba(37, 99, 235, 0.07)),
    #ffffff;
  padding: 20px;
  margin-bottom: 12px;
}

.help-manual-hero h2 {
  margin-top: 4px;
  font-size: 24px;
}

.help-manual-hero p {
  margin-top: 8px;
  max-width: 760px;
  color: #475569;
}

.help-quick-actions,
.help-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.help-quick-actions {
  margin-top: 16px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.help-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px;
}

.help-card h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.help-card p {
  margin: 0 0 12px;
  color: #475569;
  line-height: 1.5;
}

.help-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.help-card li + li {
  margin-top: 6px;
}

.help-card-actions {
  margin-top: 14px;
}

.tenant-home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.tenant-home-hero {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.1), rgba(37, 99, 235, 0.08)),
    #ffffff;
}

.tenant-home-hero h2 {
  margin-top: 4px;
  font-size: 22px;
}

.tenant-home-hero p:not(.eyebrow) {
  margin-top: 6px;
  color: var(--muted);
  max-width: 680px;
}

.tenant-home-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.client-operation { grid-column: 1 / -1; }
.client-operation-metrics, .client-operation-grid { display:grid; gap:12px; }
.client-operation-metrics { grid-template-columns:repeat(3,minmax(0,1fr)); margin:14px 0; }
.client-operation-metrics > div { padding:14px; border:1px solid var(--line); border-radius:12px; background:#fbfdff; }
.client-operation-metrics strong { display:block; font-size:1.55rem; color:var(--ink); }
.client-operation-metrics span { color:var(--muted); font-size:.9rem; }
.client-operation-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
.client-operation-section { min-width:0; padding:14px; border:1px solid var(--line); border-radius:14px; background:#fbfdff; }
.client-operation-section h3 { margin:0 0 10px; font-size:1rem; }
.client-operation-cards { display:grid; gap:9px; }
.client-operation-card { padding:12px; border:1px solid var(--line); border-radius:10px; background:#fff; }
.client-operation-card > div { display:flex; justify-content:space-between; gap:8px; }
.client-operation-card > div span { color:#08775b; background:#e6f6ef; padding:3px 7px; border-radius:999px; font-size:.75rem; font-weight:700; }
.client-operation-card p { margin:7px 0; color:var(--muted); font-size:.9rem; }
.client-operation-card small { display:block; margin-bottom:8px; color:var(--muted); }

.tenant-home-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-column: 1 / -1;
  gap: 10px;
}

.home-metric {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
  text-align: left;
  cursor: pointer;
}

.home-metric strong {
  display: block;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.home-metric span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tenant-home-list {
  overflow: hidden;
}

.home-row,
.home-check {
  display: grid;
  width: 100%;
  gap: 4px;
  padding: 13px 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.home-row:hover,
.home-check:hover {
  background: var(--panel-3);
}

.home-row strong,
.home-check strong {
  color: var(--text);
}

.home-row span,
.home-check span {
  color: var(--muted);
  font-size: 12px;
}

.home-row small {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.home-row small span {
  width: fit-content;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--text-soft);
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
}

.home-check span {
  width: fit-content;
  border-radius: 999px;
  background: var(--warning-dim);
  color: var(--warning);
  padding: 2px 8px;
  font-weight: 700;
}

.home-check.done span {
  background: var(--success-dim);
  color: var(--success);
}

@media (max-width: 760px) {
  .help-manual {
    padding: 12px;
  }

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

  .help-manual-hero h2 {
    font-size: 21px;
  }

  .tenant-home-grid,
  .tenant-home-metrics {
    grid-template-columns: 1fr;
  }
  .client-operation-metrics, .client-operation-grid { grid-template-columns:1fr; }

  .tenant-home-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .tenant-home-actions {
    justify-content: flex-start;
  }

  .conv-workspace {
    grid-template-columns: 1fr;
  }

  .conv-chat-column {
    border-right: 0;
  }

  .conv-context {
    border-top: 1px solid var(--line);
  }

  .conv-reply-box {
    align-items: stretch;
    flex-direction: column;
  }

  .conv-reply-box .button {
    justify-content: center;
  }
}

/* Tenants view: toolbar + table */
.tenants-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.tenants-table td code {
  font-size: 11px;
  color: var(--muted);
}

.tenants-table .actions {
  justify-content: flex-end;
}

/* Right-side drawer for create/edit forms */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  z-index: 41;
  display: flex;
  flex-direction: column;
}

.drawer-header,
.drawer-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
}

.drawer-header {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.drawer-header h3 {
  margin: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

/* Tenant detail hub */
.tenant-detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.tenant-detail-title {
  flex: 1;
}

.tenant-detail-title h3 {
  margin: 0;
}

.tenant-detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.tenant-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tenant-tab:hover {
  color: var(--text);
}

.tenant-tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
  font-weight: 600;
}

.detail-card {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.detail-row {
  display: flex;
  gap: 12px;
  padding: 6px 0;
}

.detail-label {
  min-width: 140px;
  color: var(--muted);
}

.color-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--line);
  vertical-align: middle;
  margin-right: 6px;
}

.feature-toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feature-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.feature-toggle input {
  width: auto;
}

.usage-bar {
  margin-top: 8px;
  height: 10px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* ============================================================
   Automatizaciones: borradores, avisos del linter y generador
   con IA (ADR-045). Todo sobre los tokens existentes, así que
   hereda el cambio de dirección visual sin tocarse.
   ============================================================ */

/* Un borrador no atiende a nadie. Se marca en el borde, no sólo con una etiqueta:
   la diferencia entre "esto contesta a mis clientes" y "esto no" tiene que verse
   de un vistazo en la lista. */
.next-step.is-draft {
  border-left: 3px solid var(--warning);
}

.pill.draft {
  background: var(--warning-dim);
  color: var(--warning);
  border-color: transparent;
  margin-left: 6px;
  vertical-align: middle;
}

/* Avisos del linter: no bloquean, pero describen algo que romperá la conversación.
   Ámbar y no rojo, porque la automatización sí está guardada y funcionando. */
.lint-warnings {
  margin: 8px 0 0;
  padding: 8px 12px 8px 28px;
  background: var(--warning-dim);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.lint-warnings li + li {
  margin-top: 5px;
}

.composer-card {
  border-left: 3px solid var(--primary);
}

.notice {
  margin: 0 0 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

.notice.danger {
  background: var(--danger-dim);
  color: var(--danger);
}

.notice.success {
  background: var(--success-dim);
  color: var(--success);
}

/* La propuesta se lee en frases, no en JSON: es lo que se puede corregir de un
   vistazo antes de aprobar (ADR-045, fase 1). */
.composer-spec {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  gap: 6px 16px;
  margin: 4px 0 0;
  font-size: 13.5px;
}

.composer-spec dt {
  color: var(--soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 2px;
}

.composer-spec dd {
  margin: 0;
  color: var(--text);
}

/* Sugerencias de por dónde empezar: temas que sus clientes ya piden o que declaró en
   el alta. Botones y no lista, porque son accionables. */
.composer-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.composer-suggestion {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
}

.composer-suggestion:hover {
  border-color: var(--primary);
}

.composer-suggestion strong {
  font-size: 13px;
  color: var(--text);
}

.composer-suggestion span {
  font-size: 11.5px;
  color: var(--soft);
}

/* La conversación de prueba: lo que va a leer el cliente, no la etiqueta del guion. */
.composer-transcript {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--panel-3);
  border-radius: var(--radius-sm);
}

.composer-transcript b {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--soft);
  margin-bottom: 8px;
}

.composer-transcript p {
  max-width: 78%;
  margin: 0 0 6px;
  padding: 7px 11px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.45;
}

.composer-transcript .t-in {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}

.composer-transcript .t-out {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 3px;
}

/* Formulario de credenciales propias del tenant (ADR-048). Los secretos nunca se
   rellenan: el servidor no los devuelve, sólo dice si están puestos. */
.credentials-form {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--panel-3);
  border-radius: var(--radius);
}

/* Lo que el cliente puede TOCAR en la previsualización. Se pinta como botón y como fila
   de lista porque enseñarlo como texto hacía creer que la respuesta no era clicable. */
.composer-transcript .t-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 78%;
  margin: -2px 0 10px auto;
  justify-content: flex-end;
}

.composer-transcript .t-choices.list {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--panel);
}

.composer-transcript .t-button {
  padding: 5px 12px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--panel);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.composer-transcript .t-list-button {
  padding: 6px 12px;
  background: var(--panel-3);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

.composer-transcript .t-row {
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
}

.composer-transcript .t-row:last-child {
  border-bottom: none;
}
