@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ==========================================================================
   SISTEMA DE DISEÑO RESPONSIVE FIRST MOBILE & PALETA CORPORATIVA DINÁMICA
   ========================================================================== */
:root {
  /* Paleta Corporativa Base (Sobrescribible dinámicamente por la BD) */
  --navy-dark: #0f172a;        /* Primario Corporativo (Sidebar, Headers, Botones) */
  --navy-medium: #1e293b;      /* Tono Medio / Borde */
  --navy-sidebar: #0f172a;     /* Fondo Barra Lateral */
  --navy-active: #1e293b;      /* Enlace activo */
  
  --text-dark: #1e293b;        /* Títulos y datos prioritarios */
  --text-body: #334155;        /* Texto estándar lectura */
  --text-muted: #64748b;       /* Labels y textos de apoyo */
  --text-light: #f8fafc;       /* Texto sobre fondos oscuros */

  --bg-app: #f8fafc;           /* Fondo general */
  --bg-card: #ffffff;          /* Fondo tarjetas */
  --border-light: #e2e8f0;     /* Bordes neutros sutiles */
  --border-subtle: #cbd5e1;    /* Bordes para inputs */

  /* Color de Acento Dinámico */
  --accent-electric: #2563eb;  /* Secundario de acento */
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.08);

  /* Estados Funcionales */
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;

  /* Geometría y Sombras */
  --radius-card: 10px;
  --radius-sm: 6px;
  --radius-btn: 6px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.02);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ==========================================================================
   TIPOGRAFÍA Y ELEMENTOS GENERALES (MOBILE-FIRST)
   ========================================================================== */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-dark);
  font-weight: 600;
  letter-spacing: -0.015em;
}

h1 { font-size: 20px; line-height: 1.3; }
h2 { font-size: 17px; line-height: 1.35; }
h3 { font-size: 15px; line-height: 1.4; }

p, span, td, th {
  font-size: 13.5px;
}

/* ==========================================================================
   LAYOUT RESPONSIVE MOBILE FIRST
   ========================================================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
}

/* SIDEBAR: En móvil es un Drawer Off-Canvas deslizable */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: -280px;
  width: 270px;
  background-color: var(--navy-sidebar);
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.25);
  overflow-y: auto;
}

.sidebar.open {
  transform: translateX(280px);
}

/* Overlay oscuro para cerrar el menú lateral en móvil */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 1040;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-header {
  padding: 1.15rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  background-color: var(--accent-electric);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-title {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.mobile-sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.mobile-sidebar-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-nav {
  padding: 0.85rem 0.65rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.07);
  color: #f8fafc;
}

.nav-link.active {
  background-color: var(--accent-electric);
  color: #ffffff;
  font-weight: 600;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.75;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #94a3b8;
}

/* ÁREA PRINCIPAL */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: var(--bg-app);
  width: 100%;
}

.topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.mobile-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  color: var(--text-dark);
}

.mobile-menu-btn:hover {
  background: #f1f5f9;
}

.page-container {
  padding: 1rem;
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
}

/* ==========================================================================
   BREAKPOINTS DESKTOP & TABLET (min-width: 992px)
   ========================================================================== */
@media (min-width: 992px) {
  .sidebar {
    position: static;
    left: 0;
    width: 250px;
    flex-shrink: 0;
    transform: none !important;
    box-shadow: none;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .sidebar-overlay {
    display: none !important;
  }

  .mobile-sidebar-close {
    display: none !important;
  }

  .mobile-menu-btn {
    display: none !important;
  }

  .topbar {
    padding: 0.85rem 2rem;
  }

  .page-container {
    padding: 1.75rem 2rem;
  }

  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  h3 { font-size: 16px; }
}

@media (max-width: 640px) {
  .topbar-user-info {
    display: none !important;
  }
}

/* ==========================================================================
   TARJETAS, KPIS Y CONTENEDORES
   ========================================================================== */
.card, .kpi-card, .glass-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 480px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
  }
}

.kpi-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-dark);
  letter-spacing: -0.02em;
}

.kpi-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ==========================================================================
   BOTONES Y ACCIONES
   ========================================================================== */
.btn-primary {
  background: var(--navy-dark);
  color: #ffffff;
  border: 1px solid var(--navy-dark);
  padding: 0.6rem 1.15rem;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-btn);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  transition: all 0.15s ease;
  min-height: 38px;
}

.btn-primary:hover {
  filter: brightness(1.15);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-electric:disabled {
  opacity: 0.6;
  cursor: not-allowed !important;
  pointer-events: none;
}

.btn-electric {
  background: var(--accent-electric);
  color: #ffffff;
  border: 1px solid var(--accent-electric);
  padding: 0.6rem 1.15rem;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-btn);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  transition: all 0.15s ease;
  min-height: 38px;
}

.btn-electric:hover {
  filter: brightness(0.9);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-dark);
  border: 1px solid var(--border-light);
  padding: 0.6rem 1.15rem;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-btn);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  transition: all 0.15s ease;
  min-height: 38px;
}

.btn-secondary:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

/* ==========================================================================
   FORMULARIOS Y CAMPOS
   ========================================================================== */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dark);
  margin-bottom: 0.35rem;
}

.form-control,
.form-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-btn);
  color: var(--text-dark);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-input:focus {
  outline: none;
  border-color: var(--accent-electric);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ==========================================================================
   TABLAS RESPONSIVE CON SCROLL HORIZONTAL FLUIDO
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
}

.table-clean {
  width: 100%;
  min-width: 580px; /* Garantiza que las columnas no se compriman ilegiblemente */
  border-collapse: collapse;
  text-align: left;
}

.table-clean th {
  padding: 0.75rem 0.85rem;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  background: #f8fafc;
  white-space: nowrap;
}

.table-clean td {
  padding: 0.85rem;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-body);
}

.table-clean tr:hover td {
  background-color: #f8fafc;
}

/* ==========================================================================
   BADGES Y ESTADOS
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-success {
  background-color: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(5, 150, 105, 0.2);
}

.badge-warning {
  background-color: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(217, 119, 6, 0.2);
}

.badge-danger {
  background-color: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

.badge-neutral {
  background-color: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

/* ==========================================================================
   MODALES RESPONSIVE (ADAPTABLES A PANTALLAS MÓVILES)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 1rem;
}

.modal-content-box {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: var(--radius-card);
  padding: 1.5rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
}

@media (max-width: 600px) {
  .modal-content-box {
    padding: 1.15rem;
    max-height: 94vh;
  }
}

/* ==========================================================================
   UTILIDADES FLEXIBLES DE GRILLA RESPONSIVE
   ========================================================================== */
.grid-responsive-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .grid-responsive-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.flex-responsive-header {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
  .flex-responsive-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}
