/* ============================================================
   DASHI — Sistema de diseño
   Tokens para tema claro/oscuro vía [data-theme] en <html>.
   Estética premium estilo Linear/Vercel: base neutra + 1 acento.
   ============================================================ */

/* ---------- Tema oscuro (default) ---------- */
:root,
[data-theme="dark"] {
  --bg:            #0a0b0f;
  --bg-grid:       rgba(255, 255, 255, 0.025);
  --surface:       rgba(22, 24, 31, 0.72);
  --surface-solid: #16181f;
  --surface-hover: #1c1f28;
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  --text:          #ecedef;
  --text-muted:    #8b909a;
  --text-faint:    #5a5f6a;

  --accent:        #6c7bff;   /* índigo */
  --accent-soft:   rgba(108, 123, 255, 0.14);
  --accent-2:      #38bdf8;   /* cyan */
  --positive:      #3fb950;
  --negative:      #f85149;
  --warning:       #d6a32b;

  --shadow:        0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);
  --glass-blur:    blur(14px);

  /* Tinta del logo: el azul marino de marca es invisible sobre fondo oscuro */
  --logo-ink:      #e9ecf8;

  /* Colores 3 y 4 para series de gráficos (1 y 2 son accent/accent-2) */
  --serie-3:       #c084fc;
  --serie-4:       #f472b6;
}

/* ---------- Tema claro ---------- */
[data-theme="light"] {
  --bg:            #f6f7f9;
  --bg-grid:       rgba(0, 0, 0, 0.025);
  --surface:       rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-hover: #fbfbfd;
  --border:        rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);

  --text:          #16181f;
  --text-muted:    #5f6671;
  --text-faint:    #9aa0ab;

  --accent:        #4f57e0;
  --accent-soft:   rgba(79, 87, 224, 0.10);
  --accent-2:      #0ea5e9;
  --positive:      #1a7f37;
  --negative:      #d1242f;
  --warning:       #9a6700;

  --shadow:        0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  --glass-blur:    blur(14px);

  --logo-ink:      #030A57;   /* azul marino de marca */

  --serie-3:       #9333ea;
  --serie-4:       #db2777;
}

/* ---------- Paletas de acento (seleccionables por tenant) ----------
   La paleta por defecto es índigo (los tokens de arriba). Cada cliente
   con estética propia ve sus colores: se setea data-palette en <html>. */
[data-palette="esmeralda"] {
  --accent:      #2ec98e;
  --accent-soft: rgba(46, 201, 142, 0.15);
  --accent-2:    #59b7f0;
  --serie-3:     #a3e635;
  --serie-4:     #2dd4bf;
}
[data-theme="light"][data-palette="esmeralda"] {
  --accent:      #0c9f6c;
  --accent-soft: rgba(12, 159, 108, 0.12);
  --accent-2:    #0284c7;
  --serie-3:     #65a30d;
  --serie-4:     #0d9488;
}
[data-palette="naranja"] {
  --accent:      #FD6A1F;
  --accent-soft: rgba(253, 106, 31, 0.16);
  --accent-2:    #f5b840;
  --serie-3:     #fb7185;
  --serie-4:     #a78bfa;
}
[data-theme="light"][data-palette="naranja"] {
  --accent:      #e85d10;
  --accent-soft: rgba(232, 93, 16, 0.12);
  --accent-2:    #c98a00;
  --serie-3:     #e11d48;
  --serie-4:     #7c3aed;
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background-color: var(--bg);
  /* Grilla sutil de puntos al estilo Vercel/Linear */
  background-image: radial-gradient(var(--bg-grid) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ---------- Tipografía utilitaria ---------- */
.mono { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }

/* ============================================================
   Toggle de tema (botón sol/luna)
   ============================================================ */
.theme-toggle, .icon-btn {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.theme-toggle:hover, .icon-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-hover); }
.theme-toggle svg, .icon-btn svg { width: 15px; height: 15px; }
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ============================================================
   Login
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}

