/* Деньги (#113). Экранные стили раздела: правит только задача раздела; компоненты — в components.css, цвета — токены из application.css. */

/* ---------- Карточки касс над журналом: клик — пересчет ---------- */
.accs {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.acc {
  color: var(--ink);
  display: grid;
  gap: var(--s-1);
  padding: 14px var(--s-4);
}

.acc:hover {
  border-color: var(--edge-2);
  text-decoration: none;
}

.acc-name {
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
}

.acc b {
  font-size: 20px;
  font-weight: 600;
}

.acc small {
  color: var(--ink-3);
  font-size: 12px;
}

.acc .acc-stale {
  color: var(--warn);
  font-weight: 600;
}

/* Целевые деньги (ЕЛС впрок) — штриховка: их нельзя тратить */
.acc.target {
  background: repeating-linear-gradient(135deg, var(--panel), var(--panel) 8px, var(--hatch) 8px, var(--hatch) 16px);
}

/* ---------- Карточка раздела: сегменты в заголовке ---------- */
.money-card > .card-h {
  padding-bottom: var(--s-3);
}

.money-card > .card-h form {
  margin: 0;
}

.money-note {
  color: var(--ink-2);
  font-size: 13px;
  margin: 0;
  padding: 0 var(--s-5) var(--s-3);
}

ol.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ---------- Журнал: фильтры в одну строку ---------- */
.filters {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-5) var(--s-4);
}

.filters :is(input:not([type="submit"], [type="hidden"]), select) {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: 14px;
  min-height: 38px;
  min-width: 0;
  padding: 0 11px;
}

.filters input[type="search"] {
  flex: 1 1 240px;
}

.filters select {
  flex: 0 1 200px;
}

.filters :is(input, select):focus-visible {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px var(--acc-2);
  outline: none;
}

.f-date {
  align-items: center;
  color: var(--ink-2);
  display: inline-flex;
  font-size: 13px;
  gap: 6px;
}

/* Строка журнала: дата · статья и комментарий · кто внес · сумма · «⋯» */
.jrow {
  grid-template-columns: 64px minmax(0, 1fr) 190px 150px 40px;
}

.jrow .r-when {
  color: var(--ink-3);
}

.j-who {
  color: var(--ink-2);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pager {
  align-items: center;
  border-top: 1px solid var(--line-2);
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: var(--s-2) var(--s-4);
  justify-content: space-between;
  padding: var(--s-3) var(--s-5);
}

/* ---------- Календарь денег и история операции ---------- */
.cal-note {
  display: grid;
  gap: var(--s-1);
  padding: var(--s-1) var(--s-5) var(--s-4);
}

.cal-note p {
  margin: 0;
  max-width: 75ch;
}

.cal-note p + p {
  color: var(--ink-2);
  font-size: 13px;
}

.cash-shortage {
  color: var(--neg);
}

.flow-row {
  grid-template-columns: minmax(0, 1fr) 160px;
  min-height: 48px;
}

.event-row {
  grid-template-columns: 150px minmax(0, 1fr) auto;
  min-height: 48px;
}

.event-row .r-sub {
  text-align: right;
}

/* ---------- Итоги по месяцам (#159): статьи × месяцы. Колонка статей стоит, месяцы листаются внутри карточки ---------- */
.mtot-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* Нижние углы — как у карточки: иначе белые липкие ячейки закрывают её скругление */
.mtot-wrap {
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  border-top: 1px solid var(--line-2);
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.mtot-wrap:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: -2px;
}

/* separate, а не collapse: с collapse у липкой колонки в Chromium пропадают рамки */
.mtot {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  min-width: 100%;
}

.mtot :is(th, td) {
  background: var(--panel);
  border-top: 1px solid var(--line-2);
  padding: 9px var(--s-4);
  text-align: right;
  vertical-align: baseline;
  white-space: nowrap;
}

.mtot :is(th, td):first-child {
  left: 0;
  padding-left: var(--s-5);
  position: sticky;
  text-align: left;
  z-index: 1;
}

.mtot :is(th, td):last-child {
  padding-right: var(--s-5);
}

.mtot :where(th[scope="row"]) {
  color: var(--ink);
  font-weight: 500;
  white-space: normal;
}

.mtot thead th {
  border-top: 0;
  color: var(--ink-3);
  font: 500 11px/1.3 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mtot thead small {
  font-size: inherit;
}

/* Нули отходят на второй план: глаз ищет месяцы, в которых что-то было */
.mtot .mtot-zero {
  color: var(--ink-3);
}

.mtot td a {
  color: var(--ink);
}

.mtot td a:hover {
  color: var(--acc);
}

.mtot .mtot-sec :is(th, td) {
  background: var(--tint);
  border-top-color: var(--line);
  font-weight: 700;
}

.mtot tfoot :is(th, td) {
  border-top: 2px solid var(--ink);
  font-size: 15px;
  font-weight: 800;
}

/* Показатели месяца (#161): группа над деньгами, «Выполнено» — доля плана */
/* Название ведёт в форму плана и факта: подчёркивание — подсказка, что группа кликается */
.mtot .mtot-metric .mtot-sec a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--edge);
  text-underline-offset: 3px;
}

