/* ==========================================================================
   1. IMPORTACIÓN Y VARIABLES DE RAÍZ (CUSTOM PROPERTIES)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* Paleta de Colores */
  --color-primary: #5A67D8; /* Índigo principal */
  --color-primary-dark: #4C51BF;
  --color-secondary: #764BA2; /* Morado para gradientes */
  --color-background: #F7FAFC; /* Fondo principal muy claro */
  --color-surface: #FFFFFF; /* Color de las tarjetas y contenedores */
  --color-text-primary: #2D3748; /* Texto principal oscuro */
  --color-text-secondary: #718096; /* Texto secundario más claro */
  --color-border: #E2E8F0; /* Bordes sutiles */
  --color-success: #38A169;
  --color-danger: #E53E3E;

  /* Tipografía */
  --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* Espaciado y Radios */
  --spacing-base: 24px;
  --spacing-vertical-sections: 24px;
  --border-radius-large: 16px; /* Para contenedores principales */
  --border-radius-medium: 10px; /* Para inputs y elementos interactivos */
  --border-radius-small: 6px; /* Para elementos pequeños como tags */

  /* Sombras */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   2. ESTILOS BASE Y GENERALES
   ========================================================================== */
* { box-sizing: border-box; }

html {
  color-scheme: light;
  font-family: var(--font-family-base);
  background-color: var(--color-background);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* padding: 40px 20px; */
  padding: 20px 20px 20px 20px;
  background-color: #F0F2F5;
}

body.modal-open {
  overflow: hidden;
}

main {
  width: min(1024px, 100%);
  background-color: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
}

/* ==========================================================================
   3. CABECERA Y TÍTULO
   ========================================================================== */
.header-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.header-logo { width: 42px; height: 42px; }

h1 {
  margin: 0;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--color-text-primary);
  letter-spacing: -1px;
}

.h1-highlight {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* InicIA la forma más inteligente de crear software */
main > p {
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 1.1rem;
  margin: 0 0 30px 0;
  font-weight: 500;
}

/* ==========================================================================
   4. FORMULARIO Y CONTENEDORES DE SECCIÓN
   ========================================================================== */
form { display: grid; gap: var(--spacing-vertical-sections); }

.section-container {
  background-color: var(--color-surface);
  border-radius: var(--border-radius-large);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  padding: var(--spacing-base);
}

/* ==========================================================================
   5. SISTEMA DE TABS
   ========================================================================== */
.tabs-header {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--spacing-base);
}

.tab-button {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  margin-bottom: -2px;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab-button:hover {
  color: var(--color-primary);
  background-color: #F7FAFC;
}

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

.tab-panel.active { display: block; }
.tab-panel { display: none; }

/* ==========================================================================
   6. ÁREAS DE TEXTO Y ARCHIVOS CARGADOS
   ========================================================================== */
textarea {
  min-height: 310px;
  resize: vertical;
  width: 100%;
  border-radius: var(--border-radius-medium);
  border: 1px solid var(--color-border);
  background-color: var(--color-background);
  padding: 16px;
  font-size: 1rem;
  color: var(--color-text-primary);
  line-height: 1.6;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.2);
}

