/* 配線容量シミュレーター（皮算用と同じ配色・ライト／ダーク・スマホ対応） */

:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f3ede3;
  --text: #2b2420;
  --text-sub: #6b5f55;
  --line: #e2d8c9;
  --accent: #a4532b;
  --accent-soft: #f3e2d6;
  --ok: #2f7a3e;
  --ok-soft: #e1f0e0;
  --warn: #9a6a00;
  --warn-soft: #fbf0d0;
  --ng: #b0301f;
  --ng-soft: #fbe2dc;
  --w-main: #c0602f;
  --w-gnd: #3f8a3a;
  --w-extra: #2f6f9a;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .07);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", Meiryo, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #272220;
    --surface-2: #211c19;
    --text: #efe7de;
    --text-sub: #b3a69a;
    --line: #3b332d;
    --accent: #e08a5c;
    --accent-soft: #3a2a21;
    --ok: #8fd18f;
    --ok-soft: #1f3322;
    --warn: #e8c060;
    --warn-soft: #3a3018;
    --ng: #f3907a;
    --ng-soft: #42221b;
    --w-main: #e8895a;
    --w-gnd: #8cc76f;
    --w-extra: #6fb0dc;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* ヘッダー */
.top { padding: 18px 16px 8px; }
.top h1 { margin: 10px 0 2px; font-size: clamp(22px, 4.5vw, 30px); line-height: 1.3; letter-spacing: .02em; }
.lead { margin: 0; color: var(--text-sub); max-width: 60em; }
.top-bar { display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12px; padding: 1px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* 2 列 */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 470px); gap: 18px; align-items: start; padding-top: 14px; padding-bottom: 24px; }
.inputs, .results { display: grid; gap: 14px; min-width: 0; }
.results { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; padding-bottom: 4px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .results { position: static; max-height: none; overflow: visible; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card h3 { margin: 16px 0 6px; font-size: 14px; color: var(--text-sub); }
.num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 13px; flex: none; }
.inline-h { display: inline-flex !important; margin: 0 !important; }

/* 入力 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 12px; }
.span2 { grid-column: span 2; }
@media (max-width: 440px) { .span2 { grid-column: auto; } }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--text-sub); min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select, button { font: inherit; color: inherit; }
input[type=number], input[type=text], select {
  width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2);
  color: var(--text); font-size: 15px;
}
input:disabled, select:disabled { opacity: .65; }
input::placeholder { color: var(--text-sub); opacity: .65; }
.unit-in { display: flex; align-items: center; gap: 6px; }
.unit-in i { font-style: normal; font-size: 13px; color: var(--text-sub); white-space: nowrap; }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--text-sub); }
.hint:empty { display: none; }

.seg { border: 0; padding: 0; margin: 14px 0 8px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.seg legend { font-size: 13px; color: var(--text-sub); padding: 0; margin-bottom: 4px; width: 100%; }
.seg label { display: inline-flex; align-items: center; gap: 6px; }
.checks-inline { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 14px; }
.checks-inline label { display: inline-flex; align-items: center; gap: 6px; }
.checks-inline select { width: auto; }

.btn { border: 1px solid var(--accent); background: transparent; color: var(--accent); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: 14px; }
.btn:hover { background: var(--accent-soft); }
.btn.small { font-size: 13px; padding: 3px 12px; margin-top: 10px; }
.icon-btn { border: 0; background: transparent; color: var(--text-sub); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--ng-soft); color: var(--ng); }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.row-actions .unit-in input { width: 80px; }

/* 編集用の表 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.edit-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.edit-table th { text-align: left; font-weight: 600; color: var(--text-sub); padding: 4px 4px; white-space: nowrap; }
.edit-table td { padding: 3px 4px; vertical-align: middle; }
.edit-table input, .edit-table select { font-size: 14px; padding: 4px 6px; }
.edit-table .w-name { min-width: 120px; }
.edit-table .w-num { min-width: 78px; }
.edit-table .w-sm { min-width: 58px; max-width: 80px; }
.edit-table .center { text-align: center; }
.data-table td input { width: 84px; }
.data-table .mini { display: block; font-size: 11px; color: var(--text-sub); }

/* 方式によって出し分け */
.is-dc .ac-only { display: none !important; }
body:not(.is-1p3w) .conn-col { display: none; }
.is-air .conduit-only { display: none !important; }
body:not(.is-air) .air-only { display: none !important; }

/* 折りたたみ */
details.sub > summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); list-style: revert; }
details.sub[open] > summary { margin-bottom: 8px; }
.tag { margin-left: 8px; font-size: 11px; padding: 0 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.mk-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 4px; }
.mk-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 10px; background: var(--surface-2); border-radius: 8px; font-size: 14px; }

