/* ═══════════════════════════════════════════════════════════
   TEMPLATE-THEME.CSS — Sistema de Inventario
   Diseño basado en Free Tailwind Admin Dashboard Template
   Paleta: #5d87ff (primary), #49beff (secondary)
   Modo: Light + Dark (toggle via .dark en <html>)
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Variables — Light Mode ── */
:root {
  --primary:        #5d87ff;
  --secondary:      #49beff;
  --success:        #13deb9;
  --warning:        #f6b51e;
  --error:          #ef4444;
  --info:           #8754ec;
  --dark:           #1c2536;
  --white:          #ffffff;
  --bodytext:       rgba(90, 106, 133, 0.75);

  --lightprimary:   rgba(93, 135, 255, 0.12);
  --lightsecondary: rgba(73, 190, 255, 0.12);
  --lightsuccess:   rgba(19, 222, 185, 0.12);
  --lightwarning:   rgba(246, 181, 30, 0.12);
  --lighterror:     rgba(239, 68, 68, 0.12);
  --lightinfo:      rgba(135, 84, 236, 0.12);

  /* Emphasis variants */
  --primaryemphasis:   color-mix(in srgb, #5d87ff 80%, #000);
  --secondaryemphasis: color-mix(in srgb, #49beff 80%, #000);
  --successemphasis:   color-mix(in srgb, #13deb9 80%, #000);
  --warningemphasis:   color-mix(in srgb, #f6b51e 80%, #000);
  --erroremphasis:     color-mix(in srgb, #ef4444 80%, #000);
  --infoemphasis:      color-mix(in srgb, #8754ec 80%, #000);

  --sidebar-width:  270px;
  --header-height:  70px;

  --bg-body:        #f6f8fb;
  --bg-sidebar:     #ffffff;
  --bg-card:        #ffffff;

  --text-heading:   #1c2536;
  --text-body:      #5a6a85;
  --text-muted:     rgba(90, 106, 133, 0.75);
  --text-primary:   #1c2536;
  --text-secondary: #5a6a85;

  --accent-cyan:    #49beff;
  --accent-pink:    #f06292;
  --accent-violet:  #8754ec;
  --bg-card-alt:    #f8faff;
  --bg-soft:        #eef4ff;
  --bg-soft-2:      #edf9ff;

  --border-color:   #dfe5ef;

  --shadow-sm:      0 0.125rem 0.25rem rgba(0, 0, 0, 0.055);
  --shadow-md:      0 1px 4px rgba(133, 146, 173, 0.2);
  --shadow-card:    0 2px 20px rgba(93, 135, 255, 0.06);
  --card-glow:      0 10px 28px rgba(93, 135, 255, 0.10);
  --shadow-lg:      0 10px 40px rgba(0, 0, 0, 0.12);

  --radius-sm:      4px;
  --radius-md:      7px;
  --radius-lg:      10px;
  --radius-xl:      14px;

  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;

  /* Transition */
  --transition-speed: 0.2s;
  --transition-ease:  ease-in-out;
}

/* ── CSS Variables — Dark Mode ── */
html.dark {
  --bg-body:        #1c2536;
  --bg-sidebar:     #1c2536;
  --bg-card:        #1c2536;
  --text-heading:   #f4f7ff;
  --text-body:      #c1cede;
  --text-muted:     #9cafc8;
  --text-primary:   #f4f7ff;
  --text-secondary: #c1cede;

  --accent-cyan:    #78d7ff;
  --accent-pink:    #ff97bf;
  --accent-violet:  #bca9ff;
  --bg-card-alt:    rgba(255,255,255,0.04);
  --bg-soft:        rgba(255,255,255,0.05);
  --bg-soft-2:      rgba(255,255,255,0.07);
  --card-glow:      0 12px 26px rgba(0, 0, 0, 0.30);

  --border-color:   #3a4a64;

  --shadow-card:    0 2px 20px rgba(0, 0, 0, 0.25);
  --shadow-lg:      0 10px 40px rgba(0, 0, 0, 0.35);

  --lightprimary:   rgba(93, 135, 255, 0.20);
  --lightsecondary: rgba(73, 190, 255, 0.20);
  --lightsuccess:   rgba(19, 222, 185, 0.20);
  --lightwarning:   rgba(246, 181, 30, 0.20);
  --lighterror:     rgba(239, 68, 68, 0.20);
  --lightinfo:      rgba(135, 84, 236, 0.20);

  --white:          #ffffff;
  --dark:           #f4f7ff;
}

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

html, body {
  height: 100%;
  font-family: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-body);
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Background pattern — opacity & image url are injected by appBuildBackgroundCss() ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('../assets/images/bg/pattern-bg.jpg');
  background-repeat: repeat;
  background-size: 900px auto;
  background-position: top center;
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.4s ease, filter 0.4s ease;
}

html.dark body::before {
  filter: invert(1) hue-rotate(180deg) brightness(0.7);
  opacity: 0.08;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
ul, ol { list-style: none; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* ── Sidebar Logo ── */
.sidebar-logo {
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-logo-link {
  display: flex;
  align-items: center;
}

.comersur-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.comersur-logo-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.comersur-logo-img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border-radius: 50%;
  flex-shrink: 0;
  padding: 3px;
  background: #f6f8ff;
  border: 1px solid rgba(93, 135, 255, 0.25);
}

.comersur-logo-text {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--text-heading);
  line-height: 1.1;
}

.comersur-logo-subtext {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18px;
  color: var(--text-muted);
  line-height: 1.2;
  opacity: 0.9;
}

/* Light mode: dark logo visible, light logo hidden */
.sidebar-logo-dark  { display: block; }
.sidebar-logo-light { display: none;  }

/* Dark mode: light logo visible, dark logo hidden */
html.dark .sidebar-logo-dark  { display: none;  }
html.dark .sidebar-logo-light { display: block; }
html.dark .comersur-logo-img {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.18);
}
html.dark .comersur-logo-text {
  color: var(--text-heading);
}

.logo-text {
  font-size: 19px;
  font-weight: 700;
  color: var(--dark);
  letter-spacing: -0.4px;
}

.logo-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--primary);
  background: var(--lightprimary);
  padding: 2px 7px;
  border-radius: 20px;
}

/* ── Sidebar Nav ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.nav-section-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--text-muted);
  padding: 18px 8px 6px;
  line-height: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-heading);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all 0.18s ease;
  white-space: nowrap;
  position: relative;
}

.nav-link i {
  width: 20px;
  text-align: center;
  font-size: 15px;
  color: var(--text-body);
  flex-shrink: 0;
  transition: color 0.18s ease;
}

.nav-link span { flex: 1; }

.nav-link:hover {
  background: var(--lightprimary);
  color: var(--primary);
}
.nav-link:hover i { color: var(--primary); }

.nav-link.active {
  background: var(--lightprimary);
  color: var(--primary);
  font-weight: 600;
}
.nav-link.active i { color: var(--primary); }

/* Nav badge (stock alerts) */
.nav-badge {
  font-size: 10px;
  font-weight: 700;
  background: var(--error);
  color: #fff;
  padding: 2px 7px;
  border-radius: 20px;
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Sidebar Footer (User) ── */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  transition: background 0.18s;
  overflow: hidden;
}
.user-info:hover { background: var(--lightprimary); }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--lightprimary);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  border: 2px solid rgba(93,135,255,0.2);
}

.user-details {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  flex: 1;
}

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

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

.logout-link {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-body);
  transition: all 0.18s;
  flex-shrink: 0;
}
.logout-link:hover { background: var(--lighterror); color: var(--error); }

