/* ============================================================
   quote-editor.css — 見積エディタ専用スタイル
   新規クラスは全て qe- プレフィクス。app.css の CSS変数(--c-*)を参照。
   デザイン: 白ベース + 濃紺 #1a2b3c + 鋼青 #0b69a3、控えめ罫線。
   ============================================================ */

/* ===== 2ペインレイアウト(エディタ | 紙面プレビュー) ===== */
.qe-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.qe-layout.qe-preview-on {
  grid-template-columns: minmax(0, 1fr) clamp(340px, 34vw, 480px);
}
.qe-layout:not(.qe-preview-on) .qe-preview-pane { display: none; }
.qe-main { min-width: 0; }

/* 画面幅1100px未満はプレビュー自動OFF(設定は保持。printには適用しない) */
@media screen and (max-width: 1099px) {
  .qe-layout.qe-preview-on { grid-template-columns: minmax(0, 1fr); }
  .qe-preview-pane { display: none !important; }
}

/* プレビュー切替ボタンのON状態 */
.qe-toggle.qe-on {
  background: var(--c-accent-tint);
  border-color: var(--c-accent);
  color: var(--c-accent-strong);
}

/* ===== プレビューペイン ===== */
.qe-preview-pane {
  position: sticky;
  top: calc(var(--header-h) + var(--nav-h) + 12px);
  max-height: calc(100vh - var(--header-h) - var(--nav-h) - 24px);
  overflow: auto;
  background: var(--c-surface-2);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-l);
  padding: 10px 12px 12px;
}
.qe-preview-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.qe-preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-muted);
  letter-spacing: .06em;
}
.qe-preview-note {
  margin: 8px 2px 0;
  font-size: 11px;
  color: var(--c-muted);
}

/* ===== 紙面(A4縦風・白紙+微影) ===== */
.qe-paper-wrap {
  background: #e8ebee;
  padding: 14px;
  border-radius: var(--radius);
}
.qe-paper {
  background: #fff;
  color: #1e2c39;
  width: 100%;
  aspect-ratio: 210 / 297;   /* A4縦比。内容が多い場合は自然に伸びる */
  padding: 9% 8%;
  box-shadow: 0 1px 3px rgba(20, 32, 44, .18), 0 8px 22px rgba(20, 32, 44, .10);
  font-size: 11.5px;
  line-height: 1.55;
}
.qe-p-meta {
  text-align: right;
  font-size: 10.5px;
  color: #3c4a56;
}
.qe-p-title {
  text-align: center;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "MS PMincho", serif;
  font-size: 20px;
  letter-spacing: .45em;
  text-indent: .45em;
  color: #1a2b3c;
  margin: 6px 0 16px;
  padding-bottom: 6px;
  border-bottom: 3px double #1a2b3c;
}
.qe-p-cols {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.qe-p-left { flex: 1 1 auto; min-width: 0; }
.qe-p-right { flex: 0 0 auto; padding-top: 2px; }
.qe-p-attn {
  display: inline-block;
  min-width: 62%;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid #1e2c39;   /* 宛名+敬称の下線 */
  padding: 0 4px 2px;
  margin-bottom: 10px;
}
.qe-p-greet {
  margin: 0 0 10px;
  font-size: 11px;
}
.qe-p-amount {
  display: inline-block;
  border: 2px solid #1a2b3c;          /* 太枠ボックス */
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 10px;
  background: #fff;
}
.qe-p-amount b {
  font-size: 16px;
  margin-left: 10px;
  letter-spacing: .02em;
}
.qe-p-terms {
  border-collapse: collapse;
  font-size: 11px;
}
.qe-p-terms th {
  text-align: left;
  font-weight: 600;
  padding: 1px 10px 1px 0;
  white-space: nowrap;
  vertical-align: top;
}
.qe-p-terms td { padding: 1px 0; }
.qe-p-co-name {
  font-size: 13px;
  font-weight: 700;
  color: #1a2b3c;
  white-space: nowrap;
}
.qe-p-co-sub {
  font-size: 11px;
  color: #3c4a56;
  white-space: nowrap;
}

/* 明細表 */
.qe-p-lines {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
  margin: 8px 0 10px;
}
.qe-p-lines th,
.qe-p-lines td {
  border: 1px solid #9aa7b1;
  padding: 3px 6px;
  vertical-align: top;
  word-break: break-word;
}
.qe-p-lines thead th {
  background: #eef2f6;
  color: #1a2b3c;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}
.qe-p-lines .qe-pl-num { text-align: right; white-space: nowrap; }
.qe-p-lines .qe-pl-head td { font-weight: 700; background: #f6f8fa; }   /* 見出し行=太字 */
.qe-p-lines .qe-pl-sub td { text-align: right; background: #fbfcfd; font-weight: 600; } /* 小計行=右寄せ */
.qe-p-lines .qe-pl-empty { text-align: center; color: #7d8b97; padding: 12px; }

/* 小計/消費税/合計 */
.qe-p-sumwrap { display: flex; justify-content: flex-end; }
.qe-p-sum {
  border-collapse: collapse;
  font-size: 11.5px;
  min-width: 46%;
}
.qe-p-sum th {
  text-align: left;
  font-weight: 600;
  padding: 2px 16px 2px 4px;
  white-space: nowrap;
}
.qe-p-sum td {
  text-align: right;
  padding: 2px 4px;
  white-space: nowrap;
}
.qe-p-sum tr.qe-p-total th,
.qe-p-sum tr.qe-p-total td {
  border-top: 2px solid #1a2b3c;
  font-size: 13px;
  font-weight: 700;
  padding-top: 5px;
}

/* 末尾備考 */
.qe-p-note { margin-top: 12px; font-size: 10.5px; }
.qe-p-note-h {
  font-weight: 600;
  border-bottom: 1px solid #c8d1d9;
  margin-bottom: 2px;
}

/* ===== 顧客別 過去見積履歴帯 ===== */
.qe-hist-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-left: 3px solid var(--c-accent);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
}
.qe-hist-head {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-head);
  white-space: nowrap;
}
.qe-hist-empty { font-size: 12px; color: var(--c-muted); }
.qe-hist-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  min-width: 0;
  flex: 1 1 auto;
  padding-bottom: 2px;
}
.qe-hist-item {
  flex: 0 0 auto;
  width: 200px;
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  padding: 6px 8px;
  background: var(--c-surface-2);
  font-size: 12px;
}
.qe-hist-l1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.qe-hist-no { font-weight: 600; color: var(--c-accent-strong); white-space: nowrap; }
.qe-hist-subj {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--c-ink);
  margin: 1px 0;
}
.qe-hist-l3 {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--c-muted);
  font-size: 11.5px;
}
.qe-hist-amt { font-weight: 600; color: var(--c-ink); }
.qe-hist-ops { display: flex; gap: 6px; margin-top: 5px; }

