/* ===== Budget pyramid ==================================================== */
.pyramid { overflow: hidden; }
.pyramid__head {
  display: grid; gap: 16px 32px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
}
@media (min-width: 900px) {
  .pyramid__head { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: end; }
}

.income__label {
  display: block;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-2); margin-bottom: 6px;
}
.income__field {
  display: flex; align-items: baseline; gap: 8px;
  border-bottom: 2px solid var(--line-strong);
  transition: border-color var(--dur) var(--ease);
  max-width: 440px;
}
.income__field:focus-within { border-color: var(--accent); }
.income__input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-hero); font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  padding: 2px 0 4px;
}
.income__input:focus { outline: none; }
.income__input[aria-invalid="true"] { color: var(--over); }
.income__currency { font-size: var(--fs-xl); font-weight: 600; color: var(--ink-3); }
.income__hint { margin: 8px 0 0; font-size: var(--fs-sm); color: var(--ink-3); }

.linklike {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent-ink);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}

.pyramid__totals {
  margin: 0;
  display: grid; gap: 10px 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.pyramid__totals > div { min-width: 0; }
.pyramid__totals dt { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.pyramid__totals dd { margin: 0; }
.pyramid__totals dd:first-of-type { font-size: var(--fs-xl); font-weight: 700; line-height: 1.2; }
.pyramid__totals .is-remainder {
  border-left: 3px solid var(--pending-mark);
  padding-left: 10px;
}
.pyramid__totals .is-remainder[data-empty="true"] { border-left-color: var(--fact); }
.pyramid__totals .is-remainder[data-empty="true"] dd:first-of-type::after {
  content: " ✓"; color: var(--fact); font-size: var(--fs-md);
}
.pyramid__meter { grid-column: 1 / -1; }

.pyramid__body {
  display: grid; gap: 20px;
  padding: 20px;
  grid-template-columns: minmax(0, 1fr);
}
.pyramid__figure { margin: 0; display: grid; gap: 10px; justify-items: center; }
.pyramid__svg { width: 100%; max-width: 380px; height: auto; overflow: visible; }

.seg__shape {
  stroke: var(--surface); stroke-width: 2; stroke-linejoin: round;
  transition: fill 280ms var(--ease), stroke 180ms var(--ease);
}
.seg[data-level="0"] .seg__shape { fill: transparent; stroke: var(--line-strong); stroke-dasharray: 4 3; stroke-width: 1.2; }
.seg[data-level="1"] .seg__shape { fill: var(--seq-1); }
.seg[data-level="2"] .seg__shape { fill: var(--seq-2); }
.seg[data-level="3"] .seg__shape { fill: var(--seq-3); }
.seg[data-level="4"] .seg__shape { fill: var(--seq-4); }
.seg[data-level="5"] .seg__shape { fill: var(--seq-5); }
.seg[data-level="6"] .seg__shape { fill: var(--seq-6); }
.seg[data-level="7"] .seg__shape { fill: var(--seq-7); }
.seg[data-level="8"] .seg__shape { fill: var(--seq-8); }
.seg.is-active .seg__shape { stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: none; }

.seg__label { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none; fill: var(--ink-2); }
.seg[data-level="1"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-1); }
.seg[data-level="2"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-2); }
.seg[data-level="3"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-3); }
.seg[data-level="4"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-4); }
.seg[data-level="5"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-5); }
.seg[data-level="6"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-6); }
.seg[data-level="7"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-7); }
.seg[data-level="8"] .seg__label:not(.seg__label--outside) { fill: var(--seq-t-8); }
.seg__label--outside { font-size: 13px; font-weight: 600; fill: var(--ink-2); }

.pyramid__caption { font-size: var(--fs-xs); color: var(--ink-3); text-align: center; max-width: 380px; }
.pyramid__legend { display: inline-flex; gap: 2px; vertical-align: middle; margin-right: 6px; }
.pyramid__legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.pyramid__legend i[data-level="2"] { background: var(--seq-2); }
.pyramid__legend i[data-level="5"] { background: var(--seq-5); }
.pyramid__legend i[data-level="8"] { background: var(--seq-8); }

.pyramid__rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.prow {
  display: grid; gap: 4px 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.prow.is-active, .prow:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: var(--surface-2); }
.prow.is-clamped { animation: clamp-nudge 320ms var(--ease); }
@keyframes clamp-nudge { 30% { transform: translateX(-3px); } 60% { transform: translateX(3px); } }
.prow__info { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.prow__index { width: 18px; color: var(--ink-3); font-size: var(--fs-xs); text-align: right; }
.prow__dot { flex: none; }
.prow__label { display: grid; margin-right: auto; min-width: 0; line-height: 1.25; }
.prow__name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.prow__pct { font-weight: 700; min-width: 4.2em; text-align: right; }
.prow__amount { color: var(--ink-2); min-width: 7.5em; text-align: right; }
.prow__carry { font-size: 11px; color: var(--fact); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow__control { display: flex; align-items: center; }

.pyramid__foot {
  display: grid; gap: 12px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
@media (min-width: 900px) {
  .pyramid__foot { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .pyramid__foot > p { grid-column: 1 / -1; margin: 0; }
}

/* Desktop: three aligned parts – triangle | category info | controls.
   Each segment is exactly one row high, so a category's band and its row line up. */
@media (min-width: 1100px) {
  .pyramid__body { grid-template-columns: 380px minmax(0, 1fr); gap: 28px; align-items: start; }
  .pyramid__svg { width: 380px; max-width: none; }
  .pyramid__rows { gap: 0; }
  .prow {
    height: var(--row-h);
    grid-template-columns: minmax(0, 1fr) minmax(180px, 280px);
    align-items: center;
    padding: 0 12px;
    border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
    background: transparent;
  }
  .prow:first-child { border-top: 1px solid var(--line); }
  .prow__info { flex-wrap: nowrap; }
  .prow.is-active, .prow:focus-within { background: var(--accent-soft); }
}
/* svg viewBox width 360 drawn at 380px → rows are 56 × 380/360 ≈ 59.1px high */
@media (min-width: 1100px) {
  .pyramid { --row-h: calc(56px * 380 / 360); }
}

.pyramid--compact .pyramid__foot .btn--ghost { display: none; }
