/* ============================================================
   TOKENS — paleta idéntica a From_sofia_chat
   ============================================================ */
:root {
  --bg:          #f4f6f9;
  --brand:       #0f2042;
  --brand-light: #3b6cb5;
  --accent:      #00c9a7;
  --accent-dark: #00a88a;
  --panel:       #ffffff;
  --panel2:      #edf1f7;
  --border:      #d0d8e4;
  --text:        #1a2744;
  --muted:       #64748b;
  --danger:      #ef4444;
  --success:     #10b981;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body.chat-mode { overflow: hidden; }

/* ============================================================
   SHOW / HIDE
   El atributo HTML `hidden` no puede sobreponerse a display:flex/grid
   declarado en CSS. Esta regla lo fuerza globalmente.
   ============================================================ */
[hidden] { display: none !important; }

/* ============================================================
   ACCESS SCREEN — blanco con topbar navy
   ============================================================ */
#access-panel {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

/* Topbar */
.access-topbar {
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
}

.topbar-brand {
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
}

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(16,185,129,.3);
}

/* Body */
.access-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 16px;
  text-align: center;
}

/* Logo topbar */
.topbar-logo {
  height: 30px;
  object-fit: contain;
}

/* Avatar de Sofía */
.sofia-avatar {
  width: 180px;
  height: 180px;
  object-fit: contain;
  margin-bottom: 16px;
  filter: drop-shadow(0 8px 24px rgba(15,32,66,.15));
}

.access-greeting {
  font-size: 26px;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 6px;
}

.access-instruction {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 28px;
  line-height: 1.55;
}

/* Form */
.access-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 360px;
}

/* Input pill — igual al original */
.cedula-field {
  width: 100%;
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #ffffff;
  box-shadow: 0 2px 12px rgba(15,32,66,.06);
  transition: box-shadow .2s, border-color .2s;
}
.cedula-field:focus-within {
  border-color: var(--brand-light);
  box-shadow: 0 2px 16px rgba(59,108,181,.15);
}

.cedula-field input {
  display: block;
  width: 100%;
  border: none;
  padding: 13px 20px;
  font-size: 16px;
  color: var(--text);
  background: transparent;
  text-align: center;
  letter-spacing: .04em;
  outline: none;
}
.cedula-field input::placeholder { color: #a0aec0; }

.access-error {
  min-height: 1.2rem;
  font-size: .825rem;
  color: var(--danger);
  text-align: center;
}

/* Botón — navy redondeado, hover en accent */
.access-btn {
  width: 100%;
  max-width: 360px;
  padding: 13px 24px;
  border: none;
  border-radius: 28px;
  background: var(--brand);
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,32,66,.2);
  transition: background .2s, box-shadow .2s, transform .1s;
}
.access-btn:hover:not(:disabled) {
  background: var(--accent);
  box-shadow: 0 6px 20px rgba(0,201,167,.35);
}
.access-btn:active { transform: scale(.98); }
.access-btn:disabled { opacity: .55; cursor: not-allowed; }

/* Footer */
.access-footer {
  padding: 20px 24px;
  text-align: center;
}
.footer-logo {
  height: 36px;
  object-fit: contain;
  opacity: .85;
}

/* ============================================================
   LOADING SCREEN — overlay navy semitransparente
   ============================================================ */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);   /* opaco: elimina sangrado visual de la topbar */
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  gap: 16px;
}

.loading-logo {
  height: 38px;
  object-fit: contain;
  margin-bottom: 12px;
  opacity: .9;
}

.loading-avatar {
  width: 140px; height: 140px;
  object-fit: contain;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 6px 28px rgba(0,0,0,.35));
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

.loading-title {
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
}

.spinner-ring {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: #7dd3fc;
  border-left-color: #86efac;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-status {
  color: rgba(255,255,255,.8);
  font-size: 14px;
}

/* ============================================================
   CHAT PANEL — panel blanco sobre fondo navy
   ============================================================ */
body.chat-mode {
  background: var(--brand);
}

#chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.chat-agent-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

.chat-agent-name {
  font-size: .95rem;
  font-weight: 600;
  color: var(--brand);
  line-height: 1.2;
}

.chat-agent-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .75rem;
  color: var(--muted);
}

.btn-logout {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
  flex-shrink: 0;
}
.btn-logout:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  gap: 8px;
  align-content: start;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  width: fit-content;
  max-width: 82%;
  min-width: 72px;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  overflow-wrap: anywhere;
  font-size: .9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  animation: msg-in .18s ease-out both;
}

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

.message-user  {
  justify-self: end;
  background: #e8eef6;
  border-color: var(--brand-light);
  color: var(--brand);
}
.message-agent {
  justify-self: start;
  color: var(--text);
}
.message-operator {
  justify-self: start;
  background: #e6f7f3;
  border-color: var(--accent-dark);
  color: var(--text);
}
.message-operator .operator-label {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 4px;
}

/* ── Grouping: bloques consecutivos del mismo sender ──────
   El agente puede enviar N bloques en un turno (to_user array).
   Reducir gap + achatar esquinas internas para efecto WhatsApp.
   ──────────────────────────────────────────────────────── */

