* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: linear-gradient(180deg, #e9eaef 0%, #e2e3e9 100%);
  color: #141824;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
input, button, textarea { font-family: inherit; }
input, textarea { color: #141824; }
input:focus, textarea:focus { outline: none; border-color: #4f46e5 !important; box-shadow: 0 0 0 3px rgba(79, 70, 229, .14); }
button { cursor: pointer; border: none; background: none; -webkit-tap-highlight-color: transparent; }
::placeholder { color: #b3b8c4; }

@keyframes ocrFade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ocrSpin { to { transform: rotate(360deg); } }
@keyframes ocrBar { 0% { transform: translateX(-100%); } 100% { transform: translateX(280%); } }
@keyframes ocrToast { 0% { opacity: 0; transform: translate(-50%, 8px); } 12% { opacity: 1; transform: translate(-50%, 0); } 88% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, 8px); } }

a { color: #4f46e5; text-decoration: none; }
a:hover { color: #4338ca; }

/* ---- Shell ---- */
.app-shell {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  background: linear-gradient(180deg, #fcfcfe 0%, #f5f6f9 280px);
  box-shadow: 0 0 70px rgba(17, 20, 34, .12);
  position: relative;
  display: flex;
  flex-direction: column;
}
/* モバイルでは全幅にして左右のグレー余白を無くす（デスクトップのみフレーム表示） */
@media (max-width: 520px) {
  .app-shell { max-width: 100%; box-shadow: none; }
}
.screen { animation: ocrFade .24s ease both; flex: 1; display: flex; flex-direction: column; }

/* ---- Shared: headers ---- */
.home-header { display: flex; align-items: center; gap: 11px; padding: 22px 22px 12px; }
.app-icon {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(135deg, #5b52f0, #4338CA);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px -6px rgba(79, 70, 229, .7);
  flex: none;
}
.app-title { font-size: 21px; font-weight: 800; letter-spacing: -.02em; }

.screen-header { display: flex; align-items: center; gap: 12px; padding: 18px 18px 4px; }
.back-btn {
  width: 36px; height: 36px; border-radius: 11px; background: #fff;
  box-shadow: 0 2px 8px -3px rgba(17, 20, 34, .2);
  display: flex; align-items: center; justify-content: center;
  color: #4b5160; font-size: 21px; line-height: 1; flex: none;
}
.screen-title { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }

/* サンプル品質セグメント */
.sample-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.quality-seg { flex: none; display: inline-flex; background: #e9eaef; border-radius: 999px; padding: 2px; }
.quality-opt { font-size: 11px; font-weight: 700; color: #6b7280; padding: 5px 10px; border-radius: 999px; }
.quality-opt.on { background: #fff; color: #4338ca; box-shadow: 0 1px 3px -1px rgba(17, 20, 34, .3); }

/* ---- Home: lead + section labels ---- */
.home-lead { padding: 2px 22px 4px; font-size: 13px; color: #6b7280; line-height: 1.7; }
.section-label-wrap { padding: 20px 22px 10px; }
.section-label { font-size: 11px; font-weight: 700; color: #9aa0b0; letter-spacing: .1em; }
.own-doc-actions { padding: 0 20px; display: flex; flex-direction: column; gap: 12px; }
.trust-line { display: flex; align-items: center; gap: 7px; padding: 14px 22px 2px; font-size: 11.5px; color: #9aa0b0; }
.trust-line svg { flex: none; }

/* AI呼び出しなしメニュー（サンプル結果を見る） */
.no-ai-btn {
  width: calc(100% - 40px); margin: 14px 20px 2px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: #fff; border: 1px solid #e6e7eb; border-radius: 13px; padding: 11px 13px; text-align: left; cursor: pointer;
}
.no-ai-title { font-size: 13px; font-weight: 700; color: #141824; }
.no-ai-sub { font-size: 10.5px; color: #9aa0b0; }

.empty-box { margin: 2px 20px; padding: 20px; border: 1.5px dashed #d7d9e0; border-radius: 16px; text-align: center; font-size: 12.5px; color: #9aa0b0; line-height: 1.7; }

/* ---- Step indicator ---- */
.step-indicator { display: flex; align-items: flex-start; padding: 12px 26px 4px; }
.step-item { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: none; }
.step-dot { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; background: #e6e7ec; color: #9aa0b0; }
.step-item.active .step-dot { background: linear-gradient(135deg, #5b52f0, #4338CA); color: #fff; box-shadow: 0 6px 14px -6px rgba(79, 70, 229, .7); }
.step-item.completed .step-dot { background: #4f46e5; color: #fff; }
.step-label { font-size: 10.5px; font-weight: 700; color: #9aa0b0; white-space: nowrap; }
.step-item.active .step-label { color: #4338ca; }
.step-item.completed .step-label { color: #6b7280; }
.step-line { flex: 1; height: 2px; background: #e6e7ec; margin: 12px 6px 0; }
.step-line.completed { background: #4f46e5; }

/* ---- Sample preview ---- */
.sample-preview-screen { padding-bottom: 108px; }
.sample-preview-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 16px 14px 0; }
.sample-preview-label { font-size: 12.5px; color: #6b7280; text-align: center; margin-bottom: 14px; line-height: 1.6; }
.sample-preview-card {
  width: 100%; max-width: 400px; border-radius: 16px; overflow: hidden;
  box-shadow: 0 10px 30px -14px rgba(17, 20, 34, .3); border: 1px solid rgba(17, 20, 34, .06);
  position: relative; display: block; padding: 0; cursor: zoom-in;
}
.sample-preview-img { width: 100%; display: block; }
.sample-preview-zoom-hint {
  position: absolute; right: 8px; bottom: 8px; background: rgba(20, 24, 36, .72); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 5px 10px; border-radius: 999px; backdrop-filter: blur(4px);
}

/* ---- Full-screen image viewer (pinch-zoom / pan) ---- */
.img-viewer {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 11, 16, .92);
  display: flex; align-items: center; justify-content: center;
  touch-action: none; overscroll-behavior: contain;
}
.viewer-close-btn {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px; width: 40px; height: 40px;
  border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff; font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center; z-index: 2;
}
.viewer-layer { position: relative; display: inline-block; will-change: transform; }
.viewer-img {
  display: block; max-width: 92vw; max-height: 88vh; touch-action: none; user-select: none;
  -webkit-user-drag: none; border-radius: 4px;
}

/* ---- Sample cards + capture actions (home) ---- */
.capture-examples-row { display: flex; gap: 10px; padding: 0 20px; }
.capture-example-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 6px 4px 8px; border-radius: 14px; transition: background .15s; }
.capture-example-item:active { background: rgba(79, 70, 229, .08); }
.mini-doc { width: 100%; height: 56px; border-radius: 10px; position: relative; overflow: hidden; }
.mini-doc-inner {
  position: absolute; left: 8px; right: 8px; top: 8px; bottom: -6px;
  background: #fff; border-radius: 5px 5px 0 0;
  box-shadow: 0 5px 10px -6px rgba(17, 20, 34, .35); padding: 6px 6px 0;
}
.mini-doc-bar { height: 5px; width: 46%; border-radius: 2px; }
.mini-doc-line { height: 3px; width: 78%; border-radius: 2px; background: rgba(17, 20, 34, .11); margin-top: 6px; }
.mini-doc-line + .mini-doc-line { width: 60%; margin-top: 4px; }
.capture-example-name { font-size: 11px; font-weight: 700; color: #6b7280; }

.camera-btn {
  width: 100%; background: linear-gradient(135deg, #5b52f0, #4338CA); color: #fff;
  border-radius: 20px; padding: 24px 20px; box-shadow: 0 18px 38px -16px rgba(79, 70, 229, .8);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.camera-icon-wrap { width: 60px; height: 60px; border-radius: 18px; background: rgba(255, 255, 255, .16); display: flex; align-items: center; justify-content: center; }
.camera-label { font-size: 16px; font-weight: 800; }
.filepick-btn {
  width: 100%; background: #fff; color: #141824; border-radius: 16px; padding: 16px 20px;
  box-shadow: 0 1px 2px rgba(17, 20, 34, .04), 0 10px 24px -16px rgba(17, 20, 34, .2);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.filepick-label { font-size: 15px; font-weight: 700; }

/* ---- Analyzing ---- */
.analyzing-screen { flex: 1; display: flex; flex-direction: column; }
.analyzing-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 20px 40px 40px; }
.preview-img { width: 140px; height: 182px; object-fit: cover; object-position: top; border-radius: 14px; box-shadow: 0 4px 14px rgba(0, 0, 0, .14); filter: saturate(.85); }
.spinner { width: 48px; height: 48px; border: 3.5px solid #e6e7ee; border-top-color: #4f46e5; border-radius: 50%; animation: ocrSpin .9s linear infinite; }
.analyzing-text-wrap { text-align: center; }
.analyzing-title { font-size: 16px; font-weight: 800; color: #141824; }
.analyzing-sub { font-size: 12.5px; color: #9aa0b0; margin-top: 6px; }
.analyzing-elapsed { margin-top: 12px; font-size: 22px; font-weight: 800; color: #4338ca; font-variant-numeric: tabular-nums; }
.analyzing-elapsed span { font-variant-numeric: tabular-nums; }
.progress-track { width: 180px; height: 5px; border-radius: 5px; background: #e6e7ee; overflow: hidden; position: relative; }
.progress-bar { position: absolute; top: 0; left: 0; width: 40%; height: 100%; border-radius: 5px; background: linear-gradient(90deg, #5b52f0, #4338CA); animation: ocrBar 1.1s ease-in-out infinite; }

/* ---- Result: 上下50/50スプリット（上=元PDF / 下=表） ---- */
.result-split { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.rs-top { flex: 1 1 0; min-height: 0; position: relative; background: #e7e9ee; }
.result-split:not(.has-top) .rs-top { display: none; }
.doc-preview { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.doc-preview-layer { position: absolute; left: 0; top: 0; width: 100%; transform-origin: 0 0; will-change: transform; }
.doc-preview-img { display: block; width: 100%; user-select: none; -webkit-user-drag: none; }
.rs-back {
  position: absolute; top: 10px; left: 10px; z-index: 3; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, .92); color: #4b5160; font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px -2px rgba(0, 0, 0, .3);
}
.rs-back-inline { position: static; width: auto; height: auto; border-radius: 10px; font-size: 13px; font-weight: 700; padding: 7px 12px; margin: 8px 0 4px 12px; }

.rs-bottom { flex: 1 1 0; min-height: 0; overflow-y: auto; overflow-x: hidden; background: #f6f7f9; border-top: 2px solid #4f46e5; padding-bottom: calc(78px + env(safe-area-inset-bottom)); }

/* 書類種別（別セクション） */
.rs-doctype { display: flex; align-items: center; gap: 10px; margin: 8px 12px 0; padding: 10px 13px; background: #eef0fe; border: 1px solid #d7dbfb; border-radius: 12px; }
.rs-doctype-label { font-size: 10px; font-weight: 800; color: #6b7280; }
.rs-doctype-val { font-size: 17px; font-weight: 800; color: #4338ca; }

/* ヘッダー項目: エリア(group)ごとにカード化 */
.rs-group { margin: 8px 12px 0; background: #fff; border: 1px solid #e6e7eb; border-radius: 12px; padding: 9px 11px 11px; }
.rs-group-title { font-size: 10.5px; font-weight: 800; color: #4338ca; letter-spacing: .04em; margin-bottom: 7px; }
.rs-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.rs-hf { min-width: 0; }
.rs-hf.full { grid-column: 1 / -1; }

/* 管理者パネル（#/admin） */
.admin-screen { padding-bottom: 40px; }
.admin-body { padding: 8px 20px; display: flex; flex-direction: column; }
.admin-note { font-size: 13px; font-weight: 700; color: #141824; margin: 6px 0 14px; }
.admin-cur { display: block; font-size: 11.5px; font-weight: 600; color: #9aa0b0; margin-top: 4px; }
.admin-label { font-size: 11px; font-weight: 800; color: #4338ca; letter-spacing: .03em; margin-top: 14px; }
.admin-input { width: 100%; font-size: 15px; color: #141824; border: 1px solid rgba(17, 20, 34, .14); border-radius: 10px; padding: 11px 12px; background: #fbfbfd; margin-top: 6px; }
.admin-hint { font-size: 10.5px; color: #9aa0b0; margin-top: 5px; }
.admin-btn { width: 100%; margin-top: 10px; padding: 13px; border-radius: 12px; font-size: 14px; font-weight: 800; color: #4b5160; background: #eef0f4; border: 1px solid #e0e2e8; }
.admin-btn.primary { color: #fff; background: linear-gradient(135deg, #5b52f0, #4338CA); border-color: transparent; box-shadow: 0 12px 24px -14px rgba(79, 70, 229, .7); }
.admin-msg { font-size: 12.5px; font-weight: 700; margin-top: 16px; min-height: 18px; }
.admin-msg.ok { color: #1f7a4d; }
.admin-msg.err { color: #dc2626; }

/* サイトのQRコード（読み取り画面） */
.qr-card { display: flex; align-items: center; gap: 14px; margin: 14px 20px 2px; padding: 14px; background: #fff; border: 1px solid #e6e7eb; border-radius: 16px; box-shadow: 0 1px 2px rgba(17, 20, 34, .04), 0 8px 22px -16px rgba(17, 20, 34, .16); }
.qr-img { flex: none; width: 96px; height: 96px; border-radius: 8px; background: #fff; }
.qr-text { min-width: 0; }
.qr-title { font-size: 13.5px; font-weight: 800; color: #141824; }
.qr-sub { font-size: 11.5px; color: #9aa0b0; line-height: 1.6; margin-top: 3px; }

/* 無料お試し回数の表示（読み取り画面） */
.quota-line { padding: 0 20px; margin-top: 6px; }
.quota-pill { display: inline-block; font-size: 11.5px; font-weight: 700; color: #4338ca; background: #eef0ff; border: 1px solid #dfe2fb; border-radius: 999px; padding: 4px 11px; }

/* AI費用カード */
.rs-cost { margin: 8px 12px 0; background: #f0f7f2; border: 1px solid #cfe7d8; border-radius: 12px; padding: 10px 12px; }
.rs-cost-main { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.rs-cost-label { font-size: 11.5px; font-weight: 700; color: #1f7a4d; }
.rs-cost-val { font-size: 15px; font-weight: 800; color: #14603b; white-space: nowrap; }
.rs-cost-jpy { font-size: 12.5px; font-weight: 700; color: #2f9862; }
.rs-cost-sub { font-size: 10.5px; color: #6b9a7f; margin-top: 4px; }
.rs-hf-label { font-size: 10px; font-weight: 700; color: #9aa0b0; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs-hf-input { width: 100%; font-size: 14px; color: #141824; border: 1px solid rgba(17, 20, 34, .12); border-radius: 8px; padding: 7px 9px; background: #fbfbfd; }

/* 合計系: 明細の下にまとめて表示 */
.rs-totals { margin: 10px 12px 0; background: #fff; border: 1px solid #e6e7eb; border-radius: 12px; padding: 6px 12px; }
.rs-total-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f0f1f4; }
.rs-total-row:last-child { border-bottom: none; }
.rs-total-label { font-size: 12.5px; color: #6b7280; font-weight: 700; flex: none; }
.rs-total-input { flex: 1; min-width: 0; text-align: right; border: none; background: transparent; font-size: 15px; color: #141824; font-variant-numeric: tabular-nums; padding: 3px 4px; }
.rs-total-input:focus { background: #eef0fe; border-radius: 6px; }
.rs-total-row.grand .rs-total-label { color: #141824; font-size: 13.5px; font-weight: 800; }
.rs-total-row.grand .rs-total-input { font-size: 19px; font-weight: 800; color: #1e293b; }

.rs-table-wrap { margin: 8px 0 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.rs-table { border-collapse: collapse; width: max-content; }
.rs-table th, .rs-table td { border-bottom: 1px solid #e6e7eb; border-right: 1px solid #eef0f2; }
.rs-table th {
  text-align: left; font-size: 11px; font-weight: 700; color: #6b7280; background: #eef0f2;
  padding: 8px 10px; white-space: nowrap; min-width: 96px; position: sticky; top: 0; z-index: 1;
}
.rs-table th.num, .rs-table td.num { text-align: right; }
.rs-table td { padding: 0; background: #fff; }
.rs-cell { width: 100%; min-width: 96px; border: none; background: transparent; font-size: 14px; color: #141824; padding: 10px; }
.rs-table td.num .rs-cell { text-align: right; font-variant-numeric: tabular-nums; }
.rs-cell:focus { background: #eef0fe; }

.rs-actions { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 460px; z-index: 35; display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid #e6e7eb; box-shadow: 0 -4px 20px -14px rgba(17, 20, 34, .25); }
.rs-actions .save-next-btn { flex: 1; padding: 14px; font-size: 15px; border-radius: 14px; }
.rs-actions .discard-btn { flex: none; width: auto; margin: 0; padding: 14px 14px; }

.memo-card { margin: 10px 12px; padding: 12px 14px; background: linear-gradient(180deg, #fffdf6, #fff7e8); border: 1px solid #f1e2b6; border-radius: 12px; }
.memo-title { font-size: 12px; font-weight: 800; color: #9a7a1e; margin-bottom: 6px; }
.memo-text { font-size: 13.5px; color: #55503c; line-height: 1.6; white-space: pre-wrap; }

.bottom-actions {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 460px;
  padding: 14px 16px 20px; background: linear-gradient(180deg, rgba(246, 247, 249, 0) 0%, #f6f7f9 34%); z-index: 20;
}
.save-next-btn { width: 100%; background: linear-gradient(135deg, #5b52f0, #4338CA); color: #fff; border-radius: 16px; padding: 18px; font-size: 16px; font-weight: 800; box-shadow: 0 16px 32px -14px rgba(79, 70, 229, .8); }
.discard-btn { width: 100%; color: #9aa0b0; font-size: 13px; font-weight: 600; padding: 13px; margin-top: 2px; }

/* ---- Bottom nav（読み取り / 履歴の2タブ） ---- */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 460px;
  display: flex; background: #fff; border-top: 1px solid #e9eaef; z-index: 40;
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 20px -14px rgba(17, 20, 34, .2);
}
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 8px; color: #9aa0b0; }
.nav-item.active { color: #4f46e5; }
.nav-icon { display: flex; }
.nav-label { font-size: 11px; font-weight: 700; }

/* ---- Home / History tabs ---- */
.scan-screen, .history-screen { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
.history-screen.has-csv { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
.history-list { padding: 6px 16px; display: flex; flex-direction: column; gap: 10px; }
.history-row { background: #fff; border: 1px solid #e6e7eb; border-radius: 15px; padding: 13px 14px; display: flex; align-items: center; gap: 13px; box-shadow: 0 1px 2px rgba(17, 20, 34, .04), 0 8px 22px -16px rgba(17, 20, 34, .16); }
.history-row.checked { border-color: #4f46e5; }
.check-btn { flex: none; width: 24px; height: 24px; border-radius: 8px; border: 2px solid #c7c9d1; background: #fff; color: #fff; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.check-btn.checked { border-color: #4f46e5; background: #4f46e5; }
.history-info { flex: 1; text-align: left; min-width: 0; }
.history-preview-row { display: flex; align-items: center; gap: 6px; }
.history-preview { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.memo-icon { font-size: 12px; }
.history-sub { font-size: 11.5px; color: #9aa0b0; margin-top: 3px; }
.chevron-sm { flex: none; color: #cccfd8; font-size: 20px; }
.hist-tag { flex: none; font-size: 10.5px; font-weight: 800; padding: 2px 8px; border-radius: 999px; letter-spacing: .02em; }

/* 書類種別フィルタ */
.filter-row { display: flex; gap: 8px; padding: 8px 16px 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.filter-chip { flex: none; font-size: 12.5px; font-weight: 700; color: #5b6072; background: #fff; border: 1px solid #e0e2e8; border-radius: 999px; padding: 7px 15px; }
.filter-chip.on { color: #fff; background: linear-gradient(135deg, #5b52f0, #4338CA); border-color: transparent; }

/* すべて選択ツールバー */
.hist-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 18px 2px; }
.select-all-btn { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: #4b5160; }
.check-box-sm { width: 20px; height: 20px; border-radius: 6px; border: 2px solid #c7c9d1; background: #fff; color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.check-box-sm.checked { border-color: #4f46e5; background: #4f46e5; }
.hist-toolbar-right { display: flex; align-items: center; gap: 12px; }
.hist-count { font-size: 11.5px; font-weight: 700; color: #9aa0b0; }
.hist-del-btn { font-size: 13px; font-weight: 800; color: #dc2626; }
.discard-btn.danger { color: #dc2626; }

/* デモ用アラート（サンプル結果を見る） */
.demo-alert { display: flex; gap: 12px; margin: 6px 20px 2px; padding: 14px; border: 1.5px solid #fcd9a4; background: linear-gradient(180deg, #fffaf0, #fff6e5); border-radius: 16px; box-shadow: 0 10px 24px -18px rgba(180, 120, 10, .5); }
.demo-alert-badge { flex: none; align-self: flex-start; font-size: 10px; font-weight: 900; letter-spacing: .06em; color: #fff; background: linear-gradient(135deg, #f59e0b, #d97706); padding: 4px 8px; border-radius: 8px; }
.demo-alert-body { min-width: 0; flex: 1; }
.demo-alert-title { font-size: 14px; font-weight: 800; color: #7c4a03; }
.demo-alert-sub { font-size: 11.5px; color: #a9741f; margin-top: 3px; line-height: 1.6; }
.demo-alert-btn { margin-top: 10px; width: 100%; padding: 12px; border-radius: 12px; font-size: 14px; font-weight: 800; color: #fff; background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 12px 24px -12px rgba(217, 119, 6, .7); }

/* ---- テンプレート選択画面 ---- */
.tpl-select-screen { padding-bottom: 40px; }
.tpl-lead { font-size: 12.5px; color: #6b7180; line-height: 1.7; padding: 4px 20px 2px; }
.tpl-list { padding: 4px 16px; display: flex; flex-direction: column; gap: 10px; }
.tpl-row { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #e6e7eb; border-radius: 15px; padding: 12px 8px 12px 14px; box-shadow: 0 1px 2px rgba(17, 20, 34, .04), 0 8px 22px -16px rgba(17, 20, 34, .16); }
.tpl-info { flex: 1; text-align: left; min-width: 0; }
.tpl-name-row { display: flex; align-items: center; gap: 7px; }
.tpl-name { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-meta { font-size: 11.5px; color: #9aa0b0; margin-top: 3px; }
.tpl-del { flex: none; width: 30px; height: 30px; border-radius: 8px; color: #b8bcc7; font-size: 20px; line-height: 1; }
.new-tpl-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: calc(100% - 32px); margin: 12px 16px 0; padding: 13px 15px; border-radius: 14px; border: 1.5px dashed #b9bdf0; background: #f5f5ff; text-align: left; }
.new-tpl-title { font-size: 14px; font-weight: 800; color: #4338ca; }
.new-tpl-sub { font-size: 11px; color: #7c81c9; }

.csv-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(56px + env(safe-area-inset-bottom)); width: 100%; max-width: 460px;
  padding: 12px 16px 14px; background: linear-gradient(180deg, rgba(246, 247, 249, 0) 0%, #f6f7f9 42%); z-index: 30;
}
.csv-btn { width: 100%; border-radius: 15px; padding: 17px; font-size: 15px; font-weight: 800; background: linear-gradient(135deg, #5b52f0, #4338CA); color: #fff; box-shadow: 0 14px 30px -12px rgba(79, 70, 229, .7); }
.csv-btn.disabled { background: #e6e7ec; color: #a3a7b2; box-shadow: none; cursor: default; }
.csv-hint { text-align: center; font-size: 11px; color: #9aa0b0; margin-top: 9px; }

/* ---- CSVプレビュー（正規化2テーブル） ---- */
.csvp-screen { padding-bottom: 40px; }
.csvp-block { margin: 14px 12px 0; }
.csvp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.csvp-title { font-size: 14px; font-weight: 800; color: #141824; }
.csvp-count { font-size: 11px; font-weight: 700; color: #9aa0b0; margin-left: 4px; }
.csvp-dl { flex: none; font-size: 12.5px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #5b52f0, #4338CA); border-radius: 10px; padding: 8px 14px; }
.csvp-note { font-size: 10.5px; color: #9aa0b0; margin-bottom: 7px; }
.csvp-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid #e6e7eb; border-radius: 10px; background: #fff; }
.csvp-table { border-collapse: collapse; width: max-content; font-size: 12.5px; }
.csvp-table th, .csvp-table td { border-right: 1px solid #eef0f2; border-bottom: 1px solid #eef0f2; padding: 7px 9px; white-space: nowrap; text-align: left; }
.csvp-table th:last-child, .csvp-table td:last-child { border-right: none; }
.csvp-table th { background: #eef0f2; color: #6b7280; font-weight: 700; position: sticky; top: 0; }
.csvp-table td { color: #141824; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* ---- Toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: #141824; color: #fff; font-size: 13px; font-weight: 700;
  padding: 12px 22px; border-radius: 999px; box-shadow: 0 10px 26px -8px rgba(17, 20, 34, .5);
  z-index: 60; white-space: nowrap; display: none;
}
#toast.show { display: block; animation: ocrToast 2.2s ease forwards; }

/* モバイルでは固定バーも全幅にする。app-shell(全幅)より狭いと左右にグレーが出るため。
   base定義より後ろに置くことで max-width:460px を確実に上書きする（メディアクエリは詳細度を上げないため順序が重要） */
@media (max-width: 520px) {
  .bottom-nav, .csv-bar, .bottom-actions, .rs-actions { max-width: 100%; }
}
