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

:root {
  --blue:    #1a73e8;
  --blue-dk: #1557b0;
  --green:   #34a853;
  --red:     #ea4335;
  --yellow:  #fbbc04;
  --gray-50: #f8f9fa;
  --gray-100:#f1f3f4;
  --gray-200:#e8eaed;
  --gray-400:#bdc1c6;
  --gray-600:#80868b;
  --gray-900:#202124;
  --surface:  #ffffff;
  --radius:   8px;
  --shadow:   0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:0 2px 6px rgba(0,0,0,.15), 0 2px 4px rgba(0,0,0,.1);
  --font: 'Google Sans', 'Roboto', -apple-system, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  line-height: 1.5;
}

/* ── App bar ────────────────────────────────────────────────────────────────── */
.app-bar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 24px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.app-bar__icon { font-size: 20px; }
.app-bar__title { font-size: 18px; font-weight: 500; letter-spacing: .01em; }
.app-bar__subtitle { font-size: 12px; opacity: .8; margin-left: 4px; }
.app-bar__spacer { flex: 1; }
.app-bar__btn {
  background: rgba(255,255,255,.15);
  border: none; border-radius: 4px;
  color: #fff; font-size: 13px; padding: 6px 14px;
  cursor: pointer; transition: background .15s;
}
.app-bar__btn:hover { background: rgba(255,255,255,.25); }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - 56px);
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 280px; min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--gray-200);
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 20px;
  overflow-y: auto;
}
.sidebar__section-title {
  font-size: 11px; font-weight: 600;
  color: var(--gray-600); text-transform: uppercase;
  letter-spacing: .08em; margin-bottom: 8px;
}
.term-list {
  display: flex; flex-direction: column; gap: 6px;
}
.term-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius);
  cursor: pointer; transition: background .12s;
  user-select: none;
}
.term-chip:hover { background: var(--gray-100); }
.term-chip input[type="checkbox"] { accent-color: var(--blue); width: 15px; height: 15px; }
.term-chip__label { font-size: 13px; line-height: 1.3; }
.term-chip__badge {
  margin-left: auto;
  background: var(--gray-100); color: var(--gray-600);
  font-size: 11px; padding: 2px 7px; border-radius: 10px;
}
.term-chip.selected { background: #e8f0fe; }
.term-chip.selected .term-chip__label { color: var(--blue); font-weight: 500; }

.btn-primary {
  width: 100%; padding: 10px;
  background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover  { background: var(--blue-dk); }
.btn-primary:disabled { background: var(--gray-400); cursor: not-allowed; }

.btn-secondary {
  width: 100%; padding: 8px;
  background: transparent; color: var(--blue);
  border: 1px solid var(--blue); border-radius: var(--radius);
  font-size: 13px; cursor: pointer; transition: background .15s;
}
.btn-secondary:hover { background: #e8f0fe; }
.btn-secondary:disabled { color: var(--gray-400); border-color: var(--gray-400); cursor: not-allowed; }

.export-group {
  display: flex; flex-direction: column; gap: 6px;
}

.sidebar__divider {
  border: none; border-top: 1px solid var(--gray-200);
  margin: 4px 0;
}

/* ── Main content ───────────────────────────────────────────────────────────── */
.main {
  flex: 1; padding: 24px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 20px;
  min-width: 0;
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 420px; gap: 12px;
  color: var(--gray-600); text-align: center;
}
.empty-state__icon { font-size: 64px; opacity: .4; }
.empty-state__title { font-size: 18px; font-weight: 500; color: var(--gray-900); }
.empty-state__sub   { font-size: 13px; }

/* ── Spinner view ────────────────────────────────────────────────────────────── */
.spinner-view {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 440px; gap: 32px;
}
.spinner-ring {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 5px solid var(--gray-200);
  border-top-color: var(--blue);
  border-right-color: var(--blue);
  animation: spin 0.9s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.spinner-msg {
  font-size: 15px; font-weight: 500;
  color: var(--gray-600); text-align: center;
  max-width: 420px; line-height: 1.6;
  font-family: var(--font);
}

/* ── KPI Cards ──────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.kpi-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-card__label { font-size: 11px; color: var(--gray-600); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kpi-card__value { font-size: 28px; font-weight: 700; color: var(--gray-900); line-height: 1.1; }
.kpi-card__sub   { font-size: 12px; color: var(--gray-600); }
.kpi-card--green .kpi-card__value { color: var(--green); }
.kpi-card--red   .kpi-card__value { color: var(--red); }
.kpi-card--blue  .kpi-card__value { color: var(--blue); }

/* ── Charts grid ────────────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 280px 1fr 1fr;
  gap: 12px;
}
@media (max-width: 1100px) {
  .charts-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .charts-grid { grid-template-columns: 1fr; }
  .sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--gray-200); }
  .layout  { flex-direction: column; }
}

.chart-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.chart-card__title { font-size: 13px; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: .06em; }
.chart-card canvas { max-height: 240px; }

/* ── Data table ─────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.table-tabs {
  display: flex; border-bottom: 1px solid var(--gray-200);
  padding: 0 16px;
}
.tab-btn {
  background: none; border: none;
  padding: 14px 16px; font-size: 13px; font-weight: 500;
  color: var(--gray-600); cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn.active { color: var(--blue); border-color: var(--blue); }
.tab-btn:hover:not(.active) { color: var(--gray-900); }

.table-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--gray-200);
}
.search-input {
  flex: 1; padding: 7px 12px;
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  font-size: 13px; color: var(--gray-900);
  background: var(--gray-50); outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--blue); background: #fff; }

.table-wrap {
  overflow-x: auto; max-height: 420px; overflow-y: auto;
}
table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--gray-50); color: var(--gray-600);
  font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; padding: 10px 14px;
  border-bottom: 1px solid var(--gray-200);
  text-align: left; white-space: nowrap;
  cursor: pointer; user-select: none;
}
thead th:hover { background: var(--gray-100); }
thead th .sort-icon { margin-left: 4px; opacity: .4; }
thead th.sorted .sort-icon { opacity: 1; color: var(--blue); }

tbody tr { border-bottom: 1px solid var(--gray-200); transition: background .1s; }
tbody tr:hover { background: var(--gray-50); }
tbody td { padding: 9px 14px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.badge--green { background: #e6f4ea; color: #137333; }
.badge--red   { background: #fce8e6; color: #c5221f; }
.badge--gray  { background: var(--gray-100); color: var(--gray-600); }

.table-footer {
  padding: 10px 16px; font-size: 12px; color: var(--gray-600);
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: space-between; align-items: center;
}

/* ── Comparativa bimestral ──────────────────────────────────────────────────── */
.comparison-section {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
}
.comparison-title { font-size: 13px; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px; }

/* ── Utils ──────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.nota-value { font-weight: 600; }
.nota-value.alta  { color: var(--green); }
.nota-value.media { color: var(--yellow); }
.nota-value.baja  { color: var(--red); }

.loading-spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.cache-badge {
  background: #e6f4ea; color: #137333;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  font-weight: 600;
}
.cache-badge--json { background: #e8f0fe; color: #1a73e8; }
