/* ==========================================================================
   BotAS — Asistente Inteligente de la ASCM
   Sistema de Diseño Institucional Ejecutivo · Auditoría Superior de la CDMX
   Paleta: Guinda Institucional Calibrado + Tonos Neutros Pizarra (Slate)
   ========================================================================== */

:root {
  /* Marca Institucional (Guinda sobrio y calibrado) */
  --brand-deep:         #3C0710;
  --brand-burgundy-dk:  #560B17;
  --brand-burgundy:     #7C1425;
  --brand-accent:       #9B1B30;
  --brand-soft:         rgba(124, 20, 37, 0.08);
  --brand-border:       rgba(124, 20, 37, 0.18);
  --on-brand:           #FFFFFF;

  /* Degradado Navbar Institucional */
  --nav-gradient:       linear-gradient(135deg, #3C0710 0%, #560B17 35%, #7C1425 72%, #4E0914 100%);
  --nav-glow:           radial-gradient(circle at 18% 0%, rgba(255, 255, 255, 0.15), transparent 45%);

  /* Neutros y Superficies (Desaturados para lectura descansada) */
  --surface-ground:     #F8FAFC;   /* Fondo general de la página */
  --surface-card:       #FFFFFF;   /* Paneles y tarjetas */
  --surface-subtle:     #F1F5F9;   /* Hover y fondos secundarios */
  --surface-active:     #E2E8F0;

  /* Escala de Bordes */
  --border-subtle:      #E2E8F0;
  --border-medium:      #CBD5E1;
  --border-focus:       #94A3B8;

  /* Tipografía y Contraste de Texto */
  --text-main:          #0F172A;   /* Slate 900 - Titulares y lectura principal */
  --text-secondary:     #334155;   /* Slate 700 - Texto de apoyo */
  --text-muted:         #64748B;   /* Slate 500 - Etiquetas y metadatos */
  --text-subtle:        #94A3B8;   /* Slate 400 - Indicadores e hints */

  /* Burbujas de Conversación */
  --user-bubble-bg:     #EBF0F6;   /* Gris claro moderno, suave y limpio */
  --user-bubble-fg:     #0F172A;   /* Texto oscuro Slate 900 de alto contraste */
  --user-bubble-border: #D1D9E4;   /* Borde suave sutil */
  --ai-bubble-bg:       #FFFFFF;
  --ai-bubble-fg:       var(--text-main);
  --ai-bubble-border:   var(--border-subtle);

  /* Sombras de Elevación */
  --shadow-xs:          0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm:          0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md:          0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg:          0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.03);
  --shadow-modal:       0 24px 38px -6px rgba(15, 23, 42, 0.22), 0 10px 16px -8px rgba(15, 23, 42, 0.12);

  /* Dimensiones y Geometría */
  --header-h:           74px;
  --radius-sm:          6px;
  --radius-md:          10px;
  --radius-lg:          16px;
  --radius-xl:          22px;
  --radius-pill:        9999px;

  /* Estados Funcionales */
  --danger:             #DC2626;
  --danger-bg:          #FEF2F2;
  --danger-border:      rgba(220, 38, 38, 0.2);

  color-scheme: light;
}

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

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
  background-color: var(--surface-ground);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


h1, h2, h3, h4 {
  margin: 0;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.015em;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

:where(a, button, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand-burgundy);
  outline-offset: 2px;
}

/* ==========================================================================
   1. Encabezado Institucional (Navbar con degradado premium)
   ========================================================================== */

.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--header-h);
  z-index: 1000;
  background: var(--nav-gradient);
  background-image: var(--nav-glow), var(--nav-gradient);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.18);
  display: flex;
  align-items: center;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  width: min(1600px, 100%);
  margin-inline: auto;
  padding: 0 28px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--on-brand);
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.brand-link:hover {
  opacity: 0.95;
}

.logo-container {
  display: flex;
  align-items: center;
  height: 100%;
}

.logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-left: 1px solid rgba(255, 255, 255, 0.25);
  padding-left: 16px;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #FFFFFF;
  line-height: 1.25;
}

.brand-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 400;
}

