/* =====================================================================
   ПЛАН: закрытие месяца и прогноз накоплений.
   Подключается после finance.css и пользуется его переменными и классами
   (money3, preset, pbar, fincard__hint).
   ===================================================================== */

/* Напоминание на обзоре в первые дни месяца. */
.fincard--remind {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(120deg, rgba(var(--accent-rgb), .16), var(--surface) 70%);
  border-color: rgba(var(--accent-rgb), .45);
}

.remind__icon { font-size: 28px; }
.remind__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.remind__body b { font-size: 16px; }
.remind__body small { color: var(--muted); font-size: 13px; line-height: 1.45; }

/* Распределение слева, прогноз и инструменты справа: на широком экране
   всё видно разом, на узком — одной колонкой в порядке работы. */
.plan-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.plan-col { display: grid; gap: 16px; }

.plancard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
}

.plancard__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.plancard__head h3 { font-size: 19px; }
.plancard__sub { color: var(--muted); font-size: 13px; margin: 4px 0 0; line-height: 1.45; }
.plancard__sub b { color: var(--text); }

.monthnav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.monthnav__btn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.monthnav__btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.monthnav__btn:disabled { opacity: .3; cursor: default; }
.monthnav__label { min-width: 84px; text-align: center; font-weight: 700; font-size: 14px; }

.closestate {
  display: inline-flex;
  margin-bottom: 16px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(251, 191, 36, .12);
  color: var(--warn);
}

.closestate.is-closed { background: rgba(74, 222, 128, .12); color: var(--ok); }

.money3--plan { padding-bottom: 16px; border-bottom: 1px solid var(--line); }

/* Наблюдения по фактам месяца. */
.insights { display: grid; gap: 7px; margin: 16px 0 18px; }

