:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #dbeafe;
  --brand-ink: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --soft: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, .12);
  --radius: 14px;
}

/* ===== ダークモード ===== */
html[data-theme="dark"] {
  --brand-light: #1e3a8a;
  --brand-ink: #7eb0ff;
  --bg: #0b1220;
  --card: #16202e;
  --soft: #1d2a3a;
  --text: #e2e8f0;
  --muted: #8fa3b8;
  --border: #2c3a4d;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

/* ===== ヘッダー ===== */
.app-header {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; }
.brand-text h1 { font-size: 20px; letter-spacing: .02em; }
.subtitle { font-size: 12px; opacity: .85; }
.header-actions { display: flex; gap: 8px; }

/* ===== レイアウト ===== */
.container { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
.layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  align-items: start;
}
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: background .2s ease;
}
.panel-title { font-size: 16px; margin-bottom: 4px; }
.panel-note { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.result-panel { position: sticky; top: 16px; }

/* ===== ボタン ===== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, filter .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,.6); color: inherit; }
.app-header .btn-ghost { color: #fff; }
.btn-icon { padding: 11px 13px; font-size: 16px; line-height: 1; }
.result-panel .btn-ghost { border-color: var(--border); color: var(--muted); }

/* ===== 工事項目フォーム ===== */
.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--brand-ink);
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--brand-light);
}
.item-group:first-child .group-title { margin-top: 4px; }
.set-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  color: #b45309;
  background: #fef3c7;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  transition: border .12s ease, box-shadow .12s ease;
}
.item.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-light); }
.item-head { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.item-head .chk { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.item-label { font-size: 15px; }

.item-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.item-opts.hidden { display: none; }
.item-opts label { font-size: 12px; color: var(--muted); display: block; }
.qty-field { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.qty-field input {
  width: 100%;
  min-width: 36px;
  padding: 9px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  text-align: center;
}
.qty-field .unit { color: var(--muted); font-size: 13px; white-space: nowrap; }
.qstep {
  flex: none;
  width: 34px;
  height: 39px;
  border: 1px solid var(--border);
  background: var(--soft);
  color: var(--text);
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.qstep:hover { background: var(--brand-light); }
.qstep:active { transform: translateY(1px); }
.item-opts select {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
}
.qty-field input:focus, .item-opts select:focus, #discount:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light);
}
.qty-hint { display: block; font-size: 11px; color: var(--muted); margin-top: 5px; }

/* ===== 見積情報（お客様名・番号・日付） ===== */
.quote-info {
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}
.qi-row { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; }
.qi-row label { font-size: 12px; color: var(--muted); display: block; }
.qi-row input, .qi-row select {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
}
.qi-row input:focus, .qi-row select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light);
}
.qi-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.qi-meta b { color: var(--text); font-weight: 700; }

/* ===== 見積り明細 ===== */
.result-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.result-table th {
  font-size: 11px; color: var(--muted); font-weight: 600;
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.result-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.d-name { font-weight: 600; }
.d-sub { font-size: 11px; color: var(--muted); }
.result-table tr.extra td { color: var(--muted); }
.result-table tr.empty td { text-align: center; color: var(--muted); padding: 28px 8px; }
.result-table tr.cat-head td {
  background: var(--soft);
  font-weight: 700;
  font-size: 12px;
  color: var(--brand-ink);
  padding-top: 10px;
}
.result-table tr.cat-sub td {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.result-table tr.cat-sub td:last-child { color: var(--text); }

/* ===== 合計欄 ===== */
.totals { margin-top: 14px; border-top: 2px solid var(--border); padding-top: 12px; }
.t-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; font-size: 14px; }
.t-row.hidden { display: none; }
.t-row.sub { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 10px; font-weight: 600; }
.t-row.grand {
  margin-top: 8px; border-top: 2px solid var(--brand); padding-top: 12px;
  font-size: 20px; font-weight: 700; color: var(--brand-ink);
}
.t-row.grand span:last-child { display: inline-block; transition: transform .18s ease; }
.t-row.grand.pulse span:last-child { transform: scale(1.07); }
.discount-row label { color: var(--muted); }
.discount-val { color: var(--danger); font-weight: 600; }
.discount-input { display: flex; align-items: center; gap: 2px; color: var(--danger); font-weight: 600; }
.discount-input input {
  width: 92px; text-align: right; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
  background: var(--card); color: var(--text);
}

/* ===== ローン月々目安 ===== */
.loan {
  margin-top: 14px;
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.loan-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.loan-term { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.loan-term select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}
.loan-amount { margin-top: 4px; font-size: 13px; }
.loan-amount b { font-size: 18px; color: var(--brand-ink); margin: 0 2px; }
.loan-note { font-size: 11px; color: var(--muted); margin-left: 4px; }

.result-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.result-actions .btn { flex: 1; min-width: max-content; font-size: 14px; padding: 11px 10px; }
.result-actions .btn-primary { flex: 1.5; }
.disclaimer { margin-top: 12px; font-size: 11px; color: var(--muted); }
.footnote { margin-top: 20px; font-size: 12px; color: var(--muted); text-align: center; }

/* ===== 印刷でのみ出す見出し ===== */
.print-title { display: none; }

/* ===== スマホ用 固定合計バー ===== */
.mobile-total {
  display: none;
  position: fixed;
  left: 12px; right: 12px; bottom: 12px;
  z-index: 40;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  border-radius: 12px;
  padding: 11px 16px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  align-items: center;
  gap: 10px;
}
.mobile-total .mt-label { font-size: 12px; opacity: .9; white-space: nowrap; }
.mobile-total b { font-size: 18px; margin-left: auto; }
.mobile-total .mt-go { font-size: 11px; opacity: .85; white-space: nowrap; }

/* ===== レスポンシブ ===== */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .result-panel { position: static; }
  .app-header { padding: 14px 16px; }
  .brand-text h1 { font-size: 18px; }
  .mobile-total:not(.hidden) { display: flex; }
  body { padding-bottom: 74px; }
}
@media (max-width: 420px) {
  .item-opts { grid-template-columns: 1fr; }
}

/* ===== 印刷（見積書としてきれいに出す） ===== */
@media print {
  :root, html[data-theme="dark"] {
    --bg: #fff; --card: #fff; --soft: #fff;
    --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
    --brand-ink: #1d4ed8; --danger: #dc2626;
  }
  .app-header .header-actions, .form-panel, .result-actions, .footnote, .panel-note, .disclaimer, .loan, .mobile-total { display: none !important; }
  body { background: #fff; }
  .layout { grid-template-columns: 1fr; }
  .app-header { background: var(--brand-dark); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .result-panel { position: static; box-shadow: none; padding: 0; }
  .container { padding-top: 16px; }
  .print-title { display: block; text-align: center; font-size: 22px; letter-spacing: .4em; margin: 4px 0 16px; }
  .panel-title { display: none; }
  .quote-info { background: #fff; border: none; padding: 0; margin-bottom: 14px; }
  .qi-row input, .qi-row select { border: none; box-shadow: none; padding: 2px 0; font-size: 14px; }
  .qi-row label { color: #000; }
  .qi-meta { font-size: 12px; }
}
