/* SPDX-FileCopyrightText: 2026 Ikki Nishihara and the kamoku contributors */
/* SPDX-License-Identifier: MIT OR Apache-2.0 */

/* 画面ごとの並び（ホーム）。登録と仕訳帳は screens-entry.css と screens-journal.css。 */

.card-title {
  font-size: var(--fs-h2);
}

/*
 * 未確認が集計に入っていないことの注記（帳票の期間の下と、ホームの口座の残高。report-pending.js）。
 * 注意ではなく、数字の読み方の事実なので、藍の印を付けた小さな1行にする。リンクは文のすぐ後ろに続ける。
 */
.pending-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
}

.pending-note > svg {
  margin-top: 2px;
  color: var(--c-primary);
}

/* ホームの「口座の残高」では、見出しのすぐ下に付ける（見出しの下の間を詰め、残高の行との間を空ける）。 */
.home-card > .pending-note {
  margin: calc(var(--sp-2) * -1) 0 var(--sp-3);
}

/* ---- ホーム ---- */
.home {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.month-picker {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.month-select {
  width: auto;
  min-width: 9.5em;
}

/* 前後の月の矢印。枠を付けて、押せるボタンに見せる。 */
.month-step {
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  color: var(--c-text);
}

/* 次にやること: 左に文とボタン、右（狭い幅では下）に件数と出金額の大きな数字（右の約700pxが空いていた）。 */
.next-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3) var(--sp-6);
  border-color: var(--c-primary);
  border-left-width: 4px;
  background: var(--c-primary-soft);
}

.next-card.has-figures {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.next-card .card-title {
  margin-bottom: var(--sp-2);
}

.next-text {
  font-size: 16px;
  font-weight: 700;
  text-wrap: pretty;
}

.next-figures {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-6);
}

.next-figures div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.next-figures dt {
  color: var(--c-muted);
  font-size: var(--fs-sm);
  font-weight: 700;
}

.next-figures dd {
  font-size: var(--fs-kpi);
  font-weight: 700;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

/* 幅1023px以下では、数字を文の下に置く（文の幅が狭くなり、「決め／て」と語の途中で折れた）。 */
@media (max-width: 1023px) {
  .next-card.has-figures {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }
}

.next-actions-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-4);
}

.kpi,
.kpi-host {
  container-type: inline-size;
}

.kpi {
  display: flex;
  flex-direction: column;
  padding: var(--sp-4) var(--sp-5);
}

.kpi-label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  color: var(--c-muted);
  font-size: var(--fs-sm);
  font-weight: 700;
}

/*
 * 大きな数字。桁の多い金額でも、カードの枠からはみ出さない大きさにする（幅390の2列で、10桁の金額がはみ出した）。
 * --chars は金額の文字の数（home-parts.js が入れる）。実測で1文字は約0.64字幅、「円」は約1.1字幅なので、
 * 枠の幅（100cqi）をその合計で割った大きさを上限にする。ふだんの桁（7〜9文字）では、いつもの大きさのまま。
 */
.kpi-value {
  --kpi-size: var(--fs-kpi);
  margin-top: var(--sp-1);
  font-size: min(var(--kpi-size), calc(100cqi / (var(--chars, 7) * 0.64 + 1.1)));
  font-weight: 700;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 前月比・前の月の実額。補助の文字だが、小さく淡いと読みにくかったので本文の色にする（大きさで金額と分ける）。 */
.kpi-diff {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
  color: var(--c-text);
  font-size: var(--fs-sm);
}

/*
 * 4枚の数字のカードは同じ高さに並ぶ。下の行（前月比と、年の利益の内訳）はカードの下の端にそろえる
 * （月のカードだけ、大きな金額の下に空白が残り、年の利益のカードと詰まり方が違って見えた）。
 */
.kpi > .kpi-diff,
.kpi > .kpi-notes {
  margin-top: auto;
  padding-top: var(--sp-2);
}

/* 2行に折れても、矢印は1行目の高さに置く。 */
.kpi-diff svg {
  margin-top: 2px;
}

.kpi-note {
  margin-top: var(--sp-2);
  color: var(--c-muted);
  font-size: var(--fs-xs);
  text-wrap: pretty;
}

/* 数字のカードの補足（期間・売上・経費）。1つずつの行にして、名前と金額が別の行に割れないようにする。 */
.kpi-notes {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--sp-2);
  color: var(--c-muted);
  font-size: var(--fs-xs);
}

