/* /styles/base.css */

/* 1. Reset Básico y Definición de Fuentes */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root {
  /* Fuente principal */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Tiempos de transición */
  --transition-fast: 200ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-medium: 350ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 500ms cubic-bezier(0.16, 1, 0.3, 1);
  
  /* Radios */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* 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 -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

/* 2. Tokens de Tema (Claro por defecto) */
:root,
html[data-theme="light"] {
  --bg: #FFFCF9;         /* Fondo principal */
  --surface: #FFFFFD;    /* Superficie (tarjetas, modales) */
  --text: #13343B;        /* Texto principal */
  --muted: #626C71;       /* Texto secundario */
  --primary: #21808D;     /* Primario (botones, links) */
  --primary-hover: #1D7480;
  --primary-text: #FFFFFF;
  --border: rgba(94, 82, 64, 0.20); /* Borde sutil */
  --glass: rgba(255, 255, 255, 0.88); /* Color del vidrio (claro) */
  --glass-border: rgba(94, 82, 64, 0.25);
  --shadow-color: rgba(94, 82, 64, 0.1);
}

/* 3. Tokens de Tema (Oscuro) */
html[data-theme="dark"] {
  --bg: #1F2121;
  --surface: #262828;
  --text: #F5F5F5;
  --muted: rgba(245, 245, 245, 0.7);
  --primary: #32B8C6;
  --primary-hover: #40cde0;
  --primary-text: #1F2121;
  --border: rgba(255, 255, 255, 0.18);
  --glass: rgba(38, 40, 40, 0.82); /* Color del vidrio (oscuro) */
  --glass-border: rgba(255, 255, 255, 0.2);
  --shadow-color: rgba(0, 0, 0, 0.15);
}

/* Detección automática de tema */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F2121;
    --surface: #262828;
    --text: #F5F5F5;
    --muted: rgba(245, 245, 245, 0.7);
    --primary: #32B8C6;
    --primary-hover: #40cde0;
    --primary-text: #1F2121;
    --border: rgba(255, 255, 255, 0.18);
    --glass: rgba(38, 40, 40, 0.82);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-color: rgba(0, 0, 0, 0.15);
  }
}

/* 4. Estilos Globales */
html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

p {
  color: var(--muted);
  margin-bottom: 1rem;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* 5. Utilidades */

/* Glassmorphism */
.glass {
  background-color: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 12px var(--shadow-color);
  border-radius: var(--radius-lg);
}

/* Estado de Foco (Accesibilidad) */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Animación de entrada */
.fade-in {
  animation: fadeIn 500ms var(--transition-medium) both;
}
.fade-in-up {
  animation: fadeInUp 350ms var(--transition-medium) both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Layout de la App Principal */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 280px; /* Ancho completo */
  flex-shrink: 0;
  height: 100%;
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  transition: width var(--transition-medium);
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--surface);
}

.sidebar.collapsed {
  width: 84px; /* Ancho colapsado */
  padding: 1.5rem 0.5rem;
}

.main-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 72px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  /* Glassmorphism en TopBar */
  background-color: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 10;
}

.page-content {
  flex-grow: 1;
  overflow-y: auto;
  padding: 2rem;
}

.page-content main {
  max-width: 1200px;
  margin: 0 auto;
}

/* Layout Público (Login, Register) */
.public-layout {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem 2rem;
  border: 1px solid var(--border);
  background-color: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

/* Loader Inicial */
.initial-loader {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  gap: 1rem;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Dashboard Responsivo */
.dashboard-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--color-background);
  padding: 1rem;
}

.dashboard-header {
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 1.5rem;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.header-title {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  color: var(--color-text);
  letter-spacing: -0.5px;
}

.header-subtitle {
  font-size: clamp(0.875rem, 2vw, 1rem);
  color: var(--color-text-secondary);
  margin: 0;
  font-weight: 400;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: clamp(0.75rem, 2vw, 1.5rem);
  margin-bottom: 2rem;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

/* Lower Grid - Responsivo */
.lower-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1rem, 3vw, 2rem);
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 1024px) {
  .lower-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    align-items: flex-start;
  }
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: all var(--duration-normal) ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.card-header {
  padding: clamp(1rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--color-card-border-inner);
  background: linear-gradient(135deg, rgba(var(--color-primary-rgb), 0.03), transparent);
}

