/* ==========================================
   ERP Sistema — Estilos Principales
   Variables CSS configurables por cliente
   ========================================== */

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

/* --- Variables del Tema (Light) --- */
:root {
  --primary: var(--theme-primary, #2563EB);
  --primary-hover: color-mix(in srgb, var(--primary) 85%, black);
  --primary-light: color-mix(in srgb, var(--primary) 15%, white);
  --secondary: var(--theme-secondary, #7C3AED);
  --accent: var(--theme-accent, #06B6D4);
  --success: #10B981; --success-light: #D1FAE5;
  --warning: #F59E0B; --warning-light: #FEF3C7;
  --danger: #EF4444;  --danger-light: #FEE2E2;
  --info: #3B82F6;    --info-light: #DBEAFE;

  --bg-body: #F1F5F9; --bg-card: #FFFFFF; --bg-sidebar: var(--theme-sidebar, #1E293B);
  --bg-input: #FFFFFF; --bg-hover: #F8FAFC;
  --text-primary: #1E293B; --text-secondary: #64748B; --text-muted: #94A3B8;
  --text-sidebar: #CBD5E1; --text-sidebar-active: #FFFFFF;
  --border-color: #E2E8F0; --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
  --radius: 10px; --radius-sm: 6px; --radius-lg: 16px;
  --sidebar-width: 260px; --sidebar-collapsed: 70px; --topbar-height: 64px;
  --font-family: 'Inter', system-ui, sans-serif;
  --transition: .25s cubic-bezier(.4,0,.2,1);
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg-body: #0F172A; --bg-card: #1E293B; --bg-sidebar: #0F172A;
  --bg-input: #334155; --bg-hover: #334155;
  --text-primary: #F1F5F9; --text-secondary: #94A3B8; --text-muted: #64748B;
  --border-color: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,.3); --shadow-lg: 0 10px 25px rgba(0,0,0,.4);
  --primary-light: color-mix(in srgb, var(--primary) 20%, #1E293B);
  --success-light: #064E3B; --warning-light: #78350F; --danger-light: #7F1D1D; --info-light: #1E3A5F;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body { font-family: var(--font-family); background: var(--bg-body); color: var(--text-primary); min-height: 100vh; overflow-x: hidden; transition: background var(--transition), color var(--transition); }
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }

/* --- Sidebar --- */
.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-width); height: 100vh;
  background: var(--bg-sidebar); color: var(--text-sidebar); z-index: 1040;
  transition: width var(--transition), transform var(--transition);
  display: flex; flex-direction: column; overflow: hidden;
  border-right: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand {
  height: var(--topbar-height); display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid rgba(255,255,255,.08); flex-shrink: 0;
}
.sidebar-brand img { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; }
.sidebar-brand span { font-weight: 700; font-size: 1.1rem; color: #fff; white-space: nowrap; overflow: hidden; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
.nav-section { padding: 8px 20px 6px; font-size: .7rem; text-transform: uppercase; letter-spacing: 1.2px; color: rgba(255,255,255,.35); font-weight: 600; margin-top: 8px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; color: var(--text-sidebar);
  font-size: .9rem; font-weight: 400; transition: all var(--transition); border-radius: 0; position: relative;
}
.nav-link i { width: 20px; text-align: center; font-size: 1.05rem; opacity: .7; transition: opacity var(--transition); }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link:hover i { opacity: 1; }
.nav-link.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav-link.active i { opacity: 1; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,.08); flex-shrink: 0; }

/* Collapsed sidebar */
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-brand span,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-footer .user-info { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 12px; }
.sidebar.collapsed .nav-link i { margin: 0; font-size: 1.2rem; }

/* --- Topbar --- */
.topbar {
  position: fixed; top: 0; right: 0; left: var(--sidebar-width); height: var(--topbar-height);
  background: var(--bg-card); border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  z-index: 1030; transition: left var(--transition), background var(--transition);
  box-shadow: var(--shadow);
}
.sidebar.collapsed ~ .topbar { left: var(--sidebar-collapsed); }
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.btn-toggle-sidebar { background: none; border: none; font-size: 1.3rem; color: var(--text-secondary); cursor: pointer; padding: 8px; border-radius: var(--radius-sm); transition: all var(--transition); }
.btn-toggle-sidebar:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-title { font-size: 1.15rem; font-weight: 600; }

/* Theme toggle */
.theme-toggle { background: var(--bg-hover); border: 1px solid var(--border-color); width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1.1rem; color: var(--text-secondary); transition: all var(--transition); }
.theme-toggle:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* User menu */
.user-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 12px; border-radius: var(--radius); transition: background var(--transition); }
.user-menu:hover { background: var(--bg-hover); }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem; }
.user-name { font-weight: 500; font-size: .9rem; }
.user-role { font-size: .75rem; color: var(--text-muted); }

