/* 領収書 仕分けツール — 画面スタイル
   ・長時間の入力作業を想定して、文字は大きめ／余白は広め
   ・明るい画面と暗い画面の両方に対応（OSの設定に追従＋手動切替）
   ・色は変数にまとめてあるので、ここだけ直せば全体の印象が変わります
*/

/* ── 配色（明るい画面） ─────────────────────────── */
/* 藍色（インディゴ）を基調に、紙の帳票を思わせる淡いグレーで組む */
:root {
  --bg:          #f1f3f8;
  --surface:     #ffffff;
  --surface-2:   #f6f7fb;
  --surface-3:   #eceef5;
  --line:        #e0e4ed;
  --line-strong: #c2c9d8;
  --text:        #171d2b;
  --text-2:      #5b6575;
  --text-3:      #8b94a5;

  --accent:      #4056d6;
  --accent-hi:   #3242b4;
  --accent-soft: #e9ecfc;
  --on-accent:   #ffffff;

  --ok:          #0f7a4d;
  --ok-soft:     #e0f4ea;
  --warn:        #955806;
  --warn-soft:   #fcf0dc;
  --err:         #bd2130;
  --err-soft:    #fdeaec;

  --radius:   12px;
  --radius-l: 16px;
  --shadow:   0 1px 2px rgba(23,29,43,.05), 0 4px 14px rgba(23,29,43,.06);
  --shadow-l: 0 8px 24px rgba(23,29,43,.10), 0 28px 70px rgba(23,29,43,.20);
  --focus:    0 0 0 3px rgba(64,86,214,.28);
}

/* ── 配色（暗い画面）───────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0e1118;
    --surface:     #161a24;
    --surface-2:   #1c212e;
    --surface-3:   #252c3c;
    --line:        #2e3648;
    --line-strong: #46506a;
    --text:        #e9ecf4;
    --text-2:      #a6afc1;
    --text-3:      #737e93;

    --accent:      #8b9bff;
    --accent-hi:   #a3b0ff;
    --accent-soft: #232b4e;
    --on-accent:   #0e1230;

    --ok:          #52cd92;
    --ok-soft:     #14301f;
    --warn:        #f0b45e;
    --warn-soft:   #392b13;
    --err:         #f58a92;
    --err-soft:    #3d1c20;

    --shadow:   0 1px 2px rgba(0,0,0,.40), 0 4px 14px rgba(0,0,0,.32);
    --shadow-l: 0 8px 24px rgba(0,0,0,.45), 0 28px 70px rgba(0,0,0,.60);
    --focus:    0 0 0 3px rgba(139,155,255,.35);
  }
}

:root[data-theme="dark"] {
  --bg:          #0e1118;
  --surface:     #161a24;
  --surface-2:   #1c212e;
  --surface-3:   #252c3c;
  --line:        #2e3648;
  --line-strong: #46506a;
  --text:        #e9ecf4;
  --text-2:      #a6afc1;
  --text-3:      #737e93;

  --accent:      #8b9bff;
  --accent-hi:   #a3b0ff;
  --accent-soft: #232b4e;
  --on-accent:   #0e1230;

  --ok:          #52cd92;
  --ok-soft:     #14301f;
  --warn:        #f0b45e;
  --warn-soft:   #392b13;
  --err:         #f58a92;
  --err-soft:    #3d1c20;

  --shadow:   0 1px 2px rgba(0,0,0,.40), 0 4px 14px rgba(0,0,0,.32);
  --shadow-l: 0 8px 24px rgba(0,0,0,.45), 0 28px 70px rgba(0,0,0,.60);
  --focus:    0 0 0 3px rgba(139,155,255,.35);
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic",
               "Noto Sans JP", "Meiryo", system-ui, sans-serif;
  font-size: 0.94rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.5em; padding: .05em .4em; margin: 0 .1em;
  font: inherit; font-size: .76em; text-align: center;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
}

::selection { background: var(--accent-soft); }

/* ── ボタン ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  padding: .45em .9em;
  font: inherit; font-size: .9rem; line-height: 1.4;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) {
  background: var(--surface-3); border-color: var(--line-strong);
  box-shadow: var(--shadow);
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: default; }

.btn-primary {
  /* わずかな縦グラデーションと、アクセント色のにじむ影で立体感を出す */
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 100%);
  border-color: var(--accent);
  color: var(--on-accent); font-weight: 700;
  box-shadow: 0 1px 2px rgba(23,29,43,.10),
              0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-hi) 100%);
  border-color: var(--accent-hi);
  box-shadow: 0 2px 4px rgba(23,29,43,.12),
              0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn-primary kbd {
  color: var(--on-accent);
  background: color-mix(in srgb, var(--on-accent) 16%, transparent);
  border-color: color-mix(in srgb, var(--on-accent) 32%, transparent);
}

.btn-quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-icon { padding: .4em .6em; }
.btn-go { padding: .6em 1.3em; font-size: 1rem; }