.card-title {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  color: var(--color-text);
}

.card-subtitle {
  font-size: clamp(0.8rem, 1.5vw, 0.9rem);
  color: var(--color-text-secondary);
  margin: 0;
  font-weight: 400;
}

.card-body {
  padding: clamp(1rem, 3vw, 1.5rem);
}

/* Tabla Responsiva */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
}

.table-dashboard {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.8rem, 1.5vw, 0.95rem);
}

.table-dashboard thead {
  background: var(--color-secondary);
  position: sticky;
  top: 0;
}

.table-dashboard thead tr {
  border-bottom: 2px solid var(--color-border);
}

.table-dashboard th {
  padding: clamp(0.75rem, 2vw, 1rem);
  text-align: left;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.table-dashboard tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background-color var(--duration-fast) ease;
}

.table-dashboard tbody tr:hover {
  background-color: var(--color-secondary);
}

.table-dashboard td {
  padding: clamp(0.75rem, 2vw, 1rem);
  color: var(--color-text);
}

.th-total,
.td-total {
  text-align: right;
  font-weight: 600;
  color: var(--color-primary);
}

.empty-row .empty-cell {
  text-align: center;
  color: var(--color-text-secondary);
  padding: 2rem 1rem !important;
  font-style: italic;
}

/* Versión Móvil - Tabla apilada */
@media (max-width: 768px) {
  .table-dashboard {
    font-size: 0.875rem;
  }

  .table-dashboard thead {
    display: none;
  }

  .table-dashboard tbody,
  .table-dashboard tr,
  .table-dashboard td {
    display: block;
    width: 100%;
  }

  .table-dashboard tr {
    margin-bottom: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
  }

  .table-dashboard td {
    padding: 0.75rem;
    padding-left: 50%;
    position: relative;
    border: none;
    border-bottom: 1px solid var(--color-border);
  }

  .table-dashboard td:last-child {
    border-bottom: none;
  }

  .table-dashboard td::before {
    content: attr(data-label);
    position: absolute;
    left: 0.75rem;
    font-weight: 600;
    color: var(--color-text);
  }
}

/* Sugerencias */
.suggestions-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.suggestion-item {
  padding: 1rem;
  background: var(--color-secondary);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--color-primary);
  color: var(--color-text);
  font-size: clamp(0.85rem, 1.5vw, 0.95rem);
  line-height: 1.5;
  transition: all var(--duration-fast) ease;
}

.suggestion-item:hover {
  background: var(--color-secondary-hover);
  transform: translateX(4px);
}

/* Empty State */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  text-align: center;
  padding: 2rem;
}

.empty-message {
  font-size: 1.1rem;
  color: var(--color-text-secondary);
  margin: 0;
}

/* Responsividad Extra - Ultra móvil */
@media (max-width: 480px) {
  .dashboard-page {
    padding: 0.75rem;
  }

  .header-title {
    font-size: 1.5rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .card-header,
  .card-body {
    padding: 0.75rem 1rem;
  }

  .table-dashboard td {
    padding: 0.5rem;
    padding-left: 45%;
    font-size: 0.8rem;
  }
}

/* Tablet Landscape */
@media (min-width: 768px) and (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .lower-grid {
    grid-template-columns: 1fr;
  }
}

/* Wrapper principal - estructura de scroll */
.dashboard-main-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--color-background);
}

/* Header fijo en la parte superior */
.dashboard-header-fixed {
  flex-shrink: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: clamp(1rem, 3vw, 1.5rem);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 0 1rem;
}

/* Contenedor scrolleable */
.dashboard-scroll-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: clamp(1rem, 3vw, 2rem) 1rem;
}

