/* AI帳票作成：共通スタイル（CSP のためインライン style は使わない） */
:root {
  --brand: #0b5cab;
  --brand-weak: #e8f1fb;
  --ok: #1e7b34;
  --warn: #b25e00;
  --muted: #5c636a;
  --unconfirmed-bg: #f1f3f5;
  /* 文字と背景のコントラスト 4.5:1 以上を確保（Bootstrap 既定の青・灰は背景 #f7f9fb 上で 4.3〜4.4） */
  --bs-primary: #0b5cab;
  --bs-primary-rgb: 11, 92, 171;
  --bs-link-color: #0b5cab;
  --bs-link-color-rgb: 11, 92, 171;
  --bs-link-hover-color: #084a8a;
  --bs-link-hover-color-rgb: 8, 74, 138;
  --bs-secondary-color: #5c636a;
  --bs-secondary-color-rgb: 92, 99, 106;
}
.btn-primary {
  --bs-btn-bg: #0b5cab; --bs-btn-border-color: #0b5cab;
  --bs-btn-hover-bg: #084a8a; --bs-btn-hover-border-color: #084a8a;
  --bs-btn-active-bg: #073f76; --bs-btn-active-border-color: #073f76;
  --bs-btn-disabled-bg: #0b5cab; --bs-btn-disabled-border-color: #0b5cab;
}
.btn-outline-primary {
  --bs-btn-color: #0b5cab; --bs-btn-border-color: #0b5cab;
  --bs-btn-hover-bg: #0b5cab; --bs-btn-hover-border-color: #0b5cab;
  --bs-btn-active-bg: #0b5cab; --bs-btn-active-border-color: #0b5cab;
}
.btn-outline-secondary {
  --bs-btn-color: #5c636a; --bs-btn-border-color: #5c636a;
  --bs-btn-hover-bg: #5c636a; --bs-btn-hover-border-color: #5c636a;
  --bs-btn-active-bg: #5c636a; --bs-btn-active-border-color: #5c636a;
}
.btn-outline-danger {
  --bs-btn-color: #b02a37; --bs-btn-border-color: #b02a37;
  --bs-btn-hover-bg: #b02a37; --bs-btn-hover-border-color: #b02a37;
  --bs-btn-active-bg: #b02a37; --bs-btn-active-border-color: #b02a37;
}
.text-muted, .text-secondary { color: #5c636a !important; }
html, body { height: 100%; }
body { font-size: 16px; background: #f7f9fb; }
.navbar-brand { font-weight: 700; letter-spacing: .02em; }
.app-main { padding-top: .75rem; padding-bottom: 5.5rem; }
.btn, .form-control, .form-select { min-height: 44px; }
.btn-sm { min-height: 36px; }
.hidden { display: none !important; }

/* ホーム */
.tpl-btn { text-align: left; padding: .9rem 1rem; font-size: 1.05rem; }
.tpl-btn small { display: block; color: var(--muted); font-size: .8rem; }
/* 押した直後（青地）でも補足の文字が読めるようにする */
.tpl-btn:hover small, .tpl-btn:focus small, .tpl-btn:active small { color: inherit; }
.section-title { font-size: .95rem; color: var(--muted); margin: 1.25rem 0 .5rem; font-weight: 600; }

/* 会話画面 */
.chat-header { position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid #dee2e6;
  padding: .5rem .75rem; }
.chat-header .title { font-weight: 700; font-size: 1.05rem; margin: 0; line-height: 1.5; }
.chat-title-block { min-width: 0; }
.record-actions-toggle { display: none; }
.record-actions .dropdown-menu {
  position: static; display: flex; gap: .5rem; min-width: 0; padding: 0; border: 0;
  background: transparent;
}
.record-action { white-space: nowrap; }
.progress-pill { font-weight: 700; color: var(--brand); white-space: nowrap; }
.panel { background: #fff; border: 1px solid #dee2e6; border-radius: .5rem; }
.panel.d-flex.flex-column { min-height: 0; }
.chat-log { overflow-y: auto; padding: .75rem; flex: 1 1 auto; min-height: 120px; }
.msg { max-width: 92%; margin-bottom: .6rem; padding: .55rem .8rem; border-radius: .75rem;
  white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.msg.user { margin-left: auto; background: var(--brand); color: #fff; border-bottom-right-radius: .2rem; }
.msg.assistant, .msg.system { background: var(--brand-weak); color: #1d2b3a; border-bottom-left-radius: .2rem; }
.msg .at { font-size: .7rem; opacity: .7; display: block; margin-top: .15rem; }
.pending-card { border: 2px solid var(--warn); border-radius: .5rem; padding: .6rem .8rem; margin: .5rem 0;
  background: #fff8ef; }
.pending-card .arrow { font-weight: 700; color: var(--warn); }
.input-bar { border-top: 1px solid #dee2e6; padding: .5rem; background: #fff; flex: 0 0 auto; }
.input-bar textarea { resize: none; }
@media (hover: none), (pointer: coarse) {
  .input-bar .ctrl-enter-hint { display: none !important; }
}
.qa-btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .45rem; }
.qa-btns .btn { min-height: 44px; min-width: 44px; }
.unmapped-box { margin-top: .4rem; padding: .4rem .55rem; background: #fff8e6; border-radius: .5rem; font-size: .9rem; }
.unmapped-box .btn { min-height: 44px; }
.ai-banner { font-size: .85rem; }

/* 入力状況 */
.group-head { cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  padding: .55rem .75rem; border-bottom: 1px solid #eef0f2; font-weight: 600; background: #fbfcfd; }
.group-head .badge { font-size: .8rem; }
.field-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .5rem .75rem; border-bottom: 1px solid #f1f3f5; cursor: pointer; min-height: 44px; }
.field-row:hover, .field-row:focus { background: #f5f9ff; outline: none; }
.field-row .lbl { flex: 0 0 42%; font-size: .9rem; }
.field-row .val { flex: 1; text-align: right; font-size: .95rem; word-break: break-all; }
.field-row.is-unconfirmed .val { color: var(--muted); }
.field-row.is-absent .val, .field-row.is-unknown .val { color: #343a40; font-weight: 600; }
.req { color: #c92a2a; font-size: .75rem; margin-left: .25rem; }
.rec { color: var(--warn); font-size: .75rem; margin-left: .25rem; }
.badge-ai { background: #e7f5ff; color: #1864ab; border: 1px solid #a5d8ff; font-size: .7rem; margin-left: .3rem; }
.badge-default { background: #f3f0ff; color: #5f3dc4; border: 1px solid #d0bfff; font-size: .7rem; margin-left: .3rem; }
.status-btns .btn { min-width: 4.5rem; }
.opt-btns .btn { margin: 0 .35rem .35rem 0; }
.fields-scroll { max-height: calc(100vh - 210px); overflow-y: auto; }

/* 経過記録 */
.tl-row { display: flex; gap: .5rem; padding: .45rem .75rem; border-bottom: 1px solid #f1f3f5; align-items: center; }
.tl-row .t { font-variant-numeric: tabular-nums; font-weight: 700; width: 3.5rem; }
.tl-row .x { flex: 1; white-space: pre-wrap; }

/* プレビュー */
.pdf-wrap { overflow: auto; background: #6c757d; padding: .75rem .75rem 1.25rem; border-radius: .5rem;
  max-height: calc(100vh - 300px); max-height: calc(100dvh - 300px); min-height: 200px; }
/* 操作の帯（F12）：［戻って修正］［確定して印刷］、印刷後は［再印刷］［訂正版を作成］を画面の下に固定。
   PDF は帯の上に収まる高さにし、帯に隠れないよう下に余白を取る。 */
body.page-preview .app-main { padding-bottom: 0; }
.action-bar { position: sticky; bottom: 0; z-index: 15; background: #fff; border-top: 1px solid #dee2e6;
  box-shadow: 0 -2px 8px rgba(0,0,0,.08); margin: .75rem -.75rem 0;
  padding: .6rem .75rem calc(.6rem + env(safe-area-inset-bottom, 0px)); }
a.blocker-link, button.blocker-link { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
a.blocker-link:hover, a.blocker-link:focus-visible { background: rgba(11, 92, 171, .12); outline: 2px solid var(--brand); }
.pdf-wrap canvas { display: block; margin: 0 auto .75rem; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.print-frame { position: absolute; width: 0; height: 0; border: 0; left: -9999px; }

/* スマホ下部タブ */
.bottom-tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #fff; border-top: 1px solid #dee2e6;
  display: flex; }
.bottom-tabs button { flex: 1; border: 0; background: none; padding: .6rem 0 .7rem; font-size: .85rem; min-height: 56px; }
.bottom-tabs button.active { color: var(--brand); font-weight: 700; border-top: 3px solid var(--brand); }
/* 会話画面（F12）：画面全体を縦の flex で割り付ける。高さの固定値の差し引きはしない。
   100dvh（対応しない端末は 100vh）= ナビ + 見出し + 案内 + 本体（残り全部）。入力欄は本体の一番下に常に見える。 */
body.page-chat {
  display: flex; flex-direction: column;
  height: 100vh;
  height: calc(100vh - var(--kb-pad, 0px));
  height: 100dvh;
  height: calc(100dvh - var(--kb-pad, 0px));
  overflow: hidden;
}
body.page-chat > .navbar, body.page-chat > .alert { flex: 0 0 auto; }
body.page-chat main.app-main {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
  padding-top: .5rem; padding-bottom: .75rem;
}
body.page-chat main.app-main > .chat-header,
body.page-chat main.app-main > .alert { flex: 0 0 auto; }
body.page-chat #panels { flex: 1 1 auto; min-height: 0; flex-wrap: nowrap; }
body.page-chat .sp-panel { min-height: 0; display: flex; flex-direction: column; }
body.page-chat .sp-panel > .panel { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
body.page-chat .sp-panel > .panel.d-flex { overflow: hidden; }
body.page-chat [data-panel="fields"] > .panel { display: flex; flex-direction: column; overflow: hidden; }
body.page-chat [data-panel="fields"] [data-pc-pane]:not(.hidden) { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
body.page-chat .fields-scroll { max-height: none; }
.chat-log-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.chat-log-wrap .chat-log { flex: 1 1 auto; min-height: 0; }
.jump-latest { position: absolute; right: .75rem; bottom: .5rem; z-index: 5; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
/* 入力欄：文章に合わせて伸びる（最大 6 行 = 行の高さ 1.5rem x 6 + 上下の余白と枠）。長い時は欄の中でスクロール */
.input-bar textarea#utterance { min-height: calc(3rem + .75rem + 2px); max-height: calc(9rem + .75rem + 2px); overflow-y: auto; }
.msg-item { display: inline; border: 0; background: none; padding: .1rem .25rem; margin: 0 -.25rem; font: inherit;
  color: inherit; text-align: left; text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer;
  border-radius: .25rem; white-space: pre-wrap; }
.msg-item:hover, .msg-item:focus-visible { background: rgba(11, 92, 171, .12); outline: 2px solid var(--brand); }
.ai-banner .btn-link { min-height: 36px; }
.app-dialog-message { white-space: pre-wrap; word-break: break-word; }

@media (max-width: 991.98px) {
  .app-main { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + var(--kb-pad, 0px)); }
  body.page-chat main.app-main { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
  /* 下部タブ（固定 56px）の上に入力欄を載せる。キーボードが出た時はタブもキーボードの上へ */
  .bottom-tabs { bottom: var(--kb-pad, 0px); }
  body.page-chat .sp-panel { display: none; }
  body.page-chat .sp-panel.active { display: flex; }
  .chat-header { align-items: flex-start !important; }
  .chat-title-block { flex: 1 1 auto; }
  .chat-header .title {
    display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  .record-actions-toggle { display: inline-block; font-size: 1.25rem; line-height: 1; min-width: 44px; }
  .record-actions .dropdown-menu {
    position: absolute; display: none; min-width: 13rem; padding: .5rem; border: var(--bs-border-width) solid var(--bs-border-color);
    background: #fff;
  }
  .record-actions .dropdown-menu.show { display: grid; gap: .4rem; }
  .record-actions .record-action { width: 100%; text-align: left; }
  #manualFieldSave { white-space: nowrap; flex: 0 0 auto; }
}
@media (min-width: 992px) {
  .bottom-tabs { display: none; }
  .app-main { padding-bottom: 1rem; }
  .sp-only { display: none !important; }
}
.toast-container { z-index: 2000; }
.login-card { max-width: 420px; margin: 8vh auto; }
.table-sm td, .table-sm th { font-size: .85rem; }
/* 倍率の表示（ボタンではない。薄くせず読めるようにする） */
.zoom-readout { pointer-events: none; cursor: default; }