/* ── ヘッダー ───────────────────────────────────── */
.topbar {
  flex: none;
  position: relative;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem .9rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  z-index: 30;
}
/* 上端の細いアクセント。画面の「顔」になる1本 */
.topbar::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg,
      var(--accent) 0%, color-mix(in srgb, var(--accent) 55%, #7c3aed) 55%,
      color-mix(in srgb, var(--accent) 45%, #0ea5e9) 100%);
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 800; font-size: 1.02rem; }
.brand span[aria-hidden] { font-size: 1.25rem; }
.brand-text { letter-spacing: .01em; }

.modes {
  display: flex; gap: .2rem; background: var(--surface-3);
  padding: .22rem; border-radius: 999px;
  border: 1px solid var(--line);
}
.mode {
  display: flex; align-items: center; gap: .4em;
  padding: .34em 1.05em; font: inherit; font-size: .9rem;
  color: var(--text-2); background: transparent;
  border: 0; border-radius: 999px; cursor: pointer;
  transition: color .12s, background .12s, box-shadow .12s;
}
.mode:hover { color: var(--text); }
.mode.active {
  background: var(--surface); color: var(--accent); font-weight: 700;
  box-shadow: var(--shadow);
}
.mode-badge {
  min-width: 1.5em; padding: 0 .4em; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn);
  font-size: .76rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.mode-badge:empty, .mode-badge[data-zero="1"] { display: none; }

.progress-wrap { display: flex; align-items: center; gap: .6rem; min-width: 190px; }
.progress { flex: 1; height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress-bar { height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s ease; }
.progress-text { font-size: .78rem; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 50;
  min-width: 230px; padding: .3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-l);
}
.menu button {
  display: block; width: 100%; padding: .5em .7em; text-align: left;
  font: inherit; font-size: .9rem; color: var(--text);
  background: transparent; border: 0; border-radius: 7px; cursor: pointer;
}
.menu button:hover { background: var(--surface-3); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem .2rem; }

/* ── 状態バー ───────────────────────────────────── */
.statusbar {
  flex: none;
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  padding: .3rem .9rem;
  font-size: .78rem; color: var(--text-2);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.statusbar code {
  padding: .05em .45em; border-radius: 5px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: .95em; font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.sb-right { margin-left: auto; display: flex; gap: .8rem; align-items: center; }

/* ── 仕分けモード ───────────────────────────────── */
.triage { flex: 1; min-height: 0; display: flex; }
.triage-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr minmax(390px, 30vw); gap: 1px; background: var(--line); }

/* 原本ビューア */
.viewer-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0;
               background: var(--surface); position: relative; }
.viewer-stage {
  flex: 1; min-height: 0; overflow: auto; padding: 1rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-3);
  background-image:
    linear-gradient(45deg, rgba(128,128,128,.06) 25%, transparent 25%, transparent 75%, rgba(128,128,128,.06) 75%),
    linear-gradient(45deg, rgba(128,128,128,.06) 25%, transparent 25%, transparent 75%, rgba(128,128,128,.06) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
}
.viewer-canvas { position: relative; display: inline-block; line-height: 0; max-width: 100%; max-height: 100%; }
.viewer-canvas img {
  display: block;
  /* 既定は「全体表示」。--stage-h は表示領域の高さをJS側で実測して入れている
     （max-height:100% は親の高さが auto だと効かないため） */
  max-width: 100%; max-height: var(--stage-h, 70vh);
  background: #fff; box-shadow: 0 6px 26px rgba(0,0,0,.28); border-radius: 3px;
  transition: transform .15s ease;
}
.viewer-canvas.zoomed { max-width: none; max-height: none; }
.viewer-canvas.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-canvas:not(.zoomed) img { cursor: zoom-in; }
.viewer-canvas embed { width: 78vh; max-width: 100%; height: 78vh; background: #fff; border-radius: 3px; }

/* AIが読み取った位置のハイライト */
.hlbox {
  position: absolute; pointer-events: none; border-radius: 4px;
  border: 2px solid transparent; background: transparent;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.hlbox.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: 0 0 0 9999px rgba(0,0,0,.28);
}

.viewer-bar {
  flex: none; display: flex; align-items: center; gap: .35rem;
  padding: .4rem .6rem; border-top: 1px solid var(--line); background: var(--surface);
}
.zoom-label { min-width: 3.4em; text-align: center; font-size: .78rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.viewer-hint { margin-left: auto; font-size: .75rem; color: var(--text-3); }

.raw-panel {
  position: absolute; inset: auto 0 0 0; max-height: 55%;
  display: flex; flex-direction: column;
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-l);
}
.raw-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .4rem .7rem; font-size: .8rem; color: var(--text-2);
  border-bottom: 1px solid var(--line);
}
.raw-panel pre {
  margin: 0; padding: .7rem; overflow: auto; font-size: .78rem; line-height: 1.7;
  white-space: pre-wrap; word-break: break-all; color: var(--text-2);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}

/* 確認カード */
.card-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
#cardForm { flex: 1; min-height: 0; overflow-y: auto; padding: .9rem 1rem 1.2rem; }

.verdict {
  display: flex; align-items: flex-start; gap: .5rem;
  padding: .55rem .75rem; margin-bottom: .6rem;
  font-size: .84rem; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--accent-hi);
}
.verdict.auto { background: var(--ok-soft); color: var(--ok); }
.verdict.busy { background: var(--surface-2); color: var(--text-2); }

.alerts { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .7rem; }
.alerts:empty { display: none; }
.alert {
  display: flex; gap: .5rem; align-items: flex-start;
  padding: .5rem .7rem; border-radius: var(--radius);
  font-size: .84rem; border-left: 3px solid;
  background: var(--warn-soft); color: var(--warn); border-color: var(--warn);
  cursor: pointer; text-align: left; width: 100%; border-top: 0; border-right: 0; border-bottom: 0;
  font-family: inherit;
}
.alert:hover { filter: brightness(.97); }
.alert.error { background: var(--err-soft); color: var(--err); border-color: var(--err); }
.alert.info  { background: var(--surface-2); color: var(--text-2); border-color: var(--line-strong); cursor: default; }

/* 入力 */
.fld { margin-bottom: .75rem; min-width: 0; }
.fld > label {
  display: flex; align-items: baseline; gap: .4em;
  margin-bottom: .2rem; font-size: .76rem; font-weight: 700; color: var(--text-2);
}
.fld > label em { color: var(--err); font-style: normal; }
.label-hint { font-weight: 400; font-size: .72rem; color: var(--text-3); }
.fld-note { margin: .25rem 0 0; font-size: .75rem; color: var(--text-3); }
.fld-note:empty { display: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.grid-2 > * { min-width: 0; }

input[type="text"], input[type="date"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%; min-width: 0;
  padding: .5em .65em;
  font: inherit; font-size: .94rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--focus);
}
input.big, select.big { font-size: 1.14rem; padding: .48em .6em; font-weight: 600; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--text-3); }
:root[data-theme="dark"] input[type="date"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) input[type="date"] { color-scheme: dark; } }

.amount-input { position: relative; }
.amount-input .yen {
  position: absolute; left: .6em; top: 50%; transform: translateY(-50%);
  font-size: 1.05rem; color: var(--text-3); pointer-events: none;
}
.amount-input input { padding-left: 1.8em; }

