:root {
  /* Tema Elea: claro + azul (paleta de elea.com) */
  --bg: #eef3fb;
  --bg-2: #e4edf9;
  --panel: #ffffff;
  --panel-2: #f5f8fd;
  --border: #e2e9f4;
  --border-strong: #cdd9ec;
  --mint: #0072c6;          /* azul brillante (acento primario) */
  --mint-2: #0033a1;        /* azul profundo */
  --emerald: #0053b8;       /* azul medio */
  --emerald-deep: #0033a1;  /* azul profundo */
  --sky: #8ad1f0;           /* celeste acento */
  --text: #16233a;
  --muted: #63728c;
  --danger: #d64553;
  --ink: #ffffff;           /* texto sobre superficies azules */
  --radius: 20px;
  --radius-sm: 13px;
  --glow: 0 10px 30px rgba(0, 51, 161, 0.22);
  --card-shadow: 0 6px 24px rgba(16, 42, 80, 0.07);
}

* { box-sizing: border-box; }

/* El atributo hidden SIEMPRE oculta. Cualquier regla con display (flex, grid) le
   gana al hidden del navegador: paso con el boton Terminar, con el login y con la
   lamparita durante la simulacion. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 600px at 12% -8%, #dfeafb 0, transparent 55%),
    radial-gradient(1000px 700px at 108% 10%, #e7f1fc 0, transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ===== Shell ===== */
.shell {
  display: grid;
  grid-template-columns: 268px 1fr;
  height: 100vh;
  padding: 16px;
  gap: 16px;
}

/* ===== Rail ===== */
.rail {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--card-shadow);
  /* La columna mide lo que la pantalla, no lo que su contenido: si el historial es
     largo se achica y hace scroll la lista, no la pagina. (Sin min-height: 0 un item de
     grilla crece con lo que tiene adentro.) El overflow es la red para pantallas muy bajas. */
  min-height: 0;
  overflow-y: auto;
}
.rail-brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  object-fit: contain; background: #fff; border: 1px solid var(--border); padding: 3px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; color: var(--emerald-deep); }
.brand-text span { font-size: 11px; color: var(--muted); }

.rail-user {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.rail-user-avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 14px; color: var(--ink);
  background: linear-gradient(160deg, var(--mint), var(--emerald));
}
.rail-user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.rail-user-name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-user-zona { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Cerrar sesion: al pie del rail, con texto. Antes era un icono ⇄ al lado del
   nombre ("cambiar de visitador") y no se entendia que era salir. */
.btn-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 10px 13px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); background: transparent; }

.rail-nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 13px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; text-align: left; position: relative;
}
.nav-item:hover { color: var(--text); background: var(--panel-2); }
.nav-item.active { color: var(--emerald-deep); background: rgba(0, 114, 198, 0.1); border-color: var(--border-strong); }

/* Historial de conversaciones: ocupa el alto que sobra del rail y hace scroll
   adentro, asi la voz y "Cerrar sesión" quedan siempre a la vista al pie. */