.brand-name {
  color: #FFFFFF;
  font-weight: 700;
}

.brand-dot {
  color: rgba(255, 255, 255, 0.4);
}

.brand-tagline {
  color: rgba(255, 255, 255, 0.8);
}

/* Acciones en la Navbar (Estado + Enlace al portal) */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  user-select: none;
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #22C55E;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
  animation: pulseDot 2.2s infinite;
}

.status-label {
  font-weight: 600;
  color: #FFFFFF;
}

.status-sep {
  color: rgba(255, 255, 255, 0.4);
}

.status-desc {
  color: rgba(255, 255, 255, 0.78);
}

.portal-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 600;
  color: #FFFFFF;
  text-decoration: none;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.portal-button:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
  color: #FFFFFF;
}

.portal-button i {
  font-size: 0.78rem;
  opacity: 0.85;
}

/* ==========================================================================
   2. Estructura de Contenido Principal (3 Columnas de Consola)
   ========================================================================== */

.content {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: stretch;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: calc(var(--header-h) + 16px) 24px 16px;
  height: 100dvh;
  transition: grid-template-columns 0.25s ease;
}

/* Estado del Rail Colapsado (Menú hamburguesa) */
.content.rail-collapsed {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.content.rail-collapsed .rail {
  display: none !important;
}

/* Paneles contenedores con tarjetas limpias */
.rail,
.chat-container,
.info-card,
.nota {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   3. Panel Lateral Izquierdo (Rail / Conversaciones)
   ========================================================================== */

.rail {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  min-height: 0;
  padding: 18px 16px;
  overflow: hidden;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  background-color: var(--brand-burgundy);
  color: var(--on-brand);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
}

.btn-new-chat:hover {
  background-color: var(--brand-burgundy-dk);
  color: var(--on-brand);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-new-chat i {
  font-size: 1rem;
}

.rail-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.rail-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}

.rail-item {
  display: block;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s ease;
  text-decoration: none;
}

.rail-item:hover {
  background: var(--surface-subtle);
  border-color: var(--border-subtle);
  color: var(--text-main);
  transform: translateY(-1px);
}

.rail-item.is-current {
  background: var(--surface-subtle);
  border-color: var(--border-subtle);
  color: var(--text-main);
  font-weight: 600;
  border-left: 3px solid var(--brand-burgundy);
  box-shadow: var(--shadow-xs);
}

.rail-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-empty {
  margin: 8px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  font-style: italic;
}

/* Sección de métricas desaturada y equilibrada */
.rail-meta {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.rail-figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.figure-card {
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 8px;
  text-align: center;
  transition: border-color 0.2s ease;
}

.figure-card:hover {
  border-color: var(--border-medium);
}

.figure-card b {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.figure-card span {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 3px;
}

/* ==========================================================================
   4. Sección Central (Chat y Conversación)
   ========================================================================== */

.chat-section {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

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

/* Cabecera del chat interno */
.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-subtle);
  background: #FFFFFF;
}

.btn-toggle-rail,
.back-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  font-size: 1.35rem;
  color: var(--text-secondary);
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex: none;
}

.btn-toggle-rail:hover,
.back-button:hover {
  background: var(--surface-subtle);
  border-color: var(--border-medium);
  color: var(--brand-burgundy);
  transform: translateY(-1px);
}

.btn-toggle-rail:active,
.back-button:active {
  transform: translateY(0);
}

.chat-title-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-title-text {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-title-tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.chat-title-actions {
  display: flex;
  align-items: center;
}

.btn-reset-chat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-reset-chat:hover {
  background: var(--surface-subtle);
  border-color: var(--border-medium);
  color: var(--text-main);
}

.btn-reset-chat i {
  font-size: 0.85rem;
}

/* Historial de Mensajes */
.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #FCFDFE;
}

.message {
  max-width: min(80ch, 90%);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

/* Avatar del asistente: Contenedor circular con espaciado equilibrado y personaje prominente */
.message-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  overflow: hidden;
  background-color: #FFFFFF;
  border: 1.5px solid var(--border-medium);
  box-shadow: var(--shadow-sm);
  padding: 2.5px;
}

.message-icon img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: auto;
  image-rendering: smooth;
}

#typing-indicator .message-icon {
  padding: 0;
}

