/* 电气工程综合计算平台 · 界面样式（手机竖屏优先，960px 以上为桌面布局） */

:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --line: #dde2ea;
  --primary: #1559b7;
  --primary-soft: #e6eefb;
  --ok: #157347;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --err: #c62828;
  --err-soft: #fdecec;
  --code-bg: #f5f7fa;
  --radius: 12px;
  --top: 52px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Cascadia Mono", "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --card: #1a2028;
    --text: #e4e8ee;
    --muted: #9aa5b4;
    --line: #2d3540;
    --primary: #6ea8ff;
    --primary-soft: #1c2a40;
    --ok: #5fcf8e;
    --ok-soft: #173024;
    --warn: #f0b84a;
    --warn-soft: #33290f;
    --err: #ff7b7b;
    --err-soft: #3a1c1c;
    --code-bg: #141920;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0.2rem 0 0.4rem; line-height: 1.3; }
h2 { font-size: 1.08rem; margin: 0 0 0.8rem; }
h3 { font-size: 0.98rem; margin: 0.9rem 0 0.4rem; }
sub { font-size: 0.72em; }
.muted { color: var(--muted); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top);
  padding: 0 4px; padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--primary); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #16243a; } }
.brand { display: flex; align-items: center; gap: 6px; color: #fff; font-weight: 700; font-size: 1.08rem; }
.icon-btn {
  width: 48px; height: 48px; border: 0; background: transparent; color: inherit;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }

.sys-msg { margin: 0; padding: 10px 14px; background: var(--err-soft); color: var(--err); white-space: pre-wrap; font-family: var(--font); font-size: 0.9rem; }

/* ---------- 布局 ---------- */
.layout { position: relative; }
.view { padding: 12px 12px 24px; max-width: 1200px; margin: 0 auto; min-width: 0; }

.drawer {
  position: fixed; z-index: 40; top: 0; bottom: 0; left: 0;
  width: min(86vw, 340px);
  background: var(--card);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateX(-102%);
  transition: transform 0.2s ease;
  padding: env(safe-area-inset-top) 0 24px;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.18);
}
.drawer-open .drawer { transform: none; }
.scrim { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.4); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-home { font-weight: 700; }
.drawer-cat > summary {
  list-style: none; cursor: pointer; padding: 12px 16px; min-height: 48px;
  display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.drawer-cat > summary::-webkit-details-marker { display: none; }
.drawer-cat > summary::after { content: "›"; margin-left: auto; color: var(--muted); transition: transform 0.15s; }
.drawer-cat[open] > summary::after { transform: rotate(90deg); }
.cno { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; font-size: 0.85em; }
.badge { background: var(--ok); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 0.75rem; font-weight: 600; }
.drawer-items { list-style: none; margin: 0; padding: 4px 0; background: var(--bg); }
.drawer-items a { display: block; padding: 10px 16px 10px 28px; min-height: 44px; color: var(--text); font-size: 0.93rem; }
.drawer-items a.planned { color: var(--muted); }
.drawer-items a.live { font-weight: 600; }
.drawer-items a.current { background: var(--primary-soft); color: var(--primary); }
.iid { font-family: var(--mono); font-size: 0.78em; color: var(--muted); }

@media (min-width: 960px) {
  #btn-menu { visibility: hidden; }
  .layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
  .drawer {
    position: sticky; top: var(--top); height: calc(100vh - var(--top));
    transform: none; box-shadow: none; border-right: 1px solid var(--line); padding-top: 0; width: auto;
  }
  .scrim { display: none; }
  .view { padding: 20px 24px 32px; }
}

/* ---------- 卡片与通用元素 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.tag {
  display: inline-block; font-size: 0.75rem; line-height: 1.6; padding: 0 7px; border-radius: 6px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.placeholder { color: var(--muted); margin: 0; }
.note { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }

.btn {
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; flex: 1; letter-spacing: 0.2em; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1522; } }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.88rem; margin-top: 6px; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }

/* ---------- 模块页 ---------- */
.mod-head { margin-bottom: 10px; }
.crumbs { font-size: 0.85rem; color: var(--muted); }
.meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.purpose { margin: 4px 0 0; color: var(--muted); font-size: 0.93rem; }

.mod-grid { display: block; }
@media (min-width: 960px) {
  .mod-grid { display: grid; grid-template-columns: minmax(300px, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
  .col-left { position: sticky; top: calc(var(--top) + 16px); }
}

.field { margin-bottom: 14px; }
.field label { display: flex; align-items: baseline; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.sym { font-family: var(--mono); font-weight: 400; color: var(--primary); font-size: 0.92em; }
.ctl-row { display: flex; gap: 8px; align-items: stretch; }
.ctl {
  flex: 1; min-width: 0; height: 48px; padding: 0 12px; font: inherit; font-size: 1.08rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  font-variant-numeric: tabular-nums;
}
.ctl:focus, .unit-sel:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.unit-sel {
  height: 48px; min-width: 76px; padding: 0 8px; font: inherit; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); color: var(--text);
}
.unit-sel.small { height: 36px; min-width: 64px; font-size: 0.9rem; }
.unit-fixed { display: inline-flex; align-items: center; min-width: 52px; justify-content: center; color: var(--muted); font-size: 0.9rem; }
.field.has-err .ctl { border-color: var(--err); background: var(--err-soft); }
.err { color: var(--err); font-size: 0.88rem; min-height: 0; }
.err:not(:empty) { margin-top: 4px; }
.form-err:not(:empty) { padding: 8px 10px; background: var(--err-soft); border-radius: 8px; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  min-height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 0.88rem; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip:active { background: var(--primary-soft); }

/* 结果 */
.result h2 { margin-bottom: 6px; }
.out { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.out:last-child { border-bottom: 0; }
.out-name { font-size: 0.92rem; color: var(--muted); min-width: 0; }
.out-val { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.val { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.12rem; }
.out.main { padding: 10px 0; }
.out.main .out-name { color: var(--text); font-weight: 600; }
.out.main .val { font-size: 1.7rem; color: var(--primary); }
.aux { margin-top: 4px; border-top: 1px solid var(--line); }
.warn-box { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 0.9rem; }

/* 折叠区 */
.fold { padding: 0; }
.fold > summary {
  list-style: none; cursor: pointer; padding: 14px; min-height: 48px; font-weight: 700;
  display: flex; align-items: center;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: "＋"; margin-left: auto; color: var(--muted); font-weight: 400; }
.fold[open] > summary::after { content: "－"; }
.fold-body { padding: 0 14px 14px; min-width: 0; }
.fold-body ul { padding-left: 1.2em; margin: 0.3rem 0; }
.fold-body li { margin: 0.2rem 0; }
.risk li { color: var(--warn); }

.formula {
  font-family: var(--mono); font-size: 0.95rem; background: var(--code-bg); border-radius: 8px;
  padding: 8px 10px; margin: 4px 0; overflow-x: auto; white-space: nowrap;
}
.formula.big { font-size: 1.02rem; border-left: 3px solid var(--primary); }
.formula.res { font-weight: 700; color: var(--primary); }
.formula .num { color: var(--ok); }
.steps-list { padding-left: 1.3em; margin: 0; }
.steps-list li { margin-bottom: 12px; }
.step-title { font-weight: 600; font-size: 0.92rem; margin-bottom: 2px; }
.formula-block { margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
.sym-table, .kv { border-collapse: collapse; width: 100%; font-size: 0.9rem; margin-top: 6px; }
.sym-table th, .sym-table td, .kv th, .kv td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.sym-table th, .kv th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.sym-table td:first-child, .sym-table td:last-child { white-space: nowrap; }

.case { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.case:last-child { border-bottom: 0; }
.case-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.case-in, .case-exp { font-size: 0.9rem; margin-top: 2px; }
.case-src { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

/* ---------- 首页、分类页 ---------- */
.home-hero { padding: 6px 0 4px; }
.search-input {
  width: 100%; height: 50px; padding: 0 14px; font: inherit; font-size: 1.02rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); margin: 8px 0 4px;
}
.search-input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.sec { margin: 18px 0 10px; font-size: 1rem; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mod-card {
  display: flex; flex-direction: column; gap: 2px; padding: 12px; min-height: 84px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text);
}
.mod-card .mname { font-weight: 700; line-height: 1.35; }
.mod-card .mcat { font-size: 0.8rem; color: var(--muted); margin-top: auto; }
.cat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) { .cat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.cat-tile {
  display: flex; flex-direction: column; padding: 12px; min-height: 76px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text);
}
.cat-tile.has-live { border-color: var(--primary); }
.cname { font-weight: 700; }
.ccount { font-size: 0.8rem; color: var(--muted); margin-top: auto; }

.item-list { list-style: none; padding: 0; margin: 0; }
.item-list.card { padding: 0 14px; }
.item-list a {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 12px 0; min-height: 48px;
  border-bottom: 1px solid var(--line); color: var(--text);
}
.item-list li:last-child a { border-bottom: 0; }
.item-list a.planned .iname { color: var(--muted); }
.item-list a.live .iname { font-weight: 700; }
.iname { flex: 1 1 60%; min-width: 0; }
.icat { font-size: 0.8rem; color: var(--muted); }
.ibadges { display: flex; gap: 4px; }
.search-results .item-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.legend { font-size: 0.82rem; }
.kv { max-width: 360px; }

/* ---------- 页脚与提示 ---------- */
.footer { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.8rem; text-align: center; }
.footer p { margin: 4px 0; }
@media (min-width: 960px) { .footer { margin-left: 300px; } }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(20, 24, 30, 0.9); color: #fff; padding: 10px 18px; border-radius: 20px; z-index: 50; font-size: 0.92rem;
}
.opt { font-size: 0.75rem; color: var(--muted); font-weight: 400; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }

/* ---------- 收藏、历史、计算书、更新提示（M3） ---------- */
.title-row { display: flex; align-items: flex-start; gap: 8px; }
.title-row h1 { flex: 1; }
.fav-btn {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font-size: 1.35rem; cursor: pointer; line-height: 1;
}
.fav-btn.on { color: #e0a100; border-color: #e0a100; }
.quick { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.quick-link { font-weight: 600; padding: 10px 0; }
.btn-row.wrap { flex-wrap: wrap; }
a.btn { display: inline-flex; align-items: center; justify-content: center; }
.btn.danger { color: var(--err); }
.hist-sum { flex-basis: 100%; }
.update-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 60;
  border: 0; border-radius: 22px; padding: 12px 20px; background: var(--primary); color: #fff; font: inherit; font-weight: 700;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); cursor: pointer;
}
.rpt-bar .ctl { width: 100%; margin: 4px 0 8px; }
.report h2 { margin-top: 18px; }
.report .rpt-title { text-align: center; }
.rpt-meta { max-width: none; margin-bottom: 8px; }
.num-cell { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.sign { display: flex; justify-content: space-between; margin-top: 28px; padding-top: 8px; }
.sign span { flex: 1; }
.rpt-foot { margin-top: 16px; }
