/* 債権管理 — 業務ツール（青みのグレーに落ち着いた青）
   飾りは減らし、罫線・余白・配置と状態の形（○・半分塗り・●）で読みやすくする。 */
:root {
  color-scheme: dark;

  /* 面と文字（青みのグレー） */
  --bg: #15191f;
  --surface: #1b2028;
  --surface-2: #232934;
  --hover: #1f2530;
  --input-bg: #10141a;
  --ink: #e6eaf0;
  --ink-2: #c2c9d4;
  --muted: #98a2b0;
  --placeholder: #808b9a;
  --line: #2b323d;
  --line-soft: #232a33;
  --line-strong: #3b4451;
  --field-line: #5d6878;   /* 入力欄の枠は背景と 3:1 以上にする */

  /* 差し色は青の1色。主ボタン・選択中のメニュー・進捗バーに使う */
  --accent: #6aa5f5;
  --accent-strong: #2f6fd1;
  --accent-hover: #2860b8;  /* ホバーは暗くして白文字のコントラストを保つ */
  --accent-ink: #ffffff;
  --accent-soft: rgba(106, 165, 245, 0.14);
  --accent-line: rgba(106, 165, 245, 0.45);
  /* 赤はマイナスの金額・削除・エラーだけに使う */
  --neg: #f0787c;
  --neg-soft: rgba(240, 120, 124, 0.14);
  --neg-line: rgba(240, 120, 124, 0.45);
  --track: #2b323d;
  --bar: #6aa5f5;

  --rail-w: 216px;
  --drawer-w: 540px;
  --font: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  /* 金額は等幅の欧文フォントで桁をそろえる。ない端末では本文のフォント＋等幅数字 */
  --font-num: "Cascadia Mono", Consolas, "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", Meiryo, system-ui, sans-serif;

  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  line-height: 1.6;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
::selection { background: rgba(106, 165, 245, 0.35); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 操作後にプログラムで移した見出しのフォーカスには枠を出さない */
[tabindex="-1"]:focus { outline: none; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
td.num, .money { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.neg { color: var(--neg); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- ボタン ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  min-height: 40px; padding: 0 16px; border-radius: 4px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.button:hover { background: var(--surface-2); border-color: #4c5664; }
.button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); font-weight: 700; }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.danger { color: var(--neg); border-color: var(--neg-line); }
.button.danger:hover { background: var(--neg-soft); border-color: var(--neg); }
.button.ghost { border-color: transparent; }
.button.ghost:hover { background: var(--surface-2); }
/* 行の「入金」: ふだんは控えめ、触れると青に変わって主操作だと分かる */
.button.pay { background: var(--surface-2); }
.button.pay:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
.button.small { min-height: 32px; padding: 0 12px; font-size: 0.85rem; }
.button.wide { width: 100%; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-button {
  width: 40px; height: 40px; border: 0; border-radius: 4px; background: transparent;
  font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); flex: none;
}
.icon-button:hover { background: var(--surface-2); color: var(--ink); }
.link-button {
  border: 0; background: none; padding: 0; color: var(--ink); font-weight: 700; cursor: pointer;
  text-align: left; text-decoration: underline; text-decoration-color: var(--line-strong);
  text-underline-offset: 4px;
}
.link-button:hover { text-decoration-color: var(--accent); }
.text-button {
  border: 0; background: none; padding: 4px 6px; color: var(--muted); font-size: 0.8rem;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.text-button:hover { color: var(--accent); }

/* ---------- ロゴ ---------- */
.brand-mark {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 8px; background: var(--accent-strong); color: var(--accent-ink);
  font-weight: 700; font-size: 1.05rem;
}

/* ---------- ログイン ---------- */
.login-view {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: var(--bg);
}
.login-card {
  width: min(420px, 100%); display: grid; gap: 18px; padding: 32px 28px;
  background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--accent);
  border-radius: 8px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand .brand-mark { width: 48px; height: 48px; font-size: 1.45rem; }
.login-brand h1 { font-size: 1.6rem; letter-spacing: 0.06em; line-height: 1.3; }
.login-brand p { font-size: 0.82rem; }

/* ---------- 骨格：左の縦メニュー ---------- */
.rail {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--rail-w); z-index: 20;
  display: flex; flex-direction: column; gap: 18px; padding: 20px 14px 16px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.brand-text strong { display: block; font-size: 1.02rem; letter-spacing: 0.06em; line-height: 1.3; }
.brand-text span { display: block; font-size: 0.7rem; color: var(--muted); }
.new-claim { width: 100%; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.tab {
  position: relative; display: flex; align-items: center; width: 100%; min-height: 40px;
  padding: 0 12px; border: 0; border-radius: 4px; background: none; color: var(--muted);
  font-weight: 600; text-align: left; cursor: pointer;
}
.tab:hover { color: var(--ink); background: var(--hover); }
.tab.active { color: var(--ink); background: var(--surface-2); font-weight: 700; }
.tab.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 2px; background: var(--accent);
}
.session { margin-top: auto; display: grid; gap: 6px; padding: 12px 4px 0; border-top: 1px solid var(--line); }
.session-who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.session-name { font-weight: 700; }
.role-badge {
  font-size: 0.72rem; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 3px;
  color: var(--ink-2); font-weight: 700;
}
.role-badge.admin { border-color: var(--accent-line); color: var(--accent); }
.session .button { justify-self: start; padding: 0 8px; margin-left: -8px; color: var(--muted); }
.session .button:hover { color: var(--ink); }

.app-main { margin-left: var(--rail-w); padding: 28px 32px 56px; }
.panel { display: grid; gap: 20px; max-width: 1280px; }
.panel > *, .drawer-body > *, .dialog-body > * { min-width: 0; }
/* 広い画面では詳細パネルを横に並べ、一覧を見たまま切り替えられるようにする */
body.drawer-split .app-main { margin-right: var(--drawer-w); }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.page-head h1 { font-size: 1.5rem; letter-spacing: 0.04em; line-height: 1.35; }
.page-head p { font-size: 0.86rem; }
.page-figure { display: grid; justify-items: end; line-height: 1.2; text-align: right; }
.page-figure .label { font-size: 0.74rem; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; }
.page-figure .value { font-family: var(--font-num); font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.page-figure .sub { font-size: 0.8rem; color: var(--muted); }

/* 罫線で区切る見出し（帳簿の欄見出し） */
.rule-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; color: var(--muted);
}
.rule-head::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- ホーム ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 32px; align-items: start; }
body.drawer-split .home-grid { grid-template-columns: minmax(0, 1fr); }
/* 横並びのときは一覧の幅が狭くなるので、補助の列を隠す */
body.drawer-split .col-wide { display: none; }
body.drawer-split .home-side { position: static; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 32px; }
.home-side { display: grid; gap: 28px; position: sticky; top: 24px; }

/* 回収待ちリスト */
.queue-head, .queue-row {
  display: grid; align-items: center; gap: 14px;
  grid-template-columns: 64px minmax(0, 1.4fr) 116px minmax(120px, 1fr) 72px;
}
.queue-head {
  padding: 0 12px 8px; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--muted); border-bottom: 1px solid var(--line-strong);
}
.queue-head .r { text-align: right; }
.queue-list { list-style: none; margin: 0; padding: 0; }
.queue-row { padding: 12px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.queue-row:hover { background: var(--hover); }
.queue-row:focus-visible { outline-offset: -2px; }
.queue-row.selected { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.days { display: grid; line-height: 1.15; }
.days b { font-family: var(--font-num); font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.days .unit { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-left: 2px; }
.days .from { font-size: 0.7rem; color: var(--muted); }
.who { display: grid; line-height: 1.4; min-width: 0; }
.who strong, .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who strong { font-size: 1rem; }
.who span { font-size: 0.78rem; color: var(--muted); }
.queue-row .remaining { text-align: right; font-family: var(--font-num); font-weight: 700; font-size: 1.02rem; font-variant-numeric: tabular-nums; }
.progress-cell { display: grid; gap: 5px; }
.progress-cell .of { font-size: 0.74rem; color: var(--muted); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.queue-row .action { text-align: right; }
.queue-empty { padding: 48px 16px; text-align: center; color: var(--muted); border-bottom: 1px solid var(--line-soft); }

/* 進み具合の細い棒。白い目盛りは「買取額」の位置（ここを超えると元が取れる） */
.bar { position: relative; height: 4px; border-radius: 2px; background: var(--track); }
.bar-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 2px; background: var(--bar); }
.bar-tick { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); }
.bar.large { height: 8px; border-radius: 4px; }
.bar.large .bar-fill { border-radius: 4px; }
.bar.large .bar-tick { top: -4px; bottom: -4px; }

/* 収支表：回収 − 買取 ＝ 実現収支、＋ 未回収 ＝ 見込み収支 */
.statement { display: grid; font-size: 0.9rem; }
.stmt-row { display: grid; grid-template-columns: 14px auto 1fr auto; align-items: baseline; gap: 6px; padding: 6px 0; }
.stmt-row .op { color: var(--muted); font-family: var(--font-num); text-align: center; }
.stmt-row .leader { min-width: 8px; }
.stmt-row .amt { font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: right; }
.stmt-row.total { border-top: 1px solid var(--line-strong); font-weight: 700; }
.stmt-row.grand { border-top: 3px double var(--line-strong); font-weight: 700; font-size: 1rem; }
.stmt-note { margin-top: 10px; display: grid; gap: 4px; font-size: 0.78rem; color: var(--muted); }
.stmt-note .money { color: var(--ink-2); }

.status-list { display: grid; }
.status-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  width: 100%; min-height: 42px; padding: 6px 6px; border: 0; border-bottom: 1px solid var(--line-soft);
  background: none; color: var(--ink); text-align: left; cursor: pointer;
}
.status-item:hover { background: var(--hover); }
.status-item .cnt { font-family: var(--font-num); font-weight: 700; }
.status-item .cnt small { font-family: var(--font); font-size: 0.72rem; font-weight: 600; color: var(--muted); margin-left: 2px; }
.status-item .amt { min-width: 92px; text-align: right; font-family: var(--font-num); font-size: 0.8rem; color: var(--muted); }

/* ---------- 状態の印 ---------- */
/* ○ 未回収 ／ 半分塗り 一部回収 ／ ● 回収済 ／ 破線 貸倒。終わったものは文字も沈める */
.mark { display: inline-flex; align-items: center; gap: 7px; font-size: 0.8rem; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.mark::before {
  content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid currentColor;
}
.mark.partial::before { background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
.mark.paid, .mark.written_off { color: var(--muted); font-weight: 600; }
.mark.paid::before { background: currentColor; }
.mark.written_off::before { border-style: dashed; }

/* ---------- ツールバー・絞り込み ---------- */
.toolbar { display: flex; gap: 12px 16px; flex-wrap: wrap; align-items: center; }
.search {
  flex: 1 1 260px; min-height: 40px; padding: 0 14px; border: 1px solid var(--field-line);
  border-radius: 4px; background: var(--input-bg);
}
.search:hover { border-color: #7a8697; }
.filter { display: flex; flex-wrap: wrap; gap: 2px 4px; }
.filter button {
  display: inline-flex; align-items: baseline; gap: 6px; min-height: 34px; padding: 4px 10px;
  border: 0; border-radius: 4px; background: none; color: var(--muted);
  font-weight: 600; font-size: 0.88rem; cursor: pointer;
}
.filter button:hover { color: var(--ink); background: var(--hover); }
.filter button.active { color: var(--ink); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
.filter .count { font-family: var(--font-num); font-size: 0.78rem; color: var(--muted); }

/* ---------- 表（罫線の台帳） ---------- */
/* position: relative で、中の sr-only（絶対配置）が横スクロール枠の外へはみ出さないようにする */
.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line-soft); }
thead th {
  padding-top: 0; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em; color: var(--muted);
  white-space: nowrap; border-bottom: 1px solid var(--line-strong);
}
th.num, td.num { text-align: right; }
.sort {
  display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; letter-spacing: inherit; cursor: pointer;
}
.sort:hover { color: var(--ink); }
.sort::after { content: "↕"; opacity: 0.35; }
th[aria-sort] .sort { color: var(--ink); }
th[aria-sort="ascending"] .sort::after { content: "↑"; opacity: 1; color: var(--accent); }
th[aria-sort="descending"] .sort::after { content: "↓"; opacity: 1; color: var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
tr.selected td { background: var(--surface-2); }
tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
/* 終わった債権は一段沈める */
tr.closed td { color: var(--muted); }
td.name { font-weight: 600; }
.nowrap, td.date { white-space: nowrap; }
td.date { font-size: 0.86rem; }
td .sub { display: block; font-size: 0.76rem; color: var(--muted); font-weight: 400; }
td.state { min-width: 116px; }
td.state .bar { width: 96px; margin-top: 6px; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .button + .button { margin-left: 6px; }
tfoot td { font-weight: 700; border-top: 3px double var(--line-strong); border-bottom: 0; }
.empty { padding: 44px 16px; text-align: center; color: var(--muted); }
code { font-family: var(--font-num); font-size: 0.85rem; color: var(--ink-2); }

/* ---------- フォーム ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 0.84rem; font-weight: 700; color: var(--ink); }
.field em { font-style: normal; font-size: 0.7rem; color: var(--neg); margin-left: 4px; font-weight: 700; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--field-line);
  border-radius: 4px; background: var(--input-bg);
}
.field input:hover, .field select:hover, .field textarea:hover { border-color: #7a8697; }
.field textarea { resize: vertical; }
.field.checkbox { display: flex; align-items: center; gap: 10px; align-self: end; min-height: 40px; }
.field.checkbox input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--placeholder); opacity: 1; }
input:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 100px var(--input-bg) inset;
  caret-color: var(--ink);
}
.hint { color: var(--muted); font-size: 0.76rem; }
.form-error { color: #ffb8bb; background: var(--neg-soft); border: 1px solid var(--neg-line); border-radius: 4px; padding: 8px 12px; font-size: 0.88rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: 1 / -1; }
.inline-form {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
}
.inline-form .field { flex: 1 1 200px; }
.preview {
  align-self: end; min-height: 40px; display: flex; flex-direction: column; justify-content: center;
  padding: 6px 12px; border: 1px dashed var(--line-strong); border-radius: 4px;
  font-size: 0.82rem; color: var(--muted);
}
.preview strong { color: var(--ink); font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ---------- 中央のダイアログ（登録・修正） ---------- */
.dialog {
  width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop, .drawer::backdrop { background: rgba(5, 4, 3, 0.7); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 1.1rem; }
.dialog-body { padding: 18px 20px; display: grid; gap: 14px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }

/* ---------- 右から出る詳細パネル ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; left: auto; z-index: 40;
  width: min(var(--drawer-w), 100vw); height: 100vh; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; border-left: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); box-shadow: -24px 0 60px rgba(0, 0, 0, 0.45);
}
.drawer[open] { animation: drawer-in 0.18s ease-out; }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer[open] { animation: none; } }
.drawer-inner { height: 100%; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 22px; border-bottom: 1px solid var(--line); }
.drawer-kicker { font-size: 0.78rem; color: var(--muted); }
.drawer-head h2 { font-size: 1.35rem; letter-spacing: 0.03em; line-height: 1.35; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 28px; display: grid; gap: 22px; align-content: start; }
.drawer-foot { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 22px; border-top: 1px solid var(--line); background: var(--surface-2); }
.drawer-foot .spacer { flex: 1; }

.balance { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.balance .label { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; color: var(--muted); }
.balance-value { display: block; font-family: var(--font-num); font-size: 2.2rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.balance .of { font-size: 0.82rem; color: var(--muted); font-family: var(--font-num); }
.bar-legend { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 0.76rem; color: var(--muted); }
.bar-legend .tick-label::before { content: ""; display: inline-block; width: 2px; height: 10px; margin-right: 6px; background: var(--ink); vertical-align: -1px; }
.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; margin: 0; }
.figures div { display: grid; gap: 2px; }
.figures dt { font-size: 0.74rem; font-weight: 700; color: var(--muted); }
.figures dd { margin: 0; font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; }
.figures dd small { font-family: var(--font); font-weight: 400; font-size: 0.74rem; color: var(--muted); }

/* 入金フォーム：金額欄に最初からカーソル、Enterで記録 */
.pay-form {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 4px;
}
.pay-form h3 { grid-column: 1 / -1; font-size: 0.92rem; }
.pay-form .amount-field { grid-column: 1 / -1; }
.amount-row { display: flex; gap: 8px; }
.amount-row input { flex: 1; min-width: 0; min-height: 46px; font-family: var(--font-num); font-size: 1.15rem; }
.pay-form .actions-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.pay-form .form-error { grid-column: 1 / -1; }
.kbd-hint { font-size: 0.74rem; color: var(--muted); }

/* 通帳：入金ごとに残額がどう減ったか */
.passbook th, .passbook td { padding: 8px 8px; }
.passbook td.date { white-space: nowrap; font-family: var(--font-num); font-size: 0.84rem; color: var(--ink-2); }
.passbook tr.opening td { color: var(--muted); }
.passbook td.bal { font-weight: 700; }
.passbook td.actions { width: 1%; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 0.88rem; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

.notice {
  display: flex; align-items: center; gap: 16px; padding: 12px 14px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-size: 0.88rem;
}
.warning-box { padding: 10px 14px; border-radius: 4px; background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--ink); font-size: 0.88rem; }
.key-box { display: flex; gap: 10px; align-items: center; padding: 12px; background: var(--input-bg); border: 1px solid var(--line-strong); border-radius: 4px; }
.key-box code { flex: 1; word-break: break-all; font-size: 0.9rem; color: var(--ink); }

.diff { display: grid; gap: 2px; font-size: 0.82rem; }
.diff .from { color: var(--muted); text-decoration: line-through; }
.diff .to { color: var(--ink); font-weight: 600; }

/* ---------- トースト（詳細パネルの上にも出す） ---------- */
.toast {
  position: fixed; inset: auto auto 24px 50%; transform: translateX(-50%); z-index: 60; margin: 0;
  max-width: calc(100vw - 32px); padding: 10px 18px; border: 1px solid var(--line-strong); border-radius: 4px;
  background: #262d38; color: var(--ink); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-weight: 600;
}
.toast.error { background: #3a1f25; color: #ffbcc0; border-color: var(--neg-line); }

/* ---------- 詳細パネルを横に並べない幅では中央寄せの余白を調整 ---------- */
@media (max-width: 1180px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-side { position: static; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

/* ---------- タブレット・スマホ：上にバー、下にメニュー ---------- */
@media (max-width: 899px) {
  .rail {
    position: sticky; top: 0; bottom: auto; width: auto; z-index: 20;
    flex-direction: row; align-items: center; gap: 10px; padding: 10px 14px;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .brand-mark { width: 32px; height: 32px; font-size: 1rem; }
  .brand-text span { display: none; }
  .new-claim { width: auto; min-height: 36px; padding: 0 12px; margin-left: auto; }
  .session { margin: 0; padding: 0; border: 0; }
  .session-who { display: none; }
  .session .button { margin: 0; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; flex-direction: row; gap: 0;
    padding: 0 4px env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line);
  }
  .tab { flex: 1; justify-content: center; min-height: 56px; padding: 0 2px; border-radius: 0; font-size: 0.8rem; text-align: center; }
  .tab.active { background: none; }
  .tab.active::before { top: 0; bottom: auto; left: 22%; right: 22%; width: auto; height: 3px; }
  .app-main { margin-left: 0; padding: 18px 16px calc(84px + env(safe-area-inset-bottom)); }
  .hide-sm { display: none; }
}

@media (max-width: 720px) {
  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 1.3rem; }
  .page-figure { justify-items: start; text-align: left; }
  .page-figure .value { font-size: 1.6rem; }
  .queue-head { display: none; }
  .queue-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "who days" "rem action" "prog prog";
    gap: 6px 12px; padding: 14px 4px;
  }
  .queue-row .who { grid-area: who; }
  .queue-row .days { grid-area: days; justify-items: end; text-align: right; }
  .queue-row .remaining { grid-area: rem; text-align: left; font-size: 1.15rem; }
  .queue-row .action { grid-area: action; }
  .queue-row .progress-cell { grid-area: prog; }
  .col-wide, .col-sm-hide { display: none; }
  td.state { min-width: 0; }
  td.state .bar { width: 72px; }
  th, td { padding: 9px 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .figures { grid-template-columns: 1fr 1fr; }
  .pay-form { grid-template-columns: 1fr; }
  .drawer-body { padding: 16px 16px 24px; }
  .drawer-head { padding-left: 16px; }
  .drawer-foot { padding: 12px 16px; }
  .balance-value { font-size: 1.9rem; }
}

/* ---------- 印刷（紙では白地・黒文字） ---------- */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #f4f4f4; --hover: #fff; --input-bg: #fff;
    --ink: #111; --ink-2: #333; --muted: #555; --placeholder: #888;
    --line: #ddd; --line-soft: #e6e6e6; --line-strong: #999; --field-line: #999;
    --accent: #1d4f91; --accent-soft: #fff; --accent-line: #1d4f91;
    --neg: #b0372d; --neg-soft: #fff; --neg-line: #b0372d;
    --track: #e6e6e6; --bar: #555;
  }
  .rail, .nav, .toolbar, .button, .filter, .text-button, .icon-button, .drawer-foot, .pay-form, .toast { display: none !important; }
  /* 詳細パネルを開いているときは、その債権だけを印刷する */
  body:has(.drawer[open]) .shell { display: none; }
  .drawer { position: absolute; top: 0; left: 0; right: auto; width: 100%; height: auto; border: 0; box-shadow: none; }
  .drawer::backdrop, .dialog::backdrop { background: transparent; }
  .drawer-body { overflow: visible; }
  .app-main { margin: 0; padding: 0; }
  body.drawer-split .app-main { margin-right: 0; }
  .home-grid { grid-template-columns: 1fr; }
}
