/* ============================================
   Luna ERP v2 — Design System CSS
   Complete styling for MPA frontend
   ============================================ */

/* ─── 1. CSS Variables (Root Tokens) ─── */
:root {
  /* Colors - Primary */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;

  /* Colors - Semantic */
  --success: #10b981;
  --success-hover: #059669;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-hover: #d97706;
  --warning-light: #fef3c7;
  --error: #ef4444;
  --error-hover: #dc2626;
  --error-light: #fee2e2;
  --info: #3b82f6;
  --info-light: #dbeafe;

  /* Colors - Gray Scale */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Colors - Surfaces */
  --bg-page: #f9fafb;
  --bg-card: #ffffff;
  --bg-sidebar: #1f2937;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;
  --space-4xl: 48px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 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);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;

  /* Font */
  --font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;

  /* Sidebar — #164: reducido 260→230px para maximizar área de contenido */
  --sidebar-width: 230px;
  --sidebar-collapsed: 58px;
}

/* ─── 2. Reset / Base Styles ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: var(--primary-hover);
}

ul, ol {
  list-style: none;
}

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

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ─── 3. Typography ─── */
h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--gray-900);
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--gray-900);
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--gray-900);
}

h4 {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--gray-800);
}

h5 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--gray-800);
}

h6 {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

p {
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

small {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ─── 4. Layout System ─── */
.main-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar styles en navbar.css — aquí solo el layout del contenido principal */

.main-content {
  margin-left: 230px; /* mismo valor que --sidebar-width */
  flex: 1;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}

/* Al colapsar sidebar, el contenido ocupa el espacio liberado */
body.sidebar-collapsed .main-content {
  margin-left: 58px; /* mismo valor que --sidebar-collapsed */
}

.content-area {
  padding: var(--space-lg); /* #164: reducido de 2xl→lg para maximizar contenido */
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg) var(--space-2xl);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

/* ─── 5. Components ─── */

/* Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0; /* Permite que el card se encoja dentro de grids/flex */
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg) var(--space-xl); /* #164: reducido de 2xl→xl */
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
}

.card-body {
  padding: var(--space-2xl);
}

.card-footer {
  padding: var(--space-lg) var(--space-2xl);
  border-top: 1px solid var(--border-color);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Buttons */
.btn-form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  line-height: 1;
  white-space: nowrap;
}

.btn-form.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-form.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-form.secondary {
  background: #fff;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.btn-form.secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.btn-form.success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

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

.btn-form.danger {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.btn-form.danger:hover {
  background: var(--error-hover);
  border-color: var(--error-hover);
}

.btn-form:disabled,
.btn-form.loading {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  line-height: 1.4;
}

.badge-success {
  background: var(--success-light);
  color: #065f46;
}

.badge-warning {
  background: var(--warning-light);
  color: #92400e;
}

.badge-error {
  background: var(--error-light);
  color: #991b1b;
}

.badge-info {
  background: var(--info-light);
  color: #1e40af;
}

.badge-secondary {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* Forms */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--space-xs);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

.form-control {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--gray-900);
  background: #fff;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-control.error {
  border-color: var(--error);
}

.form-control.error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-control::placeholder {
  color: var(--gray-400);
}

.form-select {
  display: block;
  width: 100%;
  padding: 10px 36px 10px 14px;
  font-size: 0.875rem;
  color: var(--gray-900);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 01.708 0L8 8.293l2.646-2.647a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 010-.708z'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  appearance: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
}

.form-message {
  margin-top: var(--space-xs);
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.form-message.error {
  color: var(--error);
}

.form-message .icon {
  flex-shrink: 0;
}

.required {
  color: var(--error);
  margin-left: 2px;
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

/* Content Spacing */
.content-spacing > * + * {
  margin-top: var(--space-lg);
}

/* Table */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

/* data-table: alias moderno de table.table usado en módulos v2 nuevos */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data-table thead {
  background: var(--gray-800);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
}

table.data-table thead th {
  padding: 11px 16px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background var(--transition-fast);
}

table.data-table tbody tr:nth-child(even) {
  background: var(--gray-50);
}

table.data-table tbody tr:hover {
  background: #fff7f3;
}

table.data-table tbody td {
  padding: 10px 16px;
  color: var(--gray-700);
  vertical-align: middle;
}

table.data-table tbody tr:last-child {
  border-bottom: none;
}

/* Columnas de acciones alineadas */
table.data-table td:last-child,
table.data-table th:last-child {
  text-align: right;
  white-space: nowrap;
}

/* Montos en Guaraníes: siempre a la derecha, fuente tabular */
table.data-table td.monto,
table.data-table td[data-monto] {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--gray-900);
  white-space: nowrap;
}

/* Estado vacío de tabla */
table.data-table td.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--gray-400);
  font-style: italic;
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.table thead {
  background: var(--gray-800);
  color: #fff;
}

table.table thead th {
  padding: 11px 16px; /* #164: reducido de 14px→11px para más densidad */
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

table.table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background var(--transition-fast);
}

table.table tbody tr:nth-child(even) {
  background: var(--gray-50);
}

table.table tbody tr:hover {
  background: var(--primary-light);
}

table.table tbody td {
  padding: 10px 16px; /* #164: reducido de 12px/20px→10px/16px */
  color: var(--gray-700);
}

table.table tbody tr:last-child {
  border-bottom: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 230px;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: var(--space-lg);
  animation: fadeIn var(--transition-fast);
  transition: left 0.3s ease;
}

/* Cuando el sidebar esta colapsado, el modal ocupa mas espacio */
body.sidebar-collapsed .modal-overlay {
  left: 58px;
}

.modal-container {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideIn var(--transition-normal);
}

.modal-sm { max-width: 400px; }
.modal-md { max-width: 560px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 1100px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xl) var(--space-2xl);
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--gray-500);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.modal-body {
  padding: var(--space-2xl);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-2xl);
  border-top: 1px solid var(--border-color);
}