/* --- Main Content --- */
.main-content {
  margin-left: var(--sidebar-width); padding-top: var(--topbar-height);
  min-height: 100vh; transition: margin-left var(--transition);
}
.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-collapsed); }
.content-wrapper { padding: 24px; }

/* --- Cards --- */
.card {
  background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: all var(--transition); overflow: hidden;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  background: transparent;
}
.card-header h5 { margin: 0; font-weight: 600; font-size: 1rem; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border-color); background: var(--bg-hover); }

/* KPI Cards */
.kpi-card { border: none; border-left: 4px solid var(--primary); position: relative; overflow: hidden; }
.kpi-card .kpi-icon { width: 48px; height: 48px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.kpi-card .kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.kpi-card .kpi-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 500; }
.kpi-card .kpi-change { font-size: .8rem; font-weight: 500; }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { background: var(--bg-hover); color: var(--text-secondary); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; padding: 12px 16px; border-bottom: 2px solid var(--border-color); text-align: left; white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--bg-hover); }
.table .actions { white-space: nowrap; }
.table .actions .btn { padding: 4px 8px; font-size: .8rem; }

/* DataTables overrides (Vanilla) */
.dataTables_wrapper { font-size: .9rem; padding: 16px; background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border-color); }
.dataTables_wrapper .dataTables_filter { margin-bottom: 16px; }
.dataTables_wrapper .dataTables_filter input { border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 6px 12px; background: var(--bg-input); color: var(--text-primary); margin-left: 8px; }
.dataTables_wrapper .dataTables_length select { border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 4px 8px; background: var(--bg-input); color: var(--text-primary); margin: 0 8px; }
.dataTables_wrapper table.dataTable { border-bottom: 1px solid var(--border-color); margin-bottom: 16px; }
.dataTables_wrapper table.dataTable thead th { border-bottom: 2px solid var(--border-color); color: var(--text-secondary); }
.dataTables_wrapper table.dataTable tbody tr { background: transparent; }
.dataTables_wrapper table.dataTable tbody tr:hover { background: var(--bg-hover); }
.dataTables_wrapper table.dataTable tbody td { border-top: 1px solid var(--border-color); }
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { margin-top: 16px; color: var(--text-secondary); }
.dataTables_wrapper .dataTables_paginate .paginate_button { border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 6px 12px; background: var(--bg-input); color: var(--text-primary) !important; cursor: pointer; margin: 0 4px; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--primary); color: #fff !important; border-color: var(--primary); }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover:not(.current) { background: var(--bg-hover); }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; font-size: .9rem; font-weight: 500; border: none; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition); font-family: var(--font-family); text-decoration: none; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 50%; }