#typing-indicator .message-icon img {
  width: 165%;
  height: 165%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  image-rendering: auto;
  image-rendering: smooth;
}




.message-content {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message-content p {
  margin: 0;
}

.message-content p:not(:last-child) {
  margin-bottom: 12px;
}

.message-content a {
  color: var(--brand-burgundy);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  word-break: break-word;
  transition: color 0.15s ease;
}

.message-content a:hover {
  color: var(--brand-accent);
}

.message-content .list-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 6px 0;
}

.message-content .list-number,
.message-content .bullet-point {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--brand-burgundy);
  line-height: inherit;
}

.message-content .list-content {
  flex: 1;
  min-width: 0;
  line-height: inherit;
}

/* Fallback de seguridad si un list-item no contiene .list-content para evitar que hijos inline se dividan en columnas flex */
.message-content .list-item:not(:has(.list-content)) {
  display: block;
  position: relative;
  padding-left: 22px;
}

.message-content .list-item:not(:has(.list-content)) .list-number,
.message-content .list-item:not(:has(.list-content)) .bullet-point {
  position: absolute;
  left: 0;
  top: 0;
}

.message-content pre,
.message-content table {
  max-width: 100%;
  overflow-x: auto;
}

.message-content pre {
  background: var(--surface-subtle);
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.45;
}

.message-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
}


/* Mensajes de BotAS (Blanco puro, borde sutil, elevación suave) */
.ai-message {
  align-self: flex-start;
}

.ai-message .message-content {
  background: var(--ai-bubble-bg);
  color: var(--ai-bubble-fg);
  border: 1px solid var(--ai-bubble-border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-xs);
}

/* Mensajes del Usuario (Gris claro premium y legible) */
.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.user-message .message-icon {
  display: none;
}

.user-message .message-content {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-fg);
  border: 1px solid var(--user-bubble-border);
  border-top-right-radius: 4px;
  box-shadow: var(--shadow-xs);
  font-weight: 450;
}

.user-message .message-content a {
  color: var(--brand-burgundy);
  font-weight: 600;
}

/* Indicador de escritura */
.typing-indicator {
  display: flex;
}

.typing-indicator .message-content {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 18px 20px;
}

.typing-indicator .message-content span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--brand-burgundy);
  opacity: 0.35;
  animation: typing 1s infinite;
}

.typing-indicator .message-content span:nth-of-type(2) {
  animation-delay: 0.2s;
}

.typing-indicator .message-content span:nth-of-type(3) {
  animation-delay: 0.4s;
}

.error-message {
  align-self: center;
  max-width: 80%;
  padding: 12px 18px;
  font-size: 0.88rem;
  color: var(--danger);
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-md);
}

/* ==========================================================================
   5. Barra de Entrada de Chat (Moderna y Ergonómica)
   ========================================================================== */

.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex: none;
  padding: 14px 22px 16px;
  border-top: 1px solid var(--border-subtle);
  background: #FFFFFF;
}

.textarea-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#input-text {
  width: 100%;
  min-height: 48px;
  max-height: 140px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text-main);
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  resize: none;
  overflow-y: hidden;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

#input-text::placeholder {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


#input-text:focus {
  outline: none;
  background: #FFFFFF;
  border-color: var(--brand-burgundy);
  box-shadow: 0 0 0 3px rgba(124, 20, 37, 0.10);
}

#input-text:disabled {
  background-color: var(--surface-subtle);
  cursor: not-allowed;
}

.input-footer {
  display: flex;
  align-items: center;
  padding-left: 2px;
}

.input-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  user-select: none;
}

.input-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.68rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-subtle);
  border: 1px solid var(--border-medium);
  border-radius: 4px;
}