/* 詳細（折りたたみ） */
.more { margin: .3rem 0 .8rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.more > summary {
  cursor: pointer; font-size: .8rem; color: var(--text-2); user-select: none;
  padding: .25rem 0; list-style: none; display: flex; align-items: center; gap: .4em;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before { content: "▸"; font-size: .8em; transition: transform .15s; }
.more[open] > summary::before { transform: rotate(90deg); }
.more > summary:hover { color: var(--text); }
.more-body { padding-top: .6rem; }

/* 税額内訳 */
.breakdown {
  padding: .5rem .7rem; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .8rem;
}
.breakdown table { width: 100%; border-collapse: collapse; }
.breakdown td { padding: .12rem 0; color: var(--text-2); }
.breakdown td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown tr.sum td { padding-top: .3rem; border-top: 1px solid var(--line); color: var(--text); font-weight: 700; font-size: .92rem; }

.meta { margin: .7rem 0 0; font-size: .72rem; color: var(--text-3); line-height: 1.7; }

/* 下部の操作バー */
.actionbar {
  flex: none; padding: .6rem .9rem;
  border-top: 1px solid var(--line); background: var(--surface-2);
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
}
.run-info { flex: 1; min-width: 100%; font-size: .78rem; color: var(--text-2); order: -1; }
.run-info:empty { display: none; }
.actionbar-buttons { display: flex; gap: .4rem; align-items: center; width: 100%; }
.actionbar-buttons .btn-go { margin-left: auto; }
.btn-batch {
  width: 100%; justify-content: center; order: -1;
  white-space: normal; text-align: center; line-height: 1.35;
  background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent);
  font-weight: 700;
}
.btn-batch:hover:not(:disabled) { background: color-mix(in srgb, var(--ok) 18%, var(--surface)); }

/* 何もないとき */
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.empty-card { max-width: 460px; text-align: center; }
.empty-icon { font-size: 3.4rem; line-height: 1; margin-bottom: .6rem; }
.empty-card h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
.empty-card p { margin: 0 0 1.2rem; color: var(--text-2); font-size: .9rem; }
.empty-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }

/* ── 勘定科目の絞り込み（コンボボックス）─────────── */
.combo { position: relative; }
.combo-input {
  width: 100%; padding: .48em .6em; padding-right: 2em;
  font: inherit; font-size: 1.05rem; font-weight: 600;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  cursor: pointer;
}
.combo-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); cursor: text; }
.combo::after {
  content: "▾"; position: absolute; right: .7em; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none; font-size: .8em;
}
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + .25rem); z-index: 60;
  max-height: min(340px, 46vh); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-l);
}
.combo-opt {
  display: flex; align-items: baseline; gap: .5rem;
  padding: .45em .7em; cursor: pointer; font-size: .9rem;
}
.combo-opt:hover, .combo-opt.on { background: var(--accent-soft); }
.combo-opt .nm { font-weight: 600; }
.combo-opt .tx { margin-left: auto; font-size: .74rem; color: var(--text-3); white-space: nowrap; }
.combo-opt .yo { font-size: .72rem; color: var(--text-3); }
.combo-opt mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 2px; }
.combo-empty { padding: .7em; font-size: .84rem; color: var(--text-3); text-align: center; }
.combo-group { padding: .3em .7em; font-size: .7rem; color: var(--text-3); background: var(--surface-2); position: sticky; top: 0; }

