/* 晟电板材阻抗计算器 · UI adapted from the calculation project's LayerLine shell.
 * SPDX-License-Identifier: GPL-3.0-or-later */
:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f4f4f4;
  --line: #e0e0e0;
  --line-strong: #c6c6c6;
  --text: #111111;
  --text-2: #3a3a3a;
  --muted: #6e6e6e;
  --accent: #111111;
  --accent-ink: #ffffff;
  --accent-soft: #ececec;
  --active: #111111;
  --value: #3a3a3a;
  --warn: #a86a12;
  --err-bg: #f8dfdb;
  --err: #b83a2e;
  --row-hover: #f4f4f4;
  --stripe: transparent;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);
  --chart-grid: #e0e0e0;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111111;
  --panel: #181818;
  --panel-2: #202020;
  --line: #2e2e2e;
  --line-strong: #454545;
  --text: #eeeeee;
  --text-2: #cccccc;
  --muted: #999999;
  --accent: #f0f0f0;
  --accent-ink: #181818;
  --accent-soft: #2a2a2a;
  --active: #f0f0f0;
  --value: #cccccc;
  --warn: #e0a84a;
  --err-bg: #3d1b17;
  --err: #ef7a6c;
  --row-hover: #202020;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  --chart-grid: #2e2e2e;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--sans);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -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, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--active); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; }
a { color: var(--active); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); width: 100%; max-width: 1560px; margin: 0 auto; min-height: 100vh; }
.main { min-width: 0; padding: 24px 28px 40px; outline: none; }
.page-head { margin-bottom: 20px; display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.page-head h1 { flex: 1; min-width: 0; }
.language-switch { flex-shrink: 0; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 7px; color: var(--text); background: var(--panel); font-size: 12px; cursor: pointer; }
.language-switch:disabled { opacity: .5; cursor: not-allowed; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -0.005em; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 20px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.col-nav { position: sticky; top: env(safe-area-inset-top, 0px); align-self: start; max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y: auto; display: flex; flex-direction: column; padding: 20px 8px 20px 12px; gap: 18px; border-right: 1px solid var(--line); }
.col-area { padding: 16px 18px 18px; }
.col-out { display: grid; gap: 20px; min-width: 0; }
.col-out > .col { padding: 16px 18px 18px; }
.col-title { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.area { padding: 0; }
.mobile-calc, .nav-toggle, .nav-backdrop { display: none; }

/* ---------- navigation column ---------- */
.nav-head { display: flex; align-items: center; gap: 8px; }
.app-name { font-size: 13px; 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(--line-strong); background: var(--accent-soft); }
.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(--text-2); font-size: 12px; }

.nav-tree { display: grid; gap: 2px; }
.nav-group { margin: 0; padding: 0 10px 6px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; }
.nav-group:not(:first-child) { margin-top: 18px; }
.nav-tree a { display: block; padding: 6px 10px; border-left: 2px solid transparent; border-radius: 6px; color: var(--text-2); text-decoration: none; font-size: 13px; }
.nav-tree a:hover { background: var(--row-hover); }
.nav-tree a.is-active { background: var(--accent-soft); color: var(--active); font-weight: 600; border-left-color: var(--active); border-radius: 0 6px 6px 0; }
.nav-tree a.is-flag { box-shadow: inset 3px 0 0 var(--active); }

.nav-foot { display: grid; justify-items: stretch; gap: 14px; margin: 6px 8px 0; padding-top: 18px; border-top: 1px solid var(--line); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 16px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--panel); font-size: 13px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--text-2); border-color: var(--text-2); }
.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; justify-content: 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: var(--accent-ink); }
.switch input:disabled + span { opacity: 0.45; }
.switch input:focus-visible + span { outline: 2px solid var(--active); outline-offset: 2px; }

