:root {
  --bg: #141210;
  --bg-panel: #1B1815;
  --bg-panel-2: #211D18;
  --gold: #C9A227;
  --gold-light: #E3C468;
  --cream: #F3EEE1;
  --muted: #948C7C;
  --line: #35312A;
  --font-display: 'Space Grotesk', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-display);
  min-height: 100vh;
  padding: 0 0 60px;
}
a { color: var(--gold-light); }

/* ---------- Header ---------- */
.header {
  position: relative;
  padding: 36px 40px 28px;
  border-bottom: 1px solid var(--line);
  background-image:
    repeating-linear-gradient(0deg, rgba(201,162,39,0.05) 0px, rgba(201,162,39,0.05) 1px, transparent 1px, transparent 32px),
    repeating-linear-gradient(90deg, rgba(201,162,39,0.05) 0px, rgba(201,162,39,0.05) 1px, transparent 1px, transparent 32px);
  overflow: hidden;
}
.eyebrow {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--gold); margin-bottom: 10px;
}
.header-brand { display: flex; align-items: center; gap: 22px; }
.header-logo { max-height: 52px; max-width: 320px; object-fit: contain; display: block; }
.logo-badge {
  width: 52px; height: 52px; border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #8a6d1f);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 19px; color: #1a1508; flex-shrink: 0;
  font-family: var(--font-display);
}
.header-divider { width: 1px; height: 44px; background: var(--line); }
.header-text { display: flex; flex-direction: column; }
.title {
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--cream);
}
.subtitle {
  margin-top: 6px;
  font-size: 14px;
  color: var(--muted);
}
.status-line {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(201,162,39,0.15);
}
.status-dot.error { background: #B5502E; box-shadow: 0 0 0 3px rgba(181,80,46,0.15); }
.reload-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: border-color .15s, color .15s;
}
.reload-btn:hover { border-color: var(--gold); color: var(--gold-light); }

/* ---------- Content shell ---------- */
.shell { max-width: 1240px; margin: 0 auto; padding: 0 40px; }

.demo-banner {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #1a1508;
  background: var(--gold);
  border-radius: 4px;
  padding: 8px 14px;
  display: inline-block;
  margin: 24px 0 0;
}
.demo-banner[hidden] { display: none; }

/* ---------- Loading / error ---------- */
.state-box {
  margin: 60px auto; max-width: 560px; text-align: center;
  padding: 40px 32px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-panel);
}
.state-box h3 { font-size: 17px; margin-bottom: 10px; color: var(--cream); }
.state-box p { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 6px; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 18px;
  border: 2px solid var(--line); border-top-color: var(--gold);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fallback-area {
  margin-top: 18px; text-align: left;
}
.fallback-area textarea {
  width: 100%; height: 100px; background: var(--bg); color: var(--cream);
  border: 1px solid var(--line); border-radius: 4px; padding: 10px;
  font-family: var(--font-mono); font-size: 11px; resize: vertical;
}
.btn {
  background: var(--gold); color: #141210; border: none;
  font-family: var(--font-display); font-weight: 600; font-size: 13px;
  padding: 9px 18px; border-radius: 4px; cursor: pointer; margin-top: 10px;
}
.btn:hover { background: var(--gold-light); }
.btn.ghost {
  background: none; color: var(--muted); border: 1px solid var(--line);
}
.btn.ghost:hover { color: var(--gold-light); border-color: var(--gold); }

/* ---------- Filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  padding: 24px 0; border-bottom: 1px solid var(--line);
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 160px; }
.date-range-group { display: flex; gap: 14px; flex-shrink: 0; }
.field label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
select, input[type="date"], input[type="text"] {
  background: var(--bg-panel); color: var(--cream);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 9px 10px; font-family: var(--font-display); font-size: 13px;
  min-width: 170px;
}
select:focus, input:focus {
  outline: 2px solid var(--gold-light); outline-offset: 1px; border-color: var(--gold);
}
.field-hint {
  font-family: var(--font-mono); font-size: 10px; color: #E3663E; min-height: 14px; display: block;
}
.clear-link {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  background: none; border: none; cursor: pointer; text-decoration: underline;
  padding-bottom: 10px;
}
.clear-link:hover { color: var(--gold-light); }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 28px 0; }
.budget-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 22px 22px 18px; position: relative;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 2px;
  background: var(--gold);
}
.stat-label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px;
}
.stat-value {
  font-family: var(--font-mono); font-weight: 600; font-size: clamp(26px, 3.4vw, 38px);
  color: var(--gold-light); letter-spacing: -0.01em; line-height: 1;
}
.stat-sub { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* ---------- Breakdown panels ---------- */
.breakdowns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; padding-bottom: 20px; }
.panel {
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 6px; padding: 26px;
}
.panel h4 {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 20px;
}
.empty-note { font-size: 12px; color: var(--muted); font-style: italic; }

/* ---------- Explorer panel (custom chart) ---------- */
.explorer-panel { margin-bottom: 28px; }
.explorer-controls {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 18px; margin-bottom: 22px;
}
.explorer-note { font-family: var(--font-mono); font-size: 11px; color: var(--muted); padding-bottom: 10px; }
.explorer-chart-box { width: 100%; height: 400px; position: relative; }
@media (max-width: 860px) {
  .explorer-chart-box { height: 320px; }
}
.tendencia-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin: 0 0 20px; padding-top: 24px; border-top: 1px solid var(--line);
}
.tendencia-titulo {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}

/* ---------- Pie chart panel ---------- */
.pie-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.pie-canvas-box { width: 230px; height: 230px; position: relative; }
.pie-center-label {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.pie-center-label .pcl-value { font-family: var(--font-mono); font-size: 22px; color: var(--gold-light); font-weight: 600; }
.pie-center-label .pcl-label { font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.pie-legend { width: 100%; }
.pie-legend-row {
  display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 6px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 4px;
}
.pie-legend-row:last-child { border-bottom: none; }
.pie-legend-row:hover { background: var(--bg-panel-2); }
.pie-legend-row:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 2px; }
.pie-legend-row.active .pl-label { color: var(--gold-light); }
.pl-swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.pl-label { flex: 1; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-amount { font-family: var(--font-mono); color: var(--muted); font-size: 11px; }
.pl-pct { font-family: var(--font-mono); color: var(--gold-light); font-size: 11px; width: 40px; text-align: right; }

/* ---------- Table ---------- */
.table-wrap {
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 6px;
  overflow: auto; max-height: 520px;
}
table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 720px; }
thead th {
  position: sticky; top: 0; background: var(--bg-panel-2);
  text-align: left; padding: 12px 14px; font-family: var(--font-mono);
  font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line); cursor: pointer;
  white-space: nowrap;
}
thead th:hover { color: var(--gold-light); }
thead th.sorted { color: var(--gold-light); }
tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--cream);
  white-space: nowrap;
}
tbody tr:hover { background: var(--bg-panel-2); }
tbody td.num { font-family: var(--font-mono); text-align: right; color: var(--gold-light); }
.table-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--line);
}
.section-title {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 4px 0 12px;
}
.footer-links {
  margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}
.footer-links a { color: var(--muted); text-decoration: underline; }
.footer-links a:hover { color: var(--gold-light); }

@media (max-width: 860px) {
  .header { padding: 28px 20px 22px; }
  .shell { padding: 0 20px; }
  .stats, .breakdowns, .budget-stats { grid-template-columns: 1fr; }
  .header-brand { gap: 14px; }
  .header-logo { max-height: 38px; }
  .logo-badge { width: 38px; height: 38px; }
  .header-divider { height: 34px; }
  .date-range-group { flex-wrap: wrap; }
}