/* ── 一覧モード ─────────────────────────────────── */
.listview { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.list-toolbar {
  flex: none; display: flex; align-items: center; gap: .45rem; flex-wrap: wrap;
  padding: .6rem .9rem; border-bottom: 1px solid var(--line); background: var(--surface);
}
.list-toolbar input[type="search"] { flex: 1; min-width: 190px; max-width: 340px; }
.list-toolbar select, .list-toolbar input[type="date"] { width: auto; font-size: .86rem; padding: .38em .5em; }
.tilde { color: var(--text-3); }
.list-summary { margin-left: auto; font-size: .82rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

.table-wrap { flex: 1; min-height: 0; overflow: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: .86rem; }
.grid thead th {
  position: sticky; top: 0; z-index: 2;
  padding: .45rem .6rem; text-align: left; font-size: .74rem; font-weight: 700;
  color: var(--text-2); background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.grid th.num, .grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .col-check { width: 2.4rem; text-align: center; }
.grid .col-thumb { width: 2.9rem; }
.grid .col-warn  { width: 2.2rem; text-align: center; }
.grid tbody tr { border-bottom: 1px solid var(--line); cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tbody tr.sel { background: var(--accent-soft); }
.grid td { padding: .32rem .6rem; }
.grid td.col-check { text-align: center; }
.grid img { width: 30px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: var(--surface-3); display: block; }
.grid .vendor { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid .muted { color: var(--text-3); }
.list-empty { padding: 3rem; text-align: center; color: var(--text-3); }

.pill {
  display: inline-block; padding: .05em .6em; border-radius: 999px;
  font-size: .72rem; font-weight: 700;
  background: var(--surface-3); color: var(--text-2);
}
.pill.review    { background: var(--warn-soft); color: var(--warn); }
.pill.confirmed { background: var(--ok-soft);   color: var(--ok); }
.pill.exported  { background: var(--surface-3); color: var(--text-3); }
.pill.processing{ background: var(--accent-soft); color: var(--accent-hi); }
.pill.error, .pill.deleted { background: var(--err-soft); color: var(--err); }
.pill.auto { background: var(--ok-soft); color: var(--ok); }

.bulkbar {
  flex: none; display: flex; align-items: center; gap: .5rem;
  padding: .55rem .9rem; background: var(--surface-2); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 14px rgba(0,0,0,.06);
}
.bulk-count { font-weight: 700; font-size: .9rem; }
.bulk-account { width: 220px; }
.bulk-account .combo-input { font-size: .88rem; font-weight: 400; padding: .38em .5em; }
.bulkbar .btn-quiet { color: var(--err); }
.bulkbar #btnBulkClear { margin-left: auto; }

/* ── ダイアログ ─────────────────────────────────── */
dialog {
  padding: 0; color: var(--text); background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  border-radius: 18px; box-shadow: var(--shadow-l); max-width: 94vw;
  /* 画面が低いノートPCでも「閉じる」まで届くように、はみ出したらスクロールさせる */
  max-height: 92vh; overflow: auto;
}
dialog::backdrop { background: rgba(9,12,22,.55); backdrop-filter: blur(5px) saturate(1.1); }
.dlg { width: 520px; max-width: 100%; padding: 1.4rem; }
.dlg-wide { width: 900px; }
.dlg h2 { margin: 0 0 .8rem; font-size: 1.14rem; }
.dlg h3 { margin: 1.2rem 0 .4rem; font-size: .92rem; }
.dlg-lead { margin: 0 0 .8rem; font-size: .84rem; color: var(--text-2); }
/* ボタンが多い画面（連携の設定など）でも、はみ出さずに折り返す */
.dlg-actions {
  display: flex; flex-wrap: wrap; gap: .5rem;
  justify-content: flex-end; margin-top: 1.1rem;
}
.check { display: flex; align-items: center; gap: .5rem; font-size: .86rem; color: var(--text-2); cursor: pointer; }
.check input { width: 1rem; height: 1rem; }
.export-preview { margin-top: .8rem; font-size: .85rem; color: var(--text-2); min-height: 1.4rem; }
.steps { margin: 0; padding-left: 1.3rem; font-size: .88rem; }
.steps li { margin-bottom: .4rem; }
.notes { margin: 0; padding-left: 1.3rem; font-size: .84rem; color: var(--text-2); }
.notes li { margin-bottom: .3rem; }
.keys { width: 100%; font-size: .85rem; border-collapse: collapse; }
.keys td { padding: .22rem .4rem; }
.keys td:first-child { width: 10rem; white-space: nowrap; }

.scroll-box { max-height: 56vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.rules { width: 100%; border-collapse: collapse; font-size: .84rem; }
.rules th, .rules td { padding: .35rem .55rem; text-align: left; border-bottom: 1px solid var(--line); }
.rules th { position: sticky; top: 0; background: var(--surface-2); font-size: .74rem; z-index: 1; }
.rules select, .rules input { font-size: .82rem; padding: .22em .4em; }
.rules .num { text-align: right; font-variant-numeric: tabular-nums; }
.rules tr.ready td { background: color-mix(in srgb, var(--ok) 7%, transparent); }

/* ── ドラッグ＆ドロップ ─────────────────────────── */
.dropzone {
  position: fixed; inset: 0; z-index: 200; display: none;
  align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  backdrop-filter: blur(3px);
}
.dropzone.on { display: flex; }
.dropzone-msg {
  padding: 2rem 3rem; font-size: 1.35rem; font-weight: 700;
  color: var(--accent-hi); background: var(--surface);
  border: 3px dashed var(--accent); border-radius: var(--radius-l);
}

/* ── トースト ───────────────────────────────────── */
/* 右下は「確定して次へ」ボタンの定位置なので、通知は左下に出す */
.toasts {
  position: fixed; left: 1rem; bottom: 1rem; z-index: 300;
  display: flex; flex-direction: column; gap: .5rem; align-items: flex-start;
  pointer-events: none;
}
.toast { pointer-events: auto; }
.toast {
  display: flex; align-items: center; gap: .7rem;
  max-width: 420px; padding: .65rem 1rem;
  color: #fff; background: #232c3a; border-radius: var(--radius);
  box-shadow: var(--shadow-l); font-size: .86rem;
  animation: pop .18s ease-out;
}
.toast.ok  { background: color-mix(in srgb, var(--ok) 82%, #06281a); }
.toast.err { background: color-mix(in srgb, var(--err) 82%, #300a0e); }
.toast button {
  padding: .15em .7em; font: inherit; font-size: .82rem; font-weight: 700;
  color: inherit; background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.35); border-radius: 6px; cursor: pointer;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px); } }

/* ── 画面が狭いとき ─────────────────────────────── */
@media (max-width: 1180px) {
  .triage-body { grid-template-columns: 1fr minmax(340px, 38vw); }
  .progress-wrap { display: none; }
}
@media (max-width: 900px) {
  body { overflow: auto; height: auto; min-height: 100vh; }
  .triage-body { grid-template-columns: 1fr; }
  .viewer-pane { min-height: 60vh; }
  .brand-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── 事業体の切り替え（会社・個人事業）───────────── */
.entity-wrap { position: relative; }
.entity-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .34em .7em; margin-right: .2rem; max-width: 12rem;
  font: inherit; font-size: .8rem; font-weight: 700;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: 999px; cursor: pointer;
}
.entity-chip:hover { background: var(--surface-3); }
.entity-chip:focus-visible { outline: none; box-shadow: var(--focus); }
.entity-chip > span:nth-child(2) {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entity-caret { color: var(--text-3); font-size: .7em; }
.entity-dot {
  width: .62rem; height: .62rem; border-radius: 50%; flex: none;
  background: var(--accent);
}

.entity-menu {
  position: absolute; top: calc(100% + .4rem); right: 0; z-index: 60;
  min-width: 17rem; padding: .3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-l);
}
.entity-menu button {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: .5rem; width: 100%; padding: .5rem .6rem;
  font: inherit; font-size: .85rem; text-align: left; color: var(--text);
  background: none; border: none; border-radius: 6px; cursor: pointer;
}
.entity-menu button:hover { background: var(--surface-2); }
.entity-menu button.on { background: var(--accent-soft); font-weight: 700; }
.entity-menu button.on::after { content: "✓"; color: var(--accent); }
.entity-menu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-menu-kind { font-size: .72rem; color: var(--text-3); }
.entity-menu hr { margin: .3rem 0; border: none; border-top: 1px solid var(--line); }

.entity-form { padding: .2rem 0 .4rem; }
.entity-form-actions {
  display: flex; gap: .5rem; justify-content: flex-end; margin-top: .7rem;
}
.entity-row-actions { white-space: nowrap; }
.entity-row-actions .btn { padding: .25em .5em; font-size: .78rem; }
tr.archived { opacity: .5; }
.tag-now, .tag-off {
  margin-left: .4rem; padding: .1em .45em; border-radius: 999px;
  font-size: .68rem; font-weight: 700;
}
.tag-now { color: var(--accent); background: var(--accent-soft); }
.tag-off { color: var(--text-3); background: var(--surface-3); }
.muted-inline { font-size: .75rem; color: var(--text-3); }

/* 補正表示に切り替えているあいだ、ボタンを光らせる */
#btnEnhance.on {
  color: var(--ok); background: var(--ok-soft); border-color: var(--ok);
}

/* ── 税理士提出ボタン ───────────────────────────── */
.btn-report {
  color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent);
  background: var(--ok-soft); font-weight: 700;
}
.btn-report:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ok) 16%, var(--surface));
  border-color: var(--ok);
}

.period-quick { display: flex; flex-wrap: wrap; gap: .35rem; margin: .1rem 0 .9rem; }
.period-quick button {
  font: inherit; font-size: .78rem; padding: .32em .8em; cursor: pointer;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px;
}
.period-quick button:hover { background: var(--surface-3); color: var(--text); }
.period-quick button.on {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent); font-weight: 700;
}

.report-summary {
  padding: .85rem 1rem; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .85rem; min-height: 3.4rem;
}
.report-head { display: flex; flex-wrap: wrap; gap: 1.4rem; }
.report-head div { display: flex; flex-direction: column; gap: .1rem; }
.report-head span { font-size: .72rem; color: var(--text-3); }
.report-head b { font-size: 1.05rem; }
.report-accounts { list-style: none; margin: .7rem 0 0; padding: 0; display: grid; gap: .18rem; }
.report-accounts li {
  display: grid; grid-template-columns: 1fr auto 3.6rem; gap: .6rem;
  font-size: .8rem; color: var(--text-2);
}
.report-accounts b { color: var(--text); font-variant-numeric: tabular-nums; }
.report-accounts span { text-align: right; color: var(--text-3); }
.report-warn { margin: .6rem 0 0; color: var(--warn); font-size: .8rem; }
.muted { color: var(--text-3); font-size: .78rem; margin: .4rem 0 0; }

/* ── 家事按分（事業割合）───────────────────────── */
.ratio-row { margin-bottom: .7rem; }
.ratio-input { display: flex; align-items: center; gap: .5rem; }
.ratio-num { display: flex; align-items: center; gap: .2rem; }
.ratio-num input { width: 3.8rem; text-align: right; }
.ratio-num span { color: var(--text-2); font-size: .85rem; }
.ratio-quick { display: flex; gap: .2rem; flex: 1; }
.ratio-quick button {
  flex: 1; font: inherit; font-size: .74rem; padding: .42em .1em; cursor: pointer;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px;
}
.ratio-quick button:hover,
.ratio-quick button.on { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

/* ステータスバーに「いまどの会社か」を常に出す */
.sb-entity {
  display: inline-flex; align-items: center; gap: .35rem;
  font-weight: 700; color: var(--text);
}

/* ── ログイン画面 ───────────────────────────────── */
.login-screen {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  padding: 1.5rem; background: var(--bg); overflow: auto;
}
.login-card {
  width: 360px; max-width: 100%; padding: 1.8rem 1.6rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-l); box-shadow: var(--shadow-l);
}
.login-brand { font-size: 1.05rem; font-weight: 800; margin-bottom: 1.2rem; }
.login-card h1 { margin: 0 0 .9rem; font-size: 1.2rem; }
.login-lead { margin: 0 0 1rem; font-size: .84rem; color: var(--text-2); line-height: 1.6; }
.login-card .fld { margin-bottom: .8rem; }
.login-error {
  margin: .2rem 0 .8rem; padding: .6rem .8rem; font-size: .84rem;
  color: var(--err); background: var(--err-soft); border-radius: var(--radius);
}
.login-go { width: 100%; justify-content: center; margin-top: .4rem; }

.user-chip {
  padding: .3em .7em; margin-right: .2rem;
  font: inherit; font-size: .78rem; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer;
}
.user-chip::before { content: "👤 "; }
.user-chip:hover { background: var(--surface-3); color: var(--text); }

/* ── 検索モード ─────────────────────────────────── */
.searchview { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.search-panel {
  padding: 1rem 1.1rem .8rem; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.search-head h2 { margin: 0 0 .2rem; font-size: 1.05rem; }
.search-head p { margin: 0 0 .9rem; font-size: .8rem; color: var(--text-2); }
.search-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .7rem;
}
.search-grid > * { min-width: 0; }
.search-wide { grid-column: 1 / -1; }
.search-flags {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .9rem;
}
.search-actions { margin-left: auto; display: flex; gap: .5rem; }
.search-summary {
  padding: .6rem 1.1rem; font-size: .88rem;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8em; }

/* ── 電帳法チェック ─────────────────────────────── */
.dch-counts { display: flex; gap: .5rem; flex-wrap: wrap; }
.dch-count {
  padding: .25em .7em; border-radius: 999px; font-size: .82rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line);
}
.dch-count.ok { color: var(--ok); background: var(--ok-soft); }
.dch-count.warn { color: var(--warn); background: var(--warn-soft); }
.dch-count.ng { color: var(--err); background: var(--err-soft); }
.dch-items { display: grid; gap: .45rem; margin: .9rem 0 .3rem; }
.dch-item {
  padding: .6rem .8rem; border-radius: var(--radius);
  background: var(--surface-2); border-left: 3px solid var(--line-strong);
}
.dch-item.ok { border-left-color: var(--ok); }
.dch-item.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.dch-item.ng { border-left-color: var(--err); background: var(--err-soft); }
.dch-item.info { border-left-color: var(--accent); }
.dch-item-head { font-weight: 700; font-size: .88rem; }
.dch-item-detail { font-size: .8rem; color: var(--text-2); margin-top: .18rem; line-height: 1.55; }
.dch-item-action { font-size: .8rem; margin-top: .3rem; color: var(--accent); line-height: 1.55; }
.dch-docs { display: grid; gap: .4rem; }
.dch-doc {
  display: flex; align-items: center; gap: .8rem; padding: .55rem .8rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: .84rem;
}
.dch-doc > div { flex: 1; min-width: 0; }
.dch-doc .muted { font-size: .76rem; }
.dch-tools { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.dch-result:empty { display: none; }
.dch-result-box {
  margin-top: .8rem; padding: .7rem .9rem; border-radius: var(--radius);
  font-size: .84rem; background: var(--surface-2); border: 1px solid var(--line);
}
.dch-result-box.ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok); }
.dch-result-box.ng { color: var(--err); background: var(--err-soft); border-color: var(--err); }
.dch-result-box ul { margin: .5rem 0 0; padding-left: 1.2rem; }