.dashboard-scroll-container > * {
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

/* Scrollbar personalizado (opcional) */
.dashboard-scroll-container::-webkit-scrollbar {
  width: 8px;
}

.dashboard-scroll-container::-webkit-scrollbar-track {
  background: transparent;
}

.dashboard-scroll-container::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

.dashboard-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}


/* Wrapper de la tabla de facturas */
.invoices-table-wrapper {
  width: 100%;
  overflow-y: auto;   /* scroll vertical cuando haga falta */
}

/* Desktop / tablet: scroll interno con altura limitada */
@media (min-width: 769px) {
  .invoices-table-wrapper {
    max-height: calc(100vh - 260px); /* ajusta este número si quieres */
  }
}

/* Móviles: sin límite de alto, scroll global de la página */
@media (max-width: 768px) {
  .invoices-table-wrapper {
    max-height: none;
  }
}

/* Por si acaso: que la tabla se adapte al ancho y no genere scroll horizontal */
.invoices-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoices-table th,
.invoices-table td {
  word-wrap: break-word;
  white-space: normal;
}

/* ───────────────────────────────
   VETSA AI – LAYOUT GENERAL
   ─────────────────────────────── */

.ai-page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Título y subtítulo */
.ai-page h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.ai-page > p {
  margin: 0 0 0.75rem;
  color: var(--muted-foreground, #6b7280);
}

/* ───────────────────────────────
   BOTONES SUPERIORES (Chat actual / Ver historial)
   ─────────────────────────────── */

.ai-top-actions {
  display: inline-flex;
  padding: 0.25rem;
  background: #f3f4f6;
  border-radius: 999px;
  gap: 0.25rem;
}

.ai-top-btn {
  border-radius: 999px !important;
  font-size: 0.85rem;
  line-height: 1.2;
  padding: 0.4rem 0.95rem;
  border: none;
  background: transparent;
  color: #4b5563;
  box-shadow: none;
}

.ai-top-btn.active {
  background: #0f766e;
  color: #f9fafb;
}

/* ───────────────────────────────
   CONTENEDOR DEL CHAT
   ─────────────────────────────── */

.chat-container {
  position: relative;
  margin-top: 1.25rem;
  background: var(--surface, #ffffff);
  border-radius: 1rem;
  border: 1px solid var(--border, #e5e7eb);
  box-shadow: var(--shadow-md, 0 10px 15px rgba(15, 23, 42, 0.06));
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;

  /* Altura pensada para desktop */
  min-height: 420px;
  max-height: min(720px, calc(100vh - 220px));
}

/* Zona de mensajes */
.chat-messages {
  flex: 1 1 auto;
  border-radius: 0.75rem;
  background: #f9fafb;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Input + botón enviar */
.chat-input-area {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  padding-inline: 1rem;
}

/* Botón de enviar estilo “FAB” */
.chat-send-btn {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ───────────────────────────────
   BUBBLES DEL CHAT
   ─────────────────────────────── */

.chat-bubble {
  max-width: 82%;
  font-size: 0.9rem;
  line-height: 1.45;
  padding: 0.55rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* Mensajes de Vetsa AI (izquierda) */
.chat-bubble.ai {
  align-self: flex-start;
  background: #e0f2fe;
  border-color: #bfdbfe;
  color: #0f172a;
}

/* Mensajes del usuario (derecha) */
.chat-bubble.user {
  align-self: flex-end;
  background: #0f766e;
  color: #ecfeff;
}

/* Estado “pensando” con tres puntitos */
.chat-bubble.typing {
  position: relative;
  color: #6b7280;
}

.chat-bubble.typing::after {
  content: '● ● ●';
  letter-spacing: 0.15em;
  animation: aiDots 1s infinite ease-in-out;
}

@keyframes aiDots {
  0% { opacity: 0.2; }
  50% { opacity: 1; }
  100% { opacity: 0.2; }
}

/* ───────────────────────────────
   BLOQUE DE BIENVENIDA Y ACCIONES RÁPIDAS
   ─────────────────────────────── */

.ai-welcome-block {
  margin-bottom: 0.75rem;
  padding: 0.9rem 1rem;
  border-radius: 0.75rem;
  background: #e5f3ff;
  color: #0f172a;
  font-size: 0.9rem;
}

.ai-welcome-text {
  margin: 0;
}

/* chips */
.ai-quick-actions-inline {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  overflow-x: auto;
  white-space: nowrap;
}

.ai-quick-actions-inline::-webkit-scrollbar {
  height: 4px;
}

.ai-quick-actions-inline::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 999px;
}

.ai-quick-actions-inline .btn.btn-secondary {
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* Animación al ocultar bienvenida */
.ai-fade-out {
  animation: aiFadeOut 200ms ease-out forwards;
}

@keyframes aiFadeOut {
  to {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* ───────────────────────────────
   PANEL DE HISTORIAL (slide-over)
   ─────────────────────────────── */

.ai-history-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 100%;
  background: #ffffff;
  border-left: 1px solid var(--border, #e5e7eb);
  box-shadow: -10px 0 25px rgba(15, 23, 42, 0.08);
  border-radius: 0 1rem 1rem 0;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  opacity: 1;
  transition: transform 180ms ease-out, opacity 180ms ease-out;
  z-index: 10;
}

.ai-history-hidden {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

.ai-history-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.ai-history-header h3 {
  font-size: 0.95rem;
  margin: 0;
}

.ai-history-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 0.75rem 0.75rem;
}

.ai-history-empty {
  font-size: 0.85rem;
  color: var(--muted-foreground, #6b7280);
  padding: 0.75rem 0.25rem;
}

/* Cada conversación */
.ai-history-item {
  display: flex;
  align-items: center;
  border-radius: 0.65rem;
  padding: 0.35rem 0.4rem 0.35rem 0.2rem;
  gap: 0.25rem;
}

.ai-history-item:hover {
  background: #f3f4f6;
}

.ai-history-main {
  flex: 1;
  text-align: left;
  padding: 0.45rem 0.65rem;
  border-radius: 0.55rem;
  border: none;
  background: transparent;
}

.ai-history-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.ai-history-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: #111827;
}

.ai-history-meta {
  font-size: 0.75rem;
  color: #6b7280;
}

/* Botón tres puntos */
.ai-history-menu-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  color: #9ca3af;
}

/* Menú contextual */
.ai-history-menu {
  position: absolute;
  right: 0.5rem;
  margin-top: 0.25rem;
  min-width: 180px;
  background: #ffffff;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.15);
  padding: 0.25rem;
  z-index: 20;
}

.ai-history-menu-hidden {
  display: none;
}

.ai-history-menu-item {
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  background: transparent;
  border: none;
  border-radius: 0.4rem;
}

.ai-history-menu-item:hover {
  background: #f3f4f6;
}

.ai-history-menu-item.danger {
  color: #b91c1c;
}

/* ───────────────────────────────
   MODAL DE CONFIRMACIÓN
   ─────────────────────────────── */

.ai-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.ai-modal-dialog {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 0.9rem;
  padding: 1.1rem 1.2rem 1rem;
  box-shadow: 0 20px 35px rgba(15, 23, 42, 0.35);
}

.ai-modal-title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

.ai-modal-message {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  color: var(--muted-foreground, #4b5563);
}

.ai-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ───────────────────────────────
   RESPONSIVE
   ─────────────────────────────── */

/* Tablets y móviles grandes */
@media (max-width: 960px) {
  .ai-page {
    padding-inline: 1rem;
  }

  .chat-container {
    max-height: calc(100vh - 190px);
  }

  .ai-history-panel {
    border-radius: 1rem;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border, #e5e7eb);
  }
}

/* Móviles */
@media (max-width: 640px) {
  .ai-page {
    padding-inline: 0.75rem;
  }

  .ai-top-actions {
    width: 100%;
    justify-content: center;
  }

  .chat-container {
    padding: 0.75rem;
    max-height: calc(100vh - 170px);
  }

  .chat-messages {
    padding: 0.75rem;
  }

  .chat-bubble {
    max-width: 90%;
    font-size: 0.85rem;
  }

  .ai-history-header {
    padding-inline: 0.75rem;
  }

  .ai-history-list {
    padding-inline: 0.5rem;
  }
}

/* Móviles muy pequeños */
@media (max-width: 480px) {
  .ai-page h1 {
    font-size: 1.2rem;
  }

  .ai-page > p {
    font-size: 0.85rem;
  }

  .chat-container {
    border-radius: 0.75rem;
  }

  .chat-input {
    font-size: 0.85rem;
  }
}

/* /styles/base.css */

/* 1. Reset Básico y Definición de Fuentes */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root {
  /* Fuente principal */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Tiempos de transición */
  --transition-fast: 200ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-medium: 350ms cubic-bezier(0.16, 1, 0.3, 1);
  
  /* Radios */
  --radius-sm: 4px;
  --radius-md: 6px; /* Reducido de 8px para look más pro */
  --radius-lg: 10px; /* Reducido de 12px */
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* 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 -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

/* 2. Tokens de Tema (Claro) */
:root,
html[data-theme="light"] {
  --bg: #F3F4F6;         /* Gris muy suave (mejor que blanco puro) */
  --surface: #FFFFFF;    
  --text: #111827;       /* Gris oscuro casi negro */
  --muted: #6B7280;      
  --primary: #0F766E;    /* Tu verde azulado de marca */
  --primary-hover: #0D9488;
  --primary-text: #FFFFFF;
  --border: #E5E7EB;
  --glass: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(229, 231, 235, 0.5);
  --shadow-color: rgba(0, 0, 0, 0.05);
}

/* 3. Tokens de Tema (Oscuro) */
html[data-theme="dark"] {
  --bg: #0F172A;
  --surface: #1E293B;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --primary: #2DD4BF;
  --primary-hover: #14B8A6;
  --primary-text: #0F172A;
  --border: #334155;
  --glass: rgba(30, 41, 59, 0.9);
  --glass-border: rgba(255, 255, 255, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.3);
}

/* 4. Estilos Globales */
html, body {
  height: 100%;
  width: 100%;
  overflow: hidden; /* IMPORTANTE: Evita scroll en el body */
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px; /* Base size reducido para escritorio */
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

/* Layout de la App Principal */
.app-layout {
  display: flex;
  height: 100vh; /* Altura exacta del viewport */
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 250px; /* Un poco más estrecho para ganar espacio */
  flex-shrink: 0;
  height: 100%;
  border-right: 1px solid var(--border);
  padding: 1rem;
  transition: width var(--transition-medium);
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--surface);
  z-index: 20;
}

.sidebar.collapsed {
  width: 70px;
  padding: 1rem 0.5rem;
}

.main-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%; /* Ocupa el 100% del padre, no 100vh */
  overflow: hidden;
  position: relative;
  min-width: 0; /* Fix flex overflow */
}

.topbar {
  height: 60px; /* Reducido de 72px */
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  background-color: var(--surface); /* Quitamos glass para rendimiento/nitidez */
  z-index: 10;
}

/* Contenedor de contenido scrollable */
.page-content {
  flex-grow: 1;
  overflow-y: auto; /* Scroll vertical aquí */
  overflow-x: hidden;
  padding: 1.5rem 2rem; /* Espaciado cómodo pero no gigante */
  height: 100%;
}

.page-content main {
  max-width: 1400px; /* Ancho máximo para pantallas ultra-wide */
  margin: 0 auto;
}

/* Scrollbar Global Elegante */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}
html[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #475569;
}
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: #64748B;
}

/* Utilidades */
.glass {
  background-color: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
}

.fade-in { animation: fadeIn 0.3s ease-out forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Títulos */
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
p { font-size: 0.9rem; color: var(--muted); }

/* Loader */
.initial-loader {
  display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%;
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }