/* Бюджет: план распределения дохода + учёт трат (budget.html). Общие dp-* (плашки, полосы, крупная цифра) — в debts.css.
   Цвета разделов: зелёный/красный зарезервированы за ростом/падением котировок (дизайн v2),
   поэтому капитал — бирюзовый, долг — янтарный. */
.bd .dp-h { font-size: 20px; margin: 0 0 12px; }
/* Шапка плана — заметная карточка (как плашка «Можно тратить в день» справа): владелец 08.10 — «план не видно» */
.bd-plan-card { border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border)); background: color-mix(in srgb, var(--primary) 7%, var(--surface));
                border-radius: var(--radius); padding: 16px 16px 12px; margin-bottom: 14px; }
.bd-plan-title { font-size: 22px; font-weight: 800; margin: 0 0 12px; color: var(--text); }
.bd-plan-card #bd-income { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bd-split { margin: 4px 0 12px; }
.bd-split-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--border); gap: 2px; }
.bd-split-bar i { display: block; min-width: 3px; }
.bd-seg--needs { background: #7C3AED; }
.bd-seg--wants { background: #2563EB; }
.bd-seg--capital { background: #0D9488; }
.bd-seg--debt { background: #D97706; }
.bd-seg--free { background: repeating-linear-gradient(45deg, var(--border) 0 6px, transparent 6px 12px); }
.bd-split-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; color: var(--text-soft); }
.bd-split-legend em { font-style: normal; font-weight: 700; color: var(--text); }
.bd-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.bd-income-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.bd-income-row .dp-f { flex: 1 1 180px; }

.bd-presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.bd-chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.bd-chip:hover { border-color: var(--primary); }
.bd-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.bd-total { font-size: 14px; font-weight: 600; color: var(--text-soft); margin: 2px 0 0; }
.bd-total.warn { color: #B45309; font-weight: 600; }

#bd-plan { position: relative; }
.bd-sec { --sec: #7C3AED; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; background: var(--surface); }
.bd-sec--needs { --sec: #7C3AED; }
.bd-sec--wants { --sec: #2563EB; }
.bd-sec--capital { --sec: #0D9488; }
.bd-sec--debt { --sec: #D97706; }
.bd-sec-h { display: grid; grid-template-columns: minmax(0, 1fr) 84px 110px; gap: 8px; align-items: center;
            padding: 8px 10px; background: color-mix(in srgb, var(--sec) 16%, var(--surface)); border-bottom: 1px solid color-mix(in srgb, var(--sec) 30%, var(--border)); }
.bd-sec-name { font-weight: 700; color: var(--text); }
.bd-sec-rub { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bd-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 84px 110px 28px; gap: 6px; align-items: center; padding: 5px 10px; border-bottom: 1px solid var(--border-soft, #E2E8F0); }
.bd-sec-h + .bd-row { padding-top: 8px; }
.bd-row .calc-input, .bd-sec-h .calc-input { width: 100%; min-width: 0; }
.bd-ico { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--sec); font-size: 18px; line-height: 1; cursor: pointer; padding: 0; }
.bd-ico svg { width: 18px; height: 18px; }
.bd-ico:hover { border-color: var(--sec); }
.bd-pct { position: relative; display: block; }
.bd .bd-pct .calc-input { padding-right: 26px; text-align: right; font-variant-numeric: tabular-nums; }
.bd-pct span { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 14px; line-height: 1; pointer-events: none; }
.bd-rub { text-align: right; font-variant-numeric: tabular-nums; }
.bd-sec-f { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 6px 10px 8px; font-size: 13px; }
.bd-inner { color: #B45309; }
.bd-inner:empty { display: none; }
.bd-debt-link { margin-left: auto; color: var(--primary); font-weight: 600; text-decoration: none; }
.bd-debt-link:hover { text-decoration: underline; }
.bd-add-in { border: 0; background: none; color: var(--primary); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 2px 0; }
.bd-add-in:hover { text-decoration: underline; }

.bd-icons { position: absolute; z-index: 30; width: 336px; max-width: calc(100vw - 32px); max-height: 320px; overflow-y: auto; padding: 4px 8px 8px;
            background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 23, 42, .18); }
.bd-icons-h { position: sticky; top: -4px; background: var(--surface); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 8px 2px 4px; }
.bd-icons-g { display: grid; grid-template-columns: repeat(auto-fill, 36px); gap: 4px; }
.bd-icons[hidden] { display: none !important; }
.bd-icons button { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 6px; background: none; color: var(--text-soft); font-size: 19px; cursor: pointer; }
.bd-icons button svg { width: 18px; height: 18px; }
.bd-icons button:hover { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); }

.bd-month { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.bd-month b { font-size: 16px; text-transform: capitalize; min-width: 150px; text-align: center; }
.bd-month button { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm, 6px); width: 32px; height: 32px; cursor: pointer; color: var(--text); }
.bd-month button:disabled { opacity: .35; cursor: default; }
.bd-add { margin-top: 16px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.bd-add-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
.bd-add-grid .calc-input { width: 100%; min-width: 0; }
.bd-add-grid .bd-add-note { grid-column: 1 / -1; }
.bd-add .dp-acts { margin-top: 8px; }
#bd-bars { margin-top: 14px; }
.bd-bar-row { margin-bottom: 10px; font-size: 14px; }
.bd-bar-top { display: flex; justify-content: space-between; gap: 8px; }
.bd-bar-top span:last-child { color: var(--text-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bd-bar-left { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.bd-bar-row.over .dp-bar i { background: #DC2626; }
.bd-bar-row.over .bd-bar-left { color: #DC2626; }
#bd-entries { list-style: none; margin: 14px 0 0; padding: 0; font-size: 14px; }
#bd-entries li { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border-soft, #E2E8F0); }
#bd-entries .bd-e-env { flex: 1 1 auto; min-width: 0; }
#bd-entries b { font-variant-numeric: tabular-nums; white-space: nowrap; }
#bd-cta { margin-top: 16px; }
/* Связь с «Моими финансами» — строка под кнопкой траты, по «Связать» раскрывается в панель */
.bd-sync { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.bd-sync:empty { display: none; }
.bd-sync-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bd-sync-ico { flex: 0 0 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-size: 16px; font-weight: 700;
               background: color-mix(in srgb, var(--primary) 12%, var(--surface)); color: var(--primary); }
.bd-sync-row.on .bd-sync-ico { background: color-mix(in srgb, #0D9488 15%, var(--surface)); color: #0D9488; }
.bd-sync-t { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.bd-sync-t span { color: var(--text-soft); font-size: 13px; }
.bd-sync-t a { color: var(--primary); font-weight: 600; }
.bd-sync-panel { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.bd-sync-panel > .dp-muted { margin: 0; }
.bd-sync-chk { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; cursor: pointer; }
.bd-sync-chk input { margin-top: 3px; }
.bd-sync-chk em { flex-basis: 100%; padding-left: 22px; font-style: normal; font-size: 12px; color: var(--text-muted); }
.bd-e-sync { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: color-mix(in srgb, #0D9488 14%, var(--surface)); color: #0F766E; white-space: nowrap; }
/* Название статьи — textarea с автовысотой (budget.js fitName): длинное имя переносится, а не обрезается */
.bd-name { display: block; resize: none; overflow: hidden; line-height: 1.3; }
/* Блоки узкого экрана — на десктопе их нет */
.bd-quick, #bd-view, .bd-sheet-bg, .bd-sheet-h, .bd-edit-bar { display: none; }

/* Телефон и планшет (≤ 900 px), вариант 5 «сначала день» (10.10.2026).
   Колонки calc-grid растворяются (display: contents), порядок блоков задаёт order:
   день → кнопка траты → конверты → траты. План виден только в режиме правки (.bd-editing),
   форма траты — нижняя шторка (.bd-sheet-open). */
@media (max-width: 900px) {
  /* html[data-ui] — иначе проигрываем terminal.css (html[data-ui="terminal"] .calc-grid задаёт gap 28px и align-items: start) */
  html[data-ui] .bd .calc-wrap { padding: 0; border: 0; box-shadow: none; background: none; }
  html[data-ui] .bd .calc-grid { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .bd .calc-grid > div { display: contents; }
  .bd-month { order: 1; margin: 0; justify-content: center; }
  #bd-result { order: 2; }
  #bd-err { order: 3; }
  .bd-quick { order: 3; display: block; }
  html[data-ui] .bd-quick .dt-btn { width: 100%; height: auto; min-height: 50px; font-size: 16px; font-weight: 700; justify-content: center; }
  #bd-view { order: 4; display: block; }
  #bd-entries, #bd-list-err { order: 5; margin: 0; }
  #bd-cta { order: 6; margin: 0; }
  #bd-cta:empty, #bd-bars { display: none; }

  .bd:not(.bd-editing) .bd-plan-card, .bd:not(.bd-editing) #bd-plan { display: none; }
  .bd.bd-editing .bd-month, .bd.bd-editing #bd-result, .bd.bd-editing .bd-quick, .bd.bd-editing #bd-view,
  .bd.bd-editing #bd-entries, .bd.bd-editing #bd-list-err, .bd.bd-editing #bd-cta { display: none; }
  .bd-plan-card { order: 1; margin: 0; }
  #bd-plan { order: 2; }
  .bd.bd-editing .bd-edit-bar { order: 4; display: flex; }
  .bd-edit-bar { position: sticky; bottom: 0; z-index: 20; align-items: center; gap: 10px;
                 margin-inline: calc(-1 * clamp(16px, 2.5vw, 40px)); padding: 10px clamp(16px, 2.5vw, 40px) calc(10px + env(safe-area-inset-bottom, 0px));
                 background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 16px rgba(15, 23, 42, .08); }
  .bd-edit-bar span { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: #0F766E; }
  .bd-edit-bar span.warn { color: #B45309; }
  html[data-ui] .bd-edit-bar .dt-btn { height: auto; min-height: 44px; padding: 0 22px; }

  /* Конверты: только чтение, остаток и полоса потраченного */
  .bd-v-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--text-soft); }
  .bd-v-head b { color: var(--text); font-variant-numeric: tabular-nums; }
  .bd-v-edit { border: 0; background: none; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; padding: 10px 0; }
  .bd-v-hint { font-size: 13px; color: var(--text-soft); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); border-radius: var(--radius); padding: 8px 12px; margin: 2px 0 4px; }
  .bd-v-hint button { border: 0; background: none; padding: 0; color: var(--primary); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
  .bd-v-grp { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 2px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--sec); }
  .bd-v-grp span:last-child { color: var(--text-muted); font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
  .bd-v-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
  .bd-v-row { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; width: 100%; padding: 10px 12px;
              border: 0; border-top: 1px solid var(--border-soft, #E2E8F0); background: none; color: var(--text); font: inherit; font-size: 15px; text-align: left; cursor: pointer; }
  .bd-v-row:first-child { border-top: 0; }
  .bd-v-row:active { background: color-mix(in srgb, var(--sec) 6%, var(--surface)); }
  .bd-v-row .bd-ico { width: 32px; height: 32px; border: 0; background: color-mix(in srgb, var(--sec) 12%, var(--surface)); cursor: inherit; }
  .bd-v-name { min-width: 0; font-weight: 500; line-height: 1.25; }
  .bd-v-left { text-align: right; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .bd-v-left b { display: block; font-size: 15px; }
  .bd-v-left small { font-size: 12px; color: var(--text-muted); }
  .bd-v-row.over .bd-v-left b { color: #DC2626; }
  .bd-v-row .dp-bar { grid-column: 2 / 4; height: 5px; margin: 0; }
  .bd-v-row .dp-bar i { background: var(--sec); }
  .bd-v-row.over .dp-bar i { background: #DC2626; }

  /* Форма траты — нижняя шторка */
  .bd-sheet-bg { display: block; position: fixed; inset: 0; z-index: 1000; background: rgba(15, 23, 42, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .bd-sheet-open .bd-sheet-bg { opacity: 1; pointer-events: auto; }
  #bd-add-form { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001; margin: 0; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
                 border: 0; border-radius: 18px 18px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
                 box-shadow: 0 -10px 30px rgba(15, 23, 42, .25); transform: translateY(105%); visibility: hidden;
                 transition: transform .25s ease, visibility 0s linear .25s; }
  .bd-sheet-open #bd-add-form { transform: none; visibility: visible; transition: transform .25s ease; }
  .bd-sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
  .bd-sheet-h b { font-size: 18px; }
  html[data-ui] #bd-add-form .dt-btn--primary { width: 100%; height: auto; min-height: 48px; justify-content: center; }
  body.bd-lock { overflow: hidden; }
}
@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  #bd-add-form, .bd-sheet-bg { transition: none; }
}

/* Телефон: план в режиме правки — плотная таблица, одна строка на статью.
   shared.css на ≤ 768 px ставит полям min-height 48px и 16px !important (против зума iOS) —
   высоту здесь перебиваем, 16px оставляем. */
@media (max-width: 620px) {
  .bd-sec-h { grid-template-columns: minmax(0, 1fr) 56px 84px 20px; gap: 4px; padding: 8px; }
  .bd-row { grid-template-columns: 28px minmax(0, 1fr) 56px 84px 20px; gap: 4px; padding: 4px 8px; }
  .bd-sec-h + .bd-row { padding-top: 6px; }
  .bd-ico { width: 28px; height: 28px; font-size: 15px; }
  .bd-row .dp-x { padding: 4px 0; font-size: 18px; }
  .bd .bd-row .calc-input, .bd .bd-sec-h .calc-input { min-height: 38px !important; padding: 6px; }
  .bd .bd-row .bd-name { hyphens: auto; -webkit-hyphens: auto; overflow-wrap: normal; border-color: transparent; background: transparent; padding: 6px 2px; }
  .bd .bd-row .bd-name:focus { border-color: var(--primary); background: var(--surface); padding: 6px; }
  .bd .bd-pct .calc-input { padding-right: 18px; }
  .bd-pct span { right: 6px; font-size: 13px; }
  .bd-add-grid { grid-template-columns: 1fr 1fr; }
  .bd-add-grid > .dp-f:first-child, .bd-add-grid .bd-add-note { grid-column: 1 / 3; }
}