/* ── Sidebar Overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(28, 37, 54, 0.35);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ── Body Wrapper ── */
.body-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  background: transparent;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

/* ── Universal Header (only <header> element) ── */
header.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--white);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ── Page-level topbar (div.topbar inside page-content) ── */
div.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar-title h1, div.topbar h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--dark);
}

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

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

/* Mobile toggle button */
.mobile-toggle {
  display: none;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-body);
  border: none;
  background: transparent;
  transition: all 0.18s;
  flex-shrink: 0;
}
.mobile-toggle:hover { background: var(--lightprimary); color: var(--primary); }

/* Search bar */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 14px;
  min-width: 220px;
  transition: all 0.2s;
}
.search-box:focus-within {
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 3px var(--lightprimary);
}
.search-box i { color: var(--text-muted); font-size: 13px; flex-shrink: 0; }
.search-box input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  color: var(--dark);
  width: 100%;
  font-family: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }

/* Icon buttons in topbar */
.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-body);
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  transition: all 0.18s;
  font-size: 16px;
}
.icon-btn:hover { background: var(--lightprimary); color: var(--primary); }

.icon-btn .badge-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
  border: 2px solid var(--white);
}

.icon-btn .badge-count {
  position: absolute;
  top: 4px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--error);
  border: 2px solid var(--white);
  color: white;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* Profile button in topbar */
