:root {
  --ink: #172033;
  --muted: #687386;
  --line: #dfe4ea;
  --surface: #ffffff;
  --canvas: #eef1f5;
  --blue: #2557a7;
  --blue-dark: #173d79;
  --green: #087a55;
  --red: #b73535;
}

* { box-sizing: border-box; }
body { color: var(--ink); font-family: "Inter", "Noto Sans JP", "Yu Gothic", sans-serif; }
button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(37,87,167,.2); outline-offset: 1px; }

.tab-btn { background: rgba(255,255,255,.08); transition: background .15s; font-size: .875rem; }
.tab-btn:hover { background: rgba(255,255,255,.2); }
.tab-btn.active { background: #2563eb; }

table.data-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
table.data-table th { background: #f1f5f9; border: 1px solid #cbd5e1; padding: 6px; text-align: left; white-space: nowrap; }
table.data-table td { border: 1px solid #e2e8f0; padding: 4px 6px; }
table.data-table td input { width: 100%; min-width: 58px; padding: 4px 5px; border: 1px solid transparent; border-radius: 3px; background: transparent; }
table.data-table td input:hover { border-color: #cbd5e1; background: #fff; }
table.data-table td input:focus { border-color: var(--blue); background: #fff; outline: 2px solid rgba(37,87,167,.1); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num input { text-align: right; }

.badge { display: inline-block; padding: 1px 6px; border-radius: 9999px; font-size: .7rem; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef9c3; color: #854d0e; }
.badge-ng { background: #fee2e2; color: #991b1b; }

/* ===== 見積書エディター ===== */
.editor-shell { display: grid; gap: 18px; }
.editor-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(30,42,64,.06); }
.editor-toolbar h2 { font-size: 1.35rem; font-weight: 750; letter-spacing: -.02em; }
.editor-toolbar h2 i { color: var(--blue); }
.eyebrow { margin-bottom: 3px; color: var(--blue); font-size: .66rem; font-weight: 800; letter-spacing: .18em; }
.draft-status { margin-top: 4px; color: var(--muted); font-size: .72rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.action-btn { border: 1px solid transparent; padding: 8px 11px; color: #fff; font-size: .78rem; font-weight: 700; transition: transform .12s, filter .12s; }
.action-btn:hover { filter: brightness(.94); transform: translateY(-1px); }
.action-btn.save { background: var(--blue); }
.action-btn.pdf { background: var(--red); }
.action-btn.excel { background: var(--green); }
.action-btn.secondary { border-color: #cfd5dd; color: #4b5563; background: #fff; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(460px, .92fr); align-items: start; gap: 18px; }
.edit-panel { display: grid; gap: 14px; min-width: 0; }
.form-card { padding: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 5px 20px rgba(30,42,64,.04); }
.form-card h3 { margin-bottom: 14px; padding-left: 10px; border-left: 3px solid var(--blue); font-size: .93rem; font-weight: 750; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 11px; }
.form-field { display: grid; gap: 5px; color: #4f5a6d; font-size: .7rem; font-weight: 700; }
.form-field input { width: 100%; border: 1px solid #d5dae1; background: #fbfcfd; padding: 8px 9px; color: var(--ink); font-size: .82rem; font-weight: 500; }
.form-field input:hover { border-color: #aeb7c3; }
.form-field input:focus { border-color: var(--blue); background: #fff; outline: 3px solid rgba(37,87,167,.1); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.inline-btn { border: 1px solid #bdc8d8; padding: 6px 9px; color: var(--blue); background: #f8fafc; font-size: .73rem; font-weight: 700; }
.total-card { display: flex; align-items: center; justify-content: flex-end; gap: 24px; padding: 16px 20px; color: var(--muted); background: #172033; font-size: .78rem; }
.total-card span, .total-card strong { display: grid; gap: 2px; }
.total-card b { color: #fff; font-size: 1rem; font-variant-numeric: tabular-nums; }
.total-card strong { color: #b9d0f4; }
.total-card strong b { color: #fff; font-size: 1.35rem; }

.preview-panel { position: sticky; top: 16px; min-width: 0; padding: 14px; background: #dfe3e8; border: 1px solid #d0d5dc; }
.preview-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: #4a5567; font-size: .75rem; }
.preview-heading small { color: #778194; }
.preview-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #22a06b; box-shadow: 0 0 0 3px rgba(34,160,107,.14); }
.screen-preview { overflow: auto; max-height: calc(100vh - 195px); }
.screen-preview .est-sheet { width: 100%; min-height: 700px; padding: 5.5%; box-shadow: 0 3px 15px rgba(20,28,40,.16); }

/* ===== A4見積書 ===== */
.est-sheet { background: #fff; color: #111; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; }
.est-title { margin: 6px 0 16px; border-bottom: 3px double #111; padding: 0 0 6px 1em; text-align: center; font-size: 23px; font-weight: bold; letter-spacing: 1em; }
.est-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 10px; font-size: 11px; }
.est-head > div:first-child { flex: 1; }
.est-customer { min-width: 55%; border-bottom: 1px solid #111; padding: 2px 7px; font-size: 15px; }
.est-total-box { display: inline-block; margin: 9px 0; border: 2px solid #111; padding: 5px 14px; font-size: 16px; font-weight: bold; }
.est-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 9.5px; }
.est-table th { border: 1px solid #111; background: #e9ebee; padding: 4px; }
.est-table td { border: 1px solid #111; padding: 3px 5px; }

#print-area { display: none; }
#print-area .est-sheet { width: 186mm; min-height: 273mm; margin: 0 auto; padding: 0; }

@media (max-width: 1080px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .screen-preview { max-height: none; }
  .screen-preview .est-sheet { max-width: 760px; margin: 0 auto; }
}

@media (max-width: 720px) {
  .editor-toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .total-card { align-items: flex-end; flex-direction: column; gap: 8px; }
  .preview-panel { margin-inline: -1rem; border-inline: 0; }
  .screen-preview .est-sheet { min-width: 620px; }
}

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  .no-print, body > header, body > main { display: none !important; }
  #print-area { display: block !important; }
  #print-area .est-sheet { width: 100%; min-height: auto; }
  body { margin: 0; background: #fff !important; }
  .est-table tr { break-inside: avoid; }
}