textarea::placeholder { color: #A0AEC0; }

.loaded-files-list {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.loaded-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: #EDF2F7;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-small);
  font-size: 0.875rem;
  color: var(--color-text-primary);
  font-weight: 500;
}

.file-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Botón de eliminar archivo individual */
.remove-file-btn {
  padding: 4px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  color: #64748B;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-left: 4px;
}

.remove-file-btn:hover {
  background-color: #FEE2E2;
  color: #DC2626;
  transform: none;
  box-shadow: none;
}

.remove-file-btn svg {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   7. BOTONES
   ========================================================================== */
button {
  font: inherit;
  border-radius: var(--border-radius-medium);
  padding: 12px 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:focus {
  outline: none;
  box-shadow: none;
}

/* Botón Principal (Generar) */
#generate-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: white;
  font-size: 1.1rem;
  padding: 16px 24px;
  border: none;
  box-shadow: var(--shadow-md);
}

#generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.generate-btn-icon {
    width: 20px;
    height: 20px;
}

/* Botones Secundarios */
.button-secondary {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

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

.buttons-top { display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; align-items: center; }
.buttons-group { display: none; }
.buttons-group.active-buttons { display: flex; gap: 12px; }

/* ***** CAMBIO #2: Margen vertical añadido ***** */
.button-bottom {
  margin-top: 24px;
}

/* Barra de progreso en el botón Generar */
button.generating {
  padding: 0;
  overflow: hidden;
  position: relative;
  height: 56px; /* Altura fija para igualar el botón original */
}

.button-progress-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.button-progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: #34D399;
  transition: width 0.5s ease-out;
  width: 0%;
  border-radius: 0; /* Bordes rectos */
}

.button-progress-text {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px; /* Restaurar padding vertical y horizontal */
  height: 100%; /* Ocupar toda la altura */
}

.progress-message {
  color: #FFFFFF;
  font-family: var(--font-family-base);
  font-weight: 600;
  font-size: 1.1rem;
  text-shadow: 0 0 2px black, 0 0 2px black;
}

.progress-percentage {
  color: #FF6B35;
  font-family: var(--font-family-base);
  font-weight: 700;
  font-size: 1.3rem;
  text-shadow: 0 0 2px black, 0 0 2px black;
}

#file-input, #agent-input, #image-input { display: none; }

/* Mensaje de éxito */
.status {
  min-height: 0;
  margin-top: 0; /* Por defecto sin margen */
  transition: margin-top 0.3s ease; /* Transición suave */
}

/* Cuando .status tiene contenido, agregar margen superior */
.status:not(:empty) {
  margin-top: 20px; /* Margen cuando hay contenido */
}

/* Mensaje de archivo cargado con tick verde */
.file-loaded-message {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
}

.file-loaded-text {
  color: #10b981;
  font-weight: 500;
  font-size: 0.95rem;
}

.file-loaded-icon {
  width: 20px;
  height: 20px;
  color: #10b981;
  flex-shrink: 0;
}

/* Mensaje de error con icono rojo */
.file-error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
}

.file-error-text {
  color: #ef4444;
  font-weight: 500;
  font-size: 0.95rem;
}

.file-error-icon {
  width: 20px;
  height: 20px;
  color: #ef4444;
  flex-shrink: 0;
}

.success-message {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #F0FDF4;
  border: 1px solid #86EFAC;
  border-radius: var(--border-radius-medium);
  padding: 16px 20px;
  gap: 16px;
  margin-top: 24px;
}

.success-content {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.success-text {
  color: #166534;
  font-weight: 600;
  font-size: 1rem;
}

/* Checkmark animado */
.checkmark {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.checkmark__circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: #10B981;
  fill: none;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark__check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  stroke-width: 3;
  stroke: #10B981;
  animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.6s forwards;
}

@keyframes stroke {
  100% {
    stroke-dashoffset: 0;
  }
}

/* Botón de cerrar mensaje */
.close-status-btn {
  padding: 6px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  color: #166534;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}

.close-status-btn:hover {
  background-color: #DCFCE7;
  color: #15803D;
  transform: none;
  box-shadow: none;
}

.close-status-btn svg {
  width: 18px;
  height: 18px;
}

/* Mensaje de error */
.error-message {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--border-radius-medium);
  padding: 16px 20px;
  gap: 16px;
  margin-top: 24px;
}

.error-content {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.error-text {
  color: #991B1B;
  font-weight: 600;
  font-size: 1rem;
}

.error-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  color: #DC2626;
}

.close-error-btn {
  color: #991B1B;
}

.close-error-btn:hover {
  background-color: #FEE2E2;
  color: #7F1D1D;
}

/* ==========================================================================
   8. SECCIÓN HISTÓRICO (ACORDEÓN)
   ========================================================================== */
#history-section {
  margin-top: var(--spacing-vertical-sections);
}

#history-section[hidden] { display: none; }

.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  box-shadow: none;
  margin: 0;
  border-radius: 0;
}

.accordion-header:hover .section-title { color: var(--color-primary); }

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
  text-align: left;
  flex: 1;
  background: none;
  background-clip: unset;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
}

.accordion-icon {
  font-size: 1.5rem;
  color: var(--color-primary);
  transition: transform 0.3s ease;
}

.accordion-header:not(.collapsed) .accordion-icon { transform: rotate(180deg); }

.accordion-content {
  overflow: hidden;
  transition: max-height 0.4s ease-out, opacity 0.3s ease-in-out, margin-top 0.3s ease-in-out;
  margin-top: var(--spacing-base);
  max-height: 5000px;
  opacity: 1;
}

.accordion-content.collapsed { max-height: 0; opacity: 0; margin-top: 0; }

/* History Controls */
.history-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.az-sort-icon {
  width: 18px;
  height: 18px;
  margin-left: 4px;
}

.files-grid {
  display: grid;
  gap: 16px;
  margin-top: 4px; /* Espacio para evitar que se corte el borde superior del primer card */
}

