/* =========================================================================
   app.css — Librería de componentes Innuvex Flow Admin (index + livechat)
   Todo referencia tokens semánticos de design-tokens.css — cero hex/hsl
   hardcodeado. Bitema: cada regla usa var(--...) que ya cambia con
   :root[data-theme="light"] / prefers-color-scheme.
   ========================================================================= */

/* ========================================= */
/* 1. RESET & BASE                           */
/* ========================================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100dvh;
  margin: 0;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Applied only to livechat.html via JS — locks layout to viewport height */
body.livechat-layout {
  height: 100dvh;
  overflow: hidden;
}

/* Reducción de movimiento */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

h1, h2, h3, .brand {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hidden {
  display: none !important;
}

/* ========================================= */
/* 2. TYPOGRAPHY & UTILITIES                 */
/* ========================================= */

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.font-mono { font-family: var(--font-mono); }
.text-center { text-align: center; }

.text-muted-sm       { color: var(--text-muted);     font-size: 0.85rem; }
.text-secondary-sm   { color: var(--text-secondary); font-size: 0.88rem; }
.text-secondary-xs   { color: var(--text-secondary); font-size: 0.75rem; }
.text-primary-sm     { color: var(--text-primary);   font-size: 0.85rem; }
.line-height-relaxed { line-height: 1.5; }

.mb-0    { margin-bottom: 0; }
.mt-sm   { margin-top: 0.5rem; }
.mt-md   { margin-top: 1rem; }
.mt-lg   { margin-top: 1.5rem; }
.mb-sm   { margin-bottom: 0.5rem; }
.mb-md   { margin-bottom: 1rem; }
.mb-lg   { margin-bottom: 1.5rem; }

.flex-center        { display: flex; align-items: center; }
.flex-center-gap-sm { display: flex; align-items: center; gap: 0.5rem; }
.flex-end           { display: flex; justify-content: flex-end; }
.flex-between       { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap-gap      { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }

/* Tipografía fluida para títulos */
h1, .fluid-h1 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
h2, .fluid-h2 { font-size: clamp(1.25rem, 3vw, 2rem); }
.section-title { font-size: clamp(1rem, 2vw, 1.4rem); font-family: var(--font-display); }

.hr-subtle {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
}

/* ========================================= */
/* 3. ICONOGRAFÍA SVG                        */
/* ========================================= */

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
}

.icon svg {
  width: 1em;
  height: 1em;
  display: block;
}

/* Tamaño base: hereda font-size del contexto (botones/nav = ~0.9rem) */
.icon-lg svg { width: 2rem; height: 2rem; }
.icon-xl svg { width: 3rem; height: 3rem; }

@keyframes icon-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.icon-spin svg {
  animation: icon-spin 1s linear infinite;
}

/* ========================================= */
/* 4. HEADER                                 */
/* ========================================= */

header {
  background-color: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border-subtle);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.badge-live {
  background: var(--color-success-tint);
  color: var(--color-success);
  border: 1px solid var(--color-success-border);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 4px var(--color-success-tint); }
  50% { box-shadow: 0 0 12px var(--color-success-tint); }
}

