/* ══════════════════════════════════════════════════════════════
   presupuesto.css — the Presupuesto tab on transactions.html
   ----------------------------------------------------------------
   Everything here is built from the tokens in style.css: no literal
   colours beyond the alpha washes derived from --up / --warn / --down,
   and every number is DM Mono (--font-mono) like the rest of the app.

   The one idea the whole sheet serves: a bar you can read in a second.
   Fill = how much of the budget is spent; the vertical tick = how much
   of the MONTH has elapsed. Fill left of the tick means you're ahead of
   your money; fill past it means you're spending faster than the month.
   ══════════════════════════════════════════════════════════════ */

/* ─── Tab bar ────────────────────────────────────────────────────────────────
   No margin of its own: .main is a flex column with gap:20px, so the band is
   spaced by the same rhythm as every other block on the page. */
.txn-tab-panel.hidden { display: none; }

/* ─── Month header ───────────────────────────────────────────── */
.bud-head { margin-bottom: 18px; }

.bud-head__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.bud-month {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bud-month__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bud-month__nav:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }
.bud-month__nav:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-dim); }

.bud-month__label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
  padding: 0 10px;
}

.bud-month__name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.15;
}

/* "Día 18 de 31 · 58% del mes" — a fact about the calendar, so it reads
   as data (mono) rather than prose. */
.bud-month__pace {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0.3px;
}

/* ─── Totals ─────────────────────────────────────────────────── */
.bud-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.bud-total {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 14px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.bud-total__label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.bud-total__value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  color: var(--text-primary);
}
.bud-total__value--spent { color: var(--warn); }
.bud-total__value--pos   { color: var(--up); }
.bud-total__value--neg   { color: var(--down); }

/* ─── Bars ───────────────────────────────────────────────────── */
.bud-bar { width: 100%; }

/* overflow stays VISIBLE: the pace marker deliberately overshoots the track
   top and bottom so it reads as a tick rather than a stripe. The fill rounds
   itself instead of being clipped by the track. */
.bud-bar__track {
  position: relative;
  height: 10px;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  overflow: visible;
}

.bud-bar__fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}
.bud-bar__fill--ok       { background: var(--up); }
.bud-bar__fill--cerca    { background: var(--warn); }
.bud-bar__fill--excedido { background: var(--down); }
/* A fijo is never red: it is either pending or paid, so it gets the accent
   (informational) and a calm green when settled. */
.bud-bar__fill--neutral  { background: var(--accent); }
.bud-bar__fill--cumplido { background: var(--up); }

/* Pace marker: where the month is, drawn ON TOP of the fill so "ahead" and
   "behind" are one glance apart. overflow:hidden on the track would clip it,
   so it lives above with its own stacking. */
.bud-bar__pace {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  margin-left: -1px;
  background: var(--text-primary);
  opacity: 0.85;
  border-radius: 1px;
  z-index: 2;
  pointer-events: none;
}
.bud-bar--total .bud-bar__track { height: 14px; }
.bud-bar--total { margin-bottom: 12px; }

/* ─── Projection line ────────────────────────────────────────── */
.bud-projection {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}
.bud-projection--ok   { color: var(--up); }
.bud-projection--over { color: var(--warn); }

/* ─── Empty state ────────────────────────────────────────────── */
.bud-empty {
  text-align: center;
  padding: 40px 28px;
  margin-bottom: 18px;
}
.bud-empty__icon { font-size: 34px; margin-bottom: 12px; }
.bud-empty__title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
}
.bud-empty__body {
  margin: 0 auto 22px;
  max-width: 460px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.bud-empty__actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ─── Category rows ──────────────────────────────────────────── */
.bud-list-panel { margin-bottom: 18px; }

.bud-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bud-row {
  padding: 14px 14px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background 0.15s, border-color 0.15s;
}
.bud-row:hover { background: var(--bg-panel-alt); border-color: var(--border-subtle); }

/* Only the rows that need attention carry a tint — a colour on every row is
   decoration, a colour on the two that matter is information. */
.bud-row--cerca    { background: rgba(251, 191, 36, 0.05); }
.bud-row--excedido { background: rgba(248, 113, 113, 0.06); }

.bud-row__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.bud-row__name {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}
.bud-row__icon { font-size: 14px; flex-shrink: 0; }
.bud-row__label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bud-row__tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
  letter-spacing: 0.4px;
  flex-shrink: 0;
}
.bud-row__tag--override { color: var(--accent-light); }

.bud-row__nums {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.bud-row__spent  { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.bud-row__sep    { font-size: 12px; color: var(--text-tertiary); }
.bud-row__budget { font-size: 12px; color: var(--text-secondary); }

.bud-row--excedido .bud-row__spent { color: var(--down); }
.bud-row--cerca .bud-row__spent    { color: var(--warn); }

/* Inline amount edit — the number becomes an input exactly where it was being
   read, so the row never jumps. Sized to the value, not to the container. */
.bud-row--editing { background: var(--bg-panel-alt); border-color: var(--accent); }

.bud-inline-input {
  width: 96px;
  padding: 2px 6px;
  background: var(--bg-base);
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
}
.bud-inline-input:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-dim); }