.mtot .mtot-metric .mtot-sec a:hover {
  color: var(--acc);
}

/* Форма показателя: та же таблица, что в «Итогах», поля — прямо в ячейках, как в Excel руководителя */
.metric-form {
  max-width: none;
}

.metric-form .fld-pair {
  max-width: 40rem;
}

.metric-months {
  border: 0;
  display: grid;
  gap: 6px;
  margin: 0;
  min-width: 0;
  padding: 0;
}

.metric-months legend {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  padding: 0;
}

/* relative: скрытые подписи полей (absolute) иначе вылезают из прокрутки и двигают страницу вбок */
.metric-months .mtot-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  position: relative;
}

.metric-months .mtot :is(th, td) {
  padding: 6px var(--s-2);
}

.metric-months .mtot thead th {
  padding-block: 8px;
}

.metric-months .mtot :is(th, td):first-child {
  padding-left: var(--s-3);
}

.metric-months .mtot input {
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  min-height: 36px;
  padding: 0 var(--s-2);
  text-align: right;
  width: 9ch;
}

.metric-months .mtot input:hover {
  border-color: var(--edge-2);
}

.metric-months .mtot input:focus-visible {
  background: var(--panel);
  border-color: var(--acc);
  box-shadow: 0 0 0 3px var(--acc-2);
  outline: none;
}

@media (max-width: 760px) {
  .accs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .acc b {
    font-size: 17px;
  }

  /* Пять сегментов не помещаются в 390px: листаются внутри карточки, страница вбок не едет */
  .money-card .seg {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
  }

  .money-card .seg a {
    white-space: nowrap;
  }

  .filters {
    padding: var(--s-1) var(--s-4) var(--s-4);
  }

  .money-actions .btn {
    font-size: 13px;
    padding-inline: 10px;
  }

  .filters :is(input:not([type="submit"], [type="hidden"]), select) {
    min-height: 44px;
  }

  .filters input[type="search"] {
    flex-basis: 100%;
  }

  .filters select,
  .f-date {
    flex: 1 1 calc(50% - var(--s-1));
    min-width: 0;
  }

  .f-date input {
    flex: 1 1 auto;
    width: 0;
  }

  .flow-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  /* Строка журнала на телефоне: статья и дата слева, сумма и «⋯» справа на обе строки */
  .jrow {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .jrow .r-amt {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .jrow .r-act {
    grid-column: 3;
    grid-row: 1 / span 2;
  }

  .j-who {
    display: none;
  }

  .event-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .event-row .r-when {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .money-note,
  .cal-note,
  .pager {
    padding-inline: var(--s-4);
  }

  /* Липкая колонка не закрывает ячейку, в которую пришёл фокус с Tab */
  .mtot-wrap {
    scroll-padding-left: 40vw;
  }

  .mtot :is(th, td):first-child {
    max-width: 40vw;
    padding-left: var(--s-4);
  }

  .mtot :is(th, td):last-child {
    padding-right: var(--s-4);
  }
}
