/* ── Aplicar tema inmediatamente (evita flash) ── */
html[data-theme="dark"]  { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

/* ══════════════════════════════════════════
   CSS VARIABLES — Light / Dark
   Regla: Dark = invertir black↔white por nivel
   Black 100% → White 100% en dark
   Black 80%  → White 80%  en dark
   Black 40%  → White 40%  en dark  ... etc
══════════════════════════════════════════ */
:root {
  /* Backgrounds */
  --bg-page:        #f8f8fb;
  --bg-sidebar:     #f3f4f8;
  --bg-card:        #ffffff;
  --bg-stat:        #eef0f8;
  --bg-header:      rgba(255,255,255,0.85);
  --bg-right:       #f8f8fb;
  --bg-input:       #f3f4f6;
  --bg-nav-active:  #ffffff;
  --bg-nav-hover:   #ffffff;
  --bg-error:       #fb2c36;
  --bg-success:     #00bc7d;

  /* Borders */
  --border-main:    #e9eaf0;
  --border-input:   #e5e7eb;

  /* Text */
  --text-primary:   #111827;   /* black 100% */
  --text-secondary: #374151;   /* black 80%  */
  --text-muted:     #6b7280;   /* black 40%  */
  --text-faint:     #9ca3af;   /* black 20%  */
  --text-placeholder: #d1d5db; /* black 10%  */

  /* Nav */
  --nav-text:       #6b7280;
  --nav-section:    #9ca3af;

  /* Scrollbar */
  --scrollbar:      #d1d5db;

  /* Traffic bar bg */
  --bar-bg:         #e5e7eb;

  /* Theme icon */
  --theme-icon:     'sun';
}

html.dark {
  /* Backgrounds — invertidos: lo que era claro ahora es oscuro */
  --bg-page:        #0f1117;
  --bg-sidebar:     #161b27;
  --bg-card:        #1e2433;
  --bg-stat:        #1a2035;
  --bg-header:      rgba(22,27,39,0.9);
  --bg-right:       #161b27;
  --bg-input:       #252d3d;
  --bg-nav-active:  #252d3d;
  --bg-nav-hover:   #252d3d;
  --bg-error:       #fb2c36;
  --bg-success:     #00bc7d;

  /* Borders */
  --border-main:    #2a3349;
  --border-input:   #2a3349;

  /* Text — invertidos: black→white por nivel de opacidad */
  --text-primary:   #f9fafb;   /* white 100% */
  --text-secondary: #e5e7eb;   /* white 80%  */
  --text-muted:     #9ca3af;   /* white 40%  */
  --text-faint:     #6b7280;   /* white 20%  */
  --text-placeholder: #4b5563; /* white 10%  */

  /* Nav */
  --nav-text:       #9ca3af;
  --nav-section:    #4b5563;

  /* Scrollbar */
  --scrollbar:      #2a3349;

  /* Traffic bar bg */
  --bar-bg:         #2a3349;
}

/* ── Base ── */
* { box-sizing: border-box; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  transition: background 0.3s, color 0.3s;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 200px; flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
  transition: transform .3s ease, background .3s;
  z-index: 40;
  border-right: 1px solid var(--border-main);
  height: 100vh;
  position: sticky;
  top: 0;
}
@media (max-width: 1023px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
}

/* ── Theme logos ── */
[data-theme="light"] .logo-dark  { display: none; animation: fade-out 0.3s; }
[data-theme="dark"]  .logo-light { display: none; animation: fade-out 0.3s; }

/* ── Right panel ── */
.right-panel {
  width: 230px; flex-shrink: 0;
  background: var(--bg-right);
  border-left: 1px solid var(--border-main);
  overflow: hidden;
  transition: background .3s, width .38s cubic-bezier(.4,0,.2,1), border-color .38s ease, scrollbar-color 0.3s;
}
.right-panel-inner {
  width: 230px;
  min-width: 230px;
  padding: 20px 14px;
  height: 100%;
  overflow-y: auto;
}
.right-panel.is-collapsed {
  width: 0;
  border-left-color: transparent;
}
@media (max-width: 1279px) { .right-panel { display: none; } }

/* Expand button — only shown on xl+ when panel is collapsed */
#btn-expand-panel { display: none; }
@media (min-width: 1280px) {
  #btn-expand-panel.rp-show { display: flex; }
}

/* ── Skeleton loader ── */
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-field) 25%, var(--border-main) 50%, var(--bg-field) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
  border-radius: 8px;
}

/* ── Nav items ── */
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 8px;
  font-size: 13px; color: var(--nav-text);
  cursor: pointer; white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-nav-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-nav-active); color: var(--text-primary); font-weight: 500; }
.nav-section { color: var(--nav-section); }

