/* 見積書ツール 静的モック共通スタイル（フェーズ1.5 デザイン案） */
:root {
  --ink: #1d2433;
  --sub: #5b6475;
  --line: #d9dee7;
  --bg: #f4f6f9;
  --card: #ffffff;
  --accent: #1f5fbf;
  --accent-weak: #e8f0fc;
  --warn: #c62828;
  --warn-weak: #fdecec;
  --mark: #b7791f;
  --mark-weak: #fdf3e1;
  --ok: #2e7d32;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Noto Sans JP", "Noto Sans CJK JP", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ヘッダー */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 52px;
  background: var(--ink); color: #fff;
}
.app-header .brand { font-weight: 700; letter-spacing: .04em; }
.app-header nav { display: flex; gap: 4px; }
.app-header nav a {
  color: #cfd6e4; text-decoration: none; padding: 6px 14px; border-radius: 6px;
}
.app-header nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }

.page { max-width: 1040px; margin: 0 auto; padding: 20px 24px 120px; }
.page h1 { font-size: 20px; margin: 4px 0 16px; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--accent-weak); border: 1px solid #c4d6f5; color: #18407f;
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 13px; font-weight: 500; }
.btn.link { border: none; background: none; color: var(--accent); padding: 4px 6px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 16px;
}
.card > h2 {
  font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px;
}
.card > h2 .meta { font-weight: 400; color: var(--sub); font-size: 13px; }
.card > h2 .subtotal { margin-left: auto; font-size: 14px; }

