:root {
  color-scheme: light dark;
  --bg: #eef1f6;
  --card: #ffffff;
  --sidebar: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8eefd;
  --border: #e5e8ef;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114;
    --card: #1a1c21;
    --sidebar: #17181c;
    --text: #f0f0ee;
    --muted: #9a9ea7;
    --accent: #5b8cff;
    --accent-soft: #1e2a44;
    --border: #2b2d33;
  }
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar siempre, sin importar qué otra regla de display tenga
   el elemento (ej. .nav-item usa display:block, que si no fuera por esto le empataría
   en especificidad al hidden del navegador y lo dejaría sin efecto). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-logo { max-width: 130px; max-height: 40px; object-fit: contain; flex-shrink: 0; }
.brand-name { font-weight: 700; font-size: 0.95rem; line-height: 1.2; }
.brand-sub { font-size: 0.72rem; color: var(--muted); }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-group {
  margin: 14px 8px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.87rem;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover { background: var(--accent-soft); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  font-size: 0.75rem;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

/* ---------- Main / topbar ---------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.topbar h1 { font-size: 1.1rem; margin: 0; }

.content {
  padding: 24px 28px 60px;
  max-width: 1200px;
  width: 100%;
}

/* ---------- Cards / tables (shared) ---------- */

.tarjeta {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.tarjeta h2 { margin-top: 0; font-size: 1.05rem; }

.controles {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.controles label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, button {
  font-size: 0.9rem;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  padding: 8px 16px;
}

button:hover { opacity: 0.9; }

button.secundario {
  background: var(--card);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.controles label.checkbox { flex-direction: row; align-items: center; gap: 6px; }

.resumen { margin-bottom: 12px; font-size: 0.95rem; color: var(--muted); }
.resumen strong { color: var(--text); }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

th, td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.nota {
  white-space: pre-wrap;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 12px;
}

.nota-inline {
  font-size: 0.78rem;
  color: var(--muted);
}

.subtitulo-tabla {
  font-size: 0.95rem;
  margin: 24px 0 4px;
}

/* ---------- Inicio / KPIs ---------- */

.saludo { color: var(--muted); margin: 0 0 20px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}

.kpi-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 6px; }
.kpi-valor { font-size: 1.5rem; font-weight: 700; }
.kpi-sub { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

.cards-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.card-mitad { flex: 1; min-width: 320px; }

.lista-ranking { display: flex; flex-direction: column; gap: 12px; }

.ranking-fila { display: flex; flex-direction: column; gap: 4px; }

.ranking-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
}

.ranking-nombre { color: var(--text); }
.ranking-valor { color: var(--muted); }

.ranking-barra {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.ranking-barra-fill { height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- Responsive ---------- */

@media (max-width: 820px) {
  .app { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding: 14px;
  }

  .nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 4px; }
  .nav-group { display: none; }
  .nav-item { white-space: nowrap; }
  .sidebar-footer { display: none; }

  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
}