/* ── Cards ── */
.stat-card {
  background: var(--bg-stat);
  border-radius: 14px; padding: 18px 20px;
  transition: transform 0.2s, box-shadow 0.2s, background .3s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79,70,229,0.12);
}
.chart-card {
  background: var(--bg-card);
  border-radius: 14px; padding: 18px 20px;
  transition: background .3s;
  width: 100%;
  min-width: 0; /* Permite que el contenedor se encoja */
}

/* Chart canvas responsiveness */
.chart-card canvas {
  max-width: 100% !important;
  height: auto !important;
}

/* Chart container */
.chart-card > div[style*="height"] {
  width: 100% !important;
  max-width: 100% !important;
}

/* ── Buttons ── */
.btn-primary {
  background: #4f46e5; color: white;
  font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 8px;
  border: none; cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s;
}
.btn-primary:hover { background: #4338ca; }

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border-input);
  color: var(--text-muted);
  font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 8px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s;
}
.btn-secondary:hover { opacity: 0.8; }

.btn-warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 8px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-warning:hover { background: #fde68a; border-color: #d97706; }

html.dark .btn-warning {
  background: #382413;
  border: 1px solid #845025;
  color: #ea580c;
}
html.dark .btn-warning:hover { background: #4a2f1a; border-color: #845025; }

.btn-danger {
  background: #fee2e2;
  border: 1px solid #ef4444;
  color: #991b1b;
  font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 8px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-danger:hover { background: #fecaca; border-color: #dc2626; }

html.dark .btn-danger {
  background: #3b0b0b;
  border: 1px solid #8b2a2a;
  color: #dc2626;
}
html.dark .btn-danger:hover { background: #501a1a; border-color: #8b2a2a; }

/* ── Form ── */
.form-input {
  width: 100%;
  border: 1px solid var(--border-input);
  border-radius: 8px; padding: 8px 12px;
  font-size: 13px; color: var(--text-primary);
  background: var(--bg-card);
  outline: none; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background .3s;
}
.form-input:focus {
  border-color: #a5b4fc;
  box-shadow: 0 0 0 3px rgba(165,180,252,0.2);
}
.form-label {
  display: block; font-size: 11px;
  font-weight: 500; color: var(--text-muted); margin-bottom: 4px;
}

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 11px; font-weight: 500; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-blue   { background: #e0e7ff; color: #3730a3; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-gray   { background: var(--bg-input); color: var(--text-muted); }
html.dark .badge-green  { background: #064e3b; color: #6ee7b7; }
html.dark .badge-blue   { background: #1e1b4b; color: #a5b4fc; }
html.dark .badge-orange { background: #431407; color: #fdba74; }

/* ── Traffic bars ── */
.t-bar-bg { background: var(--bar-bg); border-radius: 99px; height: 5px; flex: 1; min-width: 0; }
.t-bar     { height: 5px; border-radius: 99px; }

/* ── Header ── */
.app-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-main);
  backdrop-filter: blur(8px);
  transition: background .3s, border-color .3s;
}

/* ── Search bar ── */
.search-bar {
  background: var(--bg-input);
  border-radius: 10px; padding: 6px 12px;
  display: flex; align-items: center; gap: 8px; width: 160px;
}
.search-bar input {
  background: transparent; outline: none;
  font-size: 12px; color: var(--text-primary);
  width: 100%; border: none; font-family: inherit;
}
.search-bar kbd {
  font-size: 11px; background: var(--bg-card);
  border: 1px solid var(--border-input);
  border-radius: 4px; padding: 1px 5px;
  color: var(--text-faint); flex-shrink: 0;
}

/* ── Theme toggle button ── */
#theme-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); padding: 4px;
  border-radius: 8px; transition: color 0.15s, background 0.15s;
  display: flex; align-items: center; justify-content: center;
}
#theme-toggle:hover { color: var(--text-primary); background: var(--bg-input); }

/* ── Overlay ── */
#overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
#overlay.show { display: block; }

/* ── Scrollbar: visible only while scrolling / on hover ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: transparent; border-radius: 4px; transition: background 0.3s; }

/* Show on hover */
.sidebar:hover::-webkit-scrollbar-thumb,
.right-panel:hover::-webkit-scrollbar-thumb,
main:hover::-webkit-scrollbar-thumb { background: var(--scrollbar); }

/* Show while actively scrolling (class added by JS) */
.sidebar.is-scrolling::-webkit-scrollbar-thumb,
.right-panel.is-scrolling::-webkit-scrollbar-thumb,
main.is-scrolling::-webkit-scrollbar-thumb { background: var(--scrollbar); }

/* Firefox */
.sidebar, main {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s;
}
.right-panel {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.sidebar:hover, .right-panel:hover, main:hover,
.sidebar.is-scrolling, .right-panel.is-scrolling, main.is-scrolling {
  scrollbar-color: var(--scrollbar) transparent;
}

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp .4s ease both; }
.fade-up:nth-child(1) { animation-delay: .05s }
.fade-up:nth-child(2) { animation-delay: .12s }
.fade-up:nth-child(3) { animation-delay: .19s }
.fade-up:nth-child(4) { animation-delay: .26s }

/* ── Responsive grids ── */
.stats-grid  { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }
.charts-row1 { display: grid; grid-template-columns: 1fr minmax(240px, 260px); gap: 14px; }
.charts-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width:1023px) {
  .stats-grid  { grid-template-columns: repeat(2,1fr); }
  .charts-row1 { grid-template-columns: 1fr; }
}
@media (max-width:767px)  { .charts-row2 { grid-template-columns: 1fr; } }
@media (max-width:479px)  { .stats-grid  { grid-template-columns: 1fr; } }

/* ══════════════════════════════════════════
   LANG TOGGLE BUTTON
   Presionado (lang-active) = EN
   No presionado            = ES
══════════════════════════════════════════ */
#lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--border-input);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  transition: background 0.18s, color 0.18s, border-color 0.18s, box-shadow 0.18s, transform 0.1s;
  user-select: none;
  position: relative;
  overflow: hidden;
}

/* Indicador de idioma — dos labels superpuestos */
#lang-toggle .lang-label-es,
#lang-toggle .lang-label-en {
  transition: opacity 0.2s, transform 0.2s;
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
#lang-toggle .lang-label-en { opacity: 0; transform: translate(-50%, 6px); }
#lang-toggle .lang-placeholder { visibility: hidden; }

/* Estado: EN activo */
#lang-toggle.lang-active {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(79,70,229,0.35);
}
#lang-toggle.lang-active .lang-label-es {
  opacity: 0;
  transform: translate(-50%, -6px);
}
#lang-toggle.lang-active .lang-label-en {
  opacity: 1;
  transform: translate(-50%, -50%);
}

/* Pressed animation */
#lang-toggle:active { transform: scale(0.94); }
#lang-toggle:hover:not(.lang-active) {
  border-color: #818cf8;
  color: var(--text-primary);
  background: var(--bg-input);
}