.rail-historial { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.historial-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.historial-titulo { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.btn-nueva-conv {
  border: 1px solid var(--border); background: transparent; color: var(--emerald-deep);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.btn-nueva-conv:hover { background: var(--panel-2); }
/* La lista nunca estira la columna: tiene un alto maximo y, pasado ese alto, scroll propio. */
.historial-lista {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0;
  max-height: min(42vh, 340px); display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.historial-lista > li { flex: none; }
/* Contraida (como arranca): solo las tres mas recientes. "Ver todas las charlas" la despliega. */
.historial-lista.contraida > .historial-fila:nth-child(n + 4) { display: none; }
.historial-item {
  display: block; width: 100%; text-align: left; cursor: pointer; font-family: inherit;
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm); padding: 8px 10px;
}
.historial-item:hover { background: var(--panel-2); }
/* Cada fila: la conversacion y, al pasar por encima o enfocar, la cruz para borrarla. */
.historial-fila { position: relative; }
.historial-fila .historial-item { padding-right: 30px; }
.historial-borrar {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 24px; height: 24px; border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; opacity: 0;
}
.historial-fila:hover .historial-borrar, .historial-borrar:focus-visible { opacity: 1; }
.historial-borrar:hover { background: var(--border); color: var(--text); }
/* En pantallas tactiles no hay "pasar por encima": la cruz queda siempre a la vista. */
@media (hover: none) { .historial-borrar { opacity: 0.6; } }
.historial-pie { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn-historial-pie {
  border: 0; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 12px; padding: 2px; cursor: pointer; text-decoration: underline;
}
.btn-historial-pie:hover { color: var(--text); }
#btn-ver-historial { color: var(--emerald-deep); font-weight: 600; }
#btn-borrar-historial { margin-left: auto; }
.historial-item.active { background: rgba(0, 114, 198, 0.1); border-color: var(--border-strong); }
.historial-item-titulo {
  display: block; font-size: 13px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.historial-item-meta { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.historial-vacio { font-size: 12px; color: var(--muted); padding: 4px 2px; line-height: 1.4; }
.nav-ico { font-size: 15px; opacity: 0.9; }
.badge { position: absolute; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 8px var(--mint); }

.rail-voice { margin-top: auto; display: flex; align-items: center; justify-content: space-between; }
.rail-voice-label { font-size: 12px; color: var(--muted); }
.voice-toggle { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 3px; }
.voice-option {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  width: 30px; height: 26px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.voice-option.active { background: var(--mint); color: var(--ink); }

/* ===== Stage ===== */
.stage {
  min-width: 0;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--card-shadow);
}
.stage-top {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.stage-top .btn-ghost { margin-left: auto; }

/* Hamburguesa + marca del header + overlay (drawer): ocultos en desktop */
.hamburger {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer;
}
.hamburger:hover { background: rgba(0, 114, 198, 0.08); }
.stage-brand { align-items: center; gap: 8px; }
.stage-brand-mark { width: 26px; height: 26px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--border); padding: 2px; }
.stage-brand strong { font-size: 15px; color: var(--emerald-deep); }
.drawer-overlay {
  position: fixed; inset: 0; z-index: 55; background: rgba(6, 20, 42, 0.45);
  opacity: 0; visibility: hidden; transition: opacity 0.22s ease, visibility 0.22s ease;
}
.drawer-overlay.open { opacity: 1; visibility: visible; }
.hamburger, .stage-brand, .drawer-overlay { display: none; }
.stage-status { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c2cede; transition: background 0.2s, box-shadow 0.2s; }
.dot[data-state="listening"], .dot[data-state="speaking"], .dot[data-state="texto"] { background: var(--mint); box-shadow: 0 0 10px var(--mint); }
.dot[data-state="connecting"], .dot[data-state="thinking"] { background: #f0a800; box-shadow: 0 0 10px #f0a800; }
.dot[data-state="error"] { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

.btn-ghost {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.btn-ghost:hover { color: var(--text); background: var(--panel-2); }

/* Views */
.view { display: none; flex-direction: column; min-height: 0; flex: 1; }
.view.active { display: flex; }
.view-head { padding: 16px 20px 4px; }
.view-head h2 { margin: 0; font-size: 15px; }

/* ===== Voice hero + orb ===== */
.voice-hero {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 26px 20px 10px;
}
.orb {
  position: relative; width: 148px; height: 148px; border-radius: 50%;
  border: none; background: transparent; cursor: pointer; padding: 0;
  display: grid; place-items: center;
}
.orb-core {
  position: absolute; width: 92px; height: 92px; border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, var(--sky), var(--mint) 45%, var(--emerald-deep));
  box-shadow: var(--glow);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.orb-ring {
  position: absolute; border-radius: 50%; border: 1.5px solid rgba(0, 114, 198, 0.35);
  opacity: 0;
}
.orb-ring.r1 { width: 108px; height: 108px; }
.orb-ring.r2 { width: 128px; height: 128px; }
.orb-ring.r3 { width: 148px; height: 148px; }

.orb-bars { position: absolute; display: none; align-items: center; gap: 4px; height: 48px; }
.orb-bars i {
  width: 5px; height: 12px; border-radius: 3px; background: var(--ink);
  transform: scaleY(calc(0.5 + var(--level, 0.3) * 1.6));
  animation: bar 0.9s ease-in-out infinite;
}
.orb-bars i:nth-child(2) { animation-delay: 0.1s; }
.orb-bars i:nth-child(3) { animation-delay: 0.2s; }
.orb-bars i:nth-child(4) { animation-delay: 0.05s; }
.orb-bars i:nth-child(5) { animation-delay: 0.25s; }
.orb-bars i:nth-child(6) { animation-delay: 0.15s; }
.orb-bars i:nth-child(7) { animation-delay: 0.3s; }
@keyframes bar { 0%, 100% { transform: scaleY(calc(0.4 + var(--level,0.3))); } 50% { transform: scaleY(calc(1 + var(--level,0.3) * 1.8)); } }

/* Orb states */
.orb[data-state="idle"] .orb-core { animation: breathe 4s ease-in-out infinite; opacity: 0.9; }
.orb[data-state="texto"] .orb-core { animation: breathe 3.4s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(0.96); } 50% { transform: scale(1.02); } }

.orb[data-state="connecting"] .orb-core { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(0.94); } 50% { transform: scale(1.06); } }

.orb[data-state="listening"] .orb-ring { animation: ripple 2.4s ease-out infinite; }
.orb[data-state="listening"] .orb-ring.r2 { animation-delay: 0.6s; }
.orb[data-state="listening"] .orb-ring.r3 { animation-delay: 1.2s; }
.orb[data-state="listening"] .orb-core { animation: breathe 2.6s ease-in-out infinite; }
@keyframes ripple { 0% { opacity: 0.5; transform: scale(0.7); } 100% { opacity: 0; transform: scale(1.1); } }

.orb[data-state="thinking"] .orb-core { animation: pulse 1.4s ease-in-out infinite; }
.orb[data-state="thinking"] .orb-ring.r1 {
  opacity: 1; border-color: transparent; border-top-color: var(--mint); border-right-color: var(--mint);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.orb[data-state="speaking"] .orb-core { transform: scale(1.06); box-shadow: 0 0 55px rgba(0, 114, 198, 0.45); }
.orb[data-state="speaking"] .orb-bars { display: flex; }
.orb[data-state="speaking"] .orb-ring { animation: ripple 1.6s ease-out infinite; }

.voice-hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }

/* ===== Transcript ===== */
.transcript {
  flex: 1; min-height: 0; overflow-y: auto; padding: 8px 20px 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.transcript::-webkit-scrollbar, #precargas-list-container::-webkit-scrollbar { width: 8px; }
.transcript::-webkit-scrollbar-thumb, #precargas-list-container::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

.message { max-width: 78%; padding: 11px 15px; border-radius: 16px; line-height: 1.45; font-size: 14px; flex-shrink: 0; }
.message.user {
  align-self: flex-end; color: var(--ink); font-weight: 500;
  background: linear-gradient(160deg, var(--mint), var(--mint-2));
  border-bottom-right-radius: 5px;
}
.message.assistant {
  align-self: flex-start; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 5px;
}
.message-role { font-size: 11px; opacity: 0.7; margin-bottom: 2px; font-weight: 700; }
.session-separator { flex-shrink: 0; align-self: center; font-size: 11px; color: var(--muted); opacity: 0.8; padding: 4px 0; }
.welcome-message { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }

/* ===== Simulación de venta ===== */
.sim-elegir { padding: 4px 20px 20px; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.sim-intro { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; max-width: 720px; }
.sim-buscar {
  width: 100%; max-width: 520px; box-sizing: border-box; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2); color: var(--text); padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.sim-buscar:focus { outline: none; border-color: var(--border-strong); }
.sim-grupo-titulo { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 6px 0 8px; }
.sim-grupo { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.sim-medico {
  display: block; text-align: left; cursor: pointer; font-family: inherit; width: 100%;
  border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius-sm); padding: 10px 12px;
}
.sim-medico:hover { border-color: var(--border-strong); background: var(--panel-2); }
.sim-medico strong { display: block; font-size: 14px; color: var(--text); }
.sim-medico span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.sim-medico .sim-visita { color: var(--emerald-deep); font-weight: 600; }
.sim-vacio { color: var(--muted); font-size: 13px; }

/* Barra mientras se practica: deja claro que NO es Elea la que habla. */
.sim-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 12px 16px 0; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: rgba(0, 114, 198, 0.08);
}
.sim-banner[hidden] { display: none; }
.sim-banner-info { display: flex; flex-direction: column; min-width: 0; }
.sim-banner-etiqueta { font-size: 11px; font-weight: 700; color: var(--emerald-deep); text-transform: uppercase; letter-spacing: 0.05em; }
.sim-banner-info strong { font-size: 15px; color: var(--text); }
.sim-banner-meta { font-size: 12px; color: var(--muted); }
.sim-banner-acciones { display: flex; gap: 6px; flex-wrap: wrap; }
.sim-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer;
  border-radius: 999px; padding: 7px 12px; font-size: 12.5px; font-weight: 600; font-family: inherit;
}
.sim-btn:hover { background: var(--panel-2); }
.sim-btn.on { color: var(--emerald-deep); border-color: var(--border-strong); }
.sim-btn.primario { background: linear-gradient(160deg, var(--mint), var(--emerald)); color: var(--ink); border-color: transparent; }
.sim-aviso { margin: auto; color: var(--muted); font-size: 14px; text-align: center; max-width: 440px; line-height: 1.5; }

/* Bloque de datos: rankings/agenda en tabla o lista (toggle) */
.data-block {
  /* flex-shrink:0: sin esto el flex column del transcript APLASTA la tabla y la
     encima con los mensajes (bug visto en produccion). */
  flex-shrink: 0;
  align-self: flex-start; max-width: 92%; width: 100%;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--card-shadow);
  padding: 12px 14px; overflow: hidden;
}
.data-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.data-title { font-size: 13px; font-weight: 700; color: var(--emerald-deep); }
.data-toggle { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px; gap: 2px; }
.data-toggle-btn {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 999px;
}
.data-toggle-btn:hover { color: var(--text); }
/* Resalta el botón de la vista activa; muestra tabla o lista según data-vista */
.data-block[data-vista="tabla"] .data-toggle-btn[data-vista="tabla"],
.data-block[data-vista="lista"] .data-toggle-btn[data-vista="lista"] {
  background: var(--mint); color: var(--ink);
}
.data-block[data-vista="tabla"] .data-list,
.data-block[data-vista="lista"] .data-table-wrap { display: none; }

.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:nth-child(even) { background: rgba(0, 114, 198, 0.04); }

.data-list { list-style: none; margin: 0; padding: 0; counter-reset: fila; }
.data-list li {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 0 7px 30px; border-bottom: 1px solid var(--border); position: relative; font-size: 13px;
}
.data-list li:last-child { border-bottom: none; }
.data-list li::before {
  counter-increment: fila; content: counter(fila);
  position: absolute; left: 0; top: 7px;
  width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 114, 198, 0.1);
  color: var(--emerald-deep); font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.data-list-det { color: var(--muted); font-size: 12px; }

.agent-thinking { display: flex; gap: 5px; padding: 4px 20px 14px; }
.agent-thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); animation: blink 1.2s infinite ease-in-out; }
.agent-thinking span:nth-child(2) { animation-delay: 0.2s; }
.agent-thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ===== PreCargas ===== */
#precargas-list-container { flex: 1; overflow-y: auto; padding: 12px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.precarga-card { padding: 15px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--card-shadow); }
.precarga-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.precarga-doctor { font-weight: 700; font-size: 14px; }
.precarga-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
details { margin-top: 8px; }
summary { cursor: pointer; color: var(--mint); font-size: 13px; font-weight: 600; }
.details-content { margin-top: 8px; font-size: 13px; color: var(--muted); }
.details-content p { margin: 4px 0; }
.precarga-status { display: inline-block; font-size: 11px; color: var(--ink); background: var(--mint); padding: 2px 8px; border-radius: 999px; margin-top: 6px; }
.empty-state, .error-state { color: var(--muted); font-size: 14px; text-align: center; margin: auto; padding: 24px; }

/* Comunicados de administración: se leen tal cual (los mismos que Elea tiene en el prompt).
   Las mismas tarjetas se usan en la vista previa del panel de administración. */
.view-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; max-width: 720px; }
.comunicados-lista { flex: 1; overflow-y: auto; padding: 12px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.comunicado {
  padding: 15px 16px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--card-shadow); max-width: 760px;
}
.comunicado.nuevo { border-color: var(--mint); box-shadow: 0 0 0 1px var(--mint), var(--card-shadow); }
.comunicado.borrador { border-style: dashed; border-color: var(--border-strong); background: var(--panel-2); box-shadow: none; }
.comunicado-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.comunicado-titulo { margin: 0; font-size: 15px; line-height: 1.35; color: var(--text); }
.comunicado-etiqueta {
  flex-shrink: 0; font-size: 11px; font-weight: 700; color: var(--ink); background: var(--mint);
  padding: 2px 8px; border-radius: 999px;
}
.comunicado.borrador .comunicado-etiqueta { background: var(--muted); }
.comunicado-texto { margin: 8px 0 0; font-size: 14px; line-height: 1.55; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.comunicado-fecha { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

/* Pop-up semanal de comunicados (<dialog>). La cabecera, el pie y el botón se reusan en la
   vista previa del panel de administración. */
.comunicados-modal {
  width: min(560px, calc(100vw - 32px)); max-width: none; max-height: min(82vh, 720px); max-height: min(82dvh, 720px);
  padding: 0; border: 1px solid var(--border); border-radius: 22px; background: var(--bg); color: var(--text);
  box-shadow: 0 24px 60px rgba(6, 20, 42, 0.3); overflow: hidden;
}
.comunicados-modal[open] { display: flex; flex-direction: column; }
.comunicados-modal::backdrop { background: rgba(6, 20, 42, 0.45); }
.comunicados-modal-cab { padding: 20px 22px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.comunicados-modal-kicker { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--mint); }
.comunicados-modal-cab h2 { margin: 3px 0 0; font-size: 18px; color: var(--emerald-deep); }
.comunicados-modal .comunicados-lista { padding: 14px 22px; min-height: 0; }
.comunicados-modal-pie {
  display: flex; justify-content: flex-end; padding: 12px 22px 16px;
  background: var(--panel); border-top: 1px solid var(--border);
}
.comunicados-ok {
  padding: 12px 26px; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 15px; font-weight: 700; color: var(--ink); background: linear-gradient(160deg, var(--mint), var(--emerald));
}
/* En el celular sube desde abajo, a lo ancho, con el botón a mano del pulgar. */
@media (max-width: 480px) {
  .comunicados-modal { width: 100%; max-height: 88vh; max-height: 88dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; border-bottom: none; }
  .comunicados-modal-cab, .comunicados-modal .comunicados-lista { padding-left: 16px; padding-right: 16px; }
  .comunicados-modal-pie { padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
  .comunicados-ok { width: 100%; }
}
.error-state { color: var(--danger); }
.btn-icon { border: 1px solid var(--border); background: transparent; color: var(--danger); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; }
.btn-icon:hover { background: rgba(214, 69, 83, 0.1); }

/* ===== Composer de texto ===== */
.composer-area { position: relative; }
.composer {
  display: flex; align-items: center; gap: 8px;
  margin: 0 20px 6px; padding: 6px 6px 6px 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px;
}

/* Panel de preguntas frecuentes (se despliega hacia arriba, con animación) */
.faq-panel {
  position: absolute; bottom: calc(100% + 4px); left: 20px;
  min-width: 260px; max-width: min(420px, calc(100% - 40px));
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 12px 30px rgba(16, 42, 80, 0.14);
  padding: 6px; z-index: 6; display: flex; flex-direction: column; gap: 2px;
  transform-origin: bottom left;
  opacity: 0; transform: translateY(10px) scale(0.97); visibility: hidden; pointer-events: none;
  transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.faq-panel.open { opacity: 1; transform: translateY(0) scale(1); visibility: visible; pointer-events: auto; }
.faq-item {
  text-align: left; border: none; background: transparent; color: var(--text);
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 13.5px; line-height: 1.3;
  opacity: 0; transform: translateY(5px);
  transition: background 0.12s ease, color 0.12s ease, opacity 0.2s ease, transform 0.2s ease;
}
.faq-panel.open .faq-item { opacity: 1; transform: none; }
.faq-panel.open .faq-item:nth-child(1) { transition-delay: 0.03s; }
.faq-panel.open .faq-item:nth-child(2) { transition-delay: 0.06s; }
.faq-panel.open .faq-item:nth-child(3) { transition-delay: 0.09s; }
.faq-panel.open .faq-item:nth-child(4) { transition-delay: 0.12s; }
.faq-panel.open .faq-item:nth-child(5) { transition-delay: 0.15s; }
.faq-item:hover { background: var(--panel-2); color: var(--emerald-deep); }
/* Selector de tarea: define qué preguntas muestra la lamparita */
.faq-tareas { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 2px 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.faq-tarea {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
  padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 11.5px; font-weight: 600;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.faq-tarea:hover { color: var(--text); }
.faq-tarea.active { background: var(--mint); color: var(--ink); border-color: var(--mint); }
.composer-faq { color: var(--muted); background: transparent; }
.composer-faq:hover { background: rgba(0, 114, 198, 0.1); color: var(--mint); }
.composer-faq[aria-expanded="true"] { color: var(--ink); background: var(--mint); border-color: var(--mint); }
.composer:focus-within { border-color: var(--border-strong); }
.composer-input {
  flex: 1; min-width: 0; border: none; background: transparent;
  color: var(--text); font-size: 14px; padding: 8px 4px; outline: none;
}
.composer-input::placeholder { color: var(--muted); }
.composer-faq, .composer-mute, .composer-send {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: filter 0.15s ease, background 0.15s ease;
}
.composer-mute { color: var(--mint); }
.composer-mute[aria-pressed="false"] { color: var(--muted); background: transparent; }
.composer-mute:hover { background: rgba(0, 114, 198, 0.1); }
.composer-send {
  border: none; background: linear-gradient(160deg, var(--mint), var(--emerald));
  color: var(--ink); font-weight: 700;
}
.composer-send:hover { filter: brightness(1.06); }
.composer-send:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

/* ===== Mode bar ===== */
.mode-bar { display: flex; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); }
.mode-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 9px;
  border: none; border-radius: var(--radius-sm); padding: 15px; cursor: pointer;
  font-size: 15px; font-weight: 700; transition: transform 0.05s ease, filter 0.15s ease;
}
.mode-btn.primary { background: linear-gradient(160deg, var(--mint), var(--emerald)); color: var(--ink); }
.mode-btn.secondary { background: var(--panel); border: 1px solid var(--border-strong); color: var(--text); }
.mode-ico { font-size: 16px; }
.mode-btn:active { transform: translateY(1px); }
.mode-btn.active { box-shadow: inset 0 0 0 2px var(--mint); filter: brightness(1.03); }
.mode-btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* .mode-btn define display:flex, que le GANA al atributo hidden: sin esto el
   boton Terminar se veia siempre, incluso sin charla abierta. */
.mode-btn[hidden] { display: none; }
.mode-btn.danger { flex: 0 0 auto; background: var(--panel); border: 1px solid var(--danger); color: var(--danger); }
.mode-btn.danger:hover { background: rgba(214, 69, 83, 0.08); }

/* ===== Login overlay ===== */
.login-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(700px 460px at 30% 0%, #d9e8fb 0, transparent 60%), var(--bg);
}
.login-overlay[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 440px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 24px; padding: 30px; box-shadow: 0 18px 50px rgba(16, 42, 80, 0.12);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-logo { display: block; margin: 0 auto; height: 56px; width: auto; }
.login-brand h1 { margin: 12px 0 4px; font-size: 20px; color: var(--text); }
.login-brand p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.login-users { display: flex; flex-direction: column; gap: 10px; }
.login-user {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 13px 15px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-2);
  cursor: pointer; transition: transform 0.05s ease, border-color 0.15s ease, background 0.15s ease;
}
.login-user:hover { border-color: var(--mint); background: rgba(0, 114, 198, 0.06); }
.login-user:active { transform: translateY(1px); }
.login-user-avatar {
  width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center;
  font-weight: 800; color: var(--ink); background: linear-gradient(160deg, var(--mint), var(--emerald));
}
.login-user-texts { display: flex; flex-direction: column; }
.login-user-name { font-weight: 700; font-size: 15px; color: var(--emerald-deep); }
.login-user-zona { font-size: 12px; color: var(--muted); }

/* Login - paso de clave */
.login-pass { display: flex; flex-direction: column; gap: 12px; }
.login-back {
  align-self: flex-start; border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 0;
}
.login-back:hover { color: var(--text); }
.login-pass-user { display: flex; align-items: center; gap: 12px; }
.login-pass-user strong { font-size: 16px; }
.login-pass-input {
  width: 100%; padding: 13px 15px; border-radius: var(--radius-sm); font-size: 15px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.login-pass-input:focus { outline: none; border-color: var(--mint); }
.login-pass-submit {
  width: 100%; padding: 13px; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 15px; font-weight: 700; color: var(--ink);
  background: linear-gradient(160deg, var(--mint), var(--emerald));
}
.login-pass-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; }

.hidden { display: none !important; }

/* ===== Responsive (teléfono: rail como drawer desde la izquierda) ===== */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr; padding: 0; gap: 0; height: 100vh; height: 100dvh; }

  /* El rail se convierte en un drawer deslizable */
  .rail {
    position: fixed; top: 0; left: 0; bottom: 0; width: 300px; max-width: 84vw;
    z-index: 60; border-radius: 0; overflow-y: auto;
    transform: translateX(-100%); transition: transform 0.25s ease;
  }
  .rail.open { transform: translateX(0); box-shadow: 18px 0 50px rgba(6, 20, 42, 0.28); }

  .hamburger { display: flex; }
  .stage-brand { display: flex; }
  .drawer-overlay { display: block; }

  .stage { border-radius: 0; box-shadow: none; }
  .voice-hero { padding: 16px 16px 6px; }
  .orb { width: 120px; height: 120px; }
  .orb-core { width: 76px; height: 76px; }
  .message { max-width: 86%; }
}

/* Celular con una charla abierta: Asistente + PreCarga + Terminar no entraban y
   Terminar quedaba cortado contra el borde de la pantalla. */
@media (max-width: 480px) {
  .mode-bar { gap: 8px; padding: 12px 14px; }
  .mode-btn { padding: 13px 10px; gap: 7px; font-size: 14px; min-width: 0; }
}

/* ===== Detalles de interaccion (no cambian como se ve con mouse) ===== */
/* Sin la demora de ~300 ms del doble toque para hacer zoom en el celular. */
button, a, summary, .faq-item, .faq-tarea, .historial-item { touch-action: manipulation; }
/* Foco visible con TECLADO (Tab): un anillo del color de la marca. :focus-visible no
   aparece al hacer clic, asi que con mouse todo se ve igual que antes. */
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--mint); outline-offset: 2px;
}
.faq-item:focus-visible, .historial-item:focus-visible { outline-offset: -2px; }
/* Quien pidio menos movimiento en su sistema: sin respiracion del orbe, ondas,
   barras ni despliegues animados. El estado se sigue viendo por color y forma. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}