.header-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background 0.18s;
  border: none;
  background: transparent;
}
.header-profile:hover { background: var(--lightprimary); }

.header-profile .user-avatar {
  width: 34px;
  height: 34px;
  font-size: 12px;
}

.header-profile-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.header-profile-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--dark);
  line-height: 1.2;
}

.header-profile-role {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.2;
}

/* ── Page Content ── */
.page-content {
  flex: 1;
  padding: 24px;
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
}

.page-header-left .breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.breadcrumb-sep { opacity: 0.5; }
.breadcrumb-current { color: var(--primary); font-weight: 500; }

.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Date badge */
.date-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 20px;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
}

.card-body { padding: 24px; }

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--dark);
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  padding: 24px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(93,135,255,0.1);
}

.kpi-icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 16px;
}

/* Legacy kpi colors (keep for dashboard.php compatibility) */
.kpi-card.pink .kpi-icon, .kpi-icon.pink {
  background: var(--lightprimary); color: var(--primary);
}
.kpi-card.cyan .kpi-icon, .kpi-icon.cyan {
  background: var(--lightsecondary); color: var(--secondary);
}
.kpi-card.warn .kpi-icon, .kpi-icon.warn {
  background: var(--lightwarning); color: var(--warning);
}
.kpi-card.green .kpi-icon, .kpi-icon.green {
  background: var(--lightsuccess); color: var(--success);
}

/* Remove old pink/cyan card backgrounds */
.kpi-card.pink, .kpi-card.cyan, .kpi-card.warn, .kpi-card.green {
  background: var(--bg-card);
  border-color: var(--border-color);
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
  margin-bottom: 4px;
}

.kpi-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-body);
  margin-bottom: 4px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Charts ── */
.charts-row {
  display: grid;
  gap: 24px;
  margin-bottom: 24px;
}

.charts-row-2col { grid-template-columns: 2fr 1fr; }
.charts-row-equal { grid-template-columns: 1fr 1fr; }

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  padding: 24px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.chart-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--dark);
}

.chart-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--lightprimary);
  color: var(--primary);
}

.chart-canvas-wrap { position: relative; }
.chart-canvas-wrap.tall { min-height: 240px; }
.chart-canvas-wrap.donut { min-height: 190px; }

/* Donut legend */
.donut-legend {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-body);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-value {
  margin-left: auto;
  font-weight: 600;
  color: var(--dark);
  font-size: 14px;
}

/* ── Table Card ── */
.table-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  padding: 24px;
  margin-bottom: 24px;
}

/* ── Card Master (reusable glassmorphism-like card) ── */
.card-master {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-glow);
  overflow: hidden;
  transition: transform var(--transition-speed) var(--transition-ease),
              box-shadow var(--transition-speed) var(--transition-ease);
}
.card-master:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(93, 135, 255, 0.12);
}

.link-all {
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.18s;
}
.link-all:hover { opacity: 0.75; }

/* ── Data Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  background: transparent;
  white-space: nowrap;
}

.data-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-body);
  vertical-align: middle;
}

.data-table tbody tr { transition: background 0.12s; }
.data-table tbody tr:hover { background: var(--bg-soft); }
.data-table tbody tr:last-child td { border-bottom: none; }

.amount-cell {
  font-weight: 600;
  color: var(--success) !important;
}

/* ── Alert Banner ── */
.alert-banner {
  background: rgba(246, 181, 30, 0.1);
  border: 1px solid rgba(246, 181, 30, 0.3);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #9a7200;
  margin-bottom: 24px;
}
.alert-banner i { color: var(--warning); font-size: 15px; }
.alert-banner strong { font-weight: 700; }
.alert-banner a { color: var(--primary); font-weight: 600; }
.alert-banner a:hover { opacity: 0.8; }

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
}