/* ── 消費税の用途区分 ───────────────────────────── */
.purpose-row { margin-bottom: .7rem; }
.purpose-choices { display: flex; gap: .3rem; }
.purpose-btn {
  flex: 1; font: inherit; font-size: .78rem; padding: .45em .2em; cursor: pointer;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px; white-space: nowrap;
}
.purpose-btn:hover { background: var(--surface-3); color: var(--text); }
.purpose-btn.on {
  color: var(--accent); background: var(--accent-soft);
  border-color: var(--accent); font-weight: 700;
}
.purpose-tag {
  margin-left: .35rem; padding: .08em .4em; border-radius: 999px;
  font-size: .68rem; font-weight: 700;
  color: var(--warn); background: var(--warn-soft);
}

/* ── 家計簿モード ───────────────────────────────── */
/* 会計の欄（税区分・インボイス・部門・電帳法・内訳）は、
   家計簿では意味がないので画面から消します。 */
body.household-mode .biz-only { display: none !important; }

/* 支払方法の欄は1つだけ作り、置き場所だけを入れ替えます。
   入れ物自体は格子に影響しないよう display:contents にしています。 */
.fld-slot { display: contents; }

.householdview {
  flex: 1; min-height: 0; overflow: auto;
  background: var(--surface); padding: 1rem 1.1rem 2rem;
}
.hh-toolbar {
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  padding-bottom: .8rem; border-bottom: 1px solid var(--line);
}
.hh-toolbar input[type="month"] { font: inherit; font-size: .9rem; }
.hh-spacer { flex: 1; }

