:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --border: #ede6da;
  --text: #241c14;
  --muted: #7a6f60;
  --accent: #b3690f;
  --accent-hover: #8f530a;
  --accent-system: #d97706;
  --accent-system-hover: #b3690f;
  --accent-system-soft: #fef3e2;
  --funnel-1: #fde3b8;
  --funnel-2: #fac36a;
  --funnel-3: #ee9d2b;
  --funnel-4: #b3690f;
  --funnel-lost: #b0b0bc;
  --overdue: #ffe2e2;
  --overdue-text: #a3231e;
  --today: #fff4d6;
  --today-text: #8a6300;
  --sidebar-bg: #ffffff;
  --sidebar-text: #7a6f60;
  --sidebar-text-active: #ffffff;
  --radius: 16px;
  --shadow-card: 0 1px 2px rgba(36,28,20,0.04), 0 8px 24px -14px rgba(36,28,20,0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --panel: #251e17;
    --border: #382c22;
    --text: #f2ece3;
    --muted: #a89a87;
    --accent-system-soft: #3a2a10;
    --funnel-1: #4a3315;
    --funnel-2: #7a5218;
    --funnel-3: #b3760f;
    --funnel-4: #f0a83a;
    --funnel-lost: #55555f;
    --overdue: #3a1f1f;
    --overdue-text: #ff8f8a;
    --today: #3a331a;
    --today-text: #ffd873;
    --sidebar-bg: #1e1712;
    --sidebar-text: #a89a87;
    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -14px rgba(0,0,0,0.5);
  }
}

* { box-sizing: border-box; }

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

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

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 24px;
  border-right: 1px solid var(--border);
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }

.brand-mark {
  width: 30px; height: 30px; border-radius: 10px; background: var(--accent);
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}

.brand-name { font-weight: 700; font-size: 16px; color: var(--text); }

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

.nav-item {
  display: flex; align-items: center; gap: 10px; background: none; border: none;
  border-left: 3px solid transparent;
  color: var(--sidebar-text); padding: 10px 12px; border-radius: 10px;
  font-size: 14px; cursor: pointer; text-align: left;
}

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

.nav-item:focus-visible { outline: 2px solid var(--accent-system); outline-offset: 2px; }

.nav-item.active {
  background: var(--accent-system-soft);
  border-left-color: var(--accent-system);
  color: var(--accent-system-hover);
  font-weight: 600;
}
.nav-icon { font-size: 14px; width: 16px; text-align: center; }

.sidebar-footer { display: flex; flex-direction: column; gap: 8px; }

.content { flex: 1; padding: 24px 32px 48px; min-width: 0; }

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.content-header h1 { font-size: 22px; margin: 0; }

/* ---- sub-páginas (una sección por grupo, se togglean desde el sidebar) ---- */

.page { display: flex; flex-direction: column; gap: 16px; }
.page.hidden { display: none; }

/* El gap de .page ya separa los bloques: sin esto sumaría doble espacio. */
.page > .stat-grid, .page > .panel-grid { margin-bottom: 0; }

.page-hint {
  margin: -4px 0 0;
  font-size: 13px;
  color: var(--muted);
  max-width: 70ch;
}

.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 9px 16px; border-radius: 12px; cursor: pointer; font-size: 14px; font-weight: 500;
  text-decoration: none; display: inline-block;
}

.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }

.sidebar .btn.ghost {
  background: transparent; border-color: var(--border); color: var(--sidebar-text);
  text-align: center;
}
.sidebar .btn.ghost:hover { background: var(--accent-system-soft); }

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

.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-card); }
.stat-card-featured { background: linear-gradient(160deg, var(--accent-system) 0%, var(--accent-system-hover) 100%); border-color: transparent; color: white; }
.stat-card-featured .stat-label { color: rgba(255,255,255,0.75); }
.stat-card-featured .stat-trend { color: rgba(255,255,255,0.9); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-trend { font-size: 12px; margin-top: 6px; color: var(--accent-system); }

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

.panel .panel-hint { font-size: 12.5px; color: var(--muted); margin-top: -4px; margin-bottom: 12px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-card); }
.panel h2 { font-size: 14px; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; gap: 10px; font-size: 13px; }
.funnel-stage-name { color: var(--muted); }
.funnel-bar-track { background: var(--bg); border-radius: 6px; overflow: hidden; height: 22px; }
.funnel-bar-fill {
  height: 100%; border-radius: 6px; display: flex; align-items: center; justify-content: flex-end;
  padding-right: 8px; color: white; font-size: 11px; font-weight: 600; min-width: 24px;
}
.funnel-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.line-chart-empty { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }
/* El panel del gráfico ahora ocupa el ancho completo de la página Resumen:
   sin tope, el SVG crecería proporcionalmente y quedaría altísimo. */
.line-chart svg { width: 100%; height: auto; max-height: 240px; display: block; }
.line-chart-path { fill: none; stroke: var(--accent-system); stroke-width: 2; }
.line-chart-area { fill: var(--accent-system-soft); stroke: none; }
.line-chart-dot { fill: var(--accent-system); }

.source-list { display: flex; flex-direction: column; gap: 10px; }

.source-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.source-name { width: 100px; flex-shrink: 0; color: var(--muted); }
.source-bar-track { flex: 1; background: var(--bg); border-radius: 6px; height: 10px; overflow: hidden; }
.source-bar-fill { height: 100%; background: var(--accent-system); border-radius: 6px; }
.source-value { width: 70px; text-align: right; font-weight: 600; }

.list { display: flex; flex-direction: column; gap: 6px; }
.list-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 14px; background: var(--bg);
}
.list-row.overdue { background: var(--overdue); color: var(--overdue-text); border-color: transparent; }
.list-empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.empty-state {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow-card);
}
.empty-state h2 { margin: 0 0 8px; font-size: 16px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; }
.empty-state a { color: var(--accent-system); }

.hidden { display: none !important; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .sidebar-footer { display: none; }
  .panel-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
