/* ── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

body { font-family: 'Inter', system-ui, -apple-system, sans-serif; }

/* ── Month cross-filter badge ────────────────────────────────────────────── */
.month-filter-badge.hidden { display: none !important; }
.month-filter-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #93c5fd;
  background: #1e3a5f;
  border: 1px solid #2563eb55;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  animation: badgePop 0.15s ease-out;
}
.month-filter-badge button {
  background: none;
  border: none;
  cursor: pointer;
  color: #60a5fa;
  font-size: 0.65rem;
  line-height: 1;
  padding: 0;
  transition: color 0.15s;
}
.month-filter-badge button:hover { color: #fff; }
@keyframes badgePop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ── Table tabs: reduce top gap vs tab bar ────────────────────────────────── */
#tab-pyg-table,
#tab-comparative-table {
  margin-top: -0.75rem;
}

/* ── Tab navigation ───────────────────────────────────────────────────────── */
#tabs-nav {
  border-right: none;
}
.tab-nav-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tab-nav-scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.tab-btn {
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.65rem 1.1rem;
  border: none;
  border-bottom: 2px solid transparent;
  color: #6b7280;
  background: transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: #d1d5db; }
.tab-btn.active { color: #10b981; border-bottom-color: #10b981; }

/* ── Filter selects ───────────────────────────────────────────────────────── */
.filter-select {
  background: #1f2937;
  border: 1px solid #374151;
  color: #e5e7eb;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.5rem;
  outline: none;
  transition: border-color 0.2s;
}
.filter-select:focus { border-color: #6b7280; }

/* ── Month picker input ───────────────────────────────────────────────────── */
.filter-month {
  cursor: pointer;
  min-width: 7rem;
}

/* ── Flatpickr dark theme overrides ──────────────────────────────────────── */
.flatpickr-calendar {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 0.75rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  font-family: 'Inter', system-ui, sans-serif;
}
.flatpickr-calendar.arrowTop::before,
.flatpickr-calendar.arrowTop::after { border-bottom-color: #374151; }
.flatpickr-months { background: #111827; border-radius: 0.75rem 0.75rem 0 0; }
.flatpickr-months .flatpickr-month { color: #e5e7eb; fill: #e5e7eb; }
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month { color: #9ca3af; fill: #9ca3af; }
.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover { color: #fff; fill: #fff; }
.flatpickr-current-month input.cur-year { color: #e5e7eb; }
.flatpickr-current-month .flatpickr-monthDropdown-months {
  background: #1f2937; color: #e5e7eb;
}
/* monthSelect plugin cells */
.flatpickr-monthSelect-months { padding: 0.5rem; }
.flatpickr-monthSelect-month {
  color: #9ca3af;
  border-radius: 0.4rem;
  padding: 0.4rem 0.1rem;
  transition: background 0.12s, color 0.12s;
}
.flatpickr-monthSelect-month:hover { background: #374151; color: #f9fafb; }
.flatpickr-monthSelect-month.selected,
.flatpickr-monthSelect-month.startRange,
.flatpickr-monthSelect-month.endRange {
  background: #1d4ed8;
  color: #fff;
}
.flatpickr-monthSelect-month.disabled { color: #4b5563; opacity: 0.5; }
.numInputWrapper span { border-color: #374151; }
.numInputWrapper span:hover { background: #374151; }

/* ── Quick filter buttons ─────────────────────────────────────────────────── */
.quick-btn {
  font-size: 0.75rem;
  padding: 0.3rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #374151;
  color: #9ca3af;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.quick-btn:hover, .quick-btn.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

/* ── KPI Cards ────────────────────────────────────────────────────────────── */
.kpi-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 0.75rem;
  padding: 1.25rem;
  transition: border-color 0.2s;
}
.kpi-card:hover { border-color: #374151; }
.kpi-label {
  font-size: 0.7rem;
  color: #6b7280;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}
.kpi-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f9fafb;
  font-variant-numeric: tabular-nums;
}
.kpi-prev {
  font-size: 0.72rem;
  margin-top: 0.25rem;
  color: #e5e7eb;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.kpi-delta {
  font-size: 0.72rem;
  margin-top: 0.2rem;
  font-weight: 500;
}
.kpi-delta.positive { color: #10b981; }
.kpi-delta.negative { color: #ef4444; }
.kpi-delta.neutral  { color: #6b7280; }

/* ── Chart cards ──────────────────────────────────────────────────────────── */
.chart-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 0.75rem;
  padding: 1.5rem;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e5e7eb;
}
.chart-canvas {
  max-height: 280px;
}
#chart-waterfall {
  max-height: 340px;
}
.chart-toggle {
  font-size: 0.72rem;
  padding: 0.25rem 0.65rem;
  border-radius: 0.4rem;
  border: 1px solid #374151;
  color: #9ca3af;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.chart-toggle.active, .chart-toggle:hover {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #93c5fd;
}

/* ── P&G Table ─────────────────────────────────────────────────────────────── */
#pyg-table th {
  font-size: 0.72rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid #1f2937;
  white-space: nowrap;
}
#pyg-table th.text-left { text-align: left; }

#pyg-table thead tr.pyg-month-row th {
  border-bottom: 1px solid #243247;
}

/* Sub-header row (€ / % labels shown when subinterval is active) */
#pyg-table thead tr.pyg-sub-row th {
  font-size: 0.62rem;
  font-weight: 500;
  color: #6b7280;
  text-transform: none;
  letter-spacing: 0;
  border-bottom: 1px solid #243247;
  padding-top: 0.1rem;
  padding-bottom: 0.3rem;
  text-align: right;
  padding-right: 0.75rem; /* match td padding */
}
#pyg-table thead tr.pyg-sub-row th.is-pct {
  color: #4b5563;
  padding-left: 0.25rem;
  padding-right: 0.75rem;
}

/* Percentage companion cells in table rows */
#pyg-table td.td-pct-col {
  color: #e5e7eb;
  font-size: 0.7rem;
  font-weight: 400;
  padding-left: 0.25rem;
  padding-right: 0.75rem;
  border-left: none;
}
#pyg-table thead tr.pyg-year-row th {
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 0.68rem;
  color: #9ca3af;
  text-align: center;
  padding-top: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: none;
  position: relative;
}
#pyg-table thead tr.pyg-year-row th:not(:first-child)::after {
  content: '';
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 0.1rem;
  height: 2px;
  border-radius: 999px;
  background: #334155;
}

#pyg-table td {
  padding: 0.55rem 0.75rem;
  text-align: right;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid #111827;
  color: #d1d5db;
}
#pyg-table td:first-child {
  text-align: left;
  color: #e5e7eb;
  font-weight: 500;
}
#pyg-table tr.subtotal td {
  background: #1a2535;
  font-weight: 700;
  color: #f9fafb;
  border-top: 1px solid #2d4060;
  border-bottom: 1px solid #2d4060;
}
#pyg-table tr.total td {
  background: #1e3a5f;
  font-weight: 800;
  color: #fff;
  font-size: 0.88rem;
}
#pyg-table tr:hover td { background: #1c2537; }
#pyg-table tr.subtotal:hover td, #pyg-table tr.total:hover td { filter: brightness(1.1); }

/* Subtle separator between top-level categories */
#pyg-table tbody tr.cat-header:not(:first-of-type) td {
  box-shadow: inset 0 1px 0 #2d4060;
}

.value-positive { color: #10b981 !important; }
.value-negative { color: #ef4444 !important; }

/* ── Table column filter ────────────────────────────────────────────────────── */
#pyg-table th.th-col-clickable {
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#pyg-table th.th-col-clickable:hover {
  color: #e5e7eb;
  background: #1f2937;
}
#pyg-table th.th-col-pending {
  color: #fbbf24 !important;
  background: #2d1e0420 !important;
  box-shadow: inset 0 -2px 0 #f59e0b;
}
#pyg-table th.th-col-from {
  color: #34d399 !important;
  background: #05260f22 !important;
  box-shadow: inset 0 -2px 0 #10b981;
}
#pyg-table th.th-col-to {
  color: #34d399 !important;
  background: #05260f22 !important;
  box-shadow: inset 0 -2px 0 #10b981;
}
#pyg-table th.th-col-range {
  color: #6ee7b7 !important;
  background: #05260f14 !important;
  box-shadow: inset 0 -2px 0 #10b98144;
}