.alert a { color: inherit; font-weight: 600; text-decoration: underline; }

.alert-danger, .alert-error {
  background: var(--lighterror);
  color: #c0392b;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.alert-success {
  background: var(--lightsuccess);
  color: #0a8f78;
  border: 1px solid rgba(19, 222, 185, 0.25);
}

.alert-warning {
  background: var(--lightwarning);
  color: #9a7200;
  border: 1px solid rgba(246, 181, 30, 0.25);
}

.alert-info {
  background: var(--lightinfo);
  color: var(--info);
  border: 1px solid rgba(135, 84, 236, 0.25);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.18s ease;
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}
.btn-primary:hover {
  background: #4a74f3;
  box-shadow: 0 4px 14px rgba(93,135,255,0.4);
  color: var(--white);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--white);
}
.btn-secondary:hover { background: #36aef3; }

.btn-success {
  background: var(--success);
  color: var(--white);
}
.btn-success:hover { background: #0fbe9f; }

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

.btn-danger {
  background: var(--error);
  color: var(--white);
}
.btn-danger:hover { background: #dc2626; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover {
  background: var(--lightprimary);
  color: var(--primary);
}

.btn-outline-dark {
  background: transparent;
  color: var(--text-body);
  border: 1px solid var(--border-color);
}
.btn-outline-dark:hover { background: var(--bg-body); color: var(--dark); }

.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }

.btn-icon-sm {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* ── Badges ── */
.badge-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--lightsuccess);
  color: #0a8f78;
}

.badge-pill.badge-warning { background: var(--lightwarning); color: #9a7200; }
.badge-pill.badge-danger, .badge-pill.badge-error { background: var(--lighterror); color: #c0392b; }
.badge-pill.badge-info { background: var(--lightinfo); color: var(--info); }
.badge-pill.badge-primary { background: var(--lightprimary); color: var(--primary); }
.badge-pill.badge-secondary { background: var(--lightsecondary); color: #2a9fd6; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }

label, .form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 6px;
}

.form-control, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--dark);
  background: var(--white);
  outline: none;
  transition: all 0.18s;
  font-family: inherit;
}

.form-control:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--lightprimary);
}

.form-control::placeholder, input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

.input-icon-wrap {
  position: relative;
}
.input-icon-wrap .form-control,
.input-icon-wrap input {
  padding-left: 40px;
}
.input-icon-wrap .input-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

/* ── Dividers ── */
.divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 16px 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  font-size: 12px;
  color: var(--text-muted);
}
.divider-text::before, .divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-state i {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
  color: var(--border-color);
}

/* ── Auth Pages ── */
.auth-wrapper {
  min-height: 100vh;
  background: var(--lightprimary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(93, 135, 255, 0.12);
  padding: 40px;
  width: 100%;
  max-width: 440px;
  border: 1px solid var(--border-color);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-logo img {
  height: 42px;
  width: 42px;
  object-fit: contain;
}

.auth-logo-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--dark);
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 14px;
  color: var(--text-body);
}

.auth-footer a {
  color: var(--primary);
  font-weight: 600;
  margin-left: 4px;
}
.auth-footer a:hover { opacity: 0.8; }

.auth-form .form-control,
.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="tel"],
.auth-form select {
  background: #f8fafc;
  border-color: var(--border-color);
}

.auth-form .form-control:focus,
.auth-form input:focus,
.auth-form select:focus {
  background: var(--white);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--lightprimary);
}

.btn-auth {
  width: 100%;
  padding: 11px 20px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
  text-align: center;
  display: block;
}
.btn-auth:hover {
  background: #4a74f3;
  box-shadow: 0 4px 16px rgba(93,135,255,0.4);
  color: var(--white);
  text-decoration: none;
}

.auth-link {
  color: var(--primary);
  font-weight: 500;
  font-size: 13px;
}
.auth-link:hover { opacity: 0.8; }

