/* 帳票OCR — 共通スタイル（ビルド不要のプレーンCSS） */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d9dde3;
  --text: #1d2330;
  --muted: #5d6675;
  --primary: #1f5fbf;
  --primary-hover: #194f9f;
  --primary-soft: #e8f0fb;
  --ok: #1d7a46;
  --ok-soft: #e4f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .4rem 0 .8rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt0 { margin-top: 0; }
.hidden { display: none !important; }

/* ヘッダー */
.topbar { background: #16233b; color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: 1.25rem; padding: 0 20px; height: 54px; max-width: 1480px; margin: 0 auto; }
.brand { color: #fff; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand span { color: #8fb7ff; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { color: #c9d4e6; padding: .4rem .7rem; border-radius: 6px; white-space: nowrap; font-size: .92rem; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.userbox { display: flex; align-items: center; gap: .6rem; font-size: .85rem; }
.userbox select { background: #22324f; color: #fff; border: 1px solid #3a4b6b; border-radius: 6px; padding: .25rem .4rem; max-width: 220px; }
.userbox a, .userbox button.linklike { color: #c9d4e6; }
button.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
button.linklike:hover { text-decoration: underline; }

/* レイアウト */
.container { max-width: 1480px; margin: 0 auto; padding: 24px 20px 60px; }
.container.narrow { max-width: 560px; }
.container.medium { max-width: 960px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { padding: 16px 18px; }
.stat .num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .85rem; }

/* ボタン */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .5rem 1rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .92rem;
  cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #f0c4bf; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: .25rem .6rem; font-size: .82rem; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
form.inline { display: inline; }

/* フォーム */
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.form-row .help { color: var(--muted); font-size: .82rem; margin-top: .25rem; }
.form-row .errorlist { color: var(--danger); font-size: .85rem; list-style: none; padding: 0; margin: .25rem 0 0; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0f5; outline-offset: 0; border-color: var(--primary); }
input[type=checkbox] { width: auto; }
.form-row.check label { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.errornote { background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem; border-radius: 6px; margin-bottom: 1rem; }

/* メッセージ */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .65rem .9rem; border-radius: 6px; margin-bottom: .5rem; background: var(--primary-soft); border: 1px solid #c6d9f5; }
.messages li.success { background: var(--ok-soft); border-color: #b7e0c6; }
.messages li.error { background: var(--danger-soft); border-color: #f3c3bd; }
.messages li.warning { background: var(--warn-soft); border-color: #f1d9a8; }

/* テーブル */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th, table.list td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; font-size: .9rem; }
table.list th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: .82rem; white-space: nowrap; }
table.list tr:hover td { background: #fafbfc; }

/* バッジ */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.ok, .badge.confirmed { background: var(--ok-soft); color: var(--ok); border-color: #b7e0c6; }
.badge.low, .badge.done, .badge.needs_layout { background: var(--warn-soft); color: var(--warn); border-color: #f1d9a8; }
.badge.invalid, .badge.failed { background: var(--danger-soft); color: var(--danger); border-color: #f3c3bd; }
.badge.queued, .badge.processing { background: var(--primary-soft); color: var(--primary); border-color: #c6d9f5; }
.badge.empty { background: var(--surface-2); color: var(--muted); }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters select, .filters input { width: auto; min-width: 150px; }
.pagination { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; position: relative; padding-left: 2.2rem; margin-bottom: .6rem; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: .85rem; display: flex; align-items: center; justify-content: center; }
.copybox { display: flex; gap: .5rem; }
.copybox input { font-family: var(--mono); font-size: .82rem; }

/* ---- 枠エディタ・確認画面 共通 ---- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 16px; align-items: start; }
.viewer { background: #e6e8ec; border: 1px solid var(--border); border-radius: var(--radius); position: relative; overflow: auto; height: calc(100vh - 190px); min-height: 480px; }
.viewer-toolbar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.viewer-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 .2rem; }
.stage { position: relative; margin: 16px auto; box-shadow: 0 2px 10px rgba(0,0,0,.18); background: #fff; user-select: none; touch-action: none; }
.stage img { display: block; width: 100%; height: 100%; pointer-events: none; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage.drawing { cursor: crosshair; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); height: calc(100vh - 190px); min-height: 520px; display: flex; flex-direction: column; overflow: hidden; }
.panel-head { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel-body { padding: 12px 14px; overflow-y: auto; flex: 1; }
.panel-foot { padding: 10px 14px; border-top: 1px solid var(--border); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; background: var(--surface-2); }
.presets { display: flex; flex-wrap: wrap; gap: .35rem; }
.presets .btn { padding: .2rem .55rem; font-size: .8rem; }
.presets .btn.armed { background: var(--primary); color: #fff; border-color: var(--primary); }
.field-list { list-style: none; padding: 0; margin: 0; }
.field-item { border: 1px solid var(--border); border-radius: 6px; margin-bottom: .45rem; background: #fff; }
.field-item.selected { border-color: var(--primary); box-shadow: 0 0 0 2px #cfe0f8; }
.field-item .fi-head { display: flex; gap: .5rem; align-items: center; padding: .4rem .6rem; cursor: pointer; }
.field-item .fi-head .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.field-item .fi-head .name { flex: 1; font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-item .fi-body { padding: .2rem .6rem .7rem; border-top: 1px dashed var(--border); }
.field-item .fi-body .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.field-item .fi-body .row2 > div { min-width: 0; }
.field-item .fi-body label { font-size: .78rem; color: var(--muted); display: block; margin: .4rem 0 .15rem; }
.field-item .fi-body input, .field-item .fi-body select { padding: .3rem .45rem; font-size: .85rem; }
.fi-test { margin-top: .5rem; background: var(--surface-2); border-radius: 6px; padding: .45rem .55rem; font-size: .85rem; }
.fi-test img { max-width: 100%; display: block; margin-bottom: .3rem; border: 1px solid var(--border); background: #fff; }
.fi-test .val { font-weight: 600; word-break: break-all; }
.cols-table { width: 100%; border-collapse: collapse; margin-top: .3rem; }
.cols-table { table-layout: fixed; }
.cols-table td { padding: .15rem .15rem; }
.cols-table td:nth-child(2) { width: 78px; }
.cols-table td:nth-child(3) { width: 104px; }
.cols-table td:nth-child(4) { width: 34px; }
.cols-table input, .cols-table select { padding: .2rem .3rem !important; font-size: .8rem !important; }
.dirty-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: .3rem; }
.hint { font-size: .82rem; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: .5rem .65rem; margin-bottom: .6rem; }
kbd { font-family: var(--mono); font-size: .75rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }

/* SVG 枠 */
.box rect.frame { fill: rgba(31, 95, 191, .08); stroke: #1f5fbf; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: move; }
.box.selected rect.frame { fill: rgba(31, 95, 191, .16); stroke-width: 3; }
.box text { font-size: 12px; font-weight: 700; paint-order: stroke; stroke: #fff; stroke-width: 3px; pointer-events: none; }
.box .handle { fill: #fff; stroke: #1f5fbf; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.box .coldiv { stroke-width: 2; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.box .coldiv-hit { stroke: transparent; stroke-width: 12; cursor: ew-resize; vector-effect: non-scaling-stroke; }
.draft rect { fill: rgba(31,95,191,.12); stroke: #1f5fbf; stroke-dasharray: 5 4; stroke-width: 2; vector-effect: non-scaling-stroke; }

/* 確認画面 */
.result-item { border: 1px solid var(--border); border-radius: 6px; padding: .55rem .65rem; margin-bottom: .55rem; background: #fff; }
.result-item.focus { border-color: var(--primary); box-shadow: 0 0 0 2px #cfe0f8; }
.result-item.low, .result-item.invalid { border-left: 4px solid #e0a030; }
.result-item.invalid { border-left-color: var(--danger); }
.result-item .ri-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; margin-bottom: .3rem; }
.result-item .ri-head strong { font-size: .9rem; }
.result-item img.crop { max-width: 100%; max-height: 90px; display: block; border: 1px solid var(--border); margin-bottom: .35rem; background: #fff; }
.result-item .meta { font-size: .76rem; color: var(--muted); margin-top: .25rem; }
.result-item .cands { margin-top: .3rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.table-edit { width: 100%; border-collapse: collapse; font-size: .82rem; }
.table-edit th { background: var(--surface-2); font-weight: 600; padding: .2rem; color: var(--muted); }
.table-edit td { padding: .1rem; }
.table-edit input { padding: .2rem .3rem; font-size: .82rem; }
.table-edit input.flag { background: var(--warn-soft); border-color: #e7c27d; }
.table-edit .rm { color: var(--danger); background: none; border: 0; cursor: pointer; font-size: 1rem; }
.rbox rect { fill: rgba(29, 122, 70, .07); stroke: #1d7a46; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; }
.rbox.low rect { stroke: #d08a10; fill: rgba(208, 138, 16, .1); }
.rbox.invalid rect { stroke: #b42318; fill: rgba(180, 35, 24, .1); }
.rbox.empty rect { stroke: #8a93a3; fill: rgba(138, 147, 163, .06); stroke-dasharray: 4 3; }
.rbox.focus rect { stroke-width: 4; }
.rbox text { font-size: 12px; font-weight: 700; paint-order: stroke; stroke: #fff; stroke-width: 3px; pointer-events: none; }

.spinner { width: 16px; height: 16px; border: 2px solid #c6d9f5; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .viewer { height: 60vh; }
  .panel { height: auto; min-height: 0; }
}
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: .5rem; }
  .container { padding: 16px 16px 40px; }
  .userbox { width: 100%; justify-content: space-between; }
}

/* ---- 図面比較 ---- */
.verdict { display: inline-block; padding: .1rem .7rem; border-radius: 999px; font-weight: 700; font-size: .85rem; border: 1.5px solid; white-space: nowrap; }
.verdict.same { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.verdict.similar { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.verdict.different { color: var(--warn); border-color: #d9a441; background: var(--warn-soft); }
.verdict.incomparable { color: var(--danger); border-color: #e39a92; background: var(--danger-soft); }
.verdict.lg { font-size: 1.15rem; padding: .2rem 1rem; }
.cmp-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.cmp-summary .stat { background: var(--surface-2); border-radius: 6px; padding: 12px 14px; }
.cmp-summary .num { font-variant-numeric: tabular-nums; }
.caveat { background: var(--warn-soft); border: 1px solid #f1d9a8; border-radius: 6px; padding: .6rem .8rem; font-size: .88rem; margin-bottom: 16px; }
.notes { margin: 0 0 16px; padding-left: 1.2rem; font-size: .88rem; color: var(--muted); }
.cmp-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.cmp-figure { margin: 0; }
.cmp-figure img { display: block; width: 100%; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.cmp-legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font-size: .82rem; color: var(--muted); margin: .5rem 0 0; }
.cmp-legend i { display: inline-block; width: 22px; height: 0; border-top: 4px solid; vertical-align: middle; margin-right: .3rem; }
.cmp-legend i.old { border-color: #d73228; } .cmp-legend i.new { border-color: #1969e1; } .cmp-legend i.com { border-color: #969696; }
.cmp-legend i.box { height: 12px; border: 3px solid #eb8200; border-radius: 2px; }
.region-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.region { border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: .55rem .65rem; display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: .6rem; align-items: start; }
.region .rno { font-family: var(--mono); font-weight: 700; color: #c56d00; margin-right: .35rem; }
.region .meta { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.region button.thumb { padding: 0; border: 1px solid var(--border); border-radius: 4px; background: #fff; cursor: zoom-in; width: 150px; }
.region button.thumb img { display: block; width: 100%; height: 72px; object-fit: cover; object-position: left top; }
.badge.kind-追加 { background: #e7f0fd; color: #1557c0; border-color: #c3d8f7; }
.badge.kind-削除 { background: #fdeceb; color: #b42318; border-color: #f3c3bd; }
.badge.kind-変更 { background: #f1ecfb; color: #5b3aa8; border-color: #d9cdf3; }
.badge.red { background: #fff0f0; color: #c0261b; border-color: #f5b8b3; }
.text-diff td.old { color: #b42318; }
.text-diff td.new { color: #1557c0; }
dialog.crop-view { border: 0; border-radius: 8px; padding: 12px; max-width: min(96vw, 1840px); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog.crop-view::backdrop { background: rgba(10, 14, 20, .7); }
dialog.crop-view img { display: block; max-width: 100%; max-height: 78vh; }
dialog.crop-view .bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .5rem; }
@media (max-width: 1100px) { .cmp-grid { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .region { grid-template-columns: 1fr; } .region button.thumb { width: 100%; } }