/* 結果 */
.result-card h2 { margin-bottom: 8px; }
.verdict { font-weight: 700; font-size: 18px; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.v-ok { background: var(--ok-soft); color: var(--ok); }
.v-warn { background: var(--warn-soft); color: var(--warn); }
.v-ng { background: var(--ng-soft); color: var(--ng); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 6px 10px; }
.kpi span { display: block; font-size: 12px; color: var(--text-sub); }
.kpi b { font-size: 17px; font-variant-numeric: tabular-nums; }

.checks, .cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
.checks th, .checks td, .cmp th, .cmp td { padding: 6px 6px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.checks thead th, .cmp thead th { border-top: 0; color: var(--text-sub); font-weight: 600; white-space: nowrap; }
.checks tbody th { font-weight: 600; }
.checks small { display: block; font-weight: 400; color: var(--text-sub); font-size: 11.5px; line-height: 1.5; margin-top: 2px; }
.checks td, .cmp td { font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.p-ok { background: var(--ok-soft); color: var(--ok); }
.p-warn { background: var(--warn-soft); color: var(--warn); }
.p-ng { background: var(--ng-soft); color: var(--ng); }
.cmp tr.is-cur td { font-weight: 700; background: var(--accent-soft); }
.cmp td { white-space: nowrap; }

/* 電線管の図 */
#conduit-fig { display: grid; justify-items: center; gap: 6px; }
.conduit-svg { width: min(100%, 260px); height: auto; }
.pipe-wall { fill: var(--text-sub); opacity: .55; }
.pipe-in { fill: var(--surface-2); }
.pipe-lim { fill: none; stroke: var(--accent); stroke-width: .35; stroke-dasharray: 1.2 1; vector-effect: non-scaling-stroke; }
.w-main { fill: var(--w-main); stroke: var(--surface); stroke-width: .25; }
.w-gnd { fill: var(--w-gnd); stroke: var(--surface); stroke-width: .25; }
.w-extra { fill: var(--w-extra); stroke: var(--surface); stroke-width: .25; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 12px; color: var(--text-sub); }
.lg::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.lg-main::before { background: var(--w-main); }
.lg-gnd::before { background: var(--w-gnd); }
.lg-extra::before { background: var(--w-extra); }
.lg-lim::before { border: 1.5px dashed var(--accent); background: transparent; }

.basis { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.basis dt { color: var(--text-sub); }
.basis dd { margin: 0; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .basis { grid-template-columns: minmax(0, 1fr); } .basis dd { margin-bottom: 6px; } }

.foot { color: var(--text-sub); font-size: 12.5px; padding-bottom: 32px; }

/* ページ切り替え */
.tabs { display: flex; gap: 4px; margin: 10px 0 6px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 10px 10px 0 0; text-decoration: none; color: var(--text-sub); font-weight: 600; font-size: 14px; border: 1px solid transparent; border-bottom: 0; margin-bottom: -1px; }
.tabs a:hover { color: var(--accent); }
.tabs a[aria-current="page"] { color: var(--accent); background: var(--surface); border-color: var(--line); }

/* 区分による出し分け */
body:not(.is-ctrl) .ctrl-only { display: none !important; }
.is-hv .hv-hide { display: none !important; }
.is-hv .lv-only, .is-ctrl .lv-only { display: none !important; }

/* 説明の折りたたみ */
details.help { margin-top: 10px; font-size: 13px; background: var(--surface-2); border-radius: 10px; padding: 6px 12px; }
details.help > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.help p { margin: 6px 0; color: var(--text-sub); }

/* 遮断器の選定ページ */
.targets { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; border: 0; padding: 0; margin: 0; }
.targets legend { font-size: 13px; color: var(--text-sub); margin-bottom: 6px; padding: 0; }
.targets label { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface-2); }
.targets label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.targets b { display: block; font-size: 15px; }
.targets small { color: var(--text-sub); font-size: 12px; line-height: 1.5; }
.solve-tag { display: none; margin-left: auto; font-size: 12px; padding: 1px 10px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; }
.card.is-target { border-color: var(--accent); }
.card.is-target .solve-tag { display: inline-block; }
body[data-target="breaker"] [data-hide-for~="breaker"],
body[data-target="wire"] [data-hide-for~="wire"],
body[data-target="load"] [data-hide-for~="load"],
body[data-target="source"] [data-hide-for~="source"] { display: none !important; }
.answer { font-size: 20px; font-weight: 700; margin: 0 0 4px; line-height: 1.5; }
.answer-sub { margin: 0 0 12px; color: var(--text-sub); font-size: 13px; }
.cmp tr.is-rec td { font-weight: 700; background: var(--ok-soft); }
.cmp td.wrap { white-space: normal; }
.cmp a { font-size: 12px; }
.model-info { font-size: 12.5px; color: var(--text-sub); margin: 8px 0 0; }

/* 太陽光 */
body:not(.is-pv) .pv-only { display: none !important; }
.is-pv .pv-hide { display: none !important; }
.note { display: block; grid-column: 1 / -1; font-size: 12px; color: var(--text-sub); line-height: 1.5; margin-top: -2px; }
body:not([data-target="breaker"]) [data-show-for="breaker"] { display: none; }
.spec td:first-child { font-weight: 600; white-space: nowrap; }

/* 中性点との電圧は単相3線・三相4線だけ */
body:not(.has-n) .n-only { display: none !important; }

/* 計算する範囲の図 */
.diagram { width: 100%; height: auto; display: block; }
.diagram text { text-anchor: middle; font-size: 13px; fill: var(--text); }
.diagram .dg-s { font-size: 11px; fill: var(--text-sub); }
.diagram .dg-m { font-size: 12px; fill: var(--ng); font-weight: 600; }
.diagram .dg-box { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.5; }
.diagram .dg-w { stroke: var(--text-sub); stroke-width: 2; }
.diagram .dg-cable { stroke: var(--w-main); stroke-width: 5; stroke-linecap: round; }
.diagram .dg-conduit { fill: none; stroke: var(--w-extra); stroke-width: 1.5; stroke-dasharray: 4 3; }
.diagram .dg-mark { stroke: var(--ng); stroke-width: 1.5; stroke-dasharray: 3 3; }
.diagram .dg-n { fill: var(--accent); }
.diagram .dg-nt { fill: #fff; font-size: 12px; font-weight: 700; }
.diagram .dg-t { font-weight: 600; }
body:not(.is-hv) .hv-only { display: none !important; }

/* 言語の切り替え */
.top-bar .lang { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.top-bar .lang select { width: auto; font-size: 13px; padding: 3px 6px; }
.load-error { margin: 0; padding: 8px 16px; background: var(--ng-soft); color: var(--ng); font-size: 13px; }
@media (max-width: 640px) { .top-bar .lang select { font-size: 16px; min-height: 40px; } }
/* 右書き（アラビア語） */
[dir="rtl"] .unit-in i { margin-left: 0; margin-right: 6px; }

/* 脚注の関連アプリ */
.foot .related { margin-top: 8px; font-size: 13px; }

/* 計算する範囲の図：狭い画面では縮めすぎず、横に送って見る */
#diagram { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 640px) { #diagram .diagram { min-width: 600px; } }

/* 判定表の値は数字の途中で折らない（空白・括弧のところで折る） */
.checks td, .cmp td { overflow-wrap: normal; word-break: normal; }
@media (max-width: 360px) {
  .checks, .cmp { font-size: 12px; }
  .checks th, .checks td, .cmp th, .cmp td { padding: 5px 3px; }
  .checks thead th, .cmp thead th { white-space: normal; overflow-wrap: anywhere; }
}

/* 基準値データ：項目ごとに開く */
.data-group { border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; background: var(--surface); }
.data-group > summary { cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 14px; }
.data-group[open] > summary { border-bottom: 1px solid var(--line); }
.data-group > :not(summary) { margin: 10px 12px; }
