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

/* 設定（SC-10）と初期設定（SC-00）、期首残高の入力。 */

.settings {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/*
 * 節の目次。画面の上に付いてくるタブの並びで、今いる節に下線（aria-current）。押せる大きさは44px。
 * 狭い幅（768px未満）は、上の帯（製品名の帯）の下に付ける。
 */
.settings-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  gap: var(--sp-1);
  margin: calc(var(--sp-3) * -1) 0 var(--sp-4);
  background: var(--c-bg);
  /* 地の色と下の線を、本文の左右の端まで伸ばす（後ろを流れる本文が、目次の横からのぞかないように）。 */
  border-image: linear-gradient(var(--c-bg) calc(100% - 1px), var(--c-border) 0) fill 0 / 0 / 0 100vmax;
}

.settings-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--sp-3);
  border: 0;
  background: transparent;
  color: var(--c-muted);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.settings-tab:hover {
  color: var(--c-text);
}

.settings-tab[aria-current] {
  color: var(--c-primary);
  box-shadow: inset 0 -3px 0 var(--c-primary);
}

.settings-tab:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: -2px;
}

/*
 * 目次が付いてくるので、Tab で戻った欄や、節へ移ったときの見出しが、目次の下に隠れないようにする。
 * ページ全体の余白（layout.css）に目次の高さ（44px）を足し、節の見出しは、その下に少し空けて着く（合わせて目次の下 16px）。
 */
:root:has(.settings-nav) {
  scroll-padding-top: calc(44px + var(--sp-2));
}

.settings-section {
  --form-w: 560px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  scroll-margin-top: var(--sp-2);
}

.settings-section > h2:focus,
.settings-head > h2:focus {
  outline: none;
}

/* 見出しの横に、いまの状態（締めた日など）を並べる。狭い幅では見出しの下へ折り返す。 */
.settings-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
}

/*
 * 入力欄・期首残高の表・区切り線・保存のボタンの右の端を、1つの幅（--form-w）にそろえる
 * （欄は左の約560px、表は約720px、線と保存はカードの右端で、右の端が3通りになり、間が空いていた）。
 * 補足文は欄の幅に合わせず、カードの幅まで使う（phrase.js の .nw で塊の切れ目を優先して折る）。
 * 幅は px で決める（em だと、文字の大きい入力欄だけが長くなり、右の端がずれた）。
 */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4) var(--sp-5);
  max-width: var(--form-w);
}

.settings-section .field > :not(.field-label, .field-hint, .field-error),
.setup-card .field > :not(.field-label, .field-hint, .field-error),
.opening-form .table-wrap,
.hash-full {
  max-width: var(--form-w);
}

/* 欄の説明を1文ずつ行に分けるとき（開業日の説明。settings.js の OPENED_HINT）。 */
.hint-line {
  display: block;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  max-width: var(--form-w);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--c-border);
}

.settings-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--c-border);
}

.settings-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.settings-block h3 {
  font-size: 16px;
}

.settings-block .field {
  width: 100%;
}

/* 64文字の控えは、32文字ずつの2行に等しく分ける（枠いっぱいに並べると、末尾の数文字だけが次の行に落ちた）。
   幅は、等幅の文字32字ぶん（半字の余裕つき）と、内側の余白と線。入れ物がそれより狭いときは、入れ物いっぱいで折る。 */
.hash-full {
  display: block;
  inline-size: min(100%, calc(32.5ch + 2 * var(--sp-3) + 2px));
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-s);
  background: var(--c-surface-2);
  overflow-wrap: anywhere;
  word-break: break-all;
}

.check-out:empty {
  display: none;
}

.check-out {
  width: 100%;
}

.check-result {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid;
  border-radius: var(--radius-m);
}

.check-result > svg {
  flex-shrink: 0;
  margin-top: 2px;
}

.check-result--ok {
  border-color: var(--c-income);
  background: var(--c-ok-bg);
}

.check-result--ok > svg {
  color: var(--c-income);
}

.check-result--ng {
  border-color: var(--c-danger);
  background: var(--c-danger-bg);
}

.check-result--ng > svg {
  color: var(--c-danger);
}

/* 書き出し: ボタンと選択欄を、同じ幅の2列の格子に並べる（仕訳帳のCSVのボタンは2列ぶん）。狭い幅は1列。 */
.export-title {
  margin-top: var(--sp-2);
  font-weight: 700;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
  width: 100%;
  max-width: var(--form-w);
}

.export-grid > .btn {
  justify-content: center;
  /* 名前が長くても、枠の外へ出さずに折り返す（文字とアイコンを枠の内側に収める）。 */
  height: auto;
  min-height: var(--control-h);
  padding-block: var(--sp-2);
  text-align: center;
  white-space: normal;
}

.export-grid > .export-wide {
  grid-column: 1 / -1;
}

@media (max-width: 639px) {
  .export-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* 節の中の左右2列の入れ物（settings.js の cols）。狭い幅では、今までどおり縦に並べる。 */
.settings-cols,
.settings-col {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
}

/*
 * 1280px以上: 節の中を左右2列に並べる（カードは全幅なのに入力が左の約560pxに集まって右が空き、ページも3,000px超と
 * 長かった。見た目の採点 第2回 幅1440）。節は縦に1列のまま（目次の「いまの節」の印を、上からの位置で決めるため）。
 * - 事業者: 左に事業者名と開業日、右に課税の区分・登録番号・端数処理。保存は2列の下、右の列の右端に。
 * - 期首残高: 左に期首の日付と表、右に「科目を足す」と合計と補足。
 * - データ: 4つのまとまりを2×2に。見た目: 明るさと表の行の密度を左右に。
 */
@media (min-width: 1280px) {
  .settings-cols {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-4) var(--sp-6);
  }

  .settings-cols .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-cols + .settings-actions {
    max-width: none;
  }

  .settings-section .opening-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "date others"
      "table totals"
      "table err"
      "table hint";
    gap: var(--sp-3) var(--sp-6);
    align-items: start;
  }

  .settings-section .opening-form > .opening-date {
    grid-area: date;
  }

  .settings-section .opening-form > .opening-others {
    grid-area: others;
  }

  .settings-section .opening-form > .opening-wrap {
    grid-area: table;
  }

  .settings-section .opening-form > .opening-totals {
    grid-area: totals;
  }

  .settings-section .opening-form > .opening-err {
    grid-area: err;
  }

  .settings-section .opening-form > .opening-hint {
    grid-area: hint;
  }

  .settings-section .opening-form + .settings-actions {
    max-width: none;
  }

  .settings-data {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-5) var(--sp-6);
  }

  /* 下の段の2つは、下の区切り線を付けない（上の段の線が、段の区切りになる）。 */
  .settings-data > .settings-block:nth-child(n + 3) {
    padding-bottom: 0;
    border-bottom: 0;
  }
}

@media (max-width: 767px) {
  .settings-nav {
    top: var(--topbar-h);
  }

  .settings-tab {
    flex: 1 1 auto;
    padding: 0 var(--sp-2);
  }

  :root:has(.settings-nav) {
    scroll-padding-top: calc(var(--topbar-h) + 44px + var(--sp-2));
  }

  /* 上の帯と目次の下 12px に着く（今までと同じ位置）。 */
  .settings-section {
    scroll-margin-top: var(--sp-1);
  }
}
