:root {
  /* Brand / accent (shared) */
  --rojo: #d42b2b;
  --rojo-dark: #a81f1f;
  --verde: #1db954;
  --amarillo: #f5a623;
  --azul: #2b7ed4;

  /* Semantic tokens (shared across layouts) */
  --st-bg: var(--negro);
  --st-surface: var(--gris-900);
  --st-surface-2: var(--gris-800);
  --st-surface-3: var(--gris-750);
  --st-text: var(--blanco);
  --st-muted: var(--gris-400);
}

:root:not([data-theme]),
:root[data-theme="dark"] {
  color-scheme: dark;

  /* Neutral palette (dark) */
  --negro: #0f0f0f;
  --gris-900: #141414;
  --gris-800: #1e1e1e;
  --gris-750: #242424;
  --gris-700: #2a2a2a;
  --gris-600: #363636;
  --gris-400: #808080;
  --gris-200: #c0c0c0;
  --blanco: #f0f0f0;

  --st-line-1: rgba(255, 255, 255, 0.08);
  --st-line-2: rgba(255, 255, 255, 0.05);
  --st-hover: rgba(255, 255, 255, 0.05);
  --st-focus-ring: rgba(212, 43, 43, 0.25);

  /* AdminLTE custom-theme.css tokens (dark) */
  --bg: #0b1220;
  --surface: #111827;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #60a5fa;
  --primary-700: #2563eb;
  --secondary: #93c5fd;
  --accent: #1e3a8a;
  --ring: rgba(37, 99, 235, 0.28);

  --sidebar: #0b1220;
  --sidebar2: #111827;
  --sidebar-text: rgba(255, 255, 255, 0.92);
  --sidebar-text-muted: rgba(255, 255, 255, 0.75);
  --navHover: rgba(255, 255, 255, 0.08);

  --topbar-bg: rgba(15, 23, 42, 0.72);
  --topbar-border: rgba(255, 255, 255, 0.08);

  --footer-bg: var(--sidebar);
  --footer-text: rgba(255, 255, 255, 0.75);
  --border-soft: rgba(255, 255, 255, 0.10);
  --shadow-color: rgba(0, 0, 0, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.60);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --surface-muted: rgba(255, 255, 255, 0.03);
}

:root[data-theme="light"] {
  color-scheme: light;

  /* Neutrals for custom (dashboard/casos/admin/reportes) pages */
  --negro: #f5f7fb;
  --gris-900: #ffffff;
  --gris-800: #ffffff;
  --gris-750: #f1f5f9;
  --gris-700: #e2e8f0;
  --gris-600: #cbd5e1;
  --gris-400: #475569;
  --gris-200: #1f2937;
  --blanco: #0f172a;

  --st-line-1: rgba(15, 23, 42, 0.12);
  --st-line-2: rgba(15, 23, 42, 0.08);
  --st-hover: rgba(15, 23, 42, 0.04);
  --st-focus-ring: rgba(37, 99, 235, 0.22);

  /* AdminLTE custom-theme.css tokens (light) */
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --primary-700: #1e40af;
  --secondary: #60a5fa;
  --accent: #1e3a8a;
  --ring: rgba(37, 99, 235, 0.28);

  --sidebar: #ffffff;
  --sidebar2: #f1f5f9;
  --sidebar-text: rgba(15, 23, 42, 0.92);
  --sidebar-text-muted: rgba(15, 23, 42, 0.70);
  --navHover: rgba(15, 23, 42, 0.06);

  --topbar-bg: rgba(255, 255, 255, 0.82);
  --topbar-border: rgba(15, 23, 42, 0.10);

  --footer-bg: #ffffff;
  --footer-text: rgba(15, 23, 42, 0.70);
  --border-soft: rgba(15, 23, 42, 0.10);
  --shadow-color: rgba(15, 23, 42, 0.10);
  --shadow-strong: rgba(15, 23, 42, 0.25);
  --border-subtle: rgba(15, 23, 42, 0.06);
  --surface-muted: rgba(245, 247, 251, 0.60);
}

/* Theme toggle button */
.st-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--st-line-1);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.st-theme-toggle:hover {
  background: var(--st-hover);
}

.st-theme-toggle:active {
  transform: translateY(1px);
}

.st-theme-toggle:focus-visible {
  outline: 3px solid var(--st-focus-ring);
  outline-offset: 2px;
}

.st-theme-toggle__icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.st-theme-toggle__icon::before {
  content: "☾";
  font-size: 16px;
}

:root[data-theme="light"] .st-theme-toggle__icon::before {
  content: "☀";
}

.st-theme-toggle__text {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Compact variant for topbars/navbars */
.st-theme-toggle--nav {
  padding: 6px 8px;
  border-color: var(--st-line-2);
}

.st-theme-toggle--nav .st-theme-toggle__text {
  display: none;
}

/* Sidebar / footer variant */
.st-theme-toggle--sidebar {
  width: 100%;
  justify-content: center;
  margin-top: 12px;
}

/* Bootstrap/AdminLTE navbar integration */
.nav-link.st-theme-toggle {
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--st-line-2);
  margin: 0 6px;
}

.nav-link.st-theme-toggle:hover {
  background: var(--st-hover);
}

/* Login placement */
.panel-login .st-theme-toggle--login {
  position: absolute;
  top: 18px;
  right: 18px;
}

/* Light theme border fixes for pages with hardcoded rgba(255,255,255,0.05) */
:root[data-theme="light"] .sidebar {
  border-right-color: var(--st-line-2) !important;
}

:root[data-theme="light"] .sidebar-logo {
  border-bottom-color: var(--st-line-2) !important;
}

:root[data-theme="light"] .sidebar-pie {
  border-top-color: var(--st-line-2) !important;
}

:root[data-theme="light"] .topbar {
  border-bottom-color: var(--st-line-2) !important;
}

:root[data-theme="light"] .panel,
:root[data-theme="light"] .kpi,
:root[data-theme="light"] .tabla-wrap,
:root[data-theme="light"] .seccion,
:root[data-theme="light"] .card,
:root[data-theme="light"] .deriv-card,
:root[data-theme="light"] .modal {
  border-color: var(--st-line-2) !important;
}

:root[data-theme="light"] .panel-header,
:root[data-theme="light"] .card-header,
:root[data-theme="light"] .modal-header {
  border-bottom-color: var(--st-line-2) !important;
}

:root[data-theme="light"] .modal-footer {
  border-top-color: var(--st-line-2) !important;
}

:root[data-theme="light"] input,
:root[data-theme="light"] select,
:root[data-theme="light"] textarea {
  border-color: rgba(15, 23, 42, 0.18) !important;
}

:root[data-theme="light"] .nav-item:hover,
:root[data-theme="light"] .btn-sec:hover,
:root[data-theme="light"] .btn-cancelar:hover,
:root[data-theme="light"] .btn-modal-sec:hover,
:root[data-theme="light"] .periodo-btn:hover {
  background: var(--st-hover) !important;
}

:root[data-theme="light"] .nav-item:hover {
  color: var(--blanco) !important;
}