.send-button {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  color: var(--on-brand);
  background-color: var(--brand-burgundy);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.send-button:hover {
  background-color: var(--brand-burgundy-dk);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.send-button:disabled,
.send-button.disabled {
  background-color: var(--border-subtle);
  color: var(--text-subtle);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ==========================================================================
   6. Panel Lateral Derecho (Información y Sugerencias)
   ========================================================================== */

.info-section {
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.info-card {
  padding: 13px 14px 12px;
  flex-shrink: 0;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.chip {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: 0.92rem;
  color: var(--brand-burgundy);
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.card-head .panel-title {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-burgundy);
  margin-bottom: 1px;
}

.card-title {
  font-size: 0.90rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0;
}

.info-card p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.info-card p + p {
  margin-top: 10px;
}

.info-card strong {
  color: var(--text-main);
  font-weight: 600;
}

/* ==========================================================================
   Carrusel de Tarjetas Institucionales (Acerca de la ASCM - Diseño Compacto)
   ========================================================================== */

.institution-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 13px;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-top: 3.5px solid var(--brand-burgundy);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.institution-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-medium);
}

/* Cabecera integrada de la tarjeta */
.inst-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.inst-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inst-icon-badge {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  font-size: 0.95rem;
  color: var(--brand-burgundy);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.inst-eyebrow {
  display: block;
  font-size: 0.70rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-burgundy);
  line-height: 1.1;
}

.inst-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  line-height: 1.25;
}

/* Controles de navegación compactos */
.inst-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.inst-counter {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  line-height: 1.2;
}

.inst-arrows {
  display: flex;
  align-items: center;
  gap: 3px;
}

.inst-nav-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  font-size: 0.76rem;
  color: var(--text-secondary);
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0;
}

.inst-nav-btn:hover {
  background: #FFFFFF;
  border-color: var(--border-medium);
  color: var(--brand-burgundy);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

.inst-nav-btn:active {
  transform: translateY(0);
}

/* Contenedor viewport de diapositivas (CSS Grid: altura dinámica perfecta, sin solapamientos) */
.inst-viewport {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  min-height: 84px;
  background: transparent;
  border: none;
  padding: 4px 0 2px 0;
  position: relative;
}

.inst-slide {
  grid-area: 1 / 1 / 2 / 2;
  opacity: 0;
  visibility: hidden;
  transform: translateX(10px);
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.inst-slide.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  pointer-events: auto;
}

.inst-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.70rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-burgundy);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-pill);
  padding: 2.5px 9px;
  width: fit-content;
}

.inst-badge i {
  font-size: 0.74rem;
}

.inst-desc {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.inst-desc strong {
  color: var(--text-main);
  font-weight: 600;
}



/* Botones de sugerencia (Reducción ~10% de escala e interlineado) */
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.suggestion-btn {
  width: 100%;
  text-align: left;
  padding: 8px 11px;
  font-family: inherit;
  font-size: 0.79rem;
  font-weight: 500;
  line-height: 1.34;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-ground);
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
}

.suggestion-btn:hover {
  border-color: rgba(124, 20, 37, 0.35);
  background: #FFFFFF;
  color: var(--brand-burgundy);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.suggestion-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.suggestion-btn.fade-out {
  animation: fadeOutSlideUp 0.35s ease forwards;
}

.suggestion-btn.fade-in {
  animation: fadeInSlideDown 0.35s ease forwards;
}

/* Nota Oficial / Leyenda de Advertencia IA (Reducción ~5-10% y flex-shrink: 0) */
.nota {
  padding: 8px 10px;
  background: #FFFDF9;
  border: 1px solid rgba(217, 119, 6, 0.22);
  border-left: 3px solid #D97706;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}

.nota-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 1px;
}

.nota-header-left {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #B45309;
}

.nota-header-left i {
  font-size: 0.76rem;
}

.nota-title {
  font-weight: 700;
  font-size: 0.72rem;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.nota-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #B45309;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.25);
  padding: 0.5px 5px;
  border-radius: var(--radius-pill);
}

.nota p {
  margin: 0;
  font-size: 0.69rem;
  line-height: 1.34;
  color: var(--text-secondary);
}

.nota p strong {
  color: #92400E;
  font-weight: 600;
}

.nota-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 1px;
  font-size: 0.69rem;
  font-weight: 600;
  color: var(--brand-burgundy);
  text-decoration: none;
  transition: all 0.15s ease;
}