/* Filters Section */
.filters-section {
  padding: var(--space-lg) var(--space-2xl);
  border-bottom: 1px solid var(--border-color);
  background: var(--gray-50);
}

/* Metric Card */
.metric-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: var(--space-2xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.metric-card .metric-value {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.metric-card .metric-label {
  font-size: 0.875rem;
  opacity: 0.85;
  margin-top: var(--space-xs);
}

.metric-card.success {
  background: linear-gradient(135deg, var(--success), #059669);
}

.metric-card.warning {
  background: linear-gradient(135deg, var(--warning), #d97706);
}

.metric-card.error {
  background: linear-gradient(135deg, var(--error), #dc2626);
}

/* Alert */
.alert {
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
}

.alert-success {
  background: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-warning {
  background: var(--warning-light);
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-error {
  background: var(--error-light);
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* Loading Spinner */
.loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Dropdown */
.dropdown-container {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1500;
  padding: var(--space-xs) 0;
  animation: fadeIn var(--transition-fast);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px var(--space-lg);
  font-size: 0.875rem;
  color: var(--gray-700);
  transition: background var(--transition-fast);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background: var(--gray-50);
  color: var(--gray-900);
}

/* Navigation Links */
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 10px var(--space-xl);
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.875rem;
  font-weight: 400;
  border-radius: var(--radius-md);
  margin: 2px var(--space-sm);
  transition: all var(--transition-fast);
}

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

.nav-link.active {
  background: rgba(59, 130, 246, 0.2);
  color: #fff;
  font-weight: 500;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-link.active .nav-icon {
  opacity: 1;
}

/* Notification Badge */
.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: var(--error);
  color: #fff;
  border-radius: 50%;
  font-size: 0.6875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card);
}

/* File Upload Area */
.file-upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: var(--space-3xl);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--gray-50);
}

.file-upload-area:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.file-upload-area.has-file {
  border-color: var(--success);
  background: var(--success-light);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: var(--space-xl);
  right: var(--space-xl);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-xl);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--gray-400);
  min-width: 300px;
  max-width: 420px;
  animation: slideIn var(--transition-normal);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--primary); }

.toast-message {
  flex: 1;
  font-size: 0.875rem;
  color: var(--gray-700);
}

.toast-close {
  color: var(--gray-400);
  cursor: pointer;
  padding: var(--space-xs);
}

.toast-close:hover {
  color: var(--gray-600);
}

/* ─── 6. Responsive ─── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    /* #166: fix mobile nav — sidebar oculto por defecto en mobile */
    width: 260px !important;
    transition: transform var(--transition-slow);
  }

  /* #166: tanto .open como .mobile-open abren el sidebar */
  .sidebar.open,
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
    max-width: 100vw;
    min-width: 0;
  }

  .content-area {
    padding: var(--space-md);
    max-width: 100vw;
    min-width: 0;
  }

  .header {
    padding: var(--space-md) var(--space-lg);
  }

  .card-header {
    padding: var(--space-md) var(--space-lg);
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

  .card-body {
    padding: var(--space-lg);
  }

  /* Modales — ocupan todo el ancho disponible en mobile, sin scroll horizontal */
  .modal-overlay {
    left: 0 !important;
    padding: 8px;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
  }

  .modal-container {
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    overflow-x: hidden;
  }

  .modal-container.modal-lg,
  .modal-container.modal-md,
  .modal-container.modal-xl {
    max-width: 100%;
    width: 100%;
  }

  .modal-header {
    padding: var(--space-md) var(--space-lg);
  }

  .modal-body {
    padding: var(--space-md) var(--space-lg);
  }

  .modal-footer {
    padding: var(--space-md) var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .modal-footer .btn-form {
    flex: 1;
    justify-content: center;
    min-width: 100px;
  }

  /* FORZAR todos los inputs/selects/textareas a 100% dentro de modales y filtros */
  .modal-body input:not([type="checkbox"]):not([type="radio"]),
  .modal-body select,
  .modal-body textarea,
  .modal-body .form-control:not([type="checkbox"]):not([type="radio"]),
  .modal-body .form-select {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .modal-body input[type="checkbox"],
  .modal-body input[type="radio"] {
    width: auto !important;
    max-width: none !important;
    min-width: auto !important;
  }

  /* Evitar overflow en contenido de modales */
  .modal-body *[style*="width:"],
  .modal-body *[style*="min-width:"] {
    max-width: 100% !important;
  }

  .modal-body .form-row,
  .modal-body .form-group {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Grids dentro de modales — forzar 1 columna */
  .modal-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Formularios — una columna */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Filtros — stack vertical en mobile, TODOS los elementos 100% */
  .filters-section {
    padding: var(--space-md) var(--space-lg);
  }

  .filters-section .d-flex {
    flex-direction: column;
    align-items: stretch !important;
    width: 100%;
  }

  .filters-section .d-flex .form-group,
  .filters-section .d-flex > * {
    width: 100% !important;
    max-width: 100% !important;
  }

  .filters-section .d-flex input,
  .filters-section .d-flex select,
  .filters-section .d-flex .form-control,
  .filters-section .d-flex .form-select {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .filters-section .d-flex button {
    width: 100%;
    justify-content: center;
  }

  /* Tablas — scroll horizontal, contenidas dentro del card */
  .table-container {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  table.table {
    font-size: 0.8rem;
  }

  table.table thead th,
  table.table tbody td {
    padding: 8px 8px;
    white-space: nowrap;
  }

  /* data-table (modulos v2 nuevos) en movil:
     la tabla toma su ancho por contenido (max-content) y desborda; el contenedor
     (#tableContainer / .table-section, con overflow-x:auto) genera el scroll horizontal.
     width:max-content con !important vence el style="width:100%" inline de las tablas. */
  table.data-table {
    width: max-content !important;
    min-width: 100%;
    max-width: none !important;
  }

  table.data-table thead th,
  table.data-table tbody td {
    padding: 8px 10px;
    white-space: nowrap;
  }

  /* En movil no recortar con ellipsis: ver el contenido completo al deslizar */
  table.data-table tbody td[style*="max-width"] {
    max-width: none !important;
  }
  table.data-table tbody td > div[style*="ellipsis"] {
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }

  /* Tabs — scroll horizontal si hay muchos */
  .tabs-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Botones de accion en tablas — mas pequenos */
  .actions-group {
    gap: 2px !important;
  }

  /* Detail grids — stack en mobile */
  .detail-grid {
    grid-template-columns: 1fr !important;
  }

  /* Entity profile sections */
  .entity-profile .profile-details {
    padding: var(--space-md);
  }

  /* Metric cards grid */
  .metrics-grid,
  .metric-cards-row {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 13px;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.125rem; }

  .content-area {
    padding: var(--space-sm);
  }

  .btn-form {
    padding: 8px 14px;
    font-size: 0.8125rem;
  }

  .metric-card {
    padding: var(--space-lg);
  }

  .metric-card .metric-value {
    font-size: 1.75rem;
  }

  .toast {
    min-width: unset;
    max-width: calc(100vw - 32px);
  }

  .toast-container {
    right: var(--space-lg);
    left: var(--space-lg);
  }

  /* Modales en pantallas muy pequeñas — full width sin gaps */
  .modal-overlay {
    padding: 4px;
    align-items: center;
    justify-content: center;
  }

  .modal-container {
    border-radius: var(--radius-md);
    max-height: 94vh;
    width: 100%;
  }

  .modal-header {
    padding: var(--space-md);
  }

  .modal-body {
    padding: var(--space-md);
  }

  .modal-footer {
    padding: var(--space-md);
  }

  /* Card headers compactos */
  .card-header {
    padding: var(--space-md);
  }

  .card-header .btn-form {
    width: 100%;
    justify-content: center;
  }

  /* Filtros totalmente apilados */
  .filters-section .d-flex label {
    width: 100%;
  }
}

/* ─── 7. Utility Classes ─── */
.d-flex { display: flex; }
.gap-2 { gap: var(--space-sm); }
.gap-3 { gap: var(--space-md); }
.align-items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: var(--space-sm); }
.hidden { display: none !important; }

/* ─── 7b. Scrollbar discreto global ───
   Scrollbar fino y del color del fondo para que sea discreto en todas
   las áreas con scroll del proyecto.
   ─────────────────────────────────────── */

/* Scrollbar global — fondos claros (página, modales, tablas, dropdowns) */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--gray-200);    /* gris muy claro — casi invisible sobre blanco */
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gray-300);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Scrollbar para fondos oscuros (sidebar, log-viewer) */
.sidebar ::-webkit-scrollbar-thumb,
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
}

.sidebar ::-webkit-scrollbar-thumb:hover,
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.22);
}

/* Firefox — scrollbar thin */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--gray-200) transparent;
}

.sidebar,
.sidebar-nav {
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}

/* ─── SweetAlert2 — z-index sobre todos los modales del ERP ─── */
.swal2-container {
  z-index: 9999 !important;
  left: 230px !important;
  width: calc(100% - 230px) !important;
  transition: left 0.3s ease, width 0.3s ease;
}
body.sidebar-collapsed .swal2-container {
  left: 58px !important;
  width: calc(100% - 58px) !important;
}
@media (max-width: 768px) {
  .swal2-container {
    left: 0 !important;
    width: 100% !important;
  }
}
.swal2-popup {
  font-family: var(--font-family) !important;
  border-radius: var(--radius-xl) !important;
}
.swal2-title {
  font-size: 1.1rem !important;
  color: var(--gray-900) !important;
}
.swal2-html-container {
  font-size: 0.875rem !important;
  color: var(--gray-600) !important;
}

/* ─── 8. Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.animate-fade-in {
  animation: fadeIn var(--transition-normal);
}