.kpi-notes div {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
}

.kpi-notes dd {
  color: var(--c-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 下段の3列は、下の端をそろえる（列ごとに高さが違い、段差の空白ができた）。 */
.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-4);
  align-items: stretch;
}

.home-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
}

.home-stack > :last-child {
  flex: 1 1 auto;
}

/* カードの見出しの右の「口座の一覧」。 */
.card-link {
  font-weight: 600;
}

.ledger-text {
  font-weight: 600;
}

.ledger-more {
  margin-top: var(--sp-3);
}

.ledger-more summary {
  color: var(--c-primary);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}

.ledger-more[open] > summary {
  margin-bottom: var(--sp-2);
}

.ledger-more .facts {
  margin-top: var(--sp-2);
}

.rows {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--c-border);
}

.row-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-s);
  background: var(--c-surface-2);
  color: var(--c-muted);
}

.row-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.row-sub {
  color: var(--c-muted);
  font-size: var(--fs-xs);
  font-weight: 400;
}

.row-value {
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

/*
 * 口座の残高: 枠の中が狭いとき（名前・金額を横に並べるのに要る約21em より狭い。文字の大きさに合わせて em で測る）は、
 * 1行目に名前、2行目に種類と金額を置く。横に並べると、銀行の口座の名前が2行に折れて窮屈だった（2026-10-15 の見た目の採点、幅390）。
 */
.wallets-card {
  container-type: inline-size;
  container-name: wallets;
}

@container wallets (max-width: 21.5em) {
  .wallets-card .row {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    grid-template-areas:
      "icon name name"
      "icon sub value";
    column-gap: var(--sp-3);
    align-items: baseline;
  }

  .wallets-card .row-icon {
    grid-area: icon;
    align-self: center;
  }

  .wallets-card .row-main {
    display: contents;
  }

  .wallets-card .row-main > .keep {
    grid-area: name;
  }

  .wallets-card .row-sub {
    grid-area: sub;
  }

  .wallets-card .row-value {
    grid-area: value;
  }
}

.totals {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-top: var(--sp-3);
}

.totals div,
.facts div {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
}

.totals dt,
.facts dt {
  color: var(--c-muted);
  font-size: var(--fs-sm);
}

.totals dd,
.facts dd {
  font-weight: 700;
  white-space: nowrap;
}

.rank {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: 0;
}

.rank-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--sp-1) var(--sp-3);
  align-items: baseline;
}

.rank-name {
  min-width: 0;
}

.rank-value {
  font-weight: 700;
  white-space: nowrap;
}

/* 棒の下地は枠の色（白い地の上の surface-2 は、ライトでほとんど見えなかった）。 */
.rank-bar {
  position: relative;
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--c-border);
}

.rank-bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--w, 0%);
  border-radius: 3px;
  background: var(--c-primary);
}

.facts {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.hash-manual {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
}

.hash-manual:empty {
  display: none;
}

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

  /* 2列のときは、台帳と消費税を横に並べて、下の段を埋める（高さもそろえる）。 */
  .home-stack {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: stretch;
  }

  .home-stack > *,
  .home-stack > :last-child {
    flex: 1 1 0;
  }
}

@media (max-width: 767px) {
  .home {
    gap: var(--sp-3);
  }

  .next-card.has-figures {
    grid-template-columns: minmax(0, 1fr);
  }

  .next-figures dd {
    font-size: 20px;
  }

  .kpis {
    gap: var(--sp-3);
  }

  .kpi {
    padding: var(--sp-3) var(--sp-4);
  }

  .kpi-value {
    --kpi-size: 20px;
  }

  .month-select {
    min-width: 0;
  }

  .home-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--sp-3);
  }

  .home-stack {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }

  .home-stack > *,
  .home-stack > :last-child {
    flex: none;
  }
}