.pulse-glow {
  animation: pulse-glow 2s ease-in-out infinite;
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.btn-logout:hover {
  color: var(--color-error);
  border-color: var(--color-error-border);
}

.header-brand       { color: var(--text-primary); font-family: var(--font-display); }
.header-biz-name    { font-weight: 500; font-family: var(--font-ui); margin-right: 1rem; }
.header-logout      { margin-left: 1rem; }

/* Botón icono-solo "fantasma" (toggle de tema) — objetivo táctil 44x44 */
.btn-icon-ghost {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s;
}

.btn-icon-ghost:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* Icono sol/luna del toggle — visibilidad según tema activo */
.theme-toggle-to-dark { display: none; }
:root[data-theme="light"] .theme-toggle-to-light { display: none; }
:root[data-theme="light"] .theme-toggle-to-dark { display: inline-flex; }

/* ========================================= */
/* 5. NAVEGACIÓN SECUNDARIA (panel admin)    */
/* ========================================= */

.admin-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 61px; /* justo debajo del header sticky */
  z-index: 90;
  overflow-x: auto;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.nav-item-active {
  background: var(--color-primary-tint);
  border-color: var(--color-primary-border);
  color: var(--color-secondary);
}

.nav-item-active:hover {
  background: var(--color-primary-tint);
}

.nav-item-live {
  margin-left: auto;
  background: var(--color-success-tint);
  border-color: var(--color-success-border);
  color: var(--color-success);
}

.nav-item-live:hover {
  background: var(--color-success-tint);
  filter: brightness(1.1);
}

/* Pill genérico (paginación, filtros secundarios) — distinto de .nav-item */
.nav-pill {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: background 0.2s;
}

.nav-pill:hover {
  background: var(--bg-surface-hover);
}

.nav-link {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.2s;
}

.nav-link:hover {
  color: var(--text-primary);
}

/* Mobile: la nav secundaria se convierte en bottom-nav fija */
@media (max-width: 768px) {
  .admin-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    justify-content: space-around;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    border-bottom: none;
    padding: 0.5rem;
    z-index: 150;
  }
  .nav-item {
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.4rem 0.5rem;
    font-size: 0.68rem;
    flex: 1;
  }
  .nav-item-live { margin-left: 0; }
  /* Deja espacio para la bottom-nav fija */
  main { padding-bottom: 72px; }
}

/* ========================================= */
/* 6. LOGIN / AUTH                           */
/* ========================================= */

.auth-shell {
  max-width: 440px;
  margin: 6rem auto;
  padding: 0 1.5rem;
}

.auth-card { padding: 2.5rem 2rem; }

.auth-title {
  font-family: var(--font-display);
  margin-bottom: 0.5rem;
}

.auth-subtitle {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-sm);
}

.form-group { margin-bottom: 1.5rem; }
.form-group-no-mb { margin-bottom: 0; }

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.88rem;
}

input[type="text"], input[type="password"], input[type="tel"],
input[type="number"], input[type="time"], input[type="datetime-local"],
input[type="date"], input[type="file"], textarea, select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px !important;
}

.form-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  margin-bottom: 0;
  color: var(--text-primary);
}
.form-toggle-label input[type="checkbox"] { width: auto; cursor: pointer; }
.form-row-align-end { display: flex; align-items: center; margin-top: 1.8rem; }

/* ========================================= */
/* 7. BOTONES                                */
/* ========================================= */

.btn-primary {
  width: 100%;
  padding: 0.9rem;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-weight: 600;
  font-family: var(--font-ui);
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s, transform 0.1s, filter 0.2s;
}

.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Variante en línea (no ocupa el 100% del ancho) — filtros, toolbars */
.btn-inline { width: auto; padding: 0.75rem 1.25rem; }

.btn-cta {
  width: 100%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s, transform 0.1s, filter 0.2s;
}

.btn-cta:hover { background: var(--color-primary-hover); }
.btn-cta:active { transform: scale(0.98); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-secondary);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.2s, transform 0.1s;
}

.btn-outline:hover { background: var(--color-primary-tint); }

.btn-outline-success {
  border-color: var(--color-success);
  color: var(--color-success);
}
.btn-outline-success:hover { background: var(--color-success-tint); }

.btn-outline-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

.btn-send {
  background: var(--color-primary);
  border: none;
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.2s;
}