/* ── Comparative Table ────────────────────────────────────────────────────── */
#comparative-table {
  border-collapse: separate;
  border-spacing: 0;
}

.comp-month-selector {
  --comp-cell-w: 3.15rem;
  --comp-cell-h: 1.7rem;
  --comp-month-font: 0.66rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 0.6rem;
  margin-top: -0.15rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.comp-month-selector::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.comp-month-track {
  width: max-content;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto;
  row-gap: 0.28rem;
}
.comp-month-years,
.comp-month-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--comp-cell-w);
  gap: 0.35rem;
  width: max-content;
}
.comp-month-year {
  position: relative;
  text-align: center;
  font-size: 0.62rem;
  color: #9ca3af;
  letter-spacing: 0.02em;
  padding-bottom: 0.22rem;
}
.comp-month-year::after {
  content: '';
  position: absolute;
  left: 0.35rem;
  right: 0.35rem;
  bottom: 0;
  height: 2px;
  border-radius: 999px;
  background: #334155;
}
.comp-month-btn {
  width: var(--comp-cell-w);
  height: var(--comp-cell-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--comp-month-font);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #9ca3af;
  background: transparent;
  border: 1px solid #374151;
  border-radius: 0.4rem;
  padding: 0;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.comp-month-btn:hover {
  color: #e5e7eb;
  background: #1f2937;
}
.comp-month-btn.is-pending {
  color: #fbbf24;
  background: #2d1e0420;
  border-color: #f59e0b66;
}
.comp-month-btn.is-single,
.comp-month-btn.is-from,
.comp-month-btn.is-to {
  color: #34d399;
  background: #05260f22;
  border-color: #10b98188;
}
.comp-month-btn.is-range {
  color: #6ee7b7;
  background: #05260f14;
  border-color: #10b98144;
}

.comp-head-row { background: #0f1f35; }

.comp-th {
  font-size: 0.72rem;
  font-weight: 600;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  text-align: right;
  border-bottom: 2px solid #1e3a5f;
  white-space: nowrap;
  background: #0f1f35;
}
.comp-th.comp-th-label { text-align: left; }

.comp-row { transition: background 0.12s; }
.comp-row:hover .comp-td { background: #1c2537; }

.comp-td {
  padding: 0.7rem 1rem;
  text-align: right;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid #1a2535;
  color: #d1d5db;
}
.comp-td.comp-td-label {
  text-align: left;
  font-weight: 700;
  color: #f9fafb;
  font-size: 0.87rem;
  letter-spacing: 0.01em;
}

.comp-dev-pos {
  color: #10b981;
  font-weight: 600;
}
.comp-dev-neg {
  color: #ef4444;
  font-weight: 600;
}

/* Comparative table — mirror pyg-table visual hierarchy */
#comparative-table tr.subtotal .comp-td {
  background: #1a2535;
  font-weight: 700;
  border-top: 1px solid #2d4060;
  border-bottom: 1px solid #2d4060;
}
#comparative-table tr.subtotal .comp-td-label { color: #f9fafb; }
#comparative-table tr.total .comp-td {
  background: #1e3a5f;
  font-weight: 800;
  font-size: 0.88rem;
}
#comparative-table tr.total .comp-td-label { color: #fff; }
#comparative-table tr.subtotal:hover .comp-td,
#comparative-table tr.total:hover .comp-td { filter: brightness(1.1); }
#comparative-table tbody tr.comp-row-cat .comp-td {
  border-top: 1px solid #243247;
}
#comparative-table tbody tr.comp-row-cat:first-of-type .comp-td {
  border-top-color: transparent;
}
#comparative-table tr.comp-row-cat .comp-td-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  padding-top: 0.75rem;
}
.comp-cat-label {
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.comp-cat-chevron {
  font-size: 0.6rem; color: #6b7280;
}
.comp-color-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0;
}
.comp-td-dash { color: #f9fafb; }
#comparative-table tr.comp-row-subcat .comp-td {
  font-size: 0.78rem;
  border-bottom: 1px solid #111827;
}
.comp-td-subcat {
  padding-left: 2rem !important;
  text-align: left;
  color: #d1d5db;
}