.file-card {
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-large);
  padding: 0;
  background-color: var(--color-surface);
  transition: all 0.2s ease;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.file-card:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Estilos para drag & drop */
.file-card {
  cursor: grab;
}

.file-card:active {
  cursor: grabbing;
}

.sortable-chosen {
  /* Elemento seleccionado para arrastrar - completamente visible */
  opacity: 1 !important;
}

.sortable-ghost {
  /* Espacio vacío donde se soltará la tarjeta */
  opacity: 1;
  background-color: transparent;
  border: 3px dashed var(--color-secondary) !important;
  /* Mantener dimensiones pero ocultar contenido */
  color: transparent !important;
  box-shadow: none !important;
}

.sortable-ghost * {
  /* Ocultar todo el contenido interno */
  visibility: hidden !important;
}

.sortable-drag {
  /* Tarjeta que se está arrastrando - igual que una normal pero con borde morado grueso */
  opacity: 1 !important;
  cursor: grabbing !important;
  transform: none;
  box-shadow: var(--shadow-lg);
  border: 3px solid var(--color-secondary) !important;
  /* Asegurar que se vea por encima de todo */
  z-index: 1000;
}

/* Header de la tarjeta */
.file-card__header {
  padding: 20px 24px 16px 24px;
  background: linear-gradient(135deg, #F7FAFC 0%, #EDF2F7 100%);
  border-bottom: 1px solid var(--color-border);
}

.file-card__title-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-card__title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.4;
}

/* Sección de metadata */
.file-card__metadata {
  padding: 16px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.file-card__metadata-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.metadata-icon {
  width: 16px;
  height: 16px;
  color: var(--color-primary);
  flex-shrink: 0;
}

/* Sección de acciones */
.file-card__actions-section {
  padding: 20px 24px;
  display: flex;
  gap: 12px;
  background-color: var(--color-surface);
}

/* Botones de historial */
.history-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--border-radius-medium);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  min-height: 44px;
}

.history-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.history-btn-primary svg {
  stroke: #FFFFFF;
  stroke-width: 2;
}

.history-btn-primary svg polygon {
  fill: transparent;
  transition: fill 0.2s ease;
}

.history-btn-primary:hover svg polygon {
  fill: #10B981;
}

.history-btn-primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: white;
  border: none;
  box-shadow: var(--shadow-sm);
}

.history-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.history-btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.history-btn-secondary:hover {
  background-color: #F7FAFC;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.history-btn-danger {
  background-color: var(--color-surface);
  color: #DC2626;
  border: 1px solid #FECACA;
  box-shadow: var(--shadow-sm);
}

.history-btn-danger:hover {
  background-color: #FEF2F2;
  border-color: #DC2626;
  color: #991B1B;
  transform: translateY(-1px);
}

/* Status de la tarjeta */
.file-card__status {
  padding: 0 24px 16px 24px;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  min-height: 0;
  transition: all 0.2s ease;
}

.file-card__status:not(:empty) {
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

/* Detalles de prompts (solo en devmode) */
.file-card details {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background-color: #FAFBFC;
}

.file-card details summary {
  cursor: pointer;
  padding: 8px 0;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.9rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.file-card details summary::-webkit-details-marker {
  display: none;
}

.file-card details summary::before {
  content: '▶';
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 0.75rem;
}

.file-card details[open] summary::before {
  transform: rotate(90deg);
}

.file-card details summary:hover {
  color: var(--color-primary-dark);
}

.history-prompt-textarea {
  width: 100%;
  max-height: 200px;
  min-height: 120px;
  margin: 12px 0 0 0;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-medium);
  background-color: var(--color-surface);
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--color-text-primary);
  resize: vertical;
  line-height: 1.5;
}

.history-prompt-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.1);
}

/* ==========================================================================
   8.1 MODAL DE CONFIRMACIÓN DEL HISTÓRICO
   ========================================================================== */
.app-modal[hidden] {
  display: none;
}

.app-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}

.app-modal.is-visible {
  opacity: 1;
  pointer-events: all;
}

.app-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(3px);
}

.app-modal__container {
  position: relative;
  width: min(420px, 90%);
  background: var(--color-surface, #FFFFFF);
  border-radius: var(--border-radius-large, 16px);
  box-shadow: var(--shadow-lg, 0 24px 64px rgba(15, 23, 42, 0.25));
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transform: translateY(24px);
  transition: transform 0.24s ease;
}

.app-modal.is-visible .app-modal__container {
  transform: translateY(0);
}

.app-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-modal__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text-primary, #111827);
}

