/* ============================================================
 * style.css — 在庫管理システム プロトタイプ
 * デザイントークン → 部品 → 画面 → 印刷 → レスポンシブ の順
 * ============================================================ */

:root {
  /* 色 */
  --bg: #EDF0F2;
  --surface: #FFFFFF;
  --ink: #1B2733;
  --ink-soft: #5C6B78;
  --line: #D9DFE4;
  --brand: #22384C;        /* サイドバー・見出しの鋼色 */
  --brand-deep: #182A3B;
  --accent: #E8590C;       /* セーフティオレンジ（主要アクション） */
  --accent-soft: #FDEEE3;
  --ok: #2B8A5A;
  --ok-soft: #E3F3EB;
  --warn: #C92A2A;
  --warn-soft: #FBE9E9;
  --info-soft: #E7EEF5;

  /* 字 */
  --font-body: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", "Microsoft YaHei", "PingFang SC", sans-serif;
  --font-mono: Consolas, "SF Mono", Menlo, monospace;

  /* 寸 */
  --sidebar-w: 232px;
  --footer-h: 34px;      /* 共通フッター（ICP备案号）。出ていないときは使わない */
  --radius: 8px;
  --shadow: 0 1px 3px rgba(18, 32, 45, 0.10), 0 4px 16px rgba(18, 32, 45, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* バーコード縞モチーフ（署名的装飾。ログインとヘッダーにのみ使用） */
.barcode-stripe {
  height: 6px;
  background: repeating-linear-gradient(
    90deg,
    var(--brand-deep) 0 3px, transparent 3px 5px,
    var(--brand-deep) 5px 11px, transparent 11px 13px,
    var(--brand-deep) 13px 15px, transparent 15px 19px,
    var(--accent) 19px 23px, transparent 23px 26px
  );
}

/* ---------- ログイン ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(160deg, rgba(34, 56, 76, 0.06), rgba(232, 89, 12, 0.05)),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.login-card .barcode-stripe { height: 8px; }
.login-body { padding: 32px 32px 28px; }
.login-company {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin: 0 0 4px;
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.login-sub {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 6px;
  margin-bottom: 20px;
}
.login-body label { display: block; font-size: 12px; color: var(--ink-soft); margin: 14px 0 4px; }
.login-body input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.login-body input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.login-error { color: var(--warn); font-size: 12px; min-height: 18px; margin-top: 10px; }
.login-hint { font-size: 12px; color: var(--ink-soft); margin-top: 16px; }
.login-lang { text-align: right; margin-bottom: 8px; }

/* ---------- アプリ全体レイアウト ---------- */
#app { display: none; min-height: 100vh; }
#app.active { display: block; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--brand);
  color: #E9EEF3;
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.sidebar-brand { padding: 20px 20px 14px; }
.sidebar-brand .company { font-size: 10px; letter-spacing: 0.14em; opacity: 0.65; }
.sidebar-brand .title { font-size: 17px; font-weight: 700; letter-spacing: 0.03em; }
.sidebar-brand .proto {
  display: inline-block; font-size: 10px; color: #FFC9A8;
  border: 1px solid rgba(255, 201, 168, 0.5); border-radius: 3px; padding: 0 5px; margin-top: 4px;
}
.sidebar nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  color: #C6D2DC;
  padding: 11px 20px;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-item .icon { width: 20px; text-align: center; flex: none; }
/* ナビのグループ見出し（マスタ管理など）。サイドバーは暗色のため
 * 本文のトークンではなく nav-item(#C6D2DC) と同系の生色で薄く出す */
.nav-group {
  padding: 14px 20px 4px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: #8FA2B2;
}
.sidebar-foot { padding: 14px 20px; font-size: 12px; opacity: 0.6; }

.main-wrap { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  height: 52px;
  position: sticky; top: 0; z-index: 30;
}
.topbar .hamburger {
  display: none;
  background: none; border: 1px solid var(--line); border-radius: 6px;
  width: 36px; height: 36px; cursor: pointer; font-size: 16px;
}
.topbar .page-title { font-size: 15px; font-weight: 700; flex: 1; }
.lang-switch { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.lang-switch button {
  background: var(--surface); border: none; padding: 5px 10px; cursor: pointer;
  font-size: 12px; color: var(--ink-soft);
}
.lang-switch button.active { background: var(--brand); color: #fff; }
.topbar .user-chip { font-size: 12px; color: var(--ink-soft); }
.topbar .user-chip b { color: var(--ink); }

main#view { flex: 1; padding: 20px; max-width: 1180px; width: 100%; }

/* ---------- ポータル（ログイン後の入口） ----------
 * 在庫管理・共通商品マスタ・見積システムの3枚のカード。
 * バーコード縞（署名モチーフ）を各カードの上辺に使う */
.portal { max-width: 1020px; margin: 0 auto; }
.portal-head { margin: 6px 0 22px; }
.portal-kicker { font-size: 11px; letter-spacing: 0.14em; color: var(--ink-soft); }
.portal-title { margin: 2px 0 4px; font-size: 23px; letter-spacing: 0.02em; }
.portal-lead { margin: 0; font-size: 13px; color: var(--ink-soft); }
.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  align-items: stretch;
}
.portal-card {
  display: flex; flex-direction: column; text-align: left;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  padding: 0; font: inherit; color: inherit; text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.portal-card:hover:not(.disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(18, 32, 45, 0.12), 0 10px 28px rgba(18, 32, 45, 0.10);
}
.portal-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.portal-card.disabled { cursor: default; }
.portal-card.disabled .portal-card-body,
.portal-card.disabled .barcode-stripe { opacity: 0.55; }
.portal-card-body { flex: 1; padding: 18px 20px 14px; }
.portal-glyph {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; margin-bottom: 12px;
}
.portal-card.sys-stock .portal-glyph { background: var(--accent-soft); color: var(--accent); }
.portal-card.sys-master .portal-glyph { background: #F1EDFB; color: #5F3DC4; }
.portal-card.sys-partner .portal-glyph { background: var(--ok-soft); color: var(--ok); }
.portal-card.sys-quote .portal-glyph { background: var(--info-soft); color: var(--brand); }
/* 財務会計システム（ERPの入口）と、その中の業務 */
.portal-card.sys-finance .portal-glyph { background: #E3F1F4; color: #10606E; }
.portal-card.sys-expense .portal-glyph { background: #E3F1F4; color: #10606E; }
.portal-card.sys-remit .portal-glyph { background: #FFF1E6; color: #9A4B00; }
.portal-card.sys-admin   .portal-glyph { background: #EDE9F5; color: #4B3A7A; }
.portal-card h3 { margin: 0 0 4px; font-size: 16.5px; letter-spacing: 0.02em; }
.portal-desc { margin: 0; font-size: 12.5px; color: var(--ink-soft); line-height: 1.55; }
.portal-progress { margin-top: 14px; }
.portal-progress-label {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11.5px; color: var(--ink-soft); margin-bottom: 4px;
}
.portal-progress-label .mono { font-family: var(--font-mono); }
.portal-bar { height: 6px; border-radius: 999px; background: var(--info-soft); overflow: hidden; }
.portal-bar i {
  display: block; height: 100%; width: 0;
  background: var(--ok); border-radius: 999px;
  transition: width 0.4s ease;
}
.portal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 20px; border-top: 1px solid var(--line);
  font-size: 12.5px; background: #FAFBFC;
}
.portal-open { color: var(--accent); font-weight: 600; white-space: nowrap; }
.portal-foot-hint { font-size: 11.5px; color: var(--ink-soft); text-align: right; }
@media (max-width: 960px) {
  .portal-grid { grid-template-columns: 1fr; }
}

/* ---------- 部品 ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; letter-spacing: 0.02em; }
.card .hint { font-size: 12px; color: var(--ink-soft); margin: -6px 0 12px; }

.grid-kpi { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px;
}
.kpi .label { font-size: 12px; color: var(--ink-soft); }
.kpi .value { font-size: 26px; font-weight: 700; font-family: var(--font-mono); line-height: 1.3; }
.kpi .value small { font-size: 13px; font-weight: 400; color: var(--ink-soft); margin-left: 2px; }
.kpi.in .value { color: var(--ok); }
.kpi.out .value { color: var(--accent); }

/* 商品コードチップ（コードは常にこの表示で統一） */
.code-chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--info-soft);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 4px;
  padding: 1px 8px;
  white-space: nowrap;
}
/* SKU（共通商品マスタ発行の正式コード）。マスタ系の紫で bc と見分ける */
.code-chip.sku {
  background: #F1EDFB;
  border-left-color: #5F3DC4;
  font-size: 11.5px;
  margin-top: 2px;
}

/* テーブル
 * 長い表は縦もこの箱の中でスクロールさせ、画面の高さに収める。
 * ページ全体に縦へ伸ばすと、横スクロールバーが表の最下端にしか出ず、
 * 横に収まらない表は一番下まで行かないと横に動かせない。
 * 内側スクロールにすることで th の sticky（見出し固定）も効くようになる。
 * max() は極端に低い画面（横向きスマホ等）で表が潰れないための下限 */
.table-scroll { overflow: auto; max-height: max(calc(100vh - 180px), 320px); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th, table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  font-size: 11.5px;
  color: var(--ink-soft);
  font-weight: 600;
  letter-spacing: 0.04em;
  background: #F6F8FA;
  position: sticky; top: 0;
  z-index: 1; /* セル内の absolute 配置要素が見出しの上に重ならないように */
}
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); }
table.data tr:hover td { background: #FAFBFC; }
table.data td .muted { color: var(--ink-soft); font-size: 12px; }

/* バッジ */
.badge { display: inline-block; font-size: 11.5px; border-radius: 999px; padding: 1px 10px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.low { background: var(--accent-soft); color: var(--accent); }
.badge.zero { background: var(--warn-soft); color: var(--warn); }
.badge.tin { background: var(--ok-soft); color: var(--ok); }
.badge.tout { background: var(--accent-soft); color: var(--accent); }
.badge.tadj { background: var(--info-soft); color: var(--brand); }
/* 不良品。出庫（tout）と紛らわしくないよう、警告寄りの色にする */
.badge.tdefect { background: var(--warn-soft); color: var(--warn); }
.badge.tmaster { background: #F1EDFB; color: #5F3DC4; }
/* 経費精算。在庫の動き（tin/tout）と混ざらないよう青緑系にする */
.badge.texpense { background: #E3F1F4; color: #10606E; }
.badge.tfinance { background: #E3F1F4; color: #10606E; }
/* 振込申請。経費精算（texpense）と並ぶので暖色にして見分ける */
.badge.tremit { background: #FFF1E6; color: #9A4B00; }
.badge.tadmin { background: #EDE9F5; color: #4B3A7A; }
.badge.tlogin { background: #EEF1F4; color: var(--ink-soft); }
/* 共通商品マスタの整理状態（未整理 / 整理中 / 確定） */
.badge.mst-none { background: var(--info-soft); color: var(--ink-soft); }
.badge.mst-ai { background: #F1EDFB; color: #5F3DC4; }   /* AI候補（.tmaster と同系の紫） */
.ai-hint { color: #5F3DC4; }
.badge.mst-draft { background: var(--accent-soft); color: var(--accent); }
.badge.mst-verified { background: var(--ok-soft); color: var(--ok); }
/* 認証・社員管理 */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; cursor: pointer; font-size: 18px;
  padding: 6px 8px; line-height: 1; color: var(--ink-soft);
}
.role-tag {
  margin-left: 6px; font-size: 11px; font-weight: 600;
  background: var(--info-soft, #eef4fa); color: var(--brand, #1f4e79);
  padding: 1px 8px; border-radius: 999px;
}
/* 仮パスワードは読み上げやすいよう大きく等幅で出す */
.temp-pw {
  font-family: Consolas, Menlo, monospace; font-size: 26px; font-weight: 700;
  letter-spacing: 2px; text-align: center; user-select: all;
  padding: 16px; margin: 12px 0; border-radius: 10px;
  background: #F7F9FB; border: 2px dashed var(--brand, #1f4e79);
  word-break: break-all;
}
/* 倉庫でも押しやすいボタンサイズ（タブレット・スマホ） */
@media (max-width: 900px) {
  .btn { min-height: 44px; }
  .form-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* 接続エラーの警告バナー */
#net-banner {
  position: fixed; left: 50%; top: 12px; transform: translate(-50%, -140%);
  z-index: 9999; max-width: 92vw;
  background: var(--warn, #b3261e); color: #fff;
  padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: transform .25s ease;
}
#net-banner.show { transform: translate(-50%, 0); }
/* 情報通知（他の作業者の登録を知らせる等） */
#net-banner.notice { background: var(--brand, #1f4e79); }

/* スキャン棚卸 */
#scan-video {
  width: 100%; max-height: 38vh; border-radius: 10px;
  background: #000; object-fit: cover; display: block;
}
.scan-status {
  margin-top: 8px; padding: 8px 12px; border-radius: 8px;
  background: var(--info-soft, #eef4fa); color: var(--ink);
  font-size: 13.5px;
}
.scan-card {
  margin-top: 10px; padding: 12px; border: 2px solid var(--brand);
  border-radius: 10px; background: #fff;
}

/* データ点検 */
.badge.sev-error { background: var(--warn-soft); color: var(--warn); }
.badge.sev-warn { background: var(--accent-soft); color: var(--accent); }
.badge.sev-info { background: var(--info-soft); color: var(--brand); }
.badge.done { background: #EEF1F4; color: var(--ink-soft); }
tr.row-done { opacity: .5; }
.kpi-inline { font-size: 15px; }

/* 商品写真 */
.thumb {
  width: 40px; height: 40px; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--line);
  cursor: pointer; display: block; background: #fff;
}
.thumb:hover { box-shadow: 0 0 0 2px var(--brand); }
.thumb-none { color: var(--ink-soft); opacity: .45; display: inline-block; width: 40px; text-align: center; }
.photo-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.photo-preview {
  width: 96px; height: 96px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line); background: #fff;
}
.photo-full { max-width: 100%; max-height: 65vh; display: block; margin: 0 auto; border-radius: 8px; }

/* 倉庫区分バッジ（原料/副資材/紙コップ半製品/アルミ半製品/成品） */
.badge.wh-raw { background: #FFF4E0; color: #A05A00; }
.badge.wh-aux { background: #EEF1F4; color: #4A5560; }
.badge.wh-cup { background: #E5F3FB; color: #16608B; }
.badge.wh-alu { background: #F1EDFB; color: #5F3DC4; }
.badge.wh-fin { background: var(--ok-soft); color: var(--ok); }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13.5px;
  cursor: pointer;
}
.btn:hover { background: #F4F6F8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #D14F0A; }
.btn.dark { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.dark:hover { background: var(--brand-deep); }
.btn.danger { color: var(--warn); border-color: #EFC4C4; }
.btn.danger:hover { background: var(--warn-soft); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:focus-visible, .nav-item:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* フォーム */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 3px; }
.field label .req { color: var(--warn); margin-left: 3px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
.field .note { font-size: 11.5px; color: var(--ink-soft); margin-top: 3px; }
/* 商品ピッカー横の倉庫区分絞り込み（入庫・出庫画面） */
.picker-row { display: flex; gap: 8px; }
.picker-row select { flex: 0 0 auto; width: auto; max-width: 45%; }
.picker-row input { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* 共通商品マスタの2ペイン比較編集（左=Legacy参照 / 右=マスタ編集）。
 * 560px 以下では縦積み（上=Legacy / 下=マスタ）になる */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.master-pane h2 { font-size: 14px; margin: 0 0 12px; color: var(--ink-soft); }
.master-pane .master-legacy-value { padding: 6px 0 2px; font-size: 14px; }
.master-identity {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 0 14px; font-size: 15px;
}
.master-cust-row { display: flex; gap: 8px; flex-wrap: wrap; }
.master-cust-row select,
.master-cust-row input { flex: 1 1 140px; min-width: 0; }
/* 添えるボタン（＋新規顧客・現在の品名を使う）はラベルを折り返さず、
 * 幅が足りないときは横に潰さず下の行へ回す */
.master-cust-row .btn { white-space: nowrap; flex: none; }
.master-packaging { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }

/* 操作履歴の詳細（何を変えたか） */
.log-detail-sub { font-size: 13px; color: var(--ink-soft); margin: 18px 0 8px; }
.log-detail-sub + .table-scroll { max-height: 260px; }

/* 顧客の担当者（複数可）。名前・メール・削除ボタンを1行に並べる */
.partner-contact-row { display: flex; gap: 8px; margin-bottom: 8px; }
.partner-contact-row .pn-ct-name { flex: 1; min-width: 0; }
.partner-contact-row .pn-ct-email { flex: 1.4; min-width: 0; }
.partner-contact-row .pn-ct-del { flex: none; }

/* 顧客・仕入先を消せなかったときに、紐付いている商品を並べる欄 */
.partner-inuse { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.partner-inuse .warn-text { color: var(--warn); font-size: 13px; margin: 0 0 10px; }
.partner-inuse .table-scroll { max-height: 240px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar input[type="text"] {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; min-width: 220px;
}
.toolbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.toolbar .spacer { flex: 1; }
.toolbar label.check { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); }

/* モーダル */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 32, 43, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  width: 100%; max-width: 640px;
  overflow: hidden;
}
.modal .modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.modal .modal-head h3 { margin: 0; font-size: 15px; }
.modal .modal-head .x { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--ink-soft); }
.modal .modal-body { padding: 18px 20px; }

/* トースト */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--brand-deep); color: #fff;
  padding: 10px 22px; border-radius: 999px; font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 80;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* 差異表示（棚卸） */
.diff-pos { color: var(--ok); font-weight: 700; }
.diff-neg { color: var(--warn); font-weight: 700; }

/* ---------- ラベル発行 ---------- */
.label-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.label-item {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
  text-align: center;
}
.label-item .l-name { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.label-item .l-spec { font-size: 11px; color: var(--ink-soft); margin-bottom: 8px; }
.label-item svg { max-width: 100%; height: auto; }

/* ============================================================
 * 経費精算
 *
 * 画面の部品（一覧・編集フォーム・承認の流れ・領収書）と、
 * 印刷される申請書（.doc-sheet）。申請書は A4 横（297×210mm）で、
 * 画面上も同じ寸法で描く。画面で見たものと紙に出るものを
 * 一致させないと、承認者が画面だけ見て判を押してしまうため。
 * ============================================================ */

/* ---------- 共通の小物 ---------- */
.toolbar .grow { flex: 1; }
.btn-group { display: inline-flex; gap: 0; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 6px 6px 0; }

.sec-title { margin: 18px 0 8px; font-size: 13px; letter-spacing: 0.04em; color: var(--ink-soft); }
.card > .sec-title:first-child { margin-top: 0; }

.warn-box {
  background: var(--warn-soft); color: var(--warn);
  border-left: 3px solid var(--warn);
  border-radius: 4px; padding: 8px 12px; margin: 0 0 12px; font-size: 13px;
}

table.data tr.clickable { cursor: pointer; }

/* フォーム。label でくるむ書き方（label > 文言 + input）に合わせる */
.form-grid > label, label.block {
  display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 10px;
}
.form-grid > label input, .form-grid > label select,
label.block input, label.block select, label.block textarea {
  display: block; width: 100%; margin-top: 3px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); font-size: 14px;
}
label.block small.hint { display: block; margin-top: 3px; }

/* 選ばせずに値だけを見せる欄（経費精算の会社名など）。
 * 入力欄と縦位置が揃うよう、高さは入力欄に合わせる */
.exp-fixed {
  display: block; margin-top: 3px; padding: 8px 0;
  font-size: 14px; color: var(--ink); font-weight: 600;
}

/* ---------- 明細の編集 ---------- */
table.data.exp-edit-lines td { padding: 4px 6px; }
table.data.exp-edit-lines input {
  width: 100%; min-width: 90px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 5px; background: #fff;
}
table.data.exp-edit-lines input.l-name { min-width: 220px; }
table.data.exp-edit-lines input.num { text-align: right; font-family: var(--font-mono); }
.exp-total { font-size: 15px; }
.exp-total b { font-size: 18px; }

/* ---------- 承認の流れ ----------
 * 申请人 → 财务审核 → 总经理审批 → 出纳付款 → 财务结算 の5段。
 * どこで止まっているかが一目で分かるよう、待ちの段だけ色を変える */
.exp-flow { list-style: none; margin: 0 0 6px; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.exp-flow li {
  flex: 1; min-width: 132px;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #FAFBFC;
}
.exp-flow li.done { background: var(--ok-soft); border-color: #BFE3CF; }
.exp-flow li.waiting { background: var(--accent-soft); border-color: #F5CDB0; }
.exp-flow li.rejected { background: var(--warn-soft); border-color: #EFC4C4; }
.exp-flow-step { display: block; font-size: 11.5px; color: var(--ink-soft); }
.exp-flow-who { display: block; font-weight: 600; }
.exp-flow-state { display: block; font-size: 11.5px; }
.exp-flow li.waiting .exp-flow-state { color: var(--accent); font-weight: 600; }
.exp-flow li.rejected .exp-flow-state { color: var(--warn); font-weight: 600; }
.exp-flow li.done .exp-flow-state { color: var(--ok); }
.exp-flow-at { display: block; font-size: 11px; color: var(--ink-soft); }

/* ---------- 領収書 ---------- */
.receipt-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.receipt-item { margin: 0; text-align: center; }
.receipt-item img {
  width: 100%; height: 130px; object-fit: cover; cursor: zoom-in;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.receipt-item figcaption { font-size: 11.5px; color: var(--ink-soft); margin: 4px 0; }

.approver-block { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.approver-block h4 { margin: 0 0 8px; font-size: 14px; }
.approver-block select[multiple] { height: auto; }

/* ============================================================
 * 申請書（A4横）
 *
 * 紙の様式（汇款、报销模板.xlsm）の欄はすべて残したうえで、
 * 横幅を活かして「明細」と「付款要求・出纳填写」を左右に並べる。
 * 縦A4の詰まった見た目より読みやすくするための配置。
 * ============================================================ */
.doc-sheet-wrap { overflow-x: auto; margin-bottom: 16px; }
.doc-sheet {
  width: 297mm;
  min-height: 210mm;
  margin: 0 auto 12px;
  padding: 12mm 14mm;
  background: #fff;
  color: #000;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  /* 中国語の帳票なので、明朝系（宋体）を先に当てて紙の様式に寄せる */
  font-family: "Songti SC", SimSun, "Noto Serif SC", serif;
  font-size: 12px;
  line-height: 1.5;
}

.doc-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end;
  border-bottom: 2px solid #000; padding-bottom: 6px;
}
.doc-company { font-size: 13px; font-weight: 700; }
.doc-title {
  margin: 0; font-size: 24px; letter-spacing: 0.4em; text-indent: 0.4em; font-weight: 700;
}
.doc-no { text-align: right; font-size: 12px; }

.doc-meta {
  display: grid; grid-template-columns: 2fr 1fr 1fr 0.8fr; gap: 0 10px;
  padding: 6px 0; border-bottom: 1px solid #000;
}
.doc-field { display: flex; gap: 4px; align-items: baseline; min-height: 20px; }
.doc-label { color: #333; white-space: nowrap; }
.doc-value { flex: 1; border-bottom: 1px dotted #999; min-height: 18px; word-break: break-all; }
.doc-label-inline { color: #333; margin-right: 2px; }

.doc-remit-to { padding: 6px 0; border-bottom: 1px solid #000; }
.doc-remit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.doc-block-title { font-weight: 700; margin-bottom: 3px; }

.doc-summary {
  display: flex; gap: 6px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid #000; font-size: 13px;
}
.doc-summary .doc-value { font-weight: 700; }

/* 明細（左）と 付款要求・出纳填写（右）。
 * 名称は品名がそのまま入るので、左を広めに取って折り返しを減らす */
.doc-main { display: grid; grid-template-columns: 1.95fr 1fr; gap: 0 6mm; flex: 1; padding-top: 8px; }

table.doc-table { width: 100%; border-collapse: collapse; }
table.doc-table th, table.doc-table td {
  border: 1px solid #000; padding: 4px 6px; font-size: 12px; vertical-align: middle;
}
table.doc-table th { background: #F2F2F2; font-weight: 700; text-align: center; }
table.doc-table td.c, table.doc-table th.c { text-align: center; }
table.doc-table td.r, table.doc-table th.r { text-align: right; }
table.doc-table .w-seq { width: 34px; }
table.doc-table .w-date { width: 76px; }
table.doc-table .w-amt { width: 90px; }
table.doc-table tr.blank td { color: #BBB; height: 22px; }
table.doc-table .doc-note { color: #666; font-size: 11px; }
table.doc-table tfoot td { background: #FAFAFA; font-weight: 700; }
table.doc-table tfoot td.upper { letter-spacing: 0.05em; }

.doc-side { display: flex; flex-direction: column; gap: 6px; }
.doc-box { border: 1px solid #000; padding: 6px 8px; }
.doc-box .doc-field { margin-bottom: 2px; }
.doc-check { margin-right: 10px; white-space: nowrap; }

/* 署名欄。画面の审批流程と同じ5工程を同じ順に並べる
 * （报销人 / 财务审核 / 总经理审批 / 出纳付款 / 财务结算） */
.doc-signs {
  display: grid; grid-template-columns: repeat(5, 1fr);
  border: 1px solid #000; border-right: none; margin-top: 8px;
}
.doc-sign { border-right: 1px solid #000; padding: 4px 6px 6px; min-height: 56px; }
.doc-sign-label { font-size: 11px; color: #333; text-align: center; border-bottom: 1px solid #DDD; padding-bottom: 2px; }
.doc-sign-name { text-align: center; font-size: 13px; padding-top: 6px; min-height: 20px; }
.doc-sign-at { text-align: center; font-size: 10px; color: #666; }
/* 差し戻された工程。名前だけだと承認したように読めるので印を付ける */
.doc-sign-note { text-align: center; font-size: 10px; color: #B02525; }
.doc-sign.rejected .doc-sign-name { text-decoration: line-through; }

/* ---------- 振込申請の帳票（汇款申请单） ----------
 * 紙の様式を写さず、実務で使う項目だけを A4 一枚に詰める。
 * 使っていないサイン欄（批准人・出纳・财务结算など）は置かない。 */
.remit-doc .remit-meta { grid-template-columns: repeat(4, 1fr); }
.remit-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; margin-top: 6px; }
.remit-doc .remit-block { margin-top: 0; }
.remit-doc .remit-block .doc-field { margin-bottom: 3px; }
.remit-doc .remit-amount .doc-value { font-size: 17px; font-weight: 700; }

.remit-record { margin-top: auto; padding-top: 8px; }
.remit-record-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 1px solid #000; border-right: none;
}
.remit-record-cell { border-right: 1px solid #000; padding: 5px 8px 7px; min-height: 62px; }
.remit-record-step { font-size: 11px; color: #333; border-bottom: 1px solid #DDD; padding-bottom: 2px; }
.remit-record-name { font-size: 14px; padding-top: 5px; min-height: 20px; }
.remit-record-state { font-size: 11px; color: #333; }
.remit-record-at { font-size: 10px; color: #666; }
.remit-record-cell.rejected .remit-record-name { text-decoration: line-through; }
.remit-record-cell.rejected .remit-record-state { color: #B02525; }
.remit-paid-ref { font-size: 11px; color: #333; padding-top: 4px; }

/* 処理の流れで「审批」と「执行」を見分ける小さな札 */
.remit-kind {
  font-size: 10px; border: 1px solid var(--line); border-radius: 3px;
  padding: 0 4px; color: var(--ink-soft); background: #fff;
}

/* 領収書の台紙（申請書の後ろに続けて刷る。1枚に2点） */
.doc-attach-print { display: none; }
.attach-sheet-body {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; padding-top: 6mm;
}
.attach-sheet-body figure {
  margin: 0; display: flex; flex-direction: column; border: 1px solid #999; padding: 4mm;
}
.attach-sheet-body img { width: 100%; flex: 1; object-fit: contain; max-height: 150mm; }
.attach-sheet-body figcaption { text-align: center; font-size: 11px; padding-top: 3mm; }

/* 画面が狭いときは申請書全体を縮めて見せる（横スクロールで探させない）。
 * transform ではなく zoom を使うのは、transform だと縮んでも元の高さのまま
 * 場所を取り、申請書の下に大きな空白が残るため。 */
@media (max-width: 1520px) { .doc-sheet { zoom: 0.80; } }
@media (max-width: 1240px) { .doc-sheet { zoom: 0.62; } }
@media (max-width: 980px)  { .doc-sheet { zoom: 0.48; } }

/* ---------- 印刷 ---------- */
@media print {
  /* 棚卸用紙などを Ctrl+P で刷るとき、内側スクロールで行が切れないよう全行を展開する */
  .table-scroll { max-height: none; overflow: visible; }
}

/* ---------- 印刷（ラベルのみ出力） ---------- */
@media print {
  /* 备案号は画面での掲示義務。ラベルや伝票には刷らない */
  #site-footer { display: none !important; }

  body.printing-labels .sidebar,
  body.printing-labels .topbar,
  body.printing-labels .no-print { display: none !important; }
  body.printing-labels .main-wrap { margin-left: 0; }
  body.printing-labels main#view { padding: 0; max-width: none; }
  body.printing-labels .card { box-shadow: none; padding: 0; margin: 0; }
  body.printing-labels .label-item { break-inside: avoid; }
}

/* ---------- 印刷（経費精算の申請書だけ出力） ----------
 * 画面では A4 横の実寸（297mm）で描いているが、紙では幅を固定しない。
 * width: auto にして、渡された用紙いっぱいに広がるようにする。
 * こうしておくと、ダイアログで縦を選ばれても内容が切れずに収まる。
 *
 * 用紙の向きはここでは指定しない（理由は下の「用紙について」を参照）。 */
@media print {
  body.printing-doc .sidebar,
  body.printing-doc .topbar,
  body.printing-doc .no-print,
  body.printing-doc #chat-widget,
  body.printing-doc #toast,
  body.printing-doc #net-banner { display: none !important; }
  body.printing-doc .main-wrap { margin-left: 0; }
  body.printing-doc main#view { padding: 0; max-width: none; }
  body.printing-doc .card { box-shadow: none; padding: 0; margin: 0; }

  /* 画面の骨組み（高さの下限 100vh・フレックス）を紙では外す。
   * 残すと、申請書のほかに中身が無くても1ページ分の高さを占め、
   * 白紙のページが出てしまう。 */
  body.printing-doc #app,
  body.printing-doc .main-wrap { min-height: 0; display: block; }
  body.printing-doc main#view { flex: none; }

  body.printing-doc .doc-sheet-wrap { overflow: visible; display: block; }
  body.printing-doc .doc-sheet {
    zoom: 1;   /* 画面用の縮小を解いて等倍で刷る */
    width: auto; min-height: 0; margin: 0; padding: 0;
    box-shadow: none;
  }
  /* 申請書が1枚目、領収書の台紙が2枚目以降。break-after ではなく
   * break-before にしてあるのは、最後の1枚のあとに空白ページを作らないため */
  body.printing-doc .doc-attach-print .doc-sheet { break-before: page; }
  body.printing-doc table.doc-table tr { break-inside: avoid; }
  body.printing-doc .doc-signs { break-inside: avoid; }

  /* 領収書の台紙は「領収書も一緒に印刷する」を選んだときだけ出す */
  body.printing-doc .doc-attach-print { display: none; }
  body.printing-doc.print-attachments .doc-attach-print { display: block; }
}

/* ---------- 用紙について（@page を使わない理由） ----------
 *
 * 用紙の向きは CSS では指定せず、印刷ダイアログの設定に任せている。
 * 申請書は与えられた紙に合わせて伸縮する（.doc-sheet は印刷時 width: auto）ので、
 * ダイアログで「A4・横」を選べばそのまま横1枚に収まる。
 *
 * @page で向きを指定する方法は2通り試したが、どちらも実機で問題が出た。
 *
 *   1. 名前付きページを申請書だけに当てる
 *      （@page expense-sheet { size: A4 landscape } + .doc-sheet { page: … }）
 *      → 用紙の大きさが1つの文書の途中で変わることになり、ブラウザはその
 *        切れ目で必ずページを分ける。既定ページ側に残った（中身は無いが
 *        箱はある）ところへ白紙のページが前後1枚ずつ入った。
 *
 *   2. 文書全体に @page { size: A4 landscape } を当てる
 *      → ダイアログの向き設定と食い違うと、縦の紙に内容だけ90度回転して
 *        載り、端が切れた。ダイアログで横を選んでも直らなかった。
 *
 * どちらも「CSSが決める用紙」と「ダイアログが決める用紙」の競合が原因なので、
 * CSS側が何も主張しないようにして競合を無くしてある。
 * 画面には expPrintHint（A4横で印刷してください）を出して案内している。
 *
 * この方針を変えるとき（例えば @page を復活させるとき）は、
 * 上の2つの失敗を再現しないか必ず実機のPDFで確かめること。 */

/* ---------- 共通フッター（ICP备案号） ----------
 * ログイン画面とアプリ本体の両方の外側にあり、どちらでも同じものが出る。
 * 番号が未設定のときは .on が付かず、まったく場所を取らない
 * （そのため #login-screen などの 100vh も body.has-footer のときだけ縮める）。 */
#site-footer { display: none; }
#site-footer.on {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--footer-h);
  /* 上下の余白は控えめにする。中身＋余白＋境界線が --footer-h を超えると、
   * 上で引いている calc(100vh - var(--footer-h)) と合わなくなり、
   * 1px のスクロールバーが出る */
  padding: 6px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
}
#site-footer a { color: inherit; text-decoration: none; }
#site-footer a:hover { text-decoration: underline; }

/* フッターの分だけ画面の高さを詰め、余計なスクロールを出さない */
body.has-footer #login-screen,
body.has-footer #app,
body.has-footer .main-wrap { min-height: calc(100vh - var(--footer-h)); }

/* アプリ本体ではサイドバー（position: fixed）と重ならないように寄せる。
 * ログイン画面にはサイドバーが無いので、この指定も掛からない。 */
#app.active ~ #site-footer.on { margin-left: var(--sidebar-w); }

/* ---------- レスポンシブ ---------- */
@media (max-width: 960px) {
  /* 狭い画面ではサイドバーが引っ込むので、フッターも寄せない */
  #app.active ~ #site-footer.on { margin-left: 0; }

  .sidebar { transform: translateX(-100%); transition: transform 0.22s ease; }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.3); }
  .main-wrap { margin-left: 0; }
  .topbar .hamburger { display: block; }
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .nav-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 35; background: rgba(20,32,43,0.35);
  }
  body.nav-open .nav-backdrop { display: block; }
}

@media (max-width: 560px) {
  main#view { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: 1fr; }
  .grid-kpi { gap: 10px; }
  .kpi .value { font-size: 21px; }
  .toolbar input[type="search"], .toolbar input[type="text"] { min-width: 0; flex: 1; }
  .login-body { padding: 24px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================
 * AIチャット（使い方Q&A / js/chat.js）
 * モーダル(z-index:60)より下、サイドバー(40)より上に置く
 * ============================================================ */

#chat-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  width: 52px; height: 52px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff;
  box-shadow: var(--shadow);
}
#chat-fab:hover { background: var(--brand-deep); }

/* 小さな3Dロボット: CSSの3D変形で頭・胴体を箱として組み、
 * 首振り・浮遊・まばたき・アンテナの点滅を付ける。
 * prefers-reduced-motion では末尾の共通ルールで止まる（静止した3D姿勢のまま） */
.chat-robot3d {
  display: block; width: 34px; height: 38px;
  perspective: 120px; pointer-events: none;
}
.r3d-rig {
  position: relative; display: block;
  width: 22px; height: 26px; margin: 11px auto 0;
  transform-style: preserve-3d;
  transform: rotateX(8deg) rotateY(-18deg);
  animation: r3d-turn 6s ease-in-out infinite;
}
#chat-fab:hover .r3d-rig { animation-duration: 2s; }

/* 頭（22×15×14 の箱） */
.r3d-head {
  position: absolute; left: 0; top: 0; width: 22px; height: 15px;
  transform-style: preserve-3d;
}
.r3d-face { position: absolute; left: 0; top: 0; width: 22px; height: 15px; border-radius: 3px; }
.f-front  { background: linear-gradient(180deg, #ffffff, #e2e8ed); transform: translateZ(7px); }
.f-back   { background: #c2ccd4; transform: rotateY(180deg) translateZ(7px); }
.f-left   { width: 14px; left: 4px; background: #a9b5bf; transform: rotateY(-90deg) translateZ(11px); }
.f-right  { width: 14px; left: 4px; background: #cdd6dc; transform: rotateY(90deg) translateZ(11px); }
.f-top    { height: 14px; top: 0.5px; background: #f5f8fa; transform: rotateX(90deg) translateZ(7.5px); }
.f-bottom { height: 14px; top: 0.5px; background: #97a3ad; transform: rotateX(-90deg) translateZ(7.5px); }

/* 顔（前面に目と口） */
.r3d-eye {
  position: absolute; top: 5px; width: 4px; height: 4px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3d5870, #22384C);
  animation: chat-blink 4.5s infinite;
}
.r3d-eye:first-child { left: 4.5px; }
.r3d-eye + .r3d-eye { right: 4.5px; }
.r3d-mouth {
  position: absolute; left: 8px; bottom: 2.5px; width: 6px; height: 1.5px;
  border-radius: 1px; background: #22384C; opacity: 0.85;
}

/* 胴体（16×9×10 の箱。頭の下に少し奥まって付く） */
.r3d-body {
  position: absolute; left: 3px; top: 16px; width: 16px; height: 9px;
  transform-style: preserve-3d;
}
.r3d-bface { position: absolute; left: 0; top: 0; width: 16px; height: 9px; border-radius: 2px; }
.b-front { background: linear-gradient(180deg, #f3f6f8, #d5dde2); transform: translateZ(5px); }
.b-left  { width: 10px; left: 3px; background: #a9b5bf; transform: rotateY(-90deg) translateZ(8px); }
.b-right { width: 10px; left: 3px; background: #cdd6dc; transform: rotateY(90deg) translateZ(8px); }
.b-top   { height: 10px; top: -0.5px; background: #eef2f5; transform: rotateX(90deg) translateZ(4.5px); }
.r3d-chest {
  position: absolute; left: 5px; top: 2.5px; width: 6px; height: 3.5px;
  border-radius: 1px; background: #22384C; opacity: 0.25;
}

/* アンテナ（頭の上。ランプは点滅する） */
.r3d-antenna {
  position: absolute; left: 10.2px; top: -6px; width: 1.6px; height: 6px;
  background: #cfd6dc; transform: translateZ(0);
}
.r3d-lamp {
  position: absolute; left: 8px; top: -11px; width: 6px; height: 6px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd8a8, #f08c00);
  animation: chat-lamp 2.2s ease-in-out infinite;
}

/* 首振り＋上下の浮遊（1つのtransformにまとめる） */
@keyframes r3d-turn {
  0%, 100% { transform: translateY(1px) rotateX(8deg) rotateY(-24deg); }
  50%      { transform: translateY(-1px) rotateX(8deg) rotateY(24deg); }
}
@keyframes chat-blink {
  0%, 90%, 100% { transform: scaleY(1); }
  93%, 96% { transform: scaleY(0.15); }
}
@keyframes chat-lamp {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#chat-panel {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  width: 360px; max-width: calc(100vw - 24px);
  height: 480px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
#chat-panel[hidden] { display: none; }

.chat-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; background: var(--brand); color: #fff;
}
.chat-head #chat-title { flex: 1; font-weight: 600; }
.chat-iconbtn {
  border: none; background: transparent; color: #fff;
  cursor: pointer; font-size: 15px; padding: 2px 6px; border-radius: 4px;
}
.chat-iconbtn:hover { background: rgba(255, 255, 255, 0.15); }

#chat-msgs {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg);
}
.chat-msg {
  max-width: 85%; padding: 8px 10px; border-radius: 10px;
  white-space: pre-wrap; word-break: break-word; font-size: 13px;
}
.chat-msg.user { align-self: flex-end; background: var(--info-soft); }
.chat-msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); }
.chat-msg.thinking { color: var(--ink-soft); }
.chat-msg.err { align-self: flex-start; background: var(--warn-soft); color: var(--warn); }

#chat-disclaimer {
  padding: 4px 12px; font-size: 11px; color: var(--ink-soft);
  border-top: 1px solid var(--line);
}
#chat-form {
  display: flex; gap: 8px; padding: 8px 12px 12px; align-items: flex-end;
}
#chat-input {
  flex: 1; resize: none; padding: 8px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--font-body); font-size: 13px;
}
#chat-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

@media (max-width: 560px) {
  #chat-panel { right: 6px; bottom: 6px; height: 70vh; }
}

@media print {
  #chat-widget { display: none !important; }
}