.login-card {
  position: relative;
  width: 100%; max-width: 380px;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-topbar {
  position: fixed; top: 1.25rem; right: 1.25rem;
}

.brand {
  display: flex; align-items: center; gap: 0.6rem;
  margin-bottom: 0.4rem;
}
/* Isotipo sin fondo: la parte azul usa currentColor → se adapta al tema */
.brand-mark {
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--logo-ink);
}
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font-size: 1.45rem; font-weight: 750; letter-spacing: -0.02em; }
/* En el sidebar la marca es más compacta que en el login */
.sidebar .brand-mark { width: 30px; height: 30px; }
.sidebar .brand-name { font-size: 1.15rem; }

.brand-sub { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 2rem; }

.field { margin-top: 1.1rem; }
.field label {
  display: block; font-size: 0.78rem; color: var(--text-muted);
  margin-bottom: 0.4rem; font-weight: 500;
}
.field input {
  width: 100%; padding: 0.65rem 0.8rem;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text); font-size: 0.95rem;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input::placeholder { color: var(--text-faint); }

.btn-primary {
  margin-top: 1.6rem; width: 100%;
  padding: 0.72rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: 9px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: filter 0.18s, transform 0.05s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.form-error {
  margin-top: 1rem; font-size: 0.82rem; color: var(--negative);
  min-height: 1.2rem;
}

/* ============================================================
   Layout del dashboard
   ============================================================ */
.app { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: 208px; flex-shrink: 0;
  background: var(--surface-solid);
  border-right: 1px solid var(--border);
  padding: 1rem 0.8rem;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow: hidden;
  transition: width 0.28s ease, padding 0.28s ease, transform 0.28s ease;
}

/* Desktop: colapsar la barra para maximizar el espacio central.
   min-width:0 es necesario: los flex items tienen min-width:auto y no
   encogen por debajo de su contenido sin esto. */
.app.nav-collapsed .sidebar {
  width: 0; min-width: 0;
  padding-left: 0; padding-right: 0;
  border-right-color: transparent;
}

/* Backdrop del drawer (solo visible en mobile con la barra abierta) */
.backdrop { display: none; }
.sidebar .brand { padding: 0 0.35rem; margin-bottom: 1.4rem; }

.nav { display: flex; flex-direction: column; gap: 0.12rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 0.6rem; border-radius: 8px;
  color: var(--text-muted); font-size: 0.83rem; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 16px; height: 16px; opacity: 0.85; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-footer { margin-top: auto; }
.user-chip {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.5rem; border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-size: 0.78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.68rem; color: var(--text-faint); }

/* ---- Contenido ---- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.55rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
/* Título y subtítulo en una sola línea → barra más fina */
.topbar-title { display: flex; align-items: baseline; gap: 0.55rem; min-width: 0; }
.topbar-title h1 {
  font-size: 0.95rem; font-weight: 650; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-title p {
  font-size: 0.76rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-title p:not(:empty)::before { content: "·"; margin-right: 0.55rem; color: var(--text-faint); }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.3rem 0.7rem;
  border-radius: 8px; font-size: 0.78rem; cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}
.btn-ghost:hover { border-color: var(--negative); color: var(--negative); }

.main { padding: 1.15rem; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---- Filtros: período + segmentador ---- */
.filter-row {
  display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
#period-chips, #seg-chips { display: inline-flex; gap: 0.45rem; flex-wrap: wrap; }
.filter-sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 0.3rem; }
.chip {
  font: inherit; font-size: 0.76rem; font-weight: 500;
  padding: 0.26rem 0.75rem; border-radius: 999px;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---- Selector de paleta (sidebar) ---- */
.palette-row { display: flex; gap: 0.5rem; padding: 0.45rem 0.55rem; }
.palette-dot {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  transition: transform 0.15s, border-color 0.15s;
}
.palette-dot:hover { transform: scale(1.15); }
.palette-dot.active { border-color: var(--text); }
.pd-indigo    { background: #6c7bff; }
.pd-esmeralda { background: #2ec98e; }
.pd-naranja   { background: #FD6A1F; }

/* ---- Bento grid de KPIs ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.75rem; margin-bottom: 0.9rem;
}
.kpi-card {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}
.kpi-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.kpi-label { font-size: 0.73rem; color: var(--text-muted); font-weight: 500; }
.kpi-icon {
  width: 26px; height: 26px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  flex-shrink: 0;
}
.kpi-icon svg { width: 14px; height: 14px; }
.kpi-value {
  font-size: 1.45rem; font-weight: 720; letter-spacing: -0.02em; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi-foot { margin-top: 0.4rem; font-size: 0.7rem; color: var(--text-faint); display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.trend-up   { color: var(--positive); font-weight: 600; }
.trend-down { color: var(--negative); font-weight: 600; }

/* ---- Bento grid de gráficos ---- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0.75rem;
}
.panel {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1.05rem;
  box-shadow: var(--shadow);
}
.panel-wide  { grid-column: span 8; }
.panel-narrow { grid-column: span 4; }
.panel-full  { grid-column: span 12; }
@media (max-width: 900px) {
  .panel-wide, .panel-narrow, .panel-full { grid-column: span 12; }
}

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.3rem; }
.panel-title { font-size: 0.85rem; font-weight: 620; }
.panel-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.08rem; }
.panel-badge {
  font-size: 0.68rem; color: var(--text-muted);
  background: var(--surface-hover); border: 1px solid var(--border);
  padding: 0.16rem 0.5rem; border-radius: 999px;
}
/* Más espacio para los gráficos: el chrome se achicó, el canvas creció */
.chart { width: 100%; height: 300px; margin-top: 0.5rem; }
.chart-sm { height: 245px; }

/* ---- Estados ---- */
.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 5rem 2rem; color: var(--text-muted); gap: 0.6rem; text-align: center;
}
.state svg { width: 38px; height: 38px; opacity: 0.4; }

/* ============================================================
   Pantalla de carga: fondo desenfocado + logo + animación
   ============================================================ */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.25rem;
  background: rgba(10, 11, 15, 0.55);                 /* fallback */
  background: color-mix(in srgb, var(--bg) 58%, transparent);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.loader.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loader-card {
  position: relative; width: 108px; height: 108px;
  display: inline-flex; align-items: center; justify-content: center;
}
.loader-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
/* Logo solo, sin tile de fondo; azul de marca → currentColor según tema */
.loader-logo {
  width: 72px; height: 72px;
  color: var(--logo-ink);
  animation: logo-pulse 1.6s ease-in-out infinite;
}
.loader-text { font-size: 0.85rem; color: var(--text-muted); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes logo-pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%      { transform: scale(0.9);  opacity: 0.85; }
}

/* Mostrar/ocultar según estado de carga */
[hidden] { display: none !important; }

/* ============================================================
   Responsive — drawer en mobile + densidad adaptada
   ============================================================ */
@media (max-width: 768px) {
  /* La barra pasa a ser un drawer sobre el contenido, cerrado por defecto
     (sin depender de JS → no hay flash del menú abierto al cargar). */
  .sidebar,
  .app.nav-collapsed .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: 264px; min-width: 264px; height: 100vh;
    padding: 1.25rem 1rem;
    transform: translateX(-100%);
    border-right-color: var(--border);
    box-shadow: var(--shadow);
  }
  .app.nav-open .sidebar { transform: translateX(0); }

  /* Backdrop oscuro detrás del drawer abierto */
  .app.nav-open .backdrop {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(0,0,0,0.5);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  }

  .main { padding: 0.8rem; }
  .topbar { padding: 0.5rem 0.8rem; }
  .topbar-title h1 { font-size: 0.9rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .kpi-card { padding: 0.8rem 0.9rem; }
  .kpi-value { font-size: 1.3rem; }
  .chart { height: 250px; }
}

@media (max-width: 460px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar-title p { display: none; }               /* gana espacio el título */
}