.nota-link:hover {
  color: var(--brand-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.nota-link i {
  font-size: 0.64rem;
}

/* ==========================================================================
   7. Modal de Bienvenida (Backdrop Blur y Acabado Limpio)
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-color: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(8px);
}

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.25s ease;
}

.modal-overlay.fade-out {
  animation: fadeIn 0.25s ease reverse forwards;
}

.modal-content {
  width: min(800px, 100%);
  background: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}

.modal-body {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 36px;
}

.modal-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
}

.modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--brand-soft);
  color: var(--brand-burgundy);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
}

.speech-bubble {
  padding: 16px 20px;
  background: var(--surface-ground);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
}

.welcome-heading {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.welcome-message {
  margin: 0 0 10px;
  font-size: 0.94rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.modal-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--brand-burgundy);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.modal-link:hover {
  color: var(--brand-accent);
}

.btn-start-chat {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 12px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--on-brand);
  background-color: var(--brand-burgundy);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-start-chat:hover {
  background-color: var(--brand-burgundy-dk);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.modal-image {
  flex: none;
  width: 220px;
}

.botas-welcome {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.08));
  image-rendering: auto;
  image-rendering: smooth;
}


/* ==========================================================================
   8. Animaciones y Transiciones
   ========================================================================== */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes pulseDot {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes typing {
  0%, 100% { opacity: 0.35; transform: translateY(0); }
  50%      { opacity: 1;    transform: translateY(-2px); }
}

@keyframes fadeOutSlideUp {
  to { opacity: 0; transform: translateY(-5px); }
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   9. Barras de Desplazamiento Personalizadas (Sleek)
   ========================================================================== */

.chat-messages::-webkit-scrollbar,
.info-section::-webkit-scrollbar,
.rail-list::-webkit-scrollbar,
#input-text::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.chat-messages::-webkit-scrollbar-thumb,
.info-section::-webkit-scrollbar-thumb,
.rail-list::-webkit-scrollbar-thumb,
#input-text::-webkit-scrollbar-thumb {
  background-color: var(--border-medium);
  border-radius: var(--radius-pill);
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.info-section::-webkit-scrollbar-thumb:hover,
.rail-list::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
}

/* ==========================================================================
   10. Responsividad (Adaptación a Móviles y Tablets)
   ========================================================================== */

@media (max-width: 1360px) {
  .content {
    grid-template-columns: 240px minmax(0, 1fr) 290px;
    gap: 16px;
    padding: calc(var(--header-h) + 14px) 18px 14px;
  }
  
  .content.rail-collapsed {
    grid-template-columns: minmax(0, 1fr) 290px;
  }
  
  .header-content {
    padding: 0 18px;
  }
}

@media (max-width: 1100px) {
  .content {
    grid-template-columns: 240px minmax(0, 1fr);
    height: auto;
    min-height: 100dvh;
    gap: 16px;
  }

  .content.rail-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-section {
    height: clamp(520px, 72dvh, 720px);
  }

  .info-section {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    overflow: visible;
  }

  .rail {
    position: sticky;
    top: calc(var(--header-h) + 14px);
    align-self: start;
  }

  .rail-list {
    max-height: 42dvh;
  }
}

@media (max-width: 820px) {
  :root {
    --header-h: 64px;
  }

  .content {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: calc(var(--header-h) + 10px) 12px 14px;
    height: auto;
  }

  .header-content {
    padding: 0 14px;
  }

  .brand-text {
    padding-left: 8px;
    min-width: 0;
  }

  .brand-title {
    font-size: clamp(0.78rem, 2.8vw, 0.88rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-tagline {
    display: none;
  }

  .nav-status-badge {
    display: none;
  }

  .logo {
    height: 38px;
  }

  .portal-button {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  /* Conversaciones en carrusel horizontal tipo chip en móvil */
  .rail {
    position: static;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-radius: var(--radius-md);
  }

  .rail::-webkit-scrollbar {
    display: none;
  }

  .rail-section {
    min-width: 0;
    flex: 1;
  }

  .rail-label,
  .rail-meta,
  .rail-empty {
    display: none;
  }

  .rail-list {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    max-height: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 0;
  }

  .rail-list::-webkit-scrollbar {
    display: none;
  }

  .rail-item {
    flex-shrink: 0;
    max-width: 170px;
    padding: 6px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    white-space: nowrap;
    background: var(--surface-card);
  }

  .rail-item.is-current {
    border-left: 1px solid var(--brand-burgundy);
    border-color: var(--brand-burgundy);
    background: rgba(124, 20, 37, 0.08);
    color: var(--brand-burgundy);
    box-shadow: none;
  }

  .btn-new-chat {
    flex-shrink: 0;
    padding: 7px 12px;
    font-size: 0.82rem;
    border-radius: var(--radius-pill);
    gap: 6px;
  }

  .chat-section {
    height: clamp(480px, 75dvh, 640px);
  }

  .chat-messages {
    padding: 14px;
    gap: 14px;
  }

  .chat-title {
    padding: 10px 14px;
    gap: 10px;
  }

  .chat-title-text {
    font-size: 0.95rem;
  }

  .chat-title-tag {
    font-size: 0.72rem;
  }

  .btn-toggle-rail {
    width: 34px;
    height: 34px;
    font-size: 1.15rem;
  }

  .btn-reset-chat {
    padding: 5px 10px;
    font-size: 0.78rem;
  }

  .message {
    max-width: 96%;
    gap: 10px;
  }

  /* Burbuja circular con respiro proporcional en móvil (50px) */
  .message-icon {
    width: 50px;
    height: 50px;
    padding: 2px;
  }


  .message-content {
    padding: 12px 15px;
    font-size: 0.92rem;
  }

  .chat-input {
    padding: 10px 14px;
    gap: 10px;
    align-items: flex-end;
  }

  .textarea-wrapper {
    flex: 1;
    min-width: 0;
  }

  #input-text {
    font-size: 16px; /* Evita auto-zoom en iOS Safari */
    padding: 12px 14px;
    min-height: 48px;
    line-height: 1.4;
    overflow-y: hidden;
  }

  #input-text::placeholder {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .send-button {
    width: 48px;
    height: 48px;
    font-size: 1.15rem;
    flex-shrink: 0;
  }

  .input-hint {
    display: none;
  }


  .info-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: visible;
  }

  .suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .modal-content {
    width: min(92vw, 540px);
    max-height: 90dvh;
    margin: 12px;
  }

  .modal-body {
    flex-direction: column-reverse;
    gap: 16px;
    padding: 20px;
  }

  .modal-image {
    width: 130px;
    margin: 0 auto;
  }

  .speech-bubble {
    padding: 14px 16px;
  }

  .welcome-heading {
    font-size: 1.2rem;
  }

  .welcome-message {
    font-size: 0.88rem;
  }
}

@media (max-width: 480px) {
  :root {
    --header-h: 58px;
  }

  .header-content {
    padding: 0 10px;
  }

  .brand-link {
    gap: 10px;
  }

  .logo {
    height: 32px;
  }

  .brand-title {
    font-size: 0.74rem;
    max-width: 175px;
  }

  .brand-subtitle {
    font-size: 0.72rem;
  }

  .portal-button {
    width: 34px;
    height: 34px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
  }

  .portal-button span {
    display: none;
  }

  .portal-button i {
    font-size: 0.9rem;
    margin: 0;
  }

  .chat-title-tag {
    display: none;
  }

  .btn-reset-chat span {
    display: none;
  }

  .btn-reset-chat {
    padding: 6px 8px;
  }

  .rail-item {
    max-width: 140px;
  }

  .chat-section {
    height: clamp(450px, 73dvh, 600px);
  }

  .message {
    max-width: 98%;
    gap: 8px;
  }

  .message-icon {
    width: 45px;
    height: 45px;
    padding: 2px;
  }


  .message-content {
    padding: 10px 13px;
    font-size: 0.88rem;
  }

  .modal-image {
    width: 110px;
  }

  .btn-start-chat {
    width: 100%;
    justify-content: center;
    padding: 10px 16px;
    font-size: 0.9rem;
  }
}