/* ── Amortization section inside Config Modal ────────────────────────────── */
.da-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.da-accounts-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.da-account {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 0.5rem;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.da-account-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.da-account-name {
  flex: 1;
  background: #1f2937;
  border: 1px solid #374151;
  color: #e5e7eb;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: 0.375rem;
  outline: none;
  transition: border-color 0.15s;
}
.da-account-name:focus { border-color: #8b5cf6; }
.da-intervals {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.da-interval-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.da-interval-label {
  font-size: 0.7rem;
  color: #9ca3af;
  white-space: nowrap;
  min-width: 2.5rem;
}
.da-sel {
  background: #1f2937;
  border: 1px solid #374151;
  color: #d1d5db;
  font-size: 0.72rem;
  padding: 0.25rem 0.35rem;
  border-radius: 0.375rem;
  outline: none;
  cursor: pointer;
}
.da-sel:focus { border-color: #8b5cf6; }
.da-inp {
  background: #1f2937;
  border: 1px solid #374151;
  color: #d1d5db;
  font-size: 0.72rem;
  padding: 0.25rem 0.4rem;
  border-radius: 0.375rem;
  outline: none;
  width: 5rem;
  text-align: center;
}
.da-inp.da-year-from,
.da-inp.da-year-to { width: 4.2rem; }
.da-inp.da-balance { width: 7rem; text-align: right; }
.da-inp:focus { border-color: #8b5cf6; }
.da-balance-sign {
  font-size: 0.85rem;
  color: #ef4444;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
  margin-right: -0.1rem;
}
.da-sinfin-wrap {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
  user-select: none;
}
.da-sinfin-wrap input[type="checkbox"] {
  accent-color: #8b5cf6;
  width: 13px;
  height: 13px;
  cursor: pointer;
}
.da-sinfin-text {
  font-size: 0.95rem;
  color: #8b5cf6;
  line-height: 1;
}
.da-btn-icon {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.35rem;
  border-radius: 0.25rem;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.da-btn-icon:hover { color: #ef4444; background: #1f2937; }
.da-account-delete { margin-left: auto; flex-shrink: 0; }
.da-interval-invalid .da-interval-row,
.da-interval-overlap .da-interval-row {
  background: #3f1515;
  border: 1px solid #ef444466;
  border-radius: 0.375rem;
  padding: 0.15rem 0.35rem;
}
.da-interval-invalid .da-interval-row::after {
  content: 'Intervalo inválido: fin anterior al inicio';
  color: #f87171;
  font-size: 0.65rem;
  margin-left: 0.4rem;
  white-space: nowrap;
}
.da-interval-overlap .da-interval-row::after {
  content: 'Intervalo solapado con otro';
  color: #f87171;
  font-size: 0.65rem;
  margin-left: 0.4rem;
  white-space: nowrap;
}
.da-add-interval {
  align-self: flex-start;
  background: none;
  border: 1px dashed #374151;
  color: #8b5cf6;
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.da-add-interval:hover { border-color: #8b5cf6; color: #a78bfa; }
.da-add-account {
  align-self: flex-start;
  background: none;
  border: 1px dashed #8b5cf6;
  color: #8b5cf6;
  font-size: 0.75rem;
  padding: 0.3rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-top: 0.25rem;
}
.da-add-account:hover { background: #8b5cf620; color: #a78bfa; }

/* ── Config Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10100;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
#loading-overlay.hidden { display: none; }
.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid #374151;
  border-top-color: #10b981;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.modal-box {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 1rem;
  padding: 2rem;
  width: 100%;
  max-width: 780px;
  max-height: 85vh;
  overflow-y: auto;
}

.config-category {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
}
.config-category-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}
.account-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 2rem;
}
.account-chip {
  font-size: 0.72rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: #374151;
  color: #d1d5db;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.account-chip:hover { background: #4b5563; color: #fff; }
.account-chip.assigned { background: #065f46; color: #a7f3d0; }

/* ── Sub-category config sections ────────────────────────────────────────── */
.config-subcategory {
  border: 1px solid #374151;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
}
.config-subcategory-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.subcat-order-btns {
  display: flex;
  gap: 2px;
  margin-left: auto;
}
.btn-subcat-up, .btn-subcat-down, .btn-subcat-delete {
  background: none;
  border: 1px solid #374151;
  border-radius: 0.25rem;
  color: #6b7280;
  font-size: 0.55rem;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
  line-height: 1;
}
.btn-subcat-up:hover, .btn-subcat-down:hover { color: #e5e7eb; border-color: #6b7280; }
.btn-subcat-delete { color: #6b7280; }
.btn-subcat-delete:hover { color: #f87171; border-color: #f87171; }
.subcat-label-input {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 0.35rem;
  color: #e5e7eb;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  outline: none;
  width: 12rem;
}
.subcat-label-input:focus { border-color: #3b82f6; }

/* Add subcategory button */
.btn-add-subcat {
  display: inline-flex;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.7rem;
  color: #6b7280;
  background: none;
  border: 1px dashed #374151;
  border-radius: 0.35rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-add-subcat:hover { color: #e5e7eb; border-color: #6b7280; }

/* Chip placement popover — account-picker style, position set via JS */
.chip-target-popover-v2 {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 0.75rem;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  width: 15rem;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
}
.ctp-search-wrap {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #374151;
}
.ctp-search {
  width: 100%;
  background: #1f2937;
  border: 1px solid #374151;
  color: #e5e7eb;
  font-size: 0.72rem;
  padding: 0.3rem 0.5rem;
  border-radius: 0.375rem;
  outline: none;
}
.ctp-search:focus { border-color: #6b7280; }
.ctp-list {
  overflow-y: auto;
  padding: 0.25rem;
  flex: 1;
}
.ctp-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.4rem;
  flex-shrink: 0;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.ctp-group-header {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 400;
  color: #d1d5db;
  padding: 0.3rem 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 0.375rem;
  transition: background 0.12s;
  user-select: none;
}
.ctp-group-header:hover { background: #1f2937; color: #fff; }
.ctp-group-label { flex: 1; }
.ctp-chevron { font-size: 0.6rem; color: #6b7280; margin-left: 0.25rem; }
.ctp-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  font-size: 0.72rem;
  color: #d1d5db;
  padding: 0.3rem 0.5rem;
  border-radius: 0.375rem;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.12s;
}
.ctp-item:hover { background: #1f2937; color: #fff; }
.ctp-item-sub { padding-left: 1.1rem; color: #9ca3af; }
.ctp-item-sub:hover { color: #fff; }

/* Sub-category rows in P&G table */
#pyg-table tr.subcat-header td {
  font-size: 0.75rem;
  font-weight: 600;
  color: #d1d5db;
  background: #131e2e;
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}
#pyg-table tr.subcat-header:hover td { filter: brightness(1.15); }

/* ── Account picker popover ───────────────────────────────────────────────── */
#account-picker { display: flex; flex-direction: column; }
#account-picker.hidden { display: none; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1f2937;
  border: 1px solid #374151;
  color: #e5e7eb;
  font-size: 0.85rem;
  padding: 0.75rem 1.25rem;
  border-radius: 0.75rem;
  z-index: 100;
  transition: opacity 0.3s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.toast.hidden { display: none; }
.toast.success { border-color: #10b981; color: #a7f3d0; }
.toast.error   { border-color: #ef4444; color: #fca5a5; }

/* ── Responsive / Mobile ─────────────────────────────────────────────────── */
@media (max-width: 639px) {
  /* Cards */
  .chart-card { padding: 0.875rem; }
  .chart-header { flex-wrap: wrap; gap: 0.5rem; }
  .chart-title { font-size: 0.85rem; }

  /* Charts */
  .chart-canvas { max-height: 200px !important; }
  #chart-waterfall { max-height: 240px !important; }

  /* KPI */
  .kpi-card { padding: 0.875rem; }
  .kpi-value { font-size: 1.1rem; }
  .kpi-prev  { font-size: 0.66rem; }
  .kpi-delta { font-size: 0.68rem; }

  /* Filters: push quick-filters to its own row, right-aligned */
  .quick-filters-wrap { margin-left: auto; }

  /* Tables */
  #pyg-table th, #pyg-table td { padding: 0.4rem 0.5rem; font-size: 0.75rem; }
  .comp-th, .comp-td { padding: 0.45rem 0.6rem; font-size: 0.75rem; }
  .comp-td.comp-td-label { font-size: 0.78rem; }

  /* Account picker: full-width, fixed at bottom */
  #account-picker {
    position: fixed !important;
    bottom: 1rem;
    left: 0.75rem;
    right: 0.75rem;
    top: auto !important;
    width: auto !important;
    max-height: 60vh !important;
  }

  /* Config modal */
  .modal-box {
    padding: 1.25rem;
    border-radius: 0.75rem;
    max-height: 92vh;
  }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }

/* ── Loading skeleton ─────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #1f2937 25%, #2d3748 50%, #1f2937 75%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.5s infinite;
  border-radius: 0.25rem;
}
@keyframes skeleton-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Pie chart groups ─────────────────────────────────────────────────────── */
.pie-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  border-bottom: 1px solid #1f2937;
  padding-bottom: 2rem;
}
.pie-group:last-child { border-bottom: none; padding-bottom: 0; }
.pie-group-title {
  font-size: 0.8rem; font-weight: 600; color: #d1d5db;
  text-align: center; grid-column: 1 / -1; margin-bottom: 0.25rem;
}
.pie-side {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
  width: 100%;
}
.pie-side-label {
  font-size: 0.7rem; color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.pie-canvas-outer { position: relative; width: 100%; }
.pie-canvas-wrap { position: relative; width: 100%; aspect-ratio: 1; max-height: 480px; }
.pie-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.pie-btn-group {
  position: absolute; top: 6px; right: 6px;
  display: flex; gap: 4px; z-index: 2;
}
.pie-menu-btn {
  background: #1f2937; border: 1px solid #374151; border-radius: 0.375rem;
  color: #9ca3af; font-size: 1rem; line-height: 1;
  padding: 3px 7px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.pie-menu-btn:hover { background: #374151; color: #e5e7eb; }

/* Fullscreen overlay */
.pie-canvas-outer.pie-fullscreen {
  background: #030712;
  display: flex; flex-direction: row;
  align-items: center; justify-content: center;
  gap: 2.5rem;
  padding: 2rem;
  cursor: default;
}
.pie-canvas-outer.pie-fullscreen .pie-canvas-wrap {
  flex: 1;
  height: min(76vh, 700px);
  width: auto;
  aspect-ratio: auto;
  max-width: min(70vw, 900px);
  max-height: none;
}
.pie-canvas-outer.pie-fullscreen .pie-dropdown-container {
  width: 320px;
  max-height: 90vh;
  overflow-y: auto;
  flex-shrink: 0;
}
.pie-canvas-outer.pie-fullscreen .pie-accounts-dropdown {
  margin-top: 0;
  max-height: 90vh;
  overflow-y: auto;
}
.pie-dropdown-container { width: 100%; max-width: 340px; }
.pie-dropdown-container:has(.pie-sub-wrap) { max-width: 100%; }
.pie-accounts-dropdown {
  background: #0f172a; border: 1px solid #374151; border-radius: 0.5rem;
  padding: 0.5rem; margin-top: 0.5rem;
  font-size: 0.68rem; color: #9ca3af;
}
.pie-accounts-dropdown .acc-row {
  display: flex; justify-content: space-between; gap: 0.5rem;
  padding: 0.2rem 0.1rem; border-bottom: 1px solid #1f293750;
}
.pie-accounts-dropdown .acc-row:last-child { border-bottom: none; }
.pie-accounts-dropdown .acc-name { color: #d1d5db; }
.acc-color-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0; margin-right: 5px;
}
.acc-row-sub { padding-left: 1.1rem; }
.pie-accounts-dropdown .acc-section-header {
  display: flex; align-items: center;
  font-size: 0.68rem; font-weight: 600; color: #9ca3af;
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.35rem 0.1rem 0.15rem;
  border-top: 1px solid #1f2937;
  margin-top: 0.15rem;
}
.pie-accounts-dropdown .acc-section-header:first-child { border-top: none; margin-top: 0; }

/* ── "Otros" sub-chart breakdown ────────────────────────────────────────────── */
.pie-sub-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  margin-top: 0.5rem;
}
.pie-sub-canvas-wrap {
  width: 100%; aspect-ratio: 1; max-height: 420px;
}
.pie-sub-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.pie-sub-list { width: 100%; max-width: 340px; margin-top: 0; }