.hh-cards {
  display: grid; gap: .7rem; margin: 1rem 0 1.2rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.hh-card {
  padding: .75rem .9rem; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
}
.hh-card span { display: block; font-size: .76rem; color: var(--text-2); }
.hh-card b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.hh-card em { display: block; font-size: .72rem; color: var(--text-2); font-style: normal; }
.hh-card.plus b { color: var(--ok); }
.hh-card.minus b { color: var(--err); }
.hh-card.ghost { border-style: dashed; }
.hh-nobudget { font-size: 1rem !important; color: var(--text-2); }

.hh-columns { display: grid; gap: 1.2rem; grid-template-columns: 1.3fr 1fr; }
@media (max-width: 900px) { .hh-columns { grid-template-columns: 1fr; } }
.hh-panel h3 { font-size: .9rem; margin: 0 0 .6rem; }
.hh-panel h3.hh-sub { margin-top: 1.2rem; }

.hh-bars { display: grid; gap: .5rem; }
.hh-bar { cursor: pointer; padding: .35rem .1rem; border-radius: 6px; }
.hh-bar:hover { background: var(--surface-2); }
.hh-bar.income { cursor: default; }
.hh-bar-head { display: flex; align-items: baseline; gap: .5rem; font-size: .84rem; }
.hh-bar-head span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hh-bar-head b { font-variant-numeric: tabular-nums; }
.hh-bar-head em { font-size: .72rem; color: var(--text-2); font-style: normal; }
.hh-bar-track {
  position: relative; height: 8px; margin-top: .25rem;
  background: var(--surface-3); border-radius: 999px; overflow: hidden;
}
.hh-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.hh-bar.over .hh-bar-fill { background: var(--err); }
.hh-bar-budget {
  position: absolute; top: -2px; width: 2px; height: 12px;
  background: var(--text-2); border-radius: 1px;
}
.hh-bar-note { font-size: .72rem; color: var(--text-2); margin-top: .2rem; }
.hh-bar-note.over { color: var(--err); }

.hh-trend { display: flex; gap: .3rem; align-items: stretch; height: 130px; }
.hh-month {
  flex: 1; height: 100%;
  display: flex; flex-direction: column; align-items: center; gap: .25rem;
  cursor: pointer; border-radius: 6px; padding-bottom: .1rem;
}
.hh-month:hover, .hh-month.on { background: var(--surface-2); }
.hh-month-bars { flex: 1; display: flex; gap: 2px; align-items: flex-end; width: 100%; }
.hh-month-bars i { flex: 1; min-height: 2px; border-radius: 2px 2px 0 0; }
.hh-month-bars i.in { background: color-mix(in srgb, var(--ok) 70%, transparent); }
.hh-month-bars i.out { background: color-mix(in srgb, var(--accent) 70%, transparent); }
.hh-month span { font-size: .68rem; color: var(--text-2); }

.budget-input { width: 8rem; text-align: right; }
.budget-total { font-size: .84rem; margin: .6rem 0 0; }
.med-result { margin: .8rem 0; }
.med-ok { color: var(--ok); font-weight: 700; font-size: .88rem; }
.hh-ok b { color: var(--ok); }

/* 会社の切り替えメニューの注意書き（切り替わるのはこの端末だけ） */
.entity-menu-note {
  padding: .5rem .7rem; margin-top: .3rem;
  border-top: 1px solid var(--line);
  font-size: .72rem; color: var(--text-2); line-height: 1.5;
}

/* 自動仕訳を止めている理由（学習内容の一覧） */
.rule-why {
  display: inline-block; width: 1.15em; height: 1.15em; margin-left: .3rem;
  border-radius: 50%; text-align: center; line-height: 1.15em;
  font-size: .72rem; font-weight: 700; cursor: help;
  color: var(--warn); background: var(--warn-soft);
}

/* ── 稼働状況（処理・費用・バックアップ）──────────── */

/* ステータスバーから直接開けるボタン */
.sb-chip {
  padding: .1em .5em; border-radius: 6px;
  border: 1px solid transparent; background: transparent;
  font: inherit; color: inherit; cursor: pointer;
}
.sb-chip:hover { background: var(--surface-3); border-color: var(--line); }
.btn-sm { padding: .25em .7em; font-size: .78rem; }

/* OCRの進み具合を1本の帯で表す */
.hz-bar {
  display: flex; height: 12px; border-radius: 6px; overflow: hidden;
  background: var(--surface-3); border: 1px solid var(--line);
}
.hz-seg { display: block; height: 100%; }
.hz-seg.done    { background: var(--ok); }
.hz-seg.running { background: var(--accent); }
.hz-seg.waiting { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.hz-seg.failed  { background: var(--err); }

.hz-legend {
  display: flex; flex-wrap: wrap; gap: .2rem 1.1rem;
  margin-top: .5rem; font-size: .8rem; color: var(--text-2);
}
.hz-legend b { color: var(--text); font-size: 1.05em; }
.hz-legend .done b    { color: var(--ok); }
.hz-legend .running b { color: var(--accent); }
.hz-legend .failed b  { color: var(--err); }

.hz-note { margin: .5rem 0 0; font-size: .76rem; color: var(--text-2); line-height: 1.6; }
.hz-note code { font-size: .95em; }

/* 読み取れなかったものの一覧 */
.hz-failed { margin-top: .9rem; }
.hz-failed:empty { display: none; }
.hz-failed-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem; margin-bottom: .4rem; font-size: .85rem;
}
.hz-err { color: var(--err); font-size: .78rem; }

/* 今日・今月・累計の費用 */
.hz-cost-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.hz-cost-cell {
  flex: 1; min-width: 8rem;
  display: flex; flex-direction: column; gap: .1rem;
  padding: .6rem .8rem; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.hz-cost-label { font-size: .74rem; color: var(--text-2); }
.hz-cost-yen { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hz-cost-sub { font-size: .72rem; color: var(--text-2); }

/* バックアップの信号 */
.hz-backup-msg {
  margin: 0 0 .5rem; padding: .5rem .7rem; border-radius: 8px;
  font-size: .84rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line);
}
.hz-backup-msg.ok    { background: var(--ok-soft);   color: var(--ok);   border-color: var(--ok); }
.hz-backup-msg.warn  { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.hz-backup-msg.alert { background: var(--err-soft);  color: var(--err);  border-color: var(--err); }

.hz-list { margin: 0; padding: 0; list-style: none; font-size: .82rem; }
.hz-list li {
  display: flex; gap: .5rem; align-items: baseline;
  padding: .3rem 0; border-bottom: 1px solid var(--line);
}
.hz-list li:last-child { border-bottom: none; }
.hz-list li b { min-width: 8.5rem; font-weight: 600; }
.hz-list li.warn  { color: var(--warn); }
.hz-list li.alert { color: var(--err); }
.hz-list li.none  { color: var(--text-2); }

/* いまどの会社の費用を見ているか */
.hz-scope {
  margin: 0 0 .4rem; font-size: .78rem; font-weight: 600; color: var(--text-2);
}

/* ── AI確認モードの信号 ─────────────────────────── */
.tl-dot {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  vertical-align: baseline; cursor: help;
}
.tl-green  { background: var(--ok);
             box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.tl-yellow { background: #d9a514;
             box-shadow: 0 0 0 3px color-mix(in srgb, #d9a514 22%, transparent); }
.tl-red    { background: var(--err);
             box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 20%, transparent); }

/* ── AIチャット修正 ─────────────────────────────── */
.assist {
  margin-top: .8rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2);
}
.assist > summary {
  padding: .55rem .8rem; cursor: pointer; font-size: .84rem; font-weight: 600;
  list-style: none; user-select: none;
}
.assist > summary::-webkit-details-marker { display: none; }
.assist-hint { margin-left: .5rem; font-weight: 400; font-size: .74rem; color: var(--text-2); }
.assist-log { max-height: 180px; overflow-y: auto; padding: 0 .8rem; }
.assist-log:empty { display: none; }
.assist-msg {
  margin: .35rem 0; padding: .45rem .7rem; border-radius: 10px;
  font-size: .82rem; line-height: 1.6; width: fit-content; max-width: 92%;
  white-space: pre-wrap;
}
.assist-msg.user {
  margin-left: auto; background: var(--accent); color: var(--on-accent);
  border-bottom-right-radius: 3px;
}
.assist-msg.assistant {
  background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}
.assist-chips { display: flex; flex-wrap: wrap; gap: .35rem; padding: .5rem .8rem 0; }
.chip {
  padding: .25em .8em; font-size: .76rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text-2); cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.assist-row { display: flex; gap: .5rem; padding: .6rem .8rem .8rem; }
.assist-row input { flex: 1; }

/* ── スマホから撮影 ─────────────────────────────── */
.phone-grid { display: flex; gap: 1.1rem; align-items: flex-start; }
.phone-qr {
  width: 180px; height: 180px; flex: none;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.phone-step { margin: 0 0 .5rem; font-size: .88rem; }

/* ── 勘定科目の管理 ─────────────────────────────── */
.ac-badge {
  font-size: .68rem; padding: .05rem .35rem; border-radius: 999px;
  background: var(--accent-soft, var(--surface-3)); color: var(--text-2);
}
.ac-code { width: 5.5em; font-family: ui-monospace, monospace; }
.btn-sm { padding: .15rem .5rem; font-size: .76rem; }

/* ── スタッフアプリ連携 ─────────────────────────── */
.staff-status {
  margin: .3rem 0 .6rem; padding: .55rem .8rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  font-size: .85rem; line-height: 1.7;
}
.staff-status p { margin: 0; }
.staff-err { color: var(--err); }
/* 設定画面（モーダル）の中に出す結果表示。画面隅のトーストは
   モーダルの後ろに隠れるため、ボタンの近くにも同じ内容を出す */
.dlg-toast { margin: .5rem 0 0; }
.dlg-toast-line {
  margin: .35rem 0 0; padding: .5rem .8rem; border-radius: 10px;
  font-size: .85rem; line-height: 1.6;
  background: var(--surface-3); border: 1px solid var(--line);
}
.dlg-toast-line.ok {
  background: var(--ok-soft, var(--surface-3));
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}
.dlg-toast-line.err {
  background: var(--err-soft);
  border-color: color-mix(in srgb, var(--err) 45%, transparent);
  color: var(--err); font-weight: 600;
}

.sb-alert {
  color: var(--err); background: var(--err-soft);
  padding: .1rem .55rem; border-radius: 999px;
  font-weight: 650; cursor: pointer; white-space: nowrap;
}
#staffUrl, #aiKey, #backupDir, #backupSelect,
#mfClientId, #mfClientSecret { width: 100%; }
#mfRedirect { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: .8rem; }
#scanFolderPath { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: .82rem; }
#aiKey { font-family: ui-monospace, monospace; font-size: .8rem; }
.ai-ent-row { margin: 0 0 .7rem; }
.ai-ent-head { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .25rem; font-size: .88rem; }
.ai-ent-state { font-size: .76rem; color: var(--text-2); }
.staff-token-row { display: flex; gap: .4rem; align-items: center; }
.staff-token-row input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: .8rem; }
.staff-token-row .btn { flex: none; }

/* ── 領収書AIエージェント ───────────────────────── */
#agentLog { max-height: 150px; margin-top: .6rem; padding: 0; }
.agent-count { margin: .6rem 0 .4rem; font-size: .9rem; }
.agent-rows { max-height: 260px; }
.agent-rows tr[data-open] { cursor: pointer; }
.agent-rows tr[data-open]:hover td { background: var(--surface-3); }
.agent-actions { margin-top: .6rem; }
.agent-confirm {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  margin-top: .8rem; padding: .7rem .9rem; border-radius: 10px;
  background: var(--accent-soft, var(--surface-2));
  border: 1px solid var(--accent);
  font-size: .88rem;
}

/* エージェントの集計と変更プレビュー */
.agent-summary { margin: .6rem 0; }
.agent-sum-table { margin-top: .5rem; font-size: .82rem; }
.agent-preview {
  margin-top: .7rem; padding: .6rem .8rem; font-size: .82rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.agent-preview ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.agent-preview li { margin-bottom: .15rem; }

/* ── 仕上げ（スクロールバーと細部）───────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-3) 40%, transparent);
  border-radius: 999px; border: 2px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-3) 65%, transparent);
  border: 2px solid transparent; background-clip: content-box;
}

/* 数字は等幅で揃える（金額の桁がガタつかない） */
.num, .hz-cost-yen, .progress-text, .agent-count { font-variant-numeric: tabular-nums; }

/* ダイアログの見出しに小さなアクセント */
.dlg h2 {
  display: flex; align-items: center; gap: .45rem;
  letter-spacing: .01em;
}

/* ── 参加者の名簿 ───────────────────────────────── */
/* 選ぶ画面は「探さずに押せる」ことを優先し、関係ごとに固めて並べます */
.pick-list { max-height: 46vh; overflow-y: auto; margin-bottom: .6rem; }
.pick-group { margin-bottom: .7rem; }
.pick-group h4 {
  margin: 0 0 .35rem; font-size: .78rem; color: var(--text-2); font-weight: 600;
}
.pick-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.pick-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); cursor: pointer; font-size: .85rem;
}
.pick-chip:hover { border-color: var(--accent); }
.pick-chip input { margin: 0; }
.pick-chip.on { background: var(--accent-soft); border-color: var(--accent); }
.pick-chip .pick-org { color: var(--text-2); font-size: .76rem; }

.people-list { max-height: 34vh; overflow-y: auto; margin-bottom: .6rem; }
.people-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .1rem; border-bottom: 1px solid var(--line);
}
.people-row .people-name { flex: 1; min-width: 0; }
.people-row .people-rel { font-size: .76rem; color: var(--text-2); flex: none; }

/* 目的は「選ぶ」と「自由に書く」を縦に並べる（横に並べると欄が潰れる） */
.purpose-pick select { width: 100%; margin-bottom: .3rem; }
/* 参加者は人名なので、等幅ではなくふつうの字で見せる */
.people-row-input input { font-family: inherit; font-size: .9rem; }

/* ── スマホ（外出先・院内のiPhone/iPad）───────────────
 *
 * VPSに置いたので、スマホからも同じ画面を使います。上のボタンを
 * 並べきれないので、狭い画面では「取り込み」と「⋯」だけを残し、
 * ほかは ⋯ の中から呼べるようにしています。
 * 入力欄を16px以上にしているのは、iOSが自動で拡大するのを防ぐためです。
 */
.phone-only { display: none; }

@media (max-width: 640px) {
  .phone-only { display: block; }
  .desktop-only { display: none !important; }

  /* 上の帯は2段。1段目に会社と操作、2段目に仕分け／一覧／検索 */
  .topbar {
    flex-wrap: wrap; gap: .4rem; padding: .5rem .55rem;
    padding-top: calc(.5rem + env(safe-area-inset-top, 0px));
  }
  .brand { display: none; }
  .topbar-actions { order: 1; margin-left: 0; width: 100%; gap: .35rem; }
  .modes { order: 2; width: 100%; }
  .mode {
    flex: 1; justify-content: center; white-space: nowrap;
    padding: .5em .3em; font-size: .88rem;
  }
  /* 上に置くのは「取り込み」「AIに頼む」と会社・⋯ だけ。あとは ⋯ の中 */
  #btnExport, #btnReport, #btnUndo, #btnAgent { display: none; }
  .entity-chip { max-width: 42vw; overflow: hidden; }
  .entity-chip > span:nth-child(2) {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .user-chip {
    max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .menu-wrap { margin-left: auto; }
  .menu { min-width: min(80vw, 260px); max-height: 70vh; overflow-y: auto; }

  /* 状態バーは小さく。長いパスは省略して1行に収める */
  .statusbar { gap: .5rem; padding: .25rem .55rem; font-size: .72rem; }
  .statusbar code { max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sb-right { margin-left: 0; gap: .6rem; flex-wrap: wrap; }

  /* 領収書の画像は上、入力は下。指で送れるよう画面全体を縦スクロールにする */
  .viewer-pane { min-height: 42vh; }
  /* 画像の下の道具立ては1行に収める。説明文は狭い画面では縦に潰れるので隠す */
  .viewer-hint { display: none; }
  .viewer-bar { flex-wrap: nowrap; overflow-x: auto; gap: .3rem; padding: .35rem .5rem; }
  .card-pane { min-height: 0; }
  .actionbar { flex-wrap: wrap; gap: .4rem; padding-bottom: calc(.5rem + env(safe-area-inset-bottom, 0px)); }
  .actionbar-buttons { width: 100%; display: flex; gap: .4rem; }
  .actionbar-buttons .btn { flex: 1; justify-content: center; }
  .btn-go { flex: 2 !important; }

  /* 指で押しやすい大きさに。iOSの自動拡大も防ぐ */
  .btn { min-height: 40px; }
  input, select, textarea { font-size: 16px !important; }
  .grid-2 { grid-template-columns: 1fr; }
  /* 項目名の横に説明を置くと、狭い画面では項目名が縦に潰れる */
  .label-hint { display: block; margin-left: 0; }

  /* 設定の窓は画面いっぱいに */
  dialog { max-width: 100vw; max-height: 100vh; margin: 0; border-radius: 0; }
  .dlg { width: 100vw; padding: 1rem .8rem calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .dlg-wide { width: 100vw; }
  .dlg-actions {
    position: sticky; bottom: 0; z-index: 2;
    margin-top: .8rem; padding: .6rem 0 .2rem;
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .dlg-actions .btn { flex: 1; justify-content: center; }

  /* 一覧は横に長いので、表だけを横スクロールさせる */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 720px; }

  /* 検索の条件は2列まで。1列だと縦に長くなりすぎる */
  .search-grid { grid-template-columns: 1fr 1fr; }
  .toasts {
    left: .5rem; right: .5rem;
    bottom: calc(.5rem + env(safe-area-inset-bottom, 0px));
  }
  .toast { max-width: 100%; }
}

/* 「📷 撮る」はスマホのときだけ出す（パソコンにカメラは要らない） */
.phone-only-inline { display: none; }
@media (max-width: 640px) {
  .phone-only-inline { display: inline-flex; }
  /* 撮るボタンを置くぶん、取り込みは文字を短くして幅を稼ぐ */
  .topbar-actions .btn { padding-left: .7em; padding-right: .7em; }
}
