/* 晟电板材阻抗计算器 – three-column layout (navigation · input area · results), dark / light themes. */
:root {
  --bg: #f1f3f5;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --line: #dde1e6;
  --text: #1f2328;
  --muted: #5f6b76;
  --accent: #0d6efd;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 110, 253, 0.12);
  --active: #0d6efd;
  --value: #1a7f37;
  --warn: #9a6700;
  --err-bg: #fdecea;
  --err: #b42318;
  --row-hover: rgba(13, 110, 253, 0.07);
  --stripe: rgba(0, 0, 0, 0.025);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  --chart-grid: #e3e6ea;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16181b;
  --panel: #212529;
  --panel-2: #2b3035;
  --line: #3a4047;
  --text: #dee2e6;
  --muted: #9aa4ae;
  --accent: #0d6efd;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 110, 253, 0.22);
  --active: #3d8bfd;
  --value: #55ff55;
  --warn: #e3b341;
  --err-bg: #3b1d1d;
  --err: #ff8a80;
  --row-hover: rgba(61, 139, 253, 0.12);
  --stripe: rgba(255, 255, 255, 0.03);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  --chart-grid: #3a4047;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; color: inherit; }
a { color: var(--active); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 272px minmax(420px, 560px) minmax(380px, 1fr); gap: 14px; padding: 14px; min-height: 100vh; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.col-nav { position: sticky; top: 14px; display: flex; flex-direction: column; padding: 14px; gap: 14px; }
.col-area, .col-out { padding: 0 0 16px; }
.col-title { margin: 0; padding: 14px 18px; font-size: 18px; font-weight: 600; border-bottom: 1px solid var(--line); }
.area { padding: 6px 0; }
.mobile-calc { display: none; }

/* ---------- navigation column ---------- */
.nav-head { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.app-name { font-size: 17px; font-weight: 600; }
.menu { position: relative; }
.hamburger { display: grid; gap: 4px; width: 34px; height: 30px; padding: 6px; background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.hamburger span { display: block; height: 2px; background: var(--text); border-radius: 2px; }
.hamburger:hover, .hamburger[aria-expanded="true"] { border-color: var(--line); background: var(--panel-2); }
.menu-list { position: absolute; z-index: 30; top: 36px; left: 0; min-width: 190px; margin: 0; padding: 6px 0; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.menu-list button, .menu-list a { display: block; width: 100%; padding: 7px 16px; text-align: left; background: none; border: 0; color: var(--text); text-decoration: none; cursor: pointer; }
.menu-list button:hover, .menu-list a:hover { background: var(--row-hover); }
.menu-list .sep { height: 1px; margin: 6px 0; background: var(--line); }

.design-pick { display: grid; justify-items: center; gap: 6px; padding: 8px; background: none; border: 1px solid transparent; border-radius: 8px; cursor: pointer; }
.design-pick:hover { border-color: var(--line); }
.design-pick.is-active { border-color: var(--active); }
.design-img { display: grid; place-items: center; width: 100%; height: 96px; background: #fff; border-radius: 6px; overflow: hidden; }
.design-img img { max-width: 92%; max-height: 90px; }
.design-pick small { color: var(--active); }

.nav-tree { display: grid; gap: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.nav-group { margin: 8px 0 2px; font-weight: 600; }
.nav-group::before { content: "⌄ "; color: var(--muted); }
.nav-tree a { display: block; padding: 4px 12px; margin-left: 8px; border-radius: 4px; color: var(--text); text-decoration: none; font-size: 13px; }
.nav-tree a:hover { background: var(--row-hover); }
.nav-tree a.is-active { background: var(--text); color: var(--panel); }
.nav-tree a.is-flag { box-shadow: inset 3px 0 0 var(--active); }

.nav-foot { display: grid; justify-items: center; gap: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: pointer; }
.btn:hover { border-color: var(--active); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.calc-btn { min-width: 96px; justify-content: center; }
.calc-btn.is-busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch-row { display: flex; align-items: center; gap: 6px; }
.switch-lbl { background: none; border: 0; padding: 2px 4px; color: var(--active); cursor: pointer; }
.switch-lbl:disabled { color: var(--muted); cursor: default; }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: #fff; }
.switch input:disabled + span { opacity: 0.45; }
.switch input:focus-visible + span { outline: 2px solid var(--active); outline-offset: 2px; }

/* ---------- design type list ---------- */
.dt { display: grid; gap: 4px; width: 100%; padding: 12px 18px; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.dt:hover { background: var(--row-hover); }
.dt.is-active { background: var(--accent); color: #fff; }
.dt-head { display: flex; justify-content: space-between; gap: 12px; }
.dt-head small { opacity: 0.85; }
.dt-img { display: grid; place-items: center; height: 150px; background: #fff; border-radius: 6px; }
.dt-img img { max-height: 140px; max-width: 94%; }
.dt-note { font-size: 12px; opacity: 0.85; }

/* ---------- material table ---------- */
.mat-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 18px 10px; }
.mat-tools input { flex: 1 1 140px; min-width: 120px; }
.chip { padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: 12px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.mat-wrap { max-height: calc(100vh - 190px); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; }
.mat-table tbody tr { cursor: pointer; }
.mat-table tbody tr:nth-child(odd) { background: var(--stripe); }
.mat-table tbody tr:hover { background: var(--row-hover); }
.mat-table tbody tr.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--active); }
.mat-table .series { color: var(--muted); font-size: 12px; }
.na { color: var(--muted); }

/* ---------- form rows ---------- */
.frow { display: grid; grid-template-columns: 11em minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; padding: 9px 18px; border-bottom: 1px solid var(--line); }
.frow:hover { background: var(--row-hover); }
.frow > label, .frow > .lbl { font-size: 13.5px; }
.frow .ctl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.frow .unit { color: var(--muted); font-size: 13px; white-space: nowrap; }
.frow.is-flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
.frow.is-off { opacity: 0.55; }
.frow-note { padding: 8px 18px; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); }
.frow-note.warn { color: var(--warn); }
input[type="text"], input[type="search"], input:not([type]), select, textarea {
  width: 100%; min-width: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--text); font: inherit; font-variant-numeric: tabular-nums;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--active); outline-offset: -1px; border-color: transparent; }
input[readonly] { opacity: 0.6; }
.ctl input { max-width: 150px; }
.info { display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.info:hover { color: var(--active); }
.info svg { width: 16px; height: 16px; }

.combo { position: relative; display: flex; align-items: center; gap: 2px; }
.combo input { max-width: 150px; }
.combo-btn { width: 28px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: pointer; }
.combo-btn::after { content: ""; display: inline-block; border: 5px solid transparent; border-top-color: var(--text); transform: translateY(3px); }
.combo-list { position: absolute; z-index: 20; top: 36px; left: 0; min-width: 100%; max-height: 260px; overflow: auto; margin: 0; padding: 4px 0; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.combo-list button { display: block; width: 100%; padding: 5px 14px; text-align: left; background: none; border: 0; white-space: nowrap; cursor: pointer; }
.combo-list button:hover, .combo-list button:focus { background: var(--row-hover); outline: none; }
.combo-list small { color: var(--muted); margin-left: 8px; }

.toggle { display: flex; align-items: center; gap: 6px; }
.toggle .switch-lbl { padding: 2px 2px; }
.toggle .switch-lbl.is-on { font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- output column ---------- */
.brand { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.brand-mark { padding: 4px 10px; border: 2px solid var(--active); border-radius: 4px; color: var(--active); font-weight: 800; letter-spacing: 0.12em; }
.brand-text { display: grid; font-weight: 600; font-size: 16px; line-height: 1.25; }
.brand-text small { font-weight: 400; font-size: 12px; color: var(--muted); }
.sec-title { margin: 0; padding: 12px 18px 6px; font-size: 17px; font-weight: 600; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-right: 18px; margin-top: 6px; border-top: 1px solid var(--line); }
.sec-block { margin-top: 12px; border-top: 1px solid var(--line); }

.inputs-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; padding: 0 18px 12px; }
.sum-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 3px 6px; border-radius: 4px; background: none; border: 0; text-align: left; cursor: pointer; }
.sum-item:hover { background: var(--row-hover); }
.sum-item.is-active { box-shadow: inset 3px 0 0 var(--active); background: var(--accent-soft); }
.sum-item b { color: var(--value); font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }

.output { padding: 4px 18px 8px; overflow: auto; }
.output .empty { color: var(--muted); margin: 6px 0; }
.out-row { display: grid; grid-template-columns: minmax(12em, 1fr) minmax(0, 1fr); gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.out-row > span:first-child { font-weight: 600; font-size: 13.5px; }
.out-row > span:last-child { font-variant-numeric: tabular-nums; }
.out-row.head > span:last-child { font-weight: 600; }
.out-row.key > span:last-child { color: var(--active); font-weight: 700; font-size: 15px; }
.out-group { margin: 14px 0 2px; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
.out-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.err-box { margin: 8px 0; padding: 10px 12px; border-radius: 6px; background: var(--err-bg); color: var(--err); }
.range-wrap { overflow: auto; max-height: 420px; margin-top: 8px; border: 1px solid var(--line); border-radius: 6px; }
.range-wrap th, .range-wrap td { padding: 5px 10px; font-size: 13px; }
.chart { margin-top: 12px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.chart .legend i { display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; border-radius: 2px; }

.note { margin: 0; padding: 0 18px 8px; color: var(--muted); font-size: 12.5px; }
.json { display: block; width: calc(100% - 36px); margin: 0 18px; min-height: 120px; font: 12px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; resize: vertical; }
.btn-row { display: flex; align-items: center; gap: 8px; padding: 10px 18px 0; }
.copied { color: var(--value); font-size: 12.5px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.55); }
.modal[hidden] { display: none; }
.modal-box { width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.x { width: 30px; height: 30px; border: 0; border-radius: 6px; background: none; font-size: 22px; line-height: 1; cursor: pointer; }
.x:hover { background: var(--row-hover); }
.modal-body { padding: 14px 18px; overflow: auto; }
.modal-body p { margin: 0 0 10px; }
.modal-body ol { margin: 0; padding-left: 1.3em; }
.modal-body li { margin-bottom: 8px; }
.modal-foot { display: flex; justify-content: flex-end; padding: 10px 18px; border-top: 1px solid var(--line); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 250px minmax(0, 1fr); }
  .col-out { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 10px; gap: 10px; }
  .col-nav { position: static; }
  .nav-tree { grid-template-columns: 1fr 1fr; }
  .nav-group { grid-column: 1 / -1; }
  .nav-foot .calc-btn { display: none; }
  .mobile-calc { display: flex; justify-content: center; padding: 14px 0 0; }
  .frow { grid-template-columns: minmax(0, 1fr) auto; padding: 9px 14px; }
  .frow > label, .frow > .lbl { grid-column: 1 / -1; }
  .inputs-summary { grid-template-columns: minmax(0, 1fr); padding: 0 12px 12px; }
  .output, .sec-title, .note, .btn-row { padding-left: 14px; padding-right: 14px; }
  .json { width: calc(100% - 28px); margin: 0 14px; }
  .out-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .mat-wrap { max-height: 60vh; }
}