.btn-send:hover { background: var(--color-primary-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-resolve {
  background: var(--color-error-tint);
  color: var(--color-error);
  border: 1px solid var(--color-error-border);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.2s;
}

.btn-resolve:hover { background: var(--color-error-tint); filter: brightness(1.1); }

/* Botón icono-solo genérico (fila dinámica, borrar documento, cerrar modal) */
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.btn-icon-danger:hover {
  color: var(--color-error);
  background: var(--color-error-tint);
}

/* ========================================= */
/* 8. BADGES                                 */
/* ========================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-neutral {
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}

.badge-primary {
  background: var(--color-primary-tint);
  color: var(--color-secondary);
  border-color: var(--color-primary-border);
}

.badge-success {
  background: var(--color-success-tint);
  color: var(--color-success);
  border-color: var(--color-success-border);
}

.badge-warning {
  background: var(--color-warning-tint);
  color: var(--color-warning);
  border-color: var(--color-warning-border);
}

.badge-error {
  background: var(--color-error-tint);
  color: var(--color-error);
  border-color: var(--color-error-border);
}

.badge-premium {
  background: var(--color-warning-tint);
  color: var(--color-warning);
  border: 1px solid var(--color-warning-border);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  display: inline-block;
}

/* ========================================= */
/* 9. TOAST                                  */
/* ========================================= */

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--color-error);
  color: white;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  animation: slideUp 0.3s ease;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================= */
/* 10. CHAT LAYOUT (LIVECHAT — DESKTOP)      */
/* ========================================= */

#chat-view {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: 0; /* Let flex: 1 determine height, prevents calc() overflow on mobile */
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.badge-count {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  min-width: 20px;
  text-align: center;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.session-item {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.session-item:hover {
  background: var(--bg-surface-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* URGENT / PENDING SESSION */
.session-item.status-pending {
  border-left: 3px solid var(--color-primary);
  box-shadow: var(--shadow-urgent);
}

.session-item.status-pending .urgent-label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-secondary);
  background: var(--color-primary-tint);
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}

/* ACTIVE SESSION (Agent replied) */
.session-item.status-active {
  border-left: 3px solid var(--color-secondary);
}
.session-item.status-active .urgent-label {
  display: none;
}

/* SELECTED SESSION (Currently viewing) */
.session-item.selected {
  background: var(--color-primary-tint);
  border-color: var(--color-primary-border);
}

.session-item .hash {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}

.session-item .meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.35rem;
}

.empty-inbox {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 2rem;
}

.empty-inbox svg {
  width: 40px;
  height: 40px;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-align: center;
  padding: 2rem;
}

.chat-empty .brand-title {
  font-family: var(--font-display);
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.chat-active-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header .hash {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 500;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
}

#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg-bubble {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.msg-bubble.inbound {
  align-self: flex-start;
  background: var(--bg-bubble-in);
  border-bottom-left-radius: 2px;
}

.msg-bubble.outbound {
  align-self: flex-end;
  background: var(--bg-bubble-out);
  border: 1px solid var(--color-primary-border);
  border-bottom-right-radius: 2px;
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.msg-bubble.outbound .msg-time {
  text-align: right;
}

#compose-container {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  gap: 0.75rem;
}

#compose-container input {
  flex: 1;
}

/* ========================================= */
/* 11. MOBILE RESPONSIVE — LIVECHAT (<768px) */
/* ========================================= */

.fab-inbox {
  display: none; /* Solo visible en mobile */
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: var(--color-primary);
  color: white;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  box-shadow: var(--shadow-md);
  z-index: 200;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.fab-inbox:hover {
  background: var(--color-primary-hover);
}

.fab-inbox .badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--color-error);
  color: white;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
}

.overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
  backdrop-filter: blur(2px);
}

.mobile-only-flex {
  display: none !important;
}

@media (max-width: 768px) {
  .mobile-only-flex {
    display: flex !important;
  }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60vh;
    border-top: 1px solid var(--border-subtle);
    border-right: none;
    z-index: 160;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
  }

  .sidebar.open {
    transform: translateY(0);
  }

  .overlay.open {
    display: block;
  }
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }
  .header-right {
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }
  #biz-name {
    display: none !important; /* Hide to save vertical space when sticky */
  }
  .fab-inbox {
    display: flex;
  }
  /* Hide FAB when a chat session is active — avoid obstructing messages */
  .fab-inbox.chat-active-hide {
    display: none !important;
  }
}