/* Bloque no-último de una secuencia de agente */
.message-agent:has(+ .message-agent) {
  border-bottom-left-radius: 4px;
  margin-bottom: 0;
}
/* Bloque no-primero de una secuencia de agente */
.message-agent + .message-agent {
  border-top-left-radius: 4px;
  margin-top: -2px;
}
/* Mismo para usuario */
.message-user:has(+ .message-user) {
  border-bottom-right-radius: 4px;
}
.message-user + .message-user {
  border-top-right-radius: 4px;
  margin-top: -2px;
}

/* Typing */
.typing-indicator {
  width: fit-content;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0 14px 8px;
  flex-shrink: 0;
}

.typing-indicator .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .4;
  animation: bounce-dot 1.4s ease-in-out infinite;
}
.typing-indicator .dot:nth-child(2) { animation-delay: .2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: .4s; }

@keyframes bounce-dot {
  0%, 60%, 100% { transform: translateY(0);   opacity: .4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* Send box — pill igual al original */
.send-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 8px 10px 8px 14px;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: var(--panel);
  flex-shrink: 0;
}

.send-box textarea {
  resize: none;
  overflow-y: auto;
  min-height: 24px;
  max-height: 160px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  line-height: 1.5;
  outline: none;
  background: var(--panel);
  transition: border-color .2s, box-shadow .2s;
}
.send-box textarea:focus {
  border-color: var(--brand-light);
  box-shadow: 0 0 0 3px rgba(59,108,181,.12);
}
.send-box textarea:disabled { opacity: .45; cursor: not-allowed; }

.send-box button[type="submit"] {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.send-box button[type="submit"]:hover:not(:disabled) {
  background: var(--accent);
  transform: scale(1.06);
}
.send-box button[type="submit"]:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
  .access-topbar { padding: 8px 16px; }
  .sofia-avatar  { width: 110px; height: 110px; font-size: 2.8rem; }
  .access-greeting { font-size: 22px; }
  .access-body   { padding: 24px 16px 12px; }
}

@media (min-width: 680px) {
  body.chat-mode { display: flex; align-items: center; justify-content: center; }
  #chat-panel { height: 90dvh; border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,.45); }
}

/* ── Modo iframe: fill 100% sin card/márgenes ── */
.in-iframe body.chat-mode,
.in-iframe #access-panel {
  background: #ffffff;
  display: block;
}
.in-iframe #chat-panel {
  height: 100% !important;
  max-width: 100% !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  border-left: none !important;
  border-right: none !important;
  margin: 0 !important;
}

/* ============================================================
   STICKER
   ============================================================ */
.message-sticker {
  background: transparent;
  border: none;
  padding: 0;
  min-width: unset;
}

.sticker-img {
  width: 160px;
  height: 160px;
  object-fit: contain;
  display: block;
  border-radius: 8px;
}

/* ============================================================
   BANNER DE ERROR — bloqueos VPN/IP/sesión
   Aparece sobre el access-panel cuando el usuario es bloqueado.
   ============================================================ */
.access-error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #7f1d1d;
  color: #fef2f2;
  font-size: .85rem;
  line-height: 1.4;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
  animation: slide-down .25s ease-out;
}

@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.access-error-banner svg { flex-shrink: 0; opacity: .9; }
.access-error-banner span { flex: 1; }

.banner-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  opacity: .7;
  transition: opacity .15s;
  flex-shrink: 0;
}
.banner-close:hover { opacity: 1; }

/* ============================================================
   MODAL TÉRMINOS Y CONDICIONES
   ============================================================ */
#tos-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.tos-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,32,66,.65);
  backdrop-filter: blur(2px);
}

.tos-dialog {
  position: relative;
  z-index: 1;
  background: var(--panel);
  width: 100%;
  max-width: 540px;
  max-height: 88dvh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
  animation: sheet-up .28s cubic-bezier(.22,1,.36,1);
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@media (min-height: 600px) {
  #tos-modal { align-items: center; }
  .tos-dialog { border-radius: 18px; max-height: 80dvh; }
}

.tos-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand);
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tos-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  font-size: .82rem;
  line-height: 1.55;
  color: var(--text);
}
.tos-body::-webkit-scrollbar { width: 4px; }
.tos-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tos-intro { color: var(--muted); margin-bottom: 12px; }

.tos-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
}
.tos-list li {
  padding: 8px 10px;
  background: var(--panel2);
  border-radius: 8px;
  border-left: 3px solid var(--brand-light);
}
.tos-list li strong { color: var(--brand); }

.tos-full-link {
  margin-top: 12px;
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
}

.tos-check-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: .84rem;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1.4;
}
.tos-check-label input[type="checkbox"] {
  width: 18px; height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  accent-color: var(--brand);
  cursor: pointer;
}

.tos-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 20px 20px;
  flex-shrink: 0;
}

.tos-btn-accept {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 28px;
  background: var(--brand);
  color: #ffffff;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, opacity .2s;
}
.tos-btn-accept:hover:not(:disabled) { background: var(--accent); }
.tos-btn-accept:disabled { opacity: .4; cursor: not-allowed; }

.tos-btn-decline {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.tos-btn-decline:hover { background: var(--panel2); color: var(--text); }

/* ============================================================
   ACCESIBILIDAD
   ============================================================ */
.honeypot {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
  tabindex: -1;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