/* ---------- design type list ---------- */
.area-pane[data-pane="designTypes"] { display: grid; gap: 10px; }
.dt { display: grid; gap: 8px; width: 100%; padding: 12px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.dt:hover { background: var(--row-hover); }
.dt.is-active { background: var(--accent-soft); color: var(--text); border-color: var(--active); box-shadow: inset 2px 0 0 var(--active); }
.dt-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: 13px; }
.dt-head small { opacity: 0.85; }
.dt-img { display: grid; place-items: center; height: 120px; background: #fff; border-radius: 6px; }
.dt-img img { max-height: 110px; 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: 0 0 12px; }
.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: var(--accent-ink); }
.mat-wrap { max-height: calc(100dvh - 220px); overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
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-2); color: var(--text-2); 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: minmax(0, 1fr) 22px; gap: 4px 8px; align-items: center; margin-bottom: 12px; border-radius: 6px; }
.frow > label, .frow > .lbl { grid-column: 1; font-size: 13px; color: var(--text-2); }
.frow > .ctl { grid-column: 1; grid-row: 2; }
.frow > .info { grid-column: 2; grid-row: 2; }
.frow .ctl { display: flex; align-items: stretch; min-width: 0; min-height: 34px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 6px; }
.frow .ctl:focus-within { border-color: var(--active); box-shadow: 0 0 0 2px color-mix(in srgb, var(--active) 22%, transparent); }
.frow .ctl input, .frow .ctl select { border: 0; background: transparent; outline: none; }
.frow .unit { display: flex; align-items: center; padding: 0 10px; border-left: 1px solid var(--line); border-radius: 0 5px 5px 0; background: var(--panel-2); color: var(--muted); font: 12px var(--mono); white-space: nowrap; }
.frow .unit:empty { display: none; }
.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 { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.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-strong); border-radius: 6px;
  background: var(--panel); 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 { flex: 1; width: 100%; font-family: var(--mono); }
.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; flex: 1; min-width: 0; display: flex; align-items: stretch; }
.combo-btn { flex: none; width: 30px; min-height: 32px; padding: 0; border: 0; border-left: 1px solid var(--line); border-radius: 0 5px 5px 0; 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; }

.frow .ctl.toggle { align-items: center; gap: 8px; border: 0; background: none; box-shadow: none; }
.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; flex-wrap: wrap; align-items: center; gap: 12px; padding: 0 0 16px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.brand-logo { position: relative; display: block; width: 200px; max-width: 100%; }
.brand-logo img { display: block; width: 100%; height: auto; }
/* Preserve the supplied ShinePCB colors on both themes. */
:root[data-theme="dark"] .brand-logo { padding: 6px 8px; background: #fff; border-radius: 6px; box-sizing: border-box; }
.brand-tagline { font-size: 12px; color: var(--muted); }
.sec-title { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sec-head .sec-title { margin-bottom: 0; }

.inputs-summary { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.sum-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 6px 8px; border: 0; border-bottom: 1px dashed var(--line); border-radius: 4px; background: none; 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: 400 13px/1.5 var(--mono); text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.output { overflow: auto; }
.output .empty { color: var(--muted); margin: 6px 0; }
.out-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.out-row > span:first-child { color: var(--text-2); font-size: 13px; }
.out-row > span:last-child { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.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 0 12px; color: var(--muted); font-size: 12.5px; }
.json { display: block; width: 100%; min-height: 140px; background: var(--panel-2); font: 12px/1.5 var(--mono); resize: vertical; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 12px; }
.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) and (min-width: 901px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .inputs-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .main { padding: 24px 16px 40px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-block; margin-bottom: 10px; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 6px; padding: 4px 12px; cursor: pointer; }
  .col-nav { position: fixed; inset: env(safe-area-inset-top, 0px) auto env(safe-area-inset-bottom, 0px) 0; z-index: 40; width: min(280px, 85vw); height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); max-height: none; background: var(--panel); box-shadow: var(--shadow); transform: translateX(-102%); visibility: hidden; transition: transform 0.2s ease, visibility 0.2s; }
  .col-nav.is-open { transform: none; visibility: visible; }
  .nav-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 35; border: 0; padding: 0; background: rgb(0 0 0 / 0.4); }
  body.nav-open { overflow: hidden; }
  .nav-foot .calc-btn { display: none; }
  .mobile-calc { display: flex; padding-top: 16px; }
  .mobile-calc .calc-btn { width: 100%; }
  .mat-wrap { max-height: 60dvh; }
}
@media (max-width: 480px) {
  .page-head h1 { font-size: 22px; }
  .col-area, .col-out > .col { padding: 14px; }
  .combo-list { min-width: 0; width: max-content; max-width: calc(100vw - 88px); }
  .combo-list button { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