/* ========================================= */
/* 12. ADMIN — LAYOUT DE CONOCIMIENTO        */
/* ========================================= */

.analytics-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
}
.analytics-view.hidden {
  display: none !important;
}

.admin-container {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 2rem;
  align-items: start;
}

.admin-grid-single {
  grid-template-columns: 1fr;
}

@media (max-width: 900px) {
  .admin-grid {
    display: flex;
    flex-direction: column-reverse; /* Put main column below sidebar on mobile if default flow */
  }
}

.admin-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}

.admin-section-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.admin-section-header h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
  margin: 0;
}

.section-icon {
  width: 1.2rem;
  height: 1.2rem;
  color: var(--text-secondary);
}
.section-icon-primary   { color: var(--color-secondary); }
.section-icon-secondary { color: var(--color-secondary); }
.section-icon-success   { color: var(--color-success); }

.section-header-accent-primary   { color: var(--color-secondary); }
.section-header-accent-secondary { color: var(--color-secondary); }
.section-header-accent-success   { color: var(--color-success); }
.section-header-badge-right      { margin-left: auto; }

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

.dynamic-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.dynamic-row input {
  flex: 1;
}

@media (max-width: 768px) {
  .dynamic-row {
    flex-direction: column;
    align-items: stretch;
    background: var(--bg-surface-hover);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
  }
  .dynamic-row .btn-icon {
    align-self: flex-end;
  }
}

/* ========================================= */
/* 13. SIDEBAR PREMIUM — BASE DE CONOCIMIENTO*/
/* ========================================= */

.premium-sidebar {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  overflow: hidden;
}