/* --- Forms --- */
.form-label { display: block; font-weight: 500; margin-bottom: 6px; font-size: .88rem; color: var(--text-primary); }
.form-control {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text-primary); font-family: var(--font-family); font-size: .9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-control::placeholder { color: var(--text-muted); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea.form-control { min-height: 80px; resize: vertical; }
.form-text { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
.form-group { margin-bottom: 16px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.is-invalid { border-color: var(--danger) !important; }
.invalid-feedback { color: var(--danger); font-size: .8rem; margin-top: 4px; }

/* --- Badges --- */
.badge { display: inline-flex; align-items: center; padding: 4px 10px; font-size: .75rem; font-weight: 600; border-radius: 20px; letter-spacing: .3px; }
.bg-success { background: var(--success) !important; color: #fff !important; }
.bg-warning { background: var(--warning) !important; color: #000 !important; }
.bg-danger { background: var(--danger) !important; color: #fff !important; }
.bg-info { background: var(--info) !important; color: #fff !important; }
.bg-secondary { background: var(--text-muted) !important; color: #fff !important; }
.bg-primary { background: var(--primary) !important; color: #fff !important; }

/* --- Alerts / Flash --- */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); font-size: .9rem; display: flex; align-items: center; gap: 10px; margin-bottom: 16px; border: 1px solid transparent; animation: slideDown .3s ease; }
.alert-success { background: var(--success-light); color: #065F46; border-color: #A7F3D0; }
.alert-danger, .alert-error { background: var(--danger-light); color: #991B1B; border-color: #FCA5A5; }
.alert-warning { background: var(--warning-light); color: #92400E; border-color: #FCD34D; }
.alert-info { background: var(--info-light); color: #1E40AF; border-color: #93C5FD; }
[data-theme="dark"] .alert-success { color: #6EE7B7; }
[data-theme="dark"] .alert-danger, [data-theme="dark"] .alert-error { color: #FCA5A5; }
[data-theme="dark"] .alert-warning { color: #FCD34D; }
[data-theme="dark"] .alert-info { color: #93C5FD; }

/* --- Modal --- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1050; display: none; backdrop-filter: blur(4px); animation: fadeIn .2s ease; }
.modal-backdrop.show { display: flex; align-items: center; justify-content: center; }
.modal { background: var(--bg-card); border-radius: var(--radius-lg); width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: scaleIn .3s ease; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h5 { margin: 0; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* --- Utilities --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.fw-bold { font-weight: 700; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-100 { width: 100%; }

/* Grid */
.row { display: flex; flex-wrap: wrap; gap: 24px; }
.col { flex: 1; min-width: 0; }
.col-6 { width: calc(50% - 12px); }
.col-4 { width: calc(33.333% - 16px); }
.col-3 { width: calc(25% - 18px); }
.col-8 { width: calc(66.666% - 8px); }
.col-12 { width: 100%; }

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* --- Login Page --- */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary), var(--secondary)); padding: 20px; }
.login-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.login-card .logo { text-align: center; margin-bottom: 32px; }
.login-card .logo img { width: 64px; height: 64px; border-radius: 12px; }
.login-card .logo h2 { margin-top: 12px; font-weight: 700; font-size: 1.4rem; }
.login-card .logo p { color: var(--text-muted); font-size: .9rem; }

/* --- Install Page --- */
.install-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1E293B, #0F172A); padding: 20px; }
.install-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 600px; box-shadow: var(--shadow-lg); }
.install-steps { display: flex; justify-content: center; gap: 8px; margin-bottom: 32px; }
.install-step { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .9rem; background: var(--bg-hover); color: var(--text-muted); transition: all var(--transition); }
.install-step.active { background: var(--primary); color: #fff; }
.install-step.done { background: var(--success); color: #fff; }

/* --- Empty State --- */
.empty-state { text-align: center; padding: 48px 20px; }
.empty-state i { font-size: 3rem; color: var(--text-muted); margin-bottom: 16px; }
.empty-state h4 { color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 20px; }

/* --- Responsive --- */
@media (max-width: 1024px) {
  .col-3, .col-4 { width: calc(50% - 12px); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar.mobile-open { transform: translateX(0); }
  .topbar { left: 0 !important; }
  .main-content { margin-left: 0 !important; }
  .content-wrapper { padding: 16px; }
  .col-3, .col-4, .col-6, .col-8 { width: 100%; }
  .row { gap: 16px; }
  .card-header { flex-direction: column; align-items: flex-start; }
  .table { font-size: .8rem; }
  .table th, .table td { padding: 8px 10px; }
  .kpi-card .kpi-value { font-size: 1.3rem; }
  .d-none-mobile { display: none !important; }
  .mobile-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1035; display: none; }
  .mobile-overlay.show { display: block; }
}
@media (max-width: 480px) {
  html { font-size: 13px; }
  .login-card, .install-card { padding: 24px; }
  .content-wrapper { padding: 12px; }
}

/* --- Print --- */
@media print {
  .sidebar, .topbar, .btn, .dataTables_filter, .dataTables_length, .dataTables_paginate { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