.auth-forgot {
  display: flex;
  justify-content: flex-end;
  margin-top: -12px;
  margin-bottom: 20px;
}

.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-body);
}
.auth-remember input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
}

.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--dark);
  background: #f8fafc;
  outline: none;
  transition: all 0.18s;
  font-family: inherit;
  cursor: pointer;
}
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--lightprimary);
  background: var(--white);
}

/* ── Responsive ── */
@media (max-width: 1280px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .body-wrapper { margin-left: 0; }
  .mobile-toggle { display: flex; }
  .search-box { min-width: 180px; }
}

@media (max-width: 1024px) {
  .charts-row-2col { grid-template-columns: 1fr; }
  .charts-row-equal { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
  .search-box { display: none; }
  .topbar { padding: 0 16px; }
  .header-profile-info { display: none; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ── Table responsive ── */
.table-responsive { overflow-x: auto; }

/* ── Status text colors ── */
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-error, .text-danger { color: var(--error) !important; }
.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-dark { color: var(--dark) !important; }
.fw-600 { font-weight: 600 !important; }

/* ── Mobile Logo (topbar) ── */
.topbar-logo {
  display: none;
  align-items: center;
  gap: 8px;
}

.topbar-logo img { width: 30px; height: 30px; object-fit: contain; }
.topbar-logo span { font-size: 16px; font-weight: 700; color: var(--dark); }

@media (max-width: 1280px) {
  .topbar-logo { display: flex; }
}

/* ══════════════════════════════════════════════════════════
   DARK MODE OVERRIDES
   Activated by adding class="dark" to <html> element
   ═══════════════════════════════════════════════════════════ */

/* Base */
html.dark body {
  background: var(--bg-body);
  color: var(--text-body);
}

/* Layout */
html.dark .sidebar {
  background: var(--bg-sidebar);
  border-right-color: var(--border-color);
}

html.dark .sidebar-logo {
  border-bottom-color: var(--border-color);
}

html.dark .logo-text { color: var(--text-heading); }

html.dark .sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-color); }

html.dark .nav-section-label { color: var(--text-muted); }

html.dark .nav-link {
  color: var(--text-body);
}
html.dark .nav-link i { color: var(--text-body); }
html.dark .nav-link:hover {
  background: var(--lightprimary);
  color: var(--primary);
}
html.dark .nav-link:hover i { color: var(--primary); }
html.dark .nav-link.active {
  background: var(--lightprimary);
  color: var(--primary);
}
html.dark .nav-link.active i { color: var(--primary); }

html.dark .sidebar-footer { border-top-color: var(--border-color); }

html.dark .user-info:hover { background: var(--lightprimary); }

html.dark .user-avatar {
  background: var(--lightprimary);
  color: var(--primary);
  border-color: rgba(93,135,255,0.25);
}

html.dark .user-name { color: var(--text-heading); }
html.dark .user-role { color: var(--text-muted); }

html.dark .logout-link { color: var(--text-body); }
html.dark .logout-link:hover { background: var(--lighterror); color: var(--error); }

/* Body wrapper */
html.dark .body-wrapper { background: transparent; }

/* Topbar */
html.dark header.topbar {
  background: var(--bg-sidebar);
  border-bottom-color: var(--border-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

html.dark .topbar-logo span { color: var(--text-heading); }

html.dark .mobile-toggle {
  color: var(--text-body);
}
html.dark .mobile-toggle:hover { background: var(--lightprimary); color: var(--primary); }

html.dark .search-box {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-color);
}
html.dark .search-box:focus-within {
  border-color: var(--primary);
  background: rgba(255,255,255,0.08);
}
html.dark .search-box input { color: var(--text-heading); }
html.dark .search-box i { color: var(--text-muted); }
html.dark .search-box input::placeholder { color: var(--text-muted); }

html.dark .icon-btn {
  color: var(--text-body);
}
html.dark .icon-btn:hover { background: var(--lightprimary); color: var(--primary); }

html.dark .header-profile:hover { background: var(--lightprimary); }
html.dark .header-profile-name { color: var(--text-heading); }
html.dark .header-profile-role { color: var(--text-muted); }

/* Cards */
html.dark .card,
html.dark .chart-card,
html.dark .table-card,
html.dark .kpi-card {
  background: var(--bg-card);
  border-color: var(--border-color);
}

html.dark .card-header {
  border-bottom-color: var(--border-color);
}

html.dark .card-title { color: var(--text-heading); }

/* KPI cards */
html.dark .kpi-value { color: var(--text-heading); }
html.dark .kpi-label { color: var(--text-body); }
html.dark .kpi-sub   { color: var(--text-muted); }
html.dark .kpi-card:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

/* Charts */
html.dark .chart-header h3 { color: var(--text-heading); }

/* Tables */
html.dark .data-table thead th {
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  border-bottom-color: var(--border-color);
}
html.dark .data-table tbody td {
  color: var(--text-body);
  border-bottom-color: rgba(255,255,255,0.04);
}
html.dark .data-table tbody tr:hover { background: rgba(93,135,255,0.06); }

/* Page header */
html.dark .page-header-left h1 { color: var(--text-heading); }
html.dark .breadcrumb { color: var(--text-muted); }

/* Date badge */
html.dark .date-badge {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-color);
  color: var(--text-muted);
}

/* Alerts */
html.dark .alert-banner {
  background: rgba(246, 181, 30, 0.08);
  border-color: rgba(246, 181, 30, 0.2);
}

/* Forms */
html.dark .form-control,
html.dark input[type="text"],
html.dark input[type="email"],
html.dark input[type="password"],
html.dark input[type="number"],
html.dark input[type="tel"],
html.dark input[type="date"],
html.dark select,
html.dark textarea {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-color);
  color: var(--text-heading);
}
html.dark .form-control:focus,
html.dark input:focus,
html.dark select:focus,
html.dark textarea:focus {
  border-color: var(--primary);
  background: rgba(255,255,255,0.08);
  box-shadow: 0 0 0 3px var(--lightprimary);
}
html.dark label, html.dark .form-label { color: var(--text-heading); }

