/* ==================== RESET Y VARIABLES CSS ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #1d1e1e;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --success: #22c55e;
  --success-dark: #16a34a;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-dark: #d97706;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --danger-light: #fee2e2;
  --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;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1),
    0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --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);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --border-radius: 8px;
  --transition: all 0.2s ease-in-out;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-800);
  background: var(--gray-50);
  overflow-x: hidden;
}

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 2.25rem;
  margin: 0;
}
h2 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 2rem;
  margin: 0;
}
h3 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.75rem;
  margin: 0;
}
p {
  margin: 0;
}

/* ==================== UTILIDADES ==================== */
.hidden {
  display: none !important;
}
.text-center {
  text-align: center;
}
.text-muted {
  color: var(--gray-500);
}
.text-success {
  color: var(--success);
}
.text-warning {
  color: var(--warning);
}
.text-danger {
  color: var(--danger);
}

/* ==================== PANTALLA DE LOGIN ==================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #d1d5db  0%, #f9fafb  100%);
  padding: 1rem;
}

.login-card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-xl);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 1.5rem;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2rem;
}

.login-card h1 {
  font-size: 1.875rem;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  color: var(--gray-500);
  margin-bottom: 2rem;
  font-size: 0.875rem;
}

/* ==================== FORMULARIOS ==================== */
.form-group {
  margin-bottom: 1.25rem;
}

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-family: inherit;
  transition: var(--transition);
  background: white;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.input-with-icon {
  position: relative;
}

.input-with-icon .form-input {
  padding-left: 2.5rem;
}

.input-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  width: 16px;
  height: 16px;
}

.form-divider {
  display: flex;
  align-items: center;
  margin: 1.5rem 0 1.25rem 0;
  color: var(--gray-500);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-divider span {
  padding-right: 0.75rem;
}

.form-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

.password-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  transition: var(--transition);
}

.password-toggle:hover {
  color: var(--gray-600);
}

.eye-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==================== BOTONES ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--border-radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: var(--success-dark);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-dark);
}

.btn-outline {
  background: white;
  border-color: var(--gray-300);
  color: var(--gray-700);
}

.btn-outline:hover:not(:disabled) {
  background: var(--gray-50);
}

.btn-ghost {
  background: transparent;
  color: var(--gray-700);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--gray-100);
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 0.5rem;
  font-size: 0.875rem;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
}

/* ==================== HEADER ==================== */
.app-header {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-icon {
  font-size: 2rem;
}

.header-title h1 {
  font-size: 1.25rem;
  margin-bottom: 0.125rem;
}

.header-title p {
  font-size: 0.875rem;
  opacity: 0.9;
}

/* ==================== LAYOUT PRINCIPAL ==================== */
.main-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  width: 256px;
  background: white;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 64px;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.user-info {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--gray-100);
  border-radius: var(--border-radius);
  transition: var(--transition);
}

.sidebar.collapsed .user-info {
  display: none;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-900);
  margin-bottom: 0.125rem;
}

.user-role {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  color: var(--gray-700);
  transition: var(--transition);
  margin-bottom: 0.25rem;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  position: relative;
}

.nav-item:hover {
  background: var(--gray-100);
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

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

.nav-text {
  font-weight: 500;
}

.sidebar.collapsed .nav-text {
  display: none;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 0.75rem;
}

.nav-badge {
  background: var(--danger);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  margin-left: auto;
}

.sidebar.collapsed .nav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  padding: 0;
  font-size: 0;
}

.sidebar-footer {
  padding: 0.5rem;
  border-top: 1px solid var(--gray-200);
}

/* ==================== CONTENIDO PRINCIPAL ==================== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--gray-50);
}

.content-header {
  margin-bottom: 1.5rem;
}

.content-header h2 {
  margin-bottom: 0.25rem;
}

.content-header-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

/* ==================== CARDS Y KPIs ==================== */
.card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

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

.kpi-icon {
  font-size: 1.25rem;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.25rem;
}

.kpi-description {
  font-size: 0.75rem;
  color: var(--gray-500);
}

/* ==================== TABS ==================== */
.tabs {
  margin-bottom: 1.5rem;
}

.tab-list {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.tab-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--gray-600);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -2px;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
}

.tab-button:hover {
  color: var(--gray-800);
}

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

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ==================== TABLAS ==================== */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius);
  background: white;
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--gray-50);
}

th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-200);
}

td {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--gray-200);
  font-size: 0.875rem;
  color: var(--gray-700);
}

tbody tr:hover {
  background: var(--gray-50);
}

.table-actions {
  display: flex;
  gap: 0.5rem;
}

/* ==================== BADGES ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-primary {
  background: #dbeafe;
  color: var(--primary);
}

.badge-success {
  background: var(--success-light);
  color: var(--success-dark);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger-dark);
}

/* ==================== MODALES ==================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: white;
  border-radius: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

.modal-sm {
  max-width: 400px;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-body {
  padding: 1.5rem;
}

.modal-description {
  color: var(--gray-600);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ==================== INFO BOXES ==================== */
