/**
 * =============================================
 * DULCES DETALLES — ESTILOS GLOBALES
 * =============================================
 * Sistema de diseño con soporte para tema claro y oscuro.
 * Variables CSS centralizadas para consistencia visual.
 */

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

/* ══════════════════════════════════════════════
   VARIABLES DE TEMA — CLARO (default)
══════════════════════════════════════════════ */
:root {
  /* Colores primarios */
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #dbeafe;
  --secondary:      #64748b;
  --success:        #10b981;
  --warning:        #f59e0b;
  --danger:         #ef4444;
  --info:           #06b6d4;

  /* Fondo y superficies */
  --bg-body:        #f0f4f8;
  --bg-surface:     #ffffff;
  --bg-surface-2:   #f8fafc;
  --bg-sidebar:     #1e293b;
  --bg-sidebar-hover: #334155;

  /* Texto */
  --text-primary:   #1e293b;
  --text-secondary: #64748b;
  --text-muted:     #94a3b8;
  --text-sidebar:   #cbd5e1;
  --text-sidebar-active: #ffffff;

  /* Bordes y sombras */
  --border:         #e2e8f0;
  --border-focus:   #2563eb;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg:      0 10px 30px rgba(0,0,0,0.12);

  /* Sidebar */
  --sidebar-width:  260px;
  --sidebar-collapsed: 72px;

  /* Transiciones */
  --transition:     all 0.25s ease;
  --transition-fast: all 0.15s ease;

  /* Border radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  /* Tipografía */
  --font:       'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ══════════════════════════════════════════════
   TEMA OSCURO
══════════════════════════════════════════════ */
[data-theme="dark"] {
  --primary:        #3b82f6;
  --primary-dark:   #2563eb;
  --primary-light:  #1e3a5f;

  --bg-body:        #0f172a;
  --bg-surface:     #1e293b;
  --bg-surface-2:   #2d3748;
  --bg-sidebar:     #0f172a;
  --bg-sidebar-hover: #1e293b;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  --border:         #334155;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:      0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:      0 10px 30px rgba(0,0,0,0.5);
}

/* ══════════════════════════════════════════════
   RESET Y BASE
══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-body);
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

/* ══════════════════════════════════════════════
   LAYOUT PRINCIPAL
══════════════════════════════════════════════ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  overflow-x: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 100px;
}

.sidebar-logo {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  object-fit: contain;
  background: white;
  padding: 4px;
  flex-shrink: 0;
}

.sidebar-brand {
  color: white;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: var(--transition);
}

.sidebar.collapsed .sidebar-brand { opacity: 0; width: 0; }
.sidebar.collapsed .sidebar-logo { width: 40px; height: 40px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.nav-section-label {
  color: rgba(255,255,255,0.35);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 12px 20px 6px;
  white-space: nowrap;
  overflow: hidden;
  transition: var(--transition);
}

.sidebar.collapsed .nav-section-label { opacity: 0; height: 0; padding: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-sidebar);
  text-decoration: none;
  border-radius: 0;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition-fast);
  position: relative;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: white;
}

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

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #93c5fd;
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

.nav-label {
  opacity: 1;
  transition: var(--transition);
  flex: 1;
}

.sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }

.nav-badge {
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
}

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

/* Sidebar footer (usuario) */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info {
  overflow: hidden;
  opacity: 1;
  transition: var(--transition);
}

.sidebar.collapsed .user-info { opacity: 0; width: 0; }

.user-name {
  color: white;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

/* ── CONTENIDO PRINCIPAL ─────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s ease;
}

.main-content.expanded {
  margin-left: var(--sidebar-collapsed);
}

/* ── TOPBAR ──────────────────────────────────── */
.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
}

.btn-sidebar-toggle:hover {
  background: var(--bg-body);
  color: var(--primary);
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-theme-toggle {
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-theme-toggle:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* ── CONTENIDO DE PÁGINA ──────────────────────── */
.page-content {
  flex: 1;
  padding: 28px 28px;
  background: var(--bg-body);
}

/* ══════════════════════════════════════════════
   COMPONENTES DE CARD
══════════════════════════════════════════════ */
.card {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-sm) !important;
  transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-md) !important; }

.card-header {
  background: var(--bg-surface) !important;
  border-bottom: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
  padding: 16px 20px !important;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.card-body { padding: 20px !important; }

/* ── STATS CARDS ─────────────────────────────── */
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-icon.green  { background: #d1fae5; color: #059669; }
.stat-icon.yellow { background: #fef3c7; color: #d97706; }
.stat-icon.red    { background: #fee2e2; color: #dc2626; }
.stat-icon.indigo { background: #e0e7ff; color: #4f46e5; }
.stat-icon.pink   { background: #fce7f3; color: #db2777; }

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ══════════════════════════════════════════════
   FORMULARIOS
══════════════════════════════════════════════ */
.form-control, .form-select {
  background-color: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  font-size: 13.5px !important;
  padding: 9px 12px !important;
  transition: var(--transition-fast) !important;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12) !important;
  background-color: var(--bg-surface) !important;
}

.form-control::placeholder { color: var(--text-muted) !important; }

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* ══════════════════════════════════════════════
   BOTONES
══════════════════════════════════════════════ */
.btn {
  font-family: var(--font) !important;
  font-weight: 600 !important;
  font-size: 13px !important;
  border-radius: var(--radius-sm) !important;
  padding: 8px 16px !important;
  transition: var(--transition-fast) !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
}

.btn-primary {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
}
.btn-primary:hover { background: var(--primary-dark) !important; }

.btn-sm {
  padding: 5px 10px !important;
  font-size: 12px !important;
}

.btn-icon {
  padding: 6px !important;
  border-radius: var(--radius-sm) !important;
}

/* ══════════════════════════════════════════════
   TABLAS
══════════════════════════════════════════════ */
.table {
  color: var(--text-primary) !important;
  font-size: 13.5px !important;
}

.table th {
  font-size: 11px !important;
  font-weight: 700 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.5px !important;
  color: var(--text-secondary) !important;
  background: var(--bg-surface-2) !important;
  border-color: var(--border) !important;
  padding: 10px 12px !important;
}

.table td {
  border-color: var(--border) !important;
  padding: 10px 12px !important;
  vertical-align: middle !important;
  color: var(--text-primary) !important;
}

.table tbody tr:hover {
  background: var(--bg-surface-2) !important;
}

/* DataTables custom */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { color: var(--text-secondary); }

.dataTables_wrapper .paginate_button {
  border-radius: var(--radius-sm) !important;
  color: var(--text-secondary) !important;
}

.dataTables_wrapper .paginate_button.current,
.dataTables_wrapper .paginate_button.current:hover {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: white !important;
}

/* ══════════════════════════════════════════════
   BADGES / ESTADO DE STOCK
══════════════════════════════════════════════ */
.badge {
  font-size: 11px !important;
  font-weight: 600 !important;
  padding: 4px 9px !important;
  border-radius: 20px !important;
}

.badge-stock-ok     { background: #d1fae5; color: #065f46; }
.badge-stock-low    { background: #fef3c7; color: #92400e; }
.badge-stock-out    { background: #fee2e2; color: #991b1b; }

/* ══════════════════════════════════════════════
   MODALES
══════════════════════════════════════════════ */
.modal-content {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  color: var(--text-primary) !important;
}

.modal-header {
  border-bottom: 1px solid var(--border) !important;
  padding: 18px 24px !important;
}

.modal-title {
  font-weight: 700 !important;
  font-size: 16px !important;
}

.modal-footer { border-top: 1px solid var(--border) !important; }

.btn-close { filter: var(--btn-close-filter, none); }
[data-theme="dark"] .btn-close { filter: invert(1); }

/* ══════════════════════════════════════════════
   ALERTAS DE STOCK
══════════════════════════════════════════════ */
.stock-alert-banner {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 1px solid #f59e0b;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: #78350f;
}

.stock-alert-banner .alert-icon { font-size: 20px; }

/* ══════════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 50%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: slideUp 0.4s ease;
}

[data-theme="dark"] .login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.login-logo {
  width: 144px;
  height: 144px;
  margin: 0 auto 16px;
  display: block;
  object-fit: contain;
}

.login-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-secondary);
  text-align: center;
  font-size: 14px;
  margin-bottom: 32px;
}

/* ══════════════════════════════════════════════
   FACTURACIÓN — TABLA DE ITEMS
══════════════════════════════════════════════ */
.invoice-items-table th,
.invoice-items-table td {
  padding: 8px 10px !important;
}

.invoice-total-section {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
}

.invoice-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.invoice-total-row.grand-total {
  border-top: 2px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}

/* ══════════════════════════════════════════════
   UTILIDADES
══════════════════════════════════════════════ */
.text-primary-brand { color: var(--primary) !important; }
.bg-primary-brand   { background: var(--primary) !important; }
.border-brand       { border-color: var(--border) !important; }
.bg-surface         { background: var(--bg-surface) !important; }
.text-muted-custom  { color: var(--text-muted) !important; }

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Animaciones ─────────────────────────────── */
.fade-in {
  animation: fadeIn 0.3s ease;
}

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

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════
   RESPONSIVE — MÓVIL
══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 0 0 0 100vw rgba(0,0,0,0.5);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .page-content {
    padding: 16px;
  }

  .topbar {
    padding: 0 16px;
  }

  .page-title { font-size: 16px; }
}

@media (max-width: 576px) {
  .stat-card { flex-direction: column; text-align: center; }
  .login-card { padding: 32px 24px; }
}