/* Dividers */
html.dark .divider { border-top-color: var(--border-color); }
html.dark .divider-text::before,
html.dark .divider-text::after { background: var(--border-color); }

/* Empty state */
html.dark .empty-state { color: var(--text-muted); }
html.dark .empty-state i { color: var(--border-color); }

/* Badges */
html.dark .badge-pill.badge-primary { background: var(--lightprimary); color: var(--primary); }

/* Buttons */
html.dark .btn-outline-dark {
  border-color: var(--border-color);
  color: var(--text-body);
}
html.dark .btn-outline-dark:hover { background: rgba(255,255,255,0.06); color: var(--text-heading); }
html.dark .btn-warning { color: #1c2536; }

/* Form select */
html.dark .form-select {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-color);
  color: var(--text-heading);
}
html.dark .form-select:focus {
  border-color: var(--primary);
  background: rgba(255,255,255,0.08);
}

/* Link all */
html.dark .link-all { color: var(--primary); }

/* Profile welcome banner */
html.dark .profile-welcome {
  background: var(--lightsecondary) !important;
  border-color: rgba(73,190,255,0.12) !important;
}
html.dark .profile-welcome h2 { color: var(--text-heading) !important; }
html.dark .profile-welcome p  { color: var(--text-muted) !important; }

/* Card master dark */
html.dark .card-master {
  background: var(--bg-card);
  border-color: var(--border-color);
}
html.dark .card-master:hover {
  box-shadow: 0 8px 28px rgba(0,0,0,0.25);
}

/* ── Dark Mode Toggle Button ── */
.theme-toggle {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-body);
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-speed) var(--transition-ease);
  font-size: 16px;
}
.theme-toggle:hover {
  background: var(--lightprimary);
  color: var(--primary);
}

/* Theme icon switching */
.theme-icon-light { display: block; }
.theme-icon-dark  { display: none;  }

html.dark .theme-icon-light { display: none;  }
html.dark .theme-icon-dark  { display: block; }

/* ── Smooth transition for all color changes ── */
*, *::before, *::after {
  transition-property: background-color, border-color, color;
  transition-duration: var(--transition-speed);
  transition-timing-function: var(--transition-ease);
}