/* 相手先区分の切替 */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented label { padding: 7px 18px; cursor: pointer; background: #fff; }
.segmented label + label { border-left: 1px solid var(--line); }
.segmented label.on { background: var(--accent); color: #fff; font-weight: 600; }

/* 基本情報 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.field label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 3px; }
.field label .req { color: var(--warn); margin-left: 2px; }
.field.wide { grid-column: 1 / -1; }
input[type=text], input[type=number], input[type=date], textarea, select {
  font: inherit; color: inherit; width: 100%;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
input[type=number] { text-align: right; }
input::placeholder { color: #a3abb9; }
.field .hint { font-size: 12px; color: var(--sub); margin-top: 2px; }
.err-msg { color: var(--warn); font-size: 12px; margin-top: 3px; font-weight: 600; }
.has-err input { border-color: var(--warn); background: var(--warn-weak); }

/* 項目リスト */
.items { width: 100%; border-collapse: collapse; }
.items th {
  font-size: 12px; font-weight: 500; color: var(--sub); text-align: left;
  padding: 4px 8px; border-bottom: 1px solid var(--line);
}
.items th.num { text-align: right; }
.items td { padding: 7px 8px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.items tr:last-child td { border-bottom: none; }
.items td.chk { width: 32px; padding-top: 11px; }
.items td.name { min-width: 220px; padding-top: 11px; }
.items td.price { width: 150px; }
.items td.qty { width: 100px; }
.items td.amount { width: 110px; padding-top: 11px; }
.items tr.off td.name, .items tr.off td.amount { color: #9aa2b1; }
.items tr.off input[type=number] { color: #9aa2b1; background: #fafbfc; }
.items tr.disabled td { color: #b3bac6; }
.items tr.disabled input { background: #f3f4f6; color: #b3bac6; }
.range { display: block; font-size: 11px; color: #98a1b0; margin-top: 2px; }
.badge-mod {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--mark);
  background: var(--mark-weak); border: 1px solid #f0d9a8; border-radius: 4px;
  padding: 0 6px; margin-left: 6px; vertical-align: 1px;
}
.price-mod input { border-color: #e7c17a; background: #fffaf0; }
.master-price { display: block; font-size: 11px; color: var(--mark); margin-top: 2px; }
.ref-link { font-size: 12px; margin-left: 8px; }
.hours-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  padding: 8px 12px; background: #f7f9fc; border-radius: 6px;
}
.hours-row input { width: 80px; }
.hours-row .hint { color: var(--sub); font-size: 12px; }
.section-off { font-size: 12px; color: var(--sub); }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }

/* 調整 */
.adj-row { display: grid; grid-template-columns: 1fr 140px 140px 110px 32px; gap: 10px; align-items: start; margin-bottom: 8px; }
.adj-row .amount { padding-top: 8px; }
.adj-head { font-size: 12px; color: var(--sub); }
.toggle2 { justify-self: start; display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; height: 37px; }
.toggle2 span { padding: 7px 14px; }
.toggle2 span.on { background: var(--ink); color: #fff; }
.adj-note { font-size: 12px; color: var(--sub); }

/* 合計バー */
.total-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(20,30,50,.08);
}
.total-bar .inner {
  max-width: 1040px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 20px;
}
.total-bar .count { color: var(--sub); }
.total-bar .sum { margin-left: auto; font-size: 13px; color: var(--sub); }
.total-bar .sum strong { font-size: 24px; color: var(--ink); margin-left: 8px; }

/* プレビュー */
.preview-tools {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.tabs { display: inline-flex; background: #e3e7ee; border-radius: 8px; padding: 3px; }
.tabs a { padding: 6px 18px; border-radius: 6px; color: var(--sub); text-decoration: none; }
.tabs a.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.preview-tools .spacer { flex: 1; }
.issued-tag {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ok); font-weight: 700; background: #e8f5e9; border: 1px solid #b9dfbb;
  padding: 4px 12px; border-radius: 6px;
}
.variant-note { font-size: 12px; color: var(--sub); }

/* A4 紙面 */
.paper {
  width: 210mm; min-height: 297mm; margin: 0 auto;
  background: #fff; box-shadow: 0 2px 14px rgba(20,30,50,.14);
  padding: 16mm 16mm 18mm; color: #111; font-size: 12px;
}
.paper h1 { text-align: center; font-size: 24px; letter-spacing: .5em; margin: 0 0 8mm; font-weight: 700; }
.paper .head { display: flex; justify-content: space-between; gap: 10mm; margin-bottom: 6mm; }
.paper .to { flex: 1; }
.paper .to .client { font-size: 17px; font-weight: 700; border-bottom: 1px solid #111; padding-bottom: 2px; margin-bottom: 4mm; }
.paper .to .subject { font-size: 13px; }
.paper .to .subject b { display: inline-block; width: 3.5em; color: #444; font-weight: 500; }
.paper .issuer { width: 62mm; font-size: 11.5px; }
.paper .issuer table { border-collapse: collapse; width: 100%; }
.paper .issuer th { text-align: left; font-weight: 500; color: #444; padding: 1px 8px 1px 0; white-space: nowrap; vertical-align: top; }
.paper .issuer td { padding: 1px 0; }
.paper .issuer .org { font-size: 15px; font-weight: 700; margin-top: 3mm; }
.paper .issuer .pending { color: #999; }
.paper .grand {
  display: flex; justify-content: space-between; align-items: baseline;
  border: 1.5px solid #111; padding: 3mm 5mm; margin-bottom: 6mm;
}
.paper .grand .label { font-size: 13px; }
.paper .grand .value { font-size: 22px; font-weight: 700; }
.paper table.detail { width: 100%; border-collapse: collapse; margin-bottom: 4mm; }
.paper table.detail th, .paper table.detail td { border: 1px solid #9aa0aa; padding: 1.6mm 2.4mm; }
.paper table.detail thead th { background: #eef0f3; font-weight: 600; font-size: 11px; }
.paper table.detail tr.sec td { background: #f7f8fa; font-weight: 700; }
.paper table.detail tr.sec td .h { font-weight: 400; color: #555; margin-left: 6px; font-size: 11px; }
.paper table.detail tr.subhead td { background: #fbfbfc; font-size: 10.5px; color: #555; }
/* gui-spec 3.10: 顧客用の時間単価区分は役職ごとの金額を出さず、区分の小計行だけに金額を出す */
.paper table.detail tr.subtotal td { font-weight: 700; border-top: 1.5px solid #555; }
.paper table.detail tr.subtotal td:first-child { text-align: right; }
.paper table.detail td.role-amt { background: #fcfcfd; color: #555; } /* Q32: 意図的に出していないことが分かる「—」 */
.paper .totals { width: 80mm; margin-left: auto; border-collapse: collapse; margin-bottom: 6mm; }
.paper .totals td { padding: 1.6mm 2.4mm; border-bottom: 1px solid #c8ccd3; }
.paper .totals tr.final td { border-top: 1.5px solid #111; border-bottom: 1.5px solid #111; font-weight: 700; font-size: 14px; }
.paper .totals tr.adj td { color: #333; }
.paper .notes h3 { font-size: 12px; margin: 0 0 2mm; }
.paper .notes ul { margin: 0; padding-left: 4.5mm; }
.paper .notes li { margin-bottom: 1mm; }
/* Q37: 注記（noteLines の kind=annotation）の行だけ「•」を付けない。「※」を「•」の位置に置き、折り返しは本文の頭に揃える */
.paper .notes li.annotation { list-style: none; margin-left: -4.5mm; padding-left: 4.5mm; text-indent: -4.5mm; }
.paper .internal-stamp {
  display: inline-block; border: 1.5px solid #b71c1c; color: #b71c1c;
  font-weight: 700; padding: 0 3mm; font-size: 11px; margin-left: 3mm; vertical-align: 4px; letter-spacing: 0;
}

/* 管理費の明細表示（Q15）・内容欄（Q18）・内部用の参考値（Q16） */
.preview-sub { margin: -6px 0 14px; font-size: 12px; color: var(--sub); text-align: center; }
.mode-tag { font-size: 12px; color: var(--ink); background: #eef2fb; border: 1px solid #cfd8ec; padding: 3px 10px; border-radius: 6px; }
.paper table.detail td.desc { font-size: 10.5px; color: #333; }
.paper .internal-ref { border: 1px dashed #b71c1c; padding: 2.5mm 4mm; margin-bottom: 6mm; width: 100mm; margin-left: auto; }
.paper .internal-ref h3 { font-size: 12px; margin: 0 0 1.5mm; color: #b71c1c; }
.paper .internal-ref .h { font-weight: 400; color: #666; font-size: 10px; margin-left: 4px; }
.paper .internal-ref table { width: 100%; border-collapse: collapse; }
.paper .internal-ref td { padding: .8mm 0; }
.paper .internal-ref p.h { margin: 1.5mm 0 0; line-height: 1.5; }
.paper .mod-mark { display: inline-block; font-size: 9px; font-weight: 700; color: #8a5a00; background: #fff3d6; border: 1px solid #e7c17a; padding: 0 3px; border-radius: 3px; }
.fee-mode { margin-top: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.fee-mode > .lbl { font-size: 12px; color: var(--sub); min-width: 7.5em; }
.fee-mode .hint { color: var(--sub); font-size: 12px; }

/* 状態見本 */
.state-caption { font-size: 12px; color: var(--sub); margin: -4px 0 10px; }
.state-label {
  display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: #6b7385;
  padding: 1px 8px; border-radius: 4px; margin-bottom: 6px;
}
.summary-errors {
  background: var(--warn-weak); border: 1px solid #f3c3c3; color: var(--warn);
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600;
}

/* スマホ幅: 項目行を縦積み */
@media (max-width: 640px) {
  .app-header { padding: 0 12px; gap: 10px; }
  .app-header .brand { font-size: 13px; }
  .app-header nav a { padding: 6px 8px; }
  .page { padding: 12px 12px 110px; }
  .form-grid { grid-template-columns: 1fr; }
  .card { padding: 12px 14px; }
  .items thead { display: none; }
  .items, .items tbody, .items tr, .items td { display: block; width: 100%; }
  .items tr {
    display: grid; grid-template-columns: 28px 1fr 1fr; gap: 4px 8px;
    padding: 10px 0; border-bottom: 1px solid #eef1f5;
  }
  .items td { border: none; padding: 0; }
  .items td.chk { grid-row: 1; grid-column: 1; padding-top: 2px; width: auto; }
  .items td.name { grid-row: 1; grid-column: 2 / 4; min-width: 0; padding-top: 0; font-weight: 600; }
  .items td.price { grid-column: 2; width: auto; }
  .items td.qty { grid-column: 3; width: auto; }
  .items td.amount { grid-column: 2 / 4; width: auto; padding-top: 0; }
  .items td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--sub); }
  .items td.amount::before { display: inline !important; margin-right: 8px; }
  .adj-row { grid-template-columns: 1fr 1fr; }
  .fee-mode .segmented label { padding: 7px 12px; }
  .total-bar .inner { padding: 10px 14px; gap: 10px; }
  .total-bar .btn { padding: 8px 12px; }
  .total-bar .sum strong { font-size: 20px; }
}

/* 印刷: 紙面だけを出す */
@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .app-header, .preview-tools, .preview-sub, .no-print, .total-bar { display: none !important; }
  .page { padding: 0; max-width: none; }
  .paper { box-shadow: none; margin: 0; }
}

/* ===== フェーズ2（実装）で追加 ===== */
[hidden] { display: none !important; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.title-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.title-row h1 { margin: 0 !important; }
.title-row .spacer { flex: 1; }
.warn-msg { color: var(--mark); font-size: 12px; margin-top: 3px; }
.err-msg:empty, .warn-msg:empty { display: none; }
.has-err input, .has-err textarea { border-color: var(--warn); background: var(--warn-weak); }
.items tr.disabled td.name { color: #b3bac6; }
.pieces { font-size: 12px; color: var(--sub); background: #f7f9fc; border-radius: 6px; padding: 6px 10px; margin-top: 6px; }
.pieces ol { margin: 4px 0 0; padding-left: 20px; columns: 2; }
.toggle2 button { font: inherit; border: none; background: #fff; padding: 7px 14px; cursor: pointer; }
.toggle2 button.on { background: var(--ink); color: #fff; }
.total-bar .sum.neg strong { color: var(--warn); }
.total-bar .err-msg { margin: 0; }
.notice { background: #e8f5e9; border: 1px solid #b9dfbb; color: #1b5e20; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.notice.warn { background: var(--mark-weak); border-color: #f0d9a8; color: #7a4f00; }
.loading { color: var(--sub); padding: 40px 0; text-align: center; }
dialog.confirm { border: 1px solid var(--line); border-radius: 10px; padding: 20px 24px; max-width: 460px; width: calc(100% - 32px); }
dialog.confirm::backdrop { background: rgba(20,30,50,.35); }
dialog.confirm h2 { font-size: 16px; margin: 0 0 12px; }
dialog.confirm dl { display: grid; grid-template-columns: 6em 1fr; gap: 4px 12px; margin: 0 0 12px; }
dialog.confirm dt { color: var(--sub); }
dialog.confirm dd { margin: 0; font-weight: 600; }
dialog.confirm .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
/* 発行履歴 */
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.list th { font-size: 12px; color: var(--sub); font-weight: 500; }
table.list td.ops { white-space: nowrap; text-align: right; }
.empty { color: var(--sub); padding: 24px 0; }
/* 単価マスタ編集 */
.master-table { width: 100%; border-collapse: collapse; }
.master-table th { font-size: 12px; color: var(--sub); font-weight: 500; text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.master-table td { padding: 5px 6px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.master-table td.n input { text-align: right; }
.master-table .range-pair { display: flex; gap: 4px; align-items: center; }
.master-table .range-pair input { width: 80px; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 10px; }
.inline-fields label { font-size: 12px; color: var(--sub); }
.inline-fields input { width: 110px; }
.save-bar { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 10px 0; display: flex; gap: 12px; align-items: center; }
@media (max-width: 640px) {
  table.list thead { display: none; }
  table.list tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.list td { display: block; border: none; padding: 2px 4px; }
  .master-table, .master-table tbody, .master-table tr, .master-table td { display: block; width: 100%; }
  .master-table thead { display: none; }
  .master-table tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
}
@media print {
  .notice, .banner, dialog { display: none !important; }
}
.master-table td:first-child { min-width: 300px; }
.master-table td:first-child input { width: 100%; }
.master-table td.n input { width: 110px; }
.master-table td.ops { width: 48px; }