.bud-row__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.bud-row__status {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.bud-row__status--excedido { color: var(--down); }
.bud-row__status--cerca    { color: var(--warn); }
.bud-row__status--cumplido { color: var(--up); }

/* Row actions stay quiet until the row is hovered — the numbers are the
   point; the controls are there when you reach for them. */
.bud-row__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.bud-row:hover .bud-row__actions,
.bud-row:focus-within .bud-row__actions { opacity: 1; }

.bud-act {
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-tertiary);
  font-family: var(--font-body);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bud-act:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }
.bud-act:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-dim); }
.bud-act--danger:hover { color: var(--down); border-color: var(--down); }

/* ─── Gasto sin presupuesto ──────────────────────────────────── */
.bud-uncovered { margin-bottom: 18px; }

.bud-rows--uncovered { gap: 2px; }

.bud-unc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.bud-unc-row:hover { background: var(--bg-panel-alt); }

.bud-unc__name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  color: var(--text-primary);
}
.bud-unc__count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.bud-unc__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.bud-unc__amount {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}

.bud-uncovered__total {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

/* ─── End-of-month recap ─────────────────────────────────────── */
.bud-recap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
}
.bud-recap--ok    { border-color: rgba(52, 211, 153, 0.35); background: var(--up-dim); }
.bud-recap--mixed { background: var(--bg-panel-alt); }
.bud-recap__icon  { font-size: 18px; }
.bud-recap__text strong { color: var(--text-primary); font-family: var(--font-mono); }

/* ─── Suggestion review list (modal) ─────────────────────────── */
.bud-suggest__intro {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.bud-suggest__intro strong { color: var(--text-primary); }

.bud-suggest__rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 46vh;
  overflow-y: auto;
}

.bud-suggest__row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.bud-suggest__row:hover { background: var(--bg-panel-alt); }

.bud-suggest__check { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.bud-suggest__name {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  color: var(--text-primary);
  min-width: 0;
}

.bud-suggest__months {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.bud-suggest__amount {
  display: flex;
  align-items: center;
  gap: 6px;
}
.bud-suggest__input {
  width: 108px;
  text-align: right;
  font-family: var(--font-mono);
}
.bud-suggest__cur {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
}

/* ─── Live budget line inside the transaction modal ──────────── */
.txn-bud-line {
  padding: 11px 13px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
}
.txn-bud-line--ok       { border-left-color: var(--up); }
.txn-bud-line--cerca    { border-left-color: var(--warn); }
.txn-bud-line--excedido { border-left-color: var(--down); }
.txn-bud-line--neutral,
.txn-bud-line--cumplido { border-left-color: var(--accent); }

.txn-bud-line__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.txn-bud-line__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}
.txn-bud-line__pct {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
}
.txn-bud-line__text {
  margin-top: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}
.txn-bud-line--excedido .txn-bud-line__text { color: var(--down); }
.txn-bud-line--cerca .txn-bud-line__text    { color: var(--warn); }

.bud-bar--mini .bud-bar__track { height: 6px; }

/* ─── Ledger chip ────────────────────────────────────────────── */
.txn-bud-chip {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 6px;
  border: 1px solid;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.txn-bud-chip--cerca {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.08);
}
.txn-bud-chip--excedido {
  color: var(--down);
  border-color: rgba(248, 113, 113, 0.4);
  background: var(--down-dim);
}

/* ─── Narrow screens (≤ 380 px must still be readable) ───────── */
@media (max-width: 640px) {
  .bud-totals { grid-template-columns: 1fr; gap: 8px; }
  .bud-total { flex-direction: row; align-items: baseline; justify-content: space-between; }
  .bud-head__top { align-items: stretch; }
  .bud-month { justify-content: space-between; width: 100%; }
  .bud-month__label { min-width: 0; flex: 1; text-align: center; }
  .bud-head__top .btn { width: 100%; }

  /* Rows stack: the numbers move under the name so neither is truncated, and
     the actions become a full-width strip instead of a hover affordance that
     touch can't reveal. */
  .bud-row__head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .bud-row__foot { flex-direction: column; align-items: flex-start; gap: 8px; }
  .bud-row__actions { opacity: 1; flex-wrap: wrap; }

  .bud-unc-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .bud-unc__right { width: 100%; justify-content: space-between; }

  .bud-suggest__row {
    grid-template-columns: auto 1fr;
    row-gap: 6px;
  }
  .bud-suggest__months { grid-column: 2; }
  .bud-suggest__amount { grid-column: 2; }
  .bud-suggest__input { width: 100%; }
}

/* The pace marker must stay legible when the bar gets narrow. */
@media (max-width: 380px) {
  .bud-bar__pace { width: 3px; margin-left: -1.5px; }
  .bud-month__name { font-size: 19px; }
  .bud-total__value { font-size: 17px; }
}
