/* SND 家屋引込 概算地上高計算ツール — スタイル
   スマートフォン縦画面を基準に作り、広い画面では横断図と入力を横並びにする。 */

:root {
  --c-bg: #eef1f5;
  --c-panel: #ffffff;
  --c-text: #1a1f26;
  --c-muted: #5b6573;
  --c-line: #d3d9e1;
  --c-brand: #0b3d75;
  --c-brand-weak: #e7eef8;
  --c-result: #0a4ea8;
  --c-result-bg: #eef4ff;
  --c-wire: #d40000;
  --c-error: #b42318;
  --c-error-bg: #fef3f2;
  --c-warn: #8a5a00;
  --c-warn-bg: #fff7e0;
  --c-ok: #106b3a;
  --c-ok-bg: #e8f6ee;
  --radius: 12px;
  --tap: 52px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
}

button, input, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.noscript { padding: 16px; background: var(--c-error-bg); color: var(--c-error); font-weight: 700; margin: 0; }

/* ---------- ヘッダー ---------- */
.app-header {
  background: var(--c-brand);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.app-header__inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  flex-wrap: wrap;
}
.app-title { margin: 0; font-size: 19px; line-height: 1.35; font-weight: 700; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
.app-title__org { font-size: 15px; letter-spacing: .08em; background: #fff; color: var(--c-brand); padding: 0 6px; border-radius: 4px; }
.app-header__meta { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.version { opacity: .85; }
.net-status { padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.18); font-weight: 700; }
.net-status[data-state="offline"] { background: #ffd666; color: #3d2a00; }

.update-banner {
  display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 10px 16px; background: var(--c-warn-bg); color: var(--c-warn); font-size: 15px; font-weight: 600;
  border-bottom: 1px solid #f0d58a;
}

/* ---------- レイアウト ---------- */
.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
}
.side { display: grid; gap: 12px; align-content: start; min-width: 0; }

.panel {
  background: var(--c-panel);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,.06);
  border: 1px solid #e3e7ec;
  min-width: 0;
}
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.panel__title { margin: 0; font-size: 18px; line-height: 1.4; border-left: 5px solid var(--c-brand); padding-left: 10px; }
.panel__sub { font-size: 14px; color: var(--c-muted); font-weight: 600; margin-left: 4px; }

/* ---------- 横断図 ---------- */
.schematic-tag {
  font-size: 14px; font-weight: 700; color: var(--c-brand);
  border: 1.5px solid var(--c-brand); border-radius: 6px; padding: 1px 8px; background: var(--c-brand-weak);
}
.diagram { margin: 0; }
.diagram__svg {
  display: block; width: 100%; height: auto;
  background: #fff; border: 1px solid var(--c-line); border-radius: 8px;
}
.diagram__caption { margin-top: 8px; font-size: 13.5px; color: var(--c-muted); line-height: 1.55; }
.legend { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; white-space: nowrap; font-weight: 600; }
.legend__swatch { width: 16px; height: 12px; border-radius: 3px; display: inline-block; }
.legend__swatch--result { background: var(--c-result-bg); border: 2px solid var(--c-result); }
.legend__swatch--input { background: #fff; border: 1px dashed #777; }

/* SVG内の文字・線（画面幅に比例して拡大縮小される）。配色は横断図PNG（Ver4.5）に合わせる */
.diagram__svg text { font-family: var(--font); }
.diagram__svg .t-label { font-size: 30px; font-weight: 800; fill: #1f3550; }
.diagram__svg .t-area { font-size: 22px; font-weight: 800; fill: #2b3f55; }
.diagram__svg .t-area--private { fill: #4a7a3a; }
.diagram__svg .t-boundary { font-size: 21px; font-weight: 700; fill: #333d48; }
.diagram__svg .t-badge { font-size: 18px; font-weight: 800; fill: #1f4f7a; }
.diagram__svg .badge { fill: #fff; stroke: #1f4f7a; stroke-width: 2.5; }
.diagram__svg .t-dimlabel { font-size: 22px; font-weight: 700; fill: #4a5563; }
.diagram__svg .t-result { font-size: 34px; font-weight: 800; fill: var(--c-result); font-variant-numeric: tabular-nums; }
.diagram__svg .t-result .u, .diagram__svg .t-input .u { font-size: .72em; font-weight: 700; }
.diagram__svg .t-input { font-size: 23px; font-weight: 800; fill: #333d48; font-variant-numeric: tabular-nums; }
.diagram__svg .t-result.is-long { font-size: 28px; }
.diagram__svg .t-input--h2 { font-size: 21px; }
.diagram__svg .t-input.is-long { font-size: 17px; }
.diagram__svg .result-box { fill: var(--c-result-bg); stroke: var(--c-result); stroke-width: 2.5; }
.diagram__svg .dim { stroke: #8a9fb3; stroke-width: 2.2; fill: none; }
.diagram__svg .hdim { stroke: #6b7f92; stroke-width: 1.6; }
.diagram__svg [data-state="empty"] { fill: #8a94a3; }

/* ---------- 入力欄 ---------- */
.inputs { display: grid; gap: 14px; margin: 0; }
.field { min-width: 0; }
.field__label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; font-weight: 700; font-size: 16px; line-height: 1.45; margin-bottom: 6px; }
.field__no { color: var(--c-brand); font-size: 18px; }
.field__name { flex: 1 1 auto; min-width: 0; }
.field__method {
  font-size: 12.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap;
  background: #edf0f4; color: #3b4452; border: 1px solid #cfd5dd;
}
.field__method--actual { background: #e8f6ee; color: #106b3a; border-color: #b6e0c7; }
.field__method--visual { background: #fff1e6; color: #9a4a00; border-color: #f4cfaa; }
.field__method--rough { background: #f0ecfb; color: #4b3a8f; border-color: #d4caf2; }
.field__control { position: relative; display: flex; align-items: center; }
.field__control input {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 48px 8px 14px;
  font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums;
  border: 2px solid #aab4c1; border-radius: 10px; background: #fff;
  -webkit-appearance: none; appearance: none;
}
.field__control input::placeholder { color: #a3acb8; font-weight: 500; font-size: 18px; }
.field__control input:focus { outline: none; border-color: var(--c-brand); box-shadow: 0 0 0 4px rgba(11,61,117,.18); }
.field__unit { position: absolute; right: 14px; font-size: 18px; font-weight: 700; color: var(--c-muted); pointer-events: none; }
.field__hint { margin: 4px 2px 0; font-size: 13px; color: var(--c-muted); }
.field__error { margin: 4px 2px 0; font-size: 14.5px; font-weight: 700; color: var(--c-error); min-height: 0; }
.field__error:empty { display: none; }
.field.is-error input { border-color: var(--c-error); background: var(--c-error-bg); }
.field.is-ok input { border-color: #6f9fd8; }

/* ---------- 計算結果 ---------- */
.calc-status { margin: 0 0 10px; padding: 8px 12px; border-radius: 8px; font-size: 15px; font-weight: 700; background: #f1f3f6; color: var(--c-muted); }
.calc-status[data-state="error"] { background: var(--c-error-bg); color: var(--c-error); }
.calc-status[data-state="ok"] { background: var(--c-result-bg); color: var(--c-result); }
.calc-status[data-state="caution"] { background: var(--c-warn-bg); color: var(--c-warn); }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.result {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px; background: var(--c-result-bg); border: 2px solid #b9cdf0;
}
.result__no { font-size: 22px; font-weight: 800; color: var(--c-result); }
.result__name { font-weight: 700; font-size: 17px; line-height: 1.3; }
.result__name small { display: block; font-size: 13px; font-weight: 600; color: var(--c-muted); font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.result__value { white-space: nowrap; color: var(--c-result); }
.result__value output { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.result__unit { font-size: 18px; font-weight: 700; margin-left: 4px; }
.results[data-state="empty"] .result__value { color: #8a94a3; }
.results[data-state="empty"] .result { background: #f6f7f9; border-color: #e0e4ea; }

.note { margin: 10px 0 0; font-size: 13.5px; color: var(--c-muted); line-height: 1.6; }

/* ---------- 調査情報・確認記録 ---------- */
.record { display: grid; gap: 12px; margin: 0; }
.record__group { border: 1px solid var(--c-line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; min-width: 0; }
.record__group legend { font-weight: 700; font-size: 15px; padding: 0 6px; color: var(--c-brand); }
.record__group--check { background: #fafbfc; }
.rfield { display: grid; gap: 4px; min-width: 0; }
.rfield label { font-size: 15px; font-weight: 700; }
.rfield input, .rfield textarea {
  width: 100%; min-height: 48px; padding: 8px 12px; font-size: 17px;
  border: 1.5px solid #aab4c1; border-radius: 8px; background: #fff;
}
.rfield input[type="date"] { -webkit-appearance: none; appearance: none; min-width: 0; }
.rfield textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.rfield input:focus, .rfield textarea:focus { outline: none; border-color: var(--c-brand); box-shadow: 0 0 0 3px rgba(11,61,117,.15); }

.check-status { margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.check-status__badge { font-weight: 800; padding: 3px 12px; border-radius: 999px; background: #edf0f4; color: #3b4452; border: 1.5px solid #c3cad4; font-size: 15px; }
.check-status__text { color: var(--c-muted); }
.check-status[data-state="partial"] .check-status__badge { background: var(--c-warn-bg); color: var(--c-warn); border-color: #f0d58a; }
.check-status[data-state="done"] .check-status__badge { background: var(--c-ok-bg); color: var(--c-ok); border-color: #9fd6b5; }

/* ---------- 操作ボタン ---------- */
.actions { display: grid; gap: 10px; }
.btn {
  min-height: var(--tap); padding: 10px 16px; border-radius: 10px; font-size: 17px; font-weight: 700;
  border: 2px solid var(--c-brand); background: #fff; color: var(--c-brand); cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid #f5b400; outline-offset: 2px; }
.btn--primary { background: var(--c-brand); color: #fff; }
.btn--ghost { border-color: #c3cad4; color: #4a5361; }
.btn--small { min-height: 40px; padding: 6px 14px; font-size: 15px; }
.copy-fallback { margin-top: 10px; }
.copy-fallback summary { cursor: pointer; font-weight: 700; color: var(--c-brand); }
.copy-fallback textarea { width: 100%; margin-top: 8px; font-size: 14px; padding: 8px; border-radius: 8px; border: 1px solid var(--c-line); }

/* ---------- 注意事項 ---------- */
.panel--caution { border-color: #f0d58a; background: #fffcf2; }
.caution-text { margin: 0; font-weight: 700; line-height: 1.7; }
.caution-list { margin: 10px 0 0; padding-left: 1.3em; font-size: 14px; color: #4a5361; }
.caution-list li + li { margin-top: 4px; }

.app-footer { text-align: center; font-size: 12.5px; color: var(--c-muted); padding: 4px 8px 8px; }
.app-footer p { margin: 2px 0; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1a1f26; color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- 画面幅別 ---------- */
@media (max-width: 380px) {
  body { font-size: 16px; }
  .layout { padding-left: 8px; padding-right: 8px; gap: 10px; }
  .panel { padding: 12px 12px 14px; }
  .app-title { font-size: 17px; }
  .result__value output { font-size: 30px; }
}

@media (min-width: 600px) {
  .actions { grid-template-columns: 1fr 1fr; }
  .actions .btn--ghost { grid-column: 1 / -1; justify-self: start; }
  .record__group { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .record__group legend, .record__group .check-status, .record__group .note, .rfield--wide { grid-column: 1 / -1; }
}

/* タブレット横・PC：横断図（左）と入力（右）を横並び */
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.15fr) minmax(380px, 1fr); align-items: start; padding: 16px; gap: 16px; }
  .panel--diagram { position: sticky; top: 12px; }
  .side { gap: 14px; }
  .record__group { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-title { font-size: 21px; }
}
@media (min-width: 1200px) {
  .record__group { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- 印刷（A4 縦 1枚） ---------- */
.print-sheet { display: none; }

@page { size: A4 portrait; margin: 10mm 12mm; }

@media print {
  html, body { background: #fff !important; font-size: 10pt; }
  .app-header, .update-banner, .layout, .toast, noscript { display: none !important; }
  .print-sheet { display: block; color: #000; font-family: var(--font); }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.ps-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #0b3d75; padding-bottom: 2mm; margin-bottom: 3mm; }
.ps-head h1 { font-size: 15pt; margin: 0; color: #0b3d75; }
.ps-meta { margin: 0; font-size: 8.5pt; color: #444; }
.ps-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.ps-table caption { text-align: left; font-weight: 700; font-size: 10pt; padding: 1mm 0; }
.ps-table th, .ps-table td { border: 0.3mm solid #777; padding: 1.4mm 2mm; text-align: left; vertical-align: middle; }
.ps-table th { background: #eef1f5; font-weight: 700; white-space: nowrap; width: 1%; }
.ps-table td.num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ps-info td { min-width: 25mm; }
.ps-diagram { margin: 3mm 0; border: 0.3mm solid #777; padding: 2mm; }
.ps-diagram__title { font-weight: 700; font-size: 10pt; margin-bottom: 1mm; }
.ps-diagram__title span { font-size: 9pt; border: 0.3mm solid #0b3d75; color: #0b3d75; padding: 0 2mm; border-radius: 1mm; margin-left: 2mm; }
.ps-diagram__svg svg { display: block; width: 100%; max-height: 72mm; height: auto; margin: 0 auto; }
.ps-cols .ps-table { font-size: 8.8pt; }
.ps-cols th small { font-weight: 400; }
.ps-cols { display: grid; grid-template-columns: 1.45fr 1fr; gap: 4mm; align-items: start; }
.ps-results td.num { color: #0a4ea8; font-size: 11pt; }
.ps-status { margin: 1.5mm 0 0; font-size: 9pt; font-weight: 700; }
.ps-status:empty { display: none; }
.ps-check { margin-top: 3mm; }
.ps-remarks { height: 14mm; font-size: 8.3pt; line-height: 1.4; vertical-align: top !important; white-space: pre-wrap; word-break: break-all; }
.ps-caution { margin-top: 3mm; border: 0.4mm solid #b58900; background: #fffcf2; padding: 2mm 3mm; font-size: 8.8pt; line-height: 1.55; }
.ps-caution p { margin: 1mm 0 0; }