/* ===== 履歴ドロップダウン(ヘッダー「履歴」ボタン) ===== */
.qe-dd-wrap { position: relative; display: inline-block; }
.qe-dd {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: var(--z-dropdown, 300);
  width: 340px;
  max-height: 340px;
  overflow: auto;
  background: var(--c-surface);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-drop);
  text-align: left;
}
.qe-dd-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--c-line);
  font-size: 12.5px;
}
.qe-dd-item:last-child { border-bottom: 0; }
.qe-dd-item:hover { background: var(--c-accent-tint); }
.qe-dd-no { font-weight: 600; color: var(--c-accent-strong); white-space: nowrap; }
.qe-dd-subj {
  flex-basis: 100%;
  color: var(--c-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qe-dd-sub { flex-basis: 100%; color: var(--c-muted); font-size: 11.5px; }
.qe-dd-empty { padding: 10px; color: var(--c-muted); font-size: 12.5px; }

/* ===== 自動下書き保存バナー ===== */
.qe-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  background: var(--c-warn-tint);
  border: 1px solid var(--c-warn-line);
  color: var(--c-warn);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.qe-banner-ops { display: flex; gap: 8px; margin-left: auto; }

/* ===== 行粗利インライン表示 ===== */
.qe-grid tr.qe-gp-line td {
  padding: 0 8px 5px;
  font-size: 11.5px;
  color: var(--c-muted);
  background: #fbfcfd;
}
.qe-grid tr.qe-gp-line .qe-gp-cell { text-align: right; }
.qe-grid tr.qe-gp-line.qe-gp-neg .qe-gp-cell { color: var(--c-danger); font-weight: 600; }

/* フッター合計欄の想定粗利 */
.qe-sum-gpwrap {
  font-size: 13px;
  color: var(--c-muted);
  margin-right: auto;   /* 合計群(右寄せ)の左側に配置 */
}
.qe-sum-gpwrap b { color: var(--c-ink); }
.qe-sum-gpwrap.qe-gp-neg b { color: var(--c-danger); }
.qe-sum-gpwrap small { margin-left: 4px; }

/* ===== プレビューのみ印刷(printPreview_ が body.qe-printing を付与) ===== */
@media print {
  body.qe-printing { background: #fff; }
  body.qe-printing .app-header,
  body.qe-printing .app-nav,
  body.qe-printing .toast-container,
  body.qe-printing .modal-overlay,
  body.qe-printing #qe-toast-wrap,
  body.qe-printing .view-header,
  body.qe-printing #qe-msg,
  body.qe-printing .qe-banner,
  body.qe-printing .qe-hist-strip,
  body.qe-printing .qe-main,
  body.qe-printing .qe-preview-tools,
  body.qe-printing .qe-preview-note { display: none !important; }
  body.qe-printing main { padding: 0 !important; margin: 0 !important; }
  body.qe-printing .qe-layout { display: block !important; }
  body.qe-printing .qe-preview-pane {
    display: block !important;
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
    border: 0 !important;
    background: #fff !important;
    padding: 0 !important;
  }
  body.qe-printing .qe-paper-wrap {
    background: #fff !important;
    padding: 0 !important;
  }
  body.qe-printing .qe-paper {
    box-shadow: none !important;
    aspect-ratio: auto;
    padding: 10mm 8mm;
  }
}

/* ============================================
   実物PDF準拠の上書き（■お見積書フォルダの実例に一致させる）
   「今のフォーマットを変えない」方針: タイトル左寄せ+下線、黒帯明細ヘッダー、
   グレー金額ラベル、社印は社名に重ね、担当印は押印枠、値引き=赤字、続き行=点線
   ============================================ */
.qe-p-title {
  text-align: left !important;
  font-size: 19px; font-weight: 700; letter-spacing: .18em;
  border-bottom: 2.5px solid #111; display: inline-block;
  padding: 0 3.2em 3px 2px; margin: 4px 0 14px;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
}
.qe-p-attn { font-size: 15px; font-weight: 700; border-bottom: 1.5px solid #111; padding-bottom: 3px; }
.qe-p-attn-hon { margin-left: 2.5em; font-size: 13px; }
.qe-p-amount {
  display: flex; align-items: stretch; border: 2px solid #111; margin: 10px 0 12px; font-size: 12px;
}
.qe-p-amount-label { background: #d9d9d9; padding: 6px 10px; font-weight: 700; flex: 0 0 auto; display: flex; align-items: center; }
.qe-p-amount b { flex: 1; text-align: center; font-size: 16px; padding: 6px 10px; letter-spacing: .04em; }
.qe-p-terms th { background: #efefef; border: 1px solid #999; padding: 2px 6px; font-weight: 700; text-align: left; white-space: nowrap; }
.qe-p-terms td { border: 1px solid #999; padding: 2px 6px; min-width: 9em; }
.qe-p-terms { border-collapse: collapse; font-size: 10.5px; }

/* 自社ブロック: 社印を社名に重ねる */
.qe-p-co-block { position: relative; padding-top: 6px; min-height: 74px; }
.qe-p-seal-co {
  position: absolute; top: -14px; right: -6px; width: 62px; height: 62px; opacity: .92; pointer-events: none;
}
.qe-p-co-name { font-weight: 700; font-size: 12.5px; position: relative; z-index: 1; }
.qe-p-co-addr { font-size: 9.5px; color: #222; margin-top: 3px; line-height: 1.5; position: relative; z-index: 1; }
.qe-p-staff { margin-top: 8px; width: 100%; }
.qe-p-stampbox { display: flex; justify-content: flex-end; margin-top: 8px; }
.qe-p-stamp-blank, .qe-p-stamp-cell {
  width: 44px; height: 44px; border: 1px solid #999; display: inline-flex; align-items: center; justify-content: center;
}
.qe-p-stamp-blank { border-right: none; background: #fff; }
.qe-p-seal-me { width: 34px; height: 34px; }

/* 明細: 黒帯ヘッダー・続き行点線・値引き赤字 */
.qe-p-lines thead th { background: #111 !important; color: #fff !important; border-color: #111 !important; font-weight: 700; }
.qe-p-lines .qe-pl-head td { background: #fff !important; border-bottom-style: solid; }
.qe-p-lines tr.qe-pl-cont td { border-top-style: dashed; border-top-color: #aaa; }
.qe-p-lines tr.qe-pl-neg td, .qe-p-lines tr.qe-pl-neg .qe-pl-num { color: #c00; }
.qe-p-no { color: #667; }

/* 合計欄: 実物同様に枠線 */
.qe-p-sum th { background: #efefef; border: 1px solid #999; }
.qe-p-sum td { border: 1px solid #999; }
.qe-p-sum tr.qe-p-total th, .qe-p-sum tr.qe-p-total td { border-top: 2px solid #111; font-size: 12.5px; }

/* 備考枠 */
.qe-p-note { border: 1px solid #999; padding: 6px 8px; min-height: 46px; }
.qe-p-note-h { font-weight: 700; margin-bottom: 2px; }
/* 金額の折返し防止（プレビュー縮小時） */
.qe-p-amount b { white-space: nowrap; font-size: 14px; }
.qe-p-amount-label { font-size: 10.5px; white-space: nowrap; }

/* ============================================
   実物PDF準拠 v2 — 幾何配置の忠実再現（ユーザー指摘反映）
   ============================================ */
.qe-p-meta { text-align: right; font-size: 10px; color: #222; }
.qe-p-meta .qe-p-no { font-size: 9px; color: #778; }
.qe-p-cols { display: grid; grid-template-columns: 54% 1fr; gap: 14px; align-items: start; }
.qe-p-left { min-width: 0; }

/* 宛名 */
.qe-p-attn { font-size: 14.5px; }
.qe-p-attn-hon { margin-left: 2em; font-size: 12px; font-weight: 700; }
.qe-p-greet { font-size: 10px; line-height: 1.7; margin: 8px 0 8px; }

/* 金額ボックス: 左列幅いっぱい・グレーラベル+右寄せ気味の太字金額 */
.qe-p-amount { width: 100%; border: 2px solid #111; }
.qe-p-amount-label { flex: 0 0 42%; background: #d9d9d9; font-size: 10px; padding: 5px 8px; }
.qe-p-amount b { font-size: 14.5px; text-align: center; padding: 5px 8px; }

/* 右列: 社印は社名の上に大きく */
.qe-p-right { min-width: 0; }
.qe-p-seal-co {
  position: static; display: block; margin: 0 4px -10px auto;
  width: 84px; height: 84px; opacity: .95;
}
.qe-p-co-name { font-size: 11px; font-weight: 700; }
.qe-p-co-addr { font-size: 8.5px; line-height: 1.5; margin-top: 1px; }
.qe-p-co-addr2 { white-space: nowrap; letter-spacing: -.01em; }

/* 営業部・担当者: 実物どおり小さく */
.qe-p-staff { margin-top: 7px; width: 100%; }
.qe-p-staff th { font-size: 8.5px; padding: 1.5px 5px; width: 4.5em; }
.qe-p-staff td { font-size: 9px; padding: 1.5px 5px; }

/* 押印枠: 右端寄せ・小さめ */
.qe-p-stampbox { justify-content: flex-end; margin-top: 6px; }
.qe-p-stamp-blank, .qe-p-stamp-cell { width: 36px; height: 36px; }
.qe-p-seal-me { width: 28px; height: 28px; }

/* 明細下端に統合された合計行（実物: 別表ではなく表の続き） */
.qe-p-sumwrap { display: none; }
.qe-p-sumrow .qe-p-sumlabel { text-align: right; font-weight: 700; background: #efefef; padding-right: 8px; }
.qe-p-sumrow td { border: 1px solid #999; }
.qe-p-totalrow td { border-top: 2px solid #111; }
.qe-p-totalrow .qe-pl-num { font-weight: 700; font-size: 11.5px; }

/* 備考ボックス（常設） */
.qe-p-note { display: flex; gap: 8px; border: 1.5px solid #666; min-height: 52px; padding: 5px 8px; margin-top: 14px; font-size: 9.5px; }
.qe-p-note-h { font-weight: 700; flex: 0 0 auto; }
.qe-p-note-b { flex: 1; line-height: 1.6; }

/* 実寸設計+縮小表示方式（scalePaper_と対） */
.qe-paper-wrap { overflow: hidden; }
.qe-paper { aspect-ratio: auto !important; min-height: calc(760px * 1.414); }
@media print {
  /* 印刷時は原寸で */
  .qe-paper { transform: none !important; width: 100% !important; }
  .qe-paper-wrap { height: auto !important; overflow: visible; }
}

/* ■納期〜■備考 の実物表記: 黒地×白文字ラベル（ユーザー提供画像準拠） */
.qe-p-terms th { background: #111 !important; color: #fff !important; border-color: #111 !important; font-weight: 700; }
.qe-p-staff th { background: #111 !important; color: #fff !important; border-color: #111 !important; }
.qe-p-terms { border: 1.5px solid #111; }

/* ============================================================
   実物準拠 v3 — ユーザー提供の高解像度実物から実測した寸法・余白
   (A4設計幅760px基準。画像1797px→760px換算率0.423で採寸)
   ============================================================ */
.qe-paper { padding: 54px 54px 40px !important; }

/* 日付(右上15px) → タイトル(20px・下線・下38px空き) */
.qe-p-meta { font-size: 15px; margin: 0 0 4px; }
.qe-p-meta .qe-p-no { font-size: 10px; }
.qe-p-title {
  font-size: 20px !important; font-weight: 700; letter-spacing: .08em;
  border-bottom: 2px solid #111 !important; padding: 0 64px 6px 2px !important;
  margin: 8px 0 38px !important;
}

/* 2カラム: 左330px / ガター63px / 右259px（実測比） */
.qe-p-cols { display: grid !important; grid-template-columns: 330px 1fr !important; column-gap: 63px !important; }

/* 宛名: 18.5px太字・太下線・御中は右端寄り */
.qe-p-attn {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 18.5px !important; font-weight: 700;
  border-bottom: 2.5px solid #111 !important; padding: 0 8px 8px 2px !important;
}
.qe-p-attn-hon { margin-left: 0 !important; font-size: 16px !important; font-weight: 700; }
.qe-p-greet { font-size: 12px !important; line-height: 2.05 !important; margin: 14px 0 10px !important; }

/* 金額ボックス: 太枠・グレーラベル42%・金額18.5px中央 */
.qe-p-amount { border: 2.5px solid #111 !important; }
.qe-p-amount-label { flex: 0 0 42% !important; background: #d9d9d9 !important; color: #111 !important; font-size: 13px !important; font-weight: 700; padding: 6px 10px !important; }
.qe-p-amount b { font-size: 18.5px !important; padding: 5px 8px !important; }

/* ■5項目・■営業部/担当者: グレー地×黒太字（v2の黒地指定を上書き） */
.qe-p-terms { width: 100%; margin-top: 12px; border: 1.5px solid #111 !important; }
.qe-p-terms th {
  background: #d9d9d9 !important; color: #111 !important; border: 1px solid #444 !important;
  font-size: 11px !important; font-weight: 700; width: 42%; padding: 2px 8px !important;
}
.qe-p-terms td { border: 1px solid #444 !important; font-size: 11px !important; padding: 2px 8px !important; }

/* 右列: 社印127px角を右上に、会社名はその下方88pxから */
.qe-p-right { position: relative; }
.qe-p-seal-co {
  position: absolute !important; top: -6px; right: -2px;
  width: 127px !important; height: 127px !important; margin: 0 !important; opacity: .93;
}
.qe-p-co-name { font-size: 14px !important; font-weight: 700; margin-top: 88px; position: relative; z-index: 1; }
.qe-p-co-addr { font-size: 12px !important; margin-top: 6px !important; line-height: 1.6; position: relative; z-index: 1; }
.qe-p-co-addr2 { white-space: nowrap; font-size: 11.5px !important; }
.qe-p-staff { margin-top: 14px !important; }
.qe-p-staff th { width: 35% !important; font-size: 11px !important; padding: 2px 8px !important; }
.qe-p-staff td { font-size: 11px !important; padding: 2px 8px !important; }

/* 押印枠: 48×46の2マス・右端 */
.qe-p-stampbox { margin-top: 16px !important; }
.qe-p-stamp-blank, .qe-p-stamp-cell { width: 48px !important; height: 46px !important; border: 1.5px solid #444 !important; }
.qe-p-stamp-blank { border-right: none !important; }
.qe-p-seal-me { width: 38px !important; height: 38px !important; }

/* 明細: ヘッダーのみ黒地白字13px・セル11px */
.qe-p-lines { margin-top: 26px; }
.qe-p-lines thead th { font-size: 13px !important; padding: 4px 6px !important; }
.qe-p-lines td { font-size: 11px !important; padding: 3px 6px !important; }

/* 合計行: ラベルは白地右寄せ太字（実物準拠） */
.qe-p-sumrow .qe-p-sumlabel { background: #fff !important; font-size: 12px; }
.qe-p-totalrow .qe-pl-num { font-size: 13px !important; }

/* 備考ボックス */
.qe-p-note { font-size: 11px !important; min-height: 64px !important; margin-top: 18px !important; }
/* 空行の高さ（実物の行送り相当） */
.qe-pl-filler td { height: 17px; }