.insight {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.insight__icon { flex: none; width: 20px; text-align: center; }

.insights__more {
  justify-self: start;
  border: 0;
  background: none;
  padding: 2px 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.insights__more:hover { text-decoration: underline; }
.insight--bad { color: #fecaca; background: rgba(248, 113, 113, .09); }
.insight--good { color: #bbf7d0; background: rgba(74, 222, 128, .08); }
.insight--warn { color: #fde68a; background: rgba(251, 191, 36, .09); margin-bottom: 12px; }

/* Ползунок суммы — главный элемент, поэтому крупный. */
.distribute { margin-bottom: 16px; }
.distribute__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.distribute__label { color: var(--muted); font-size: 14px; }
.distribute__value { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.distribute__presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.preset--xs { padding: 6px 11px; font-size: 12px; font-weight: 600; }

/* Валюта закрытия: маленький переключатель рядом с «Распределяем». */
.segmented--cur { flex: none; margin-right: auto; align-self: center; padding: 2px; }
.segmented--cur .segmented__btn { padding: 4px 11px; font-size: 13px; min-width: 34px; }

/* Сумма фиксированной строки и её валюта в одной строке формы. */
.field > .pi-amount { display: flex; gap: 8px; margin: 0; color: inherit; font-size: inherit; }
.pi-amount input { flex: 1; min-width: 0; }
.pi-amount select { flex: none; width: 72px; }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  outline: none;
  margin: 6px 0;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--text);
  border: 4px solid var(--bg);
  box-shadow: 0 0 0 1px var(--line), 0 4px 12px rgba(0, 0, 0, .5);
  cursor: grab;
}

.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: 4px solid var(--bg);
  cursor: grab;
}

/* Полоса долей: сегменты растут через flex-grow. */
.splitbar { display: flex; gap: 3px; height: 14px; margin: 4px 0 6px; }
.splitbar--thin { height: 6px; gap: 2px; margin: 9px 0; }
.splitbar__seg { border-radius: 999px; min-width: 4px; transition: flex-grow .3s ease; }

.splitbar__seg--rest {
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--bg-soft) 6px 12px);
}

.planrows { display: grid; }

.planrow {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.planrow__dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.planrow__dot--rest { background: var(--surface-2); border: 1px dashed var(--muted); }
.planrow__dot--over { background: var(--danger); }

.planrow__name {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.planrow--rest .planrow__name { cursor: default; }
.planrow__name b { font-size: 15px; font-weight: 600; }
button.planrow__name:hover b { color: var(--accent-ink); }
.planrow__name small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.planrow__name small.is-ok { color: var(--ok); }
.planrow__name small.is-warn { color: var(--warn); }
.planrow__rule { color: var(--muted); font-size: 12px; white-space: nowrap; }
.planrow__sum { font-weight: 800; font-size: 16px; white-space: nowrap; }

.planrow__amount {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  width: 104px;
  padding: 0 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color .15s;
}

.planrow__amount:focus-within { border-color: var(--accent); }
.planrow__amount span { color: var(--muted); font-weight: 700; }

.planrow__amount input,
.ins__share input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  text-align: right;
  -moz-appearance: textfield;
}

.planrow__amount input { padding: 8px 0; font-weight: 800; font-size: 16px; }

.planrow__amount input::-webkit-outer-spin-button,
.planrow__amount input::-webkit-inner-spin-button,
.ins__share input::-webkit-outer-spin-button,
.ins__share input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Крестик неяркий, чтобы не спорить с суммой, но всегда виден:
   на телефоне наведения нет. */
.planrow__del {
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s, color .15s, background .15s;
}

.planrow__del:hover, .planrow__del:focus-visible { opacity: 1; color: var(--danger); background: rgba(248, 113, 113, .12); }

.plan-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.plan-actions__spacer { flex: 1; }
.plan-actions .btn--primary:disabled { opacity: .45; cursor: default; transform: none; }

/* Итог месяца — зелёная плашка, главный вывод панели. */
.plansum {
  margin-top: 18px;
  padding: 16px 18px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.plansum__main { display: flex; flex-direction: column; gap: 4px; }
.plansum__label { color: var(--muted); font-size: 13px; }
.plansum__value { color: var(--ok); font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.plansum__text { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 8px 0 0; }

/* ---------- Прогноз ---------- */
.fc-group { margin-bottom: 14px; }
.fc-group__label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow-x: auto;
  scrollbar-width: none;
}

.segmented::-webkit-scrollbar { display: none; }

.segmented__btn {
  flex: 1 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.segmented__btn:hover { color: var(--text); }

.segmented__btn.is-on {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 2px 8px rgba(0, 0, 0, .35);
}

.fc-toggles { display: grid; gap: 10px; margin: 16px 0 4px; }

/* Переключатель вместо голого чекбокса: на телефоне в него проще попасть. */
.switch { position: relative; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch b { color: var(--text); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }

.switch__track {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: background .2s, border-color .2s;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .2s, background .2s;
}

.switch input:checked + .switch__track { background: rgba(var(--accent-rgb), .3); border-color: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch--sm .switch__track { width: 34px; height: 20px; }
.switch--sm .switch__track::after { width: 14px; height: 14px; }
.switch--sm input:checked + .switch__track::after { transform: translateX(14px); }

.fc-result { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.fc-result__main { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.fc-result__label { color: var(--muted); font-size: 13px; }
.fc-result__value { color: var(--ok); font-size: 40px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }

.fc-rows { display: grid; gap: 8px; }
.fc-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--muted); }
.fc-row b { color: var(--text); font-size: 15px; white-space: nowrap; }
.fc-row--muted b { color: var(--muted); font-weight: 600; }

.fc-chart { position: relative; margin: 16px 0 8px; }
.fc-chart__svg { width: 100%; height: 170px; display: block; }
.fc-chart__labels { position: relative; height: 16px; margin-top: -18px; pointer-events: none; }
.fc-chart__labels span { position: absolute; top: 0; transform: translateX(-50%); color: var(--muted); font-size: 11px; white-space: nowrap; }
.fc-chart__labels span:first-child { transform: none; }
.fc-chart__labels span:last-child { transform: translateX(-100%); }

.fc-chart__legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.fc-chart__legend span { display: flex; align-items: center; gap: 6px; }
.fc-chart__legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

.fc-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }

.fc-fact {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
}

.fc-fact b { font-size: 16px; font-weight: 800; }
.fc-fact span { color: var(--muted); font-size: 12px; line-height: 1.4; }

/* ---------- Куда вложить ---------- */
.cushion {
  padding: 14px 16px;
  margin-bottom: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.cushion.is-full { border-color: rgba(74, 222, 128, .4); }
.cushion__top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; margin-bottom: 9px; }
.cushion__top span:last-child { color: var(--muted); font-weight: 500; white-space: nowrap; }
.cushion p { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 9px 0 0; }

.inline-select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 1px 4px;
  font-size: 12px;
}

.mix { margin-bottom: 14px; }
.mix__bar { display: flex; gap: 3px; height: 10px; }
.mix__bar span { border-radius: 999px; min-width: 4px; }
.mix__legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 9px; font-size: 12px; color: var(--muted); }
.mix__legend span { display: flex; align-items: center; gap: 6px; }
.mix__legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.mix__rate { margin-left: auto; color: var(--text); font-weight: 600; }

.inv-empty { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 14px; }

.instruments { display: grid; gap: 6px; }

.ins {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  transition: border-color .15s, background .15s;
}

.ins.is-on { background: var(--surface-2); }
.ins.is-open { border-color: rgba(var(--accent-rgb), .5); }
.ins__main { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }

.ins__name {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.ins__name b { font-size: 14px; font-weight: 600; }
.ins:not(.is-on) .ins__name b { color: var(--muted); }
.ins__name small { color: var(--muted); font-size: 11.5px; }
.ins__group { font-style: normal; font-weight: 700; }

.ins__share {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 64px;
  padding: 0 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  flex: none;
}

.ins__share:focus-within { border-color: var(--accent); }
.ins__share span { color: var(--muted); font-size: 12px; }
.ins__share input { padding: 6px 0; font-weight: 700; }

.ins__money { width: 64px; text-align: right; font-weight: 800; white-space: nowrap; flex: none; }

.ins__details {
  display: grid;
  gap: 6px;
  padding: 0 12px 12px 56px;
  font-size: 12.5px;
  line-height: 1.5;
}

.ins__details div span { color: var(--muted); margin-right: 8px; }
.ins__details p { color: var(--muted); margin: 2px 0; }
.ins__details .linkbtn { justify-self: start; }

/* ---------- История закрытий ---------- */
#plan-history .section-head--sub { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.closes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }

.closerow {
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s;
}

.closerow:hover, .closerow.is-current { border-color: var(--accent); }
.closerow__top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.closerow__top b::first-letter { text-transform: uppercase; }
.closerow__top span { color: var(--muted); font-size: 13px; }
.closerow__items { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12px; }

/* Подвкладки нужны только там, где панели идут одной колонкой. */
.plan-tabs { display: none; margin-bottom: 14px; }

/* minmax(0, …): иначе ширину колонки задаёт самый широкий ряд кнопок
   и карточка вылезает за экран. */
@media (max-width: 1100px) {
  .plan-grid { grid-template-columns: minmax(0, 1fr); }
  .plan-tabs { display: flex; }
  .plan-tabs .segmented__btn { flex: 1 1 0; }

  [data-view="fin-plan"]:not([data-pane="close"]) #plan-close,
  [data-view="fin-plan"]:not([data-pane="close"]) #plan-history,
  [data-view="fin-plan"]:not([data-pane="forecast"]) #plan-forecast,
  [data-view="fin-plan"]:not([data-pane="invest"]) #plan-invest { display: none; }
}

.plan-col > * { min-width: 0; }

@media (max-width: 760px) {
  .plancard { padding: 18px 16px; }
  .plancard__head h3 { font-size: 18px; }
  .distribute__value { font-size: 26px; }
  .planrow { gap: 9px; }
  .planrow__name b { font-size: 14px; }
  .planrow__rule { display: none; }
  .planrow__amount { width: 88px; padding: 0 8px; }
  .planrow__del { width: 24px; margin-left: -4px; }
  .plan-actions .btn--primary { flex-basis: 100%; justify-content: center; order: 5; }
  .plan-actions__spacer { display: none; }
  .plansum__value { font-size: 30px; }
  .fc-result__value { font-size: 34px; }
  .segmented__btn { padding: 8px 7px; font-size: 12px; }
  .fc-chart__svg { height: 140px; }
  .fc-facts { grid-template-columns: 1fr; }
  .fc-fact { flex-direction: row; align-items: baseline; gap: 10px; }
  .fc-fact b { flex: none; }
  .ins__main { padding: 10px; gap: 8px; }
  .ins__money { width: 54px; font-size: 13px; }
  .ins__share { width: 58px; }
  .ins__share input { font-size: 16px; }
  .ins__details { padding-left: 12px; }
  .fincard--remind { flex-wrap: wrap; }
  .fincard--remind .btn { flex-basis: 100%; justify-content: center; }
  .closes { grid-template-columns: 1fr; }
  .mix__rate { margin-left: 0; flex-basis: 100%; }
}