.app-modal__close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-secondary, #6B7280);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease;
}

.app-modal__close-btn:hover {
  color: var(--color-text-primary, #111827);
}

.app-modal__body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: var(--color-text-secondary, #4B5563);
  font-size: 0.95rem;
}

.app-modal__warning {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--border-radius-medium, 10px);
  background: #FEF2F2;
  color: #B91C1C;
  font-weight: 600;
}

.app-modal__warning-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.app-modal__warning-text {
  overflow-wrap: anywhere;
}

.app-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.app-modal__cancel-btn,
.app-modal__confirm-btn {
  min-width: 120px;
  min-height: 44px;
  border-radius: var(--border-radius-medium, 10px);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.app-modal__cancel-btn {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.app-modal__cancel-btn:hover {
  background-color: #F7FAFC;
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.app-modal__confirm-btn {
  border: 1px solid #FECACA;
  background: var(--color-surface, #FFFFFF);
  color: #DC2626;
  box-shadow: var(--shadow-sm, 0 8px 20px rgba(15, 23, 42, 0.12));
}

.app-modal__confirm-btn:hover {
  background-color: #FEF2F2;
  border-color: #DC2626;
  color: #991B1B;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm, 0 8px 20px rgba(15, 23, 42, 0.12));
}

.app-modal__container--busy {
  gap: 24px;
  padding: 36px;
  align-items: center;
  text-align: center;
  width: min(520px, 90%);
}

.app-modal__header--center {
  width: 100%;
  justify-content: center;
}

.app-modal__body--center {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.busy-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  color: var(--color-text-secondary, #4B5563);
  font-size: 0.95rem;
}

.busy-indicator__spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(90, 103, 216, 0.18);
  border-top-color: var(--color-primary, #5A67D8);
  border-right-color: var(--color-secondary, #764BA2);
  animation: busy-indicator-spin 1s linear infinite;
  box-shadow: 0 12px 32px rgba(90, 103, 216, 0.25);
}

.busy-indicator__text {
  margin: 0;
  max-width: none;
  line-height: 1.5;
  font-weight: 500;
}

@keyframes busy-indicator-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Responsive */
@media (max-width: 640px) {
  .file-card__actions-section {
    flex-direction: column;
  }

  .history-btn {
    width: 100%;
  }

  .file-card__metadata {
    flex-direction: column;
    gap: 12px;
  }

  .file-card__header,
  .file-card__metadata,
  .file-card__actions-section,
  .file-card__status {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ==========================================================================
   9. FOOTER
   ========================================================================== */
footer { text-align: center; padding: 0; }
.footer-box { background-color: transparent; border: none; padding: 16px 0; }
.footer-authors { margin: 0 0 8px; color: var(--color-text-secondary); font-weight: 500; font-size: 0.9rem; }
.footer-authors strong { color: var(--color-text-secondary); font-weight: 600; }

.footer-names-list {
  list-style: none; padding: 0; margin: 0;
  color: var(--color-text-secondary); font-weight: 500; font-size: 0.9rem;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
}

.footer-names-list li:not(:last-child)::after {
  content: "•"; color: #CBD5E0; padding-left: 10px;
}

/* ==========================================================================
   10. ESTILOS DE ICONOS PERSONALIZADOS
   ========================================================================== */
.emoji, .clip-icon, .reset-icon, .image-icon { font-family: inherit; }

.clip-icon, .reset-icon, .image-icon, .accordion-icon {
    display: inline-block;
    width: 1.2em;
    height: 1.2em;
    background-color: currentColor;
    mask-repeat: no-repeat;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
}
.clip-icon { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48'%3E%3C/path%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48'%3E%3C/path%3E%3C/svg%3E"); }
.reset-icon { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'%3E%3C/polyline%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'%3E%3C/path%3E%3Cline x1='10' y1='11' x2='10' y2='17'%3E%3C/line%3E%3Cline x1='14' y1='11' x2='14' y2='17'%3E%3C/line%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'%3E%3C/polyline%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'%3E%3C/path%3E%3Cline x1='10' y1='11' x2='10' y2='17'%3E%3C/line%3E%3Cline x1='14' y1='11' x2='14' y2='17'%3E%3C/line%3E%3C/svg%3E"); }
.image-icon { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'%3E%3C/circle%3E%3Cpolyline points='21 15 16 10 5 21'%3E%3C/polyline%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'%3E%3C/circle%3E%3Cpolyline points='21 15 16 10 5 21'%3E%3C/polyline%3E%3C/svg%3E"); }
.accordion-icon { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); }

/* ==========================================================================
   VISOR PDF
   ========================================================================== */
.pdf-viewer-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 200px;
  max-height: 90vh;
  background-color: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--border-radius-medium);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.pdf-resize-handle {
  width: 100%;
  height: 12px;
  background-color: var(--color-border);
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  flex-shrink: 0;
  transition: background-color 0.2s ease;
}

.pdf-resize-handle:hover {
  background-color: var(--color-primary);
}

.pdf-resize-handle:active {
  background-color: var(--color-primary-dark);
}

.pdf-resize-handle svg {
  width: 40px;
  height: 12px;
  color: var(--color-text-secondary);
  opacity: 0.8;
}

.pdf-resize-handle:hover svg {
  color: white;
  opacity: 1;
}

.pdf-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: #F7FAFC;
  border-bottom: 1px solid var(--color-border);
  gap: 16px;
  flex-shrink: 0;
}

.pdf-controls-left,
.pdf-controls-center,
.pdf-controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pdf-control-btn {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-small);
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-primary);
}

.pdf-control-btn:hover:not(:disabled) {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.pdf-control-btn:active:not(:disabled) {
  transform: translateY(0);
}

.pdf-control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pdf-control-btn svg {
  width: 20px;
  height: 20px;
}

.pdf-page-info,
.pdf-zoom-info {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-primary);
  min-width: 60px;
  text-align: center;
  user-select: none;
}

.pdf-canvas-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px;
  overflow: auto;
  min-height: 0; /* Importante para que flex-shrink funcione correctamente */
  background-color: #E5E7EB;
  background-image:
    linear-gradient(45deg, #D1D5DB 25%, transparent 25%),
    linear-gradient(-45deg, #D1D5DB 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #D1D5DB 75%),
    linear-gradient(-45deg, transparent 75%, #D1D5DB 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.pdf-page-wrapper {
  display: block;
  margin-bottom: 10px;
  background-color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pdf-page-canvas {
  display: block;
}

#pdf-canvas {
  display: block;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  background-color: white;
  /* Centrar el canvas cuando es más pequeño que el contenedor */
  /* margin: auto permite scroll completo cuando es más grande */
  margin: auto;
  /* Permitir que el canvas crezca al hacer zoom */
  /* No usar max-width/max-height para permitir el zoom correcto */
}

/* ==========================================================================
   COMBO REASONING LEVEL - Selector personalizado de nivel de razonamiento
   ========================================================================== */
.container-combo_llm_reasoning_level__control {
  position: relative;
  width: 280px;
  margin-left: auto;
}

.combo_llm_reasoning_level {
  width: 280px;
  position: relative;
}

.combo_llm_reasoning_level__label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #64748b;
}

.combo_llm_reasoning_level__wrapper {
  position: relative;
  width: 100%;
}

.combo_llm_reasoning_level__button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.2rem;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #ffffff;
  color: #2d3748;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.combo_llm_reasoning_level__button:hover {
  background-color: #f7fafc;
  border-color: #764ba2;
  color: #764ba2;
}

.combo_llm_reasoning_level__button:hover .combo_llm_reasoning_level__value {
  color: #764ba2;
}

.combo_llm_reasoning_level__button:focus {
  outline: none;
}

.combo_llm_reasoning_level__button-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.combo_llm_reasoning_level__placeholder {
  color: #94a3b8;
  font-weight: 400;
}

.combo_llm_reasoning_level__value {
  color: #1e293b;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combo_llm_reasoning_level__icon,
.combo_llm_reasoning_level__option-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  display: block;
}

.combo_llm_reasoning_level__chevron {
  width: 1.25rem;
  height: 1.25rem;
  color: currentColor;
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.combo_llm_reasoning_level__chevron--open {
  transform: rotate(180deg);
}

.combo_llm_reasoning_level__options {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.14);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.97);
  transform-origin: top;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
  z-index: 10;
}

.combo_llm_reasoning_level__options--open {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  pointer-events: auto;
}

.combo_llm_reasoning_level__options--open-upward {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 0.5rem;
  transform-origin: bottom;
}

.combo_llm_reasoning_level__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.combo_llm_reasoning_level__option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  color: #1e293b;
  cursor: pointer;
  transition: none;
}

.combo_llm_reasoning_level__option:hover {
  background: rgb(226, 232, 240);
  color: #1e293b;
}

.combo_llm_reasoning_level__option--selected {
  background: rgb(226, 232, 240);
  color: #475569;
}

.combo_llm_reasoning_level__option--selected:hover {
  background: rgb(226, 232, 240);
  color: #475569;
}