:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --card: #ffffff;
  --text: #1f1e1c;
  --muted: #5f5e5a;
  --line: #d3d1c7;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --warn-bg: #faeeda;
  --warn-text: #633806;
  --danger: #a32d2d;
}
* { box-sizing: border-box; }
/* 「隠す」(hidden)指定を、display:grid や flex の見た目の指定より必ず優先させる。
   これが無いと、grid や flex を付けた欄は hidden にしても表示されたままになる */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.shop { font-size: 20px; font-weight: 600; margin-right: auto; }
.book { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.book-info { font-size: 14px; color: var(--muted); }
.ver { font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px; border: 1px solid #b4b2a9; border-radius: 10px;
  background: var(--card); cursor: pointer; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.messages { margin: 12px 20px 0; padding: 12px 16px; background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; }
.messages ul { margin: 4px 0 0; padding-left: 1.3em; }
.messages .close { float: right; min-height: 36px; }

.empty { max-width: 640px; margin: 60px auto; padding: 0 20px; text-align: center; }
.empty-title { font-size: 22px; font-weight: 600; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 20px; }
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .preview { position: sticky; top: 12px; }
}

.step { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; margin-bottom: 12px; }
.step-title { font-size: 15px; color: var(--muted); margin-bottom: 8px; }
.step-title .sub { margin-left: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  min-height: 52px; padding: 4px 16px; border: 1px solid #b4b2a9; border-radius: 10px;
  background: var(--card); cursor: pointer; text-align: left; line-height: 1.3;
}
.seg button.on { background: var(--accent-bg); border-color: var(--accent); color: #0c447c; font-weight: 600; box-shadow: inset 0 0 0 1px var(--accent); }
.seg button .price { display: block; font-size: 14px; }
.sub-seg:not(:empty) { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.seg button.ghost { border-style: dashed; color: var(--muted); }
.seg button.manual-btn { border-style: dashed; }

.labor { display: flex; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid #eceae4; cursor: pointer; }
.labor:last-child { border-bottom: none; }
.labor input { width: 24px; height: 24px; }
.labor .name { flex: 1; }
.labor .amt { color: var(--muted); font-variant-numeric: tabular-nums; }
/* 作業の「?」ボタンと説明(絵と文章) */
.labor-item { border-bottom: 1px solid #eceae4; }
.labor-item:last-child { border-bottom: none; }
.labor-row { display: flex; align-items: center; gap: 10px; }
.labor-row .labor { flex: 1; border-bottom: none; }
.help-btn { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--accent); background: #fff; color: var(--accent); font-size: 19px; font-weight: 700; cursor: pointer; }
.help-btn.on { background: var(--accent); color: #fff; }
.help-box { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin: 0 0 12px; padding: 12px 14px; background: #f7f6f2; border-radius: 12px; }
.help-pic svg { display: block; width: 270px; max-width: 100%; height: auto; }
.help-text { flex: 1 1 220px; margin: 0; font-size: 15px; line-height: 1.75; white-space: pre-line; }
.help-src { display: inline-block; margin-top: 6px; font-size: 12px; line-height: 1.5; color: var(--muted); }
/* 「目安:」の行。いつやるかが一目で分かるよう、色付きの枠で目立たせる */
.help-key { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0 2px; padding: 8px 12px; background: #fff4d6; border-left: 5px solid #ba7517; border-radius: 0 8px 8px 0; font-weight: 700; color: #412402; line-height: 1.6; white-space: normal; }
.help-key-label { flex: none; padding: 0 8px; border-radius: 6px; background: #ba7517; color: #fff; font-size: 13px; line-height: 1.9; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; }
.grid2 label { display: flex; flex-direction: column; font-size: 14px; color: var(--muted); }
.grid2 input, .grid2 select {
  margin-top: 4px; min-height: 48px; padding: 0 12px; border: 1px solid #b4b2a9; border-radius: 10px;
  background: #fff; font-size: 17px; color: var(--text);
}
.size-pick { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.size-pick label { display: flex; flex-direction: column; font-size: 14px; color: var(--muted); }
.size-pick select { margin-top: 4px; min-height: 52px; min-width: 96px; padding: 0 12px; border: 1px solid #b4b2a9; border-radius: 10px; background: #fff; font-size: 22px; color: var(--text); }
.size-pick .sep { font-size: 22px; padding-bottom: 10px; }
.numpad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px auto 0; max-width: 360px; } /* 左右の真ん中に置く */
.numpad button { min-height: 60px; font-size: 26px; border: 1px solid #b4b2a9; border-radius: 12px; background: #fff; cursor: pointer; }
.numpad button:active { background: var(--accent-bg); }
.numpad button.sub { font-size: 17px; color: var(--muted); }
.numpad button.wide { grid-column: span 2; }
.numpad button.full { grid-column: 1 / -1; }
/* 高さと文字の大きさを固定する。変わると、押した瞬間に下のボタンがずれて押し間違える */
.numpad-display { grid-column: 1 / -1; height: 60px; line-height: 60px; overflow: hidden; white-space: nowrap; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--accent-bg); color: #0c447c; font-size: 28px; font-weight: 600; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.numpad-display.is-empty { color: #8a99ad; font-weight: 400; letter-spacing: 0; }
#cPhone[readonly] { background: #fff; cursor: pointer; }
.link-btn { margin-top: 10px; padding: 8px 0; border: none; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 15px; }
.manual { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.hint { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.err, .err-list { color: var(--danger); font-size: 15px; }
.err-list { margin: 8px 0 0; padding-left: 1.2em; }
.err:empty, .err-list:empty { display: none; }

.actions { display: flex; gap: 10px; margin-top: 12px; }
.actions .primary { flex: 1; font-size: 18px; }

/* 見積書:A4の用紙に収まる大きさで固定(180mm × 255mm)。
   A4(210mm × 297mm)より上下左右に十分な余裕を残している。iPad などは、ページの余白の指定を無視して
   自分の余白(パソコンより大きいことがある)で印刷するため、ぎりぎりの大きさだと2枚目にはみ出す。
   中身の行数が変わっても、紙の上の位置と大きさは毎回同じになる。
   画面では、この固定の大きさのまま枠の幅に合わせて縮小して見せる(app.js の fitSheet)。 */
/* 画面では、机(灰色)の上にA4の紙(白)を置いたように見せる。紙の余白は白い影(15mm)で描く */
.sheet-wrap { position: relative; overflow: hidden; background: #e2e0d8; border-radius: 10px; }
.sheet-wrap .sheet { box-shadow: 0 0 0 15mm #fff, 0 0 0 calc(15mm + 1px) #c9c7bd; }
.sheet {
  width: 180mm; height: 255mm; transform-origin: top left;
  display: flex; flex-direction: column; overflow: hidden;
  padding: 0 0.5mm; /* 表の右端の線が、はみ出し防止の切り取りで消えないように */
  background: #fff; color: #000; font-size: 10pt; line-height: 1.45;
}
.sheet .sh-head { display: flex; align-items: flex-end; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 2mm; }
.sheet .sh-title { font-size: 20pt; font-weight: 700; letter-spacing: 0.4em; }
.sheet .sh-dates { text-align: right; font-size: 9.5pt; }
.sheet table { width: 100%; border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { border: 0.3mm solid #555; padding: 0 2mm; height: 7.2mm; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sheet th { background: #e8e8e8; font-weight: 600; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet td.n { text-align: right; }
/* 品名は途中で切らず、長ければ2行に折り返す。行が高くなった分は下のメモ欄が縮むので、紙の大きさは変わらない */
.sheet td.wrap { white-space: normal; overflow-wrap: anywhere; line-height: 1.3; padding-top: 0.8mm; padding-bottom: 0.8mm; }
/* タイヤの行(明細の1行目)は、品名が短くても長くても、いつも2行分の高さ */
.sheet tr.tire-row td { height: 11.5mm; }
.sheet tr.tire-row .nm2 { max-height: 2.6em; overflow: hidden; }
.sheet td.c { text-align: center; }
.sheet .info { margin-top: 3mm; }
.sheet .info th { width: 30mm; text-align: left; } /* iPad の文字(カタカナが全角幅)でも「タイヤサイズ」が入る幅 */
.sheet .info td.name { font-size: 12pt; }
.sheet .sh-lead { display: flex; justify-content: space-between; align-items: flex-end; margin: 3mm 0 2mm; }
.sheet .total-box { border-bottom: 0.6mm solid #000; font-size: 11pt; padding: 0 1mm 0.5mm 0; }
.sheet .total-box strong { font-size: 17pt; margin-left: 4mm; }
.sheet .items tr.subtotal td { background: #e4e4e4; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
/* 太線の上(小計〜消費税)は薄い灰色、太線の下の合計だけ濃い灰色。白黒印刷でも区別がつく濃さにする */
.sheet .items tr.grand td { font-weight: 700; font-size: 11.5pt; border-top: 0.6mm solid #000; background: #c4c4c4; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet .items td.label { text-align: right; }
.sheet .notes { margin: 2.5mm 0 0; padding-left: 1.2em; font-size: 9pt; }
.sheet .memo { flex: 1; min-height: 15mm; margin-top: 3mm; border: 0.3mm solid #555; padding: 1mm 2mm; font-size: 8.5pt; color: #555; }
.sheet .shopinfo { margin-top: 3mm; display: flex; justify-content: flex-end; align-items: baseline; gap: 6mm; }
.sheet .shopinfo .nm { font-size: 13pt; font-weight: 700; }
.sheet .placeholder { color: #a32d2d; }

@media print {
  /* 紙の余白はブラウザに任せず(0にする)、余白を含めたA4の紙1枚分(210mm × 296mm)を自前で作る。
     iPad は余白の指定を無視したうえ、中身を紙の幅いっぱいに拡大して刷る。
     余白ごと1枚の紙として作っておけば、拡大されても上下左右の余白が同じ割合で残る。
     パソコンのブラウザでは、余白0のおかげで日付やURL(ヘッダーとフッター)も入らなくなる。 */
  @page { size: A4; margin: 0; }
  html, body { margin: 0; padding: 0; background: #fff; }
  .no-print, .top, .messages, .empty { display: none !important; }
  .layout { display: block; padding: 0; }
  .sheet-wrap {
    width: 210mm; height: 296mm !important; padding: 20mm 15mm 0; margin: 0;
    background: none; border: none; border-radius: 0; overflow: hidden;
  }
  .sheet-wrap .sheet { box-shadow: none; }
  .sheet { transform: none !important; margin: 0 auto; break-inside: avoid; page-break-inside: avoid; }
  .sheet .placeholder { display: none; }
}