/* Dark mode */
html.dark #lang-toggle.lang-active {
  background: #4f46e5;
  border-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99,102,241,0.4);
}

/* ── Right Panel Promo Cards ── */
.rp-promo-card {
  border-radius: 12px;
  padding: 12px;
  background: var(--bg-field);
  border: 1px solid var(--border-main);
}

.rp-promo-card.current {
  --tw-ring-shadow: var(--tw-ring-inset, ) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
  box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
}

.rp-promo-card.multiple {
  margin-bottom: 8px;
}

.rp-promo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rp-promo-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-promo-stats {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.rp-promo-stat-icon {
  width: 12px;
  height: 12px;
  display: inline-block;
}

.rp-promo-stat-icon.emerald {
  color: #10b981;
}

.rp-promo-url-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-main);
}

.rp-promo-url {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  text-decoration: none;
}

.rp-promo-url:hover {
  text-decoration: underline;
}

.rp-promo-no-url {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  font-style: italic;
}

.rp-promo-single-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rp-promo-single-url-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-main);
}

/* ── Right Panel Activity ── */
.rp-activity-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.rp-activity-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.rp-activity-icon-wrapper {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.rp-activity-icon-wrapper.winner {
  background: #d1fae5;
}

.rp-activity-icon-wrapper.no-winner {
  background: #f1f5f9;
}

html.dark .rp-activity-icon-wrapper.winner {
  background: rgba(16, 185, 129, 0.2);
}

html.dark .rp-activity-icon-wrapper.no-winner {
  background: rgba(71, 85, 105, 0.4);
}

.rp-activity-icon {
  width: 12px;
  height: 12px;
}

.rp-activity-icon.winner {
  color: #059669;
}

.rp-activity-icon.no-winner {
  color: #94a3b8;
}

html.dark .rp-activity-icon.winner {
  color: #34d399;
}

html.dark .rp-activity-icon.no-winner {
  color: #94a3b8;
}

.rp-activity-content {
  min-width: 0;
}

.rp-activity-participant {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-activity-description {
  font-size: 12px;
  color: var(--text-faint);
}

/* ── Footer ── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 32px;
  padding: 14px 0;
  border-top: 1px solid var(--border-main);
  font-size: 11px;
  color: var(--text-faint);
  transition: border-color .3s, color .3s;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.footer-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  opacity: 0.6;
}

.footer-brand {
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
}

.footer-sep {
  color: var(--text-placeholder);
}

.footer-copy {
  color: var(--text-faint);
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.footer-link {
  color: var(--text-faint);
  text-decoration: none;
  transition: color .2s;
}

.footer-link:hover {
  color: var(--text-muted);
}

.footer-version {
  font-family: 'Sora', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-placeholder);
  background: var(--bg-input);
  border: 1px solid var(--border-main);
  border-radius: 4px;
  padding: 1px 6px;
}