/* Override transition for performance-critical elements */
.sidebar,
.body-wrapper,
.topbar {
  transition: background-color var(--transition-speed) var(--transition-ease),
              border-color var(--transition-speed) var(--transition-ease),
              transform 0.3s ease,
              box-shadow 0.3s ease;
}

/* ── Scroll behavior during dark toggle ── */
html.dark ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
html.dark ::-webkit-scrollbar-track { background: transparent; }
html.dark ::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
html.dark ::-webkit-scrollbar-thumb:hover { background: #4a5568; }

/* ── Paginación personalizada ── */
.pagination-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    padding: 16px 0 8px;
}
.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #dfe5ef;
    color: #5a6a85;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
    background: #fff;
}
.pagination-btn:hover { background: #ecf2ff; border-color: #5d87ff; color: #5d87ff; }
.pagination-btn.active { background: #5d87ff; border-color: #5d87ff; color: #fff; font-weight: 600; }

/* Bootstrap pagination — integración con el tema */
.pagination .page-link {
    border-radius: 8px !important;
    margin: 0 2px;
    border-color: var(--border-color);
    color: var(--text-body);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
    background: var(--bg-card);
}
.pagination .page-link:hover {
    background: var(--lightprimary);
    border-color: var(--primary);
    color: var(--primary);
}
.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.pagination .page-item.disabled .page-link {
    opacity: 0.45;
    pointer-events: none;
}

/* ── Validación de formularios ── */
.is-invalid {
    border-color: #fa896b !important;
    box-shadow: 0 0 0 3px rgba(250, 137, 107, 0.15) !important;
}
.is-invalid:focus {
    border-color: #fa896b !important;
    box-shadow: 0 0 0 3px rgba(250, 137, 107, 0.25) !important;
}
.validation-error {
    font-size: 13.5px;
    border-radius: 8px;
    margin-bottom: 12px;
}

/* ══════════════════════════════════════════════════════════
   DARK MODE — FIXES COMPLEMENTARIOS
   ══════════════════════════════════════════════════════════ */

/* ── Paginación (botones standalone) ── */
html.dark .pagination-btn {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-body);
}
html.dark .pagination-btn:hover {
  background: var(--lightprimary);
  border-color: var(--primary);
  color: var(--primary);
}
html.dark .pagination-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Alertas — texto legible en dark ── */
html.dark .alert-banner {
  color: #fcd34d;
}
html.dark .alert-banner i { color: var(--warning); }
html.dark .alert-danger,
html.dark .alert-error  { color: #f87171; }
html.dark .alert-success { color: #34d399; }
html.dark .alert-warning { color: #fbbf24; }
html.dark .alert-info    { color: var(--accent-violet); }

/* ── Páginas de autenticación ── */
html.dark .auth-wrapper {
  background: rgba(28, 37, 54, 0.98);
}
html.dark .auth-card {
  background: var(--bg-card);
  border-color: var(--border-color);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
html.dark .auth-logo-text,
html.dark .auth-title {
  color: var(--text-heading);
}
html.dark .auth-subtitle { color: var(--text-muted); }
html.dark .auth-footer   { color: var(--text-body); }
html.dark .auth-remember { color: var(--text-body); }
html.dark .auth-form .form-control,
html.dark .auth-form input[type="text"],
html.dark .auth-form input[type="email"],
html.dark .auth-form input[type="password"],
html.dark .auth-form input[type="tel"],
html.dark .auth-form select {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-color);
  color: var(--text-heading);
}
html.dark .auth-form .form-control:focus,
html.dark .auth-form input:focus,
html.dark .auth-form select:focus {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--lightprimary);
}
html.dark .auth-form .form-control::placeholder,
html.dark .auth-form input::placeholder {
  color: var(--text-muted);
}

/* ── Topbar h1 / page titles genéricos ── */
html.dark .topbar-title h1,
html.dark div.topbar h1 {
  color: var(--text-heading);
}

/* ── Table hover base (fuera de card-master) ── */
html.dark .data-table tbody tr:hover {
  background: rgba(93, 135, 255, 0.07);
}

/* ── Select option (best-effort cross-browser) ── */
html.dark select option {
  background: #1c2536;
  color: var(--text-heading);
}