.premium-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.premium-title {
  font-family: var(--font-display);
  color: var(--color-secondary);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.premium-body {
  padding: 1.5rem;
}

.doc-card {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  transition: all 0.2s ease;
}

.doc-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.doc-name {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-all;
}

.doc-meta {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.doc-status {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.doc-empty-state {
  text-align: center;
  padding: 1.5rem;
  background: var(--bg-app);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-subtle);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-completed { background: var(--color-success); }
.status-processing { background: var(--color-warning); animation: pulse-amber 2s infinite; }
.status-error { background: var(--color-error); }

@keyframes pulse-amber {
  0%, 100% { box-shadow: 0 0 0 0 var(--color-warning-tint); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.file-input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.file-input-wrapper-stacked input[type="file"],
.file-input-wrapper-stacked .btn-primary {
  width: 100%;
}

.file-input-wrapper input[type="file"] {
  border: 1px dashed var(--border-subtle);
  cursor: pointer;
  font-size: 0.85rem;
}

.file-input-wrapper input[type="file"]::file-selector-button {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-right: 1rem;
  font-family: var(--font-ui);
  transition: background 0.2s;
}

.file-input-wrapper input[type="file"]::file-selector-button:hover {
  background: var(--bg-surface);
}

.file-input-wrapper .btn-primary {
  padding: 0.9rem 1.5rem;
  font-size: 0.95rem;
}

.doc-upload-hint {
  font-size: 0.75rem;
  line-height: 1.4;
  margin-top: -0.5rem;
  margin-bottom: 1.5rem;
}

.doc-section-label {
  font-size: 0.85rem;
  font-family: var(--font-ui);
  color: var(--text-primary);
  margin-bottom: 1rem;
}

/* MOBILE PREMIUM DETAILS */
.mobile-details {
  display: none;
}

@media (max-width: 900px) {
  .premium-sidebar {
    display: none;
  }
  .mobile-details {
    display: block;
    margin-bottom: 1rem;
  }
  .mobile-details details {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
  }
  .mobile-details summary {
    list-style: none;
    padding: 1rem 1.5rem;
    font-family: var(--font-display);
    color: var(--color-secondary);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    outline: none;
  }
  .mobile-details summary::-webkit-details-marker {
    display: none;
  }
  .mobile-details summary::after {
    content: '+';
    font-size: 1.5rem;
    font-weight: 400;
    line-height: 1;
    margin-left: auto;
    transition: transform 0.2s;
  }
  .mobile-details details[open] summary::after {
    content: '−';
  }
  .mobile-details .premium-body {
    border-top: 1px solid var(--border-subtle);
  }
}

/* ========================================= */
/* 14. AUDITORÍA — TABLA / MODAL / PAGINACIÓN*/
/* ========================================= */

.audit-container { max-width: 1200px; margin: 2rem auto; }
.audit-filters-card { margin-bottom: 2rem; overflow: visible; }
.audit-filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  align-items: flex-end;
}
.audit-filters-grid .btn-inline {
  width: 100%;
}
@media (max-width: 768px) {
  .audit-filters-grid {
    grid-template-columns: 1fr;
  }
}
.audit-summary { margin-bottom: 1rem; font-size: 0.95rem; min-height: 1.4rem; }

.table-wrap { overflow-x: auto; }

.audit-table { width: 100%; text-align: left; border-collapse: collapse; color: var(--text-primary); }
.audit-th { padding: 1rem 0.5rem; color: var(--text-secondary); border-bottom: 1px solid var(--border-subtle); }
.audit-td { padding: 1rem 0.5rem; }
.audit-td-mono { padding: 1rem 0.5rem; font-family: var(--font-mono); font-size: 0.9rem; }
.audit-tr { border-bottom: 1px solid var(--border-subtle); }
.audit-intent-badge {
  background: var(--bg-surface-hover);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  color: var(--text-secondary);
}
.pagination-controls { display: flex; gap: 0.5rem; align-items: center; }
.pagination-indicator { margin: 0 1rem; font-weight: 500; }

/* Modal genérico (detalle de conversación de auditoría) */
.modal-inline {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-inline-card {
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

.modal-summary-box {
  background: var(--bg-surface-hover);
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}
.modal-section-title {
  color: var(--text-primary);
  margin-bottom: 1rem;
  font-family: var(--font-display);
}
.modal-events-list { display: flex; flex-direction: column; gap: 0.8rem; }
.modal-event-row {
  padding: 0.6rem 0.9rem;
  border-left: 2px solid var(--border-subtle);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ========================================= */
/* 15. MÉTRICAS (IFRAME METABASE)            */
/* ========================================= */

.analytics-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  background: var(--bg-app);
  color: var(--color-secondary);
}
.analytics-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: calc(100dvh - 56px);
  border: none;
  display: block;
}

/* Panel de estado reutilizable: loading fallback / error / upsell */
.state-panel {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  max-width: 460px;
}
.state-panel-icon { color: var(--text-muted); margin-bottom: 0.5rem; }
.state-panel-icon-accent { color: var(--color-secondary); margin-bottom: 1rem; }
.state-panel-text { margin-bottom: 1.5rem; font-size: 0.95rem; }
.state-panel-title {
  font-family: var(--font-display);
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}
.state-panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 3rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.state-panel-list {
  text-align: left;
  list-style: none;
  padding: 0;
  margin-bottom: 2rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
  width: 100%;
}
.state-panel-list li {
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.state-panel-list .icon { color: var(--color-success); }
.state-panel-cta { width: 100%; }

/* ========================================= */
/* 16. MICRO-INTERACCIONES / FOCO / SKELETON */
/* ========================================= */

.nav-item,
.nav-pill,
.btn-outline,
.btn-cta,
.btn-primary,
.btn-logout,
.btn-resolve,
.btn-send,
.session-item,
.doc-card {
  transition: all 0.2s ease;
}

.nav-item:hover,
.btn-outline:hover {
  transform: translateY(-1px);
}

.btn-primary:hover,
.btn-cta:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-surface) 25%,
    var(--bg-surface-hover) 50%,
    var(--bg-surface) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row {
  height: 48px;
  margin-bottom: 0.75rem;
}

.skeleton-text-sm { height: 12px; width: 60%; margin-bottom: 0.5rem; }
.skeleton-text-md { height: 16px; width: 80%; margin-bottom: 0.5rem; }