.info-box {
  background: var(--gray-100);
  padding: 1rem;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--gray-700);
}

.success-box {
  background: var(--success-light);
  border: 1px solid #bbf7d0;
  padding: 1rem;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--success-dark);
}

/* ==================== TOAST NOTIFICATIONS ==================== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: white;
  padding: 1rem 1.25rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid var(--gray-300);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

.toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

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

/* ==================== EMPTY STATE ==================== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-500);
}

.empty-state-icon {
  font-size: 4rem;
  opacity: 0.5;
  margin-bottom: 1rem;
}

/* ==================== ICONOS SVG ==================== */
.svg-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==================== RESPONSIVE ==================== */

/* Botón de menú móvil */
.mobile-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.5rem;
  margin-left: auto;
}

.mobile-menu-toggle .svg-icon {
  width: 24px;
  height: 24px;
}

/* Overlay para cerrar sidebar en móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 190;
}

.sidebar-overlay.active {
  display: block;
}

/* Tablet: 1024px */
@media (max-width: 1024px) {
  .sidebar {
    width: 200px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .header-content {
    padding: 0.75rem 1rem;
  }

  .main-content {
    padding: 1rem;
  }
}

/* Mobile: 768px */
@media (max-width: 768px) {
  /* Mostrar botón de menú */
  .mobile-menu-toggle {
    display: flex;
  }

  /* Sidebar oculto por defecto */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Header ajustes */
  .header-content {
    padding: 0.75rem 1rem;
  }

  .header-icon {
    font-size: 1.5rem;
  }

  .header-title h1 {
    font-size: 1rem;
  }

  .header-title p {
    font-size: 0.75rem;
    display: none;
  }

  /* Contenido principal */
  .main-content {
    padding: 1rem;
  }

  /* KPIs en una columna */
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .kpi-value {
    font-size: 1.5rem;
  }

  /* Header de contenido responsivo */
  .content-header-actions {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }

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

  /* Tabs horizontales con scroll */
  .tab-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

  .tab-button {
    padding: 0.625rem 1rem;
    font-size: 0.8rem;
  }

  /* Tablas responsivas */
  .table-container {
    margin: 0 -1rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  th, td {
    padding: 0.625rem 0.75rem;
    font-size: 0.8rem;
  }

  .table-actions {
    flex-direction: column;
    gap: 0.25rem;
  }

  .table-actions .btn {
    width: 100%;
  }

  /* Modales */
  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    max-height: 95vh;
    border-radius: 12px 12px 0 0;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 1rem;
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
  }

  /* Formularios en 2 columnas a 1 */
  .form-row {
    flex-direction: column;
    gap: 0;
  }

  /* Toasts */
  .toast-container {
    left: 1rem;
    right: 1rem;
    top: auto;
    bottom: 1rem;
  }

  .toast {
    min-width: auto;
    max-width: 100%;
  }

  /* Login responsive */
  .login-card {
    padding: 1.5rem;
    margin: 0;
    border-radius: 8px;
  }

  .login-card h1 {
    font-size: 1.5rem;
  }

  /* Botones táctiles más grandes */
  .btn {
    min-height: 44px;
    padding: 0.75rem 1.25rem;
  }

  .btn-sm {
    min-height: 36px;
    padding: 0.5rem 0.75rem;
  }

  /* Cards más compactas */
  .card {
    padding: 1rem;
  }

  /* Acciones de tabla en columna */
  .table-actions {
    flex-wrap: wrap;
  }
}

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

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .header-content {
    gap: 0.5rem;
  }

  .header-icon {
    font-size: 1.25rem;
  }

  .header-title h1 {
    font-size: 0.9rem;
  }

  .kpi-card {
    padding: 1rem;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .empty-state {
    padding: 2rem 1rem;
  }

  .empty-state-icon {
    font-size: 3rem;
  }

  /* Ocultar columnas menos importantes en móvil */
  .hide-mobile {
    display: none !important;
  }
}

/* Touch-friendly interactions */
@media (hover: none) {
  .btn:hover,
  .nav-item:hover,
  tbody tr:hover {
    background: inherit;
  }

  .btn:active {
    opacity: 0.8;
  }

  .nav-item:active {
    background: var(--gray-100);
  }
}

/* ==================== PERMISSION TOGGLE SWITCHES ==================== */
.permission-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.permission-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.permission-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--gray-300);
  transition: var(--transition);
  border-radius: 24px;
}

.permission-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: var(--transition);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.permission-toggle input:checked + .permission-slider {
  background-color: var(--success);
}

.permission-toggle input:checked + .permission-slider::before {
  transform: translateX(20px);
}

.permission-toggle input:focus + .permission-slider {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.permission-toggle input:disabled + .permission-slider {
  opacity: 0.5;
  cursor: not-allowed;
}
