/* app.css —— 设计器界面样式（v2.1 视觉调整）
   字号整体上调一档，参照「光伏小超人」电缆工具：
   正文 14px、面板标题 15.5px、字段标签 11～12px、指标数字 24px 级。 */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--tx-base);
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px max(24px, calc((100vw - 1392px) / 2));
  background: #ffffff;
  border-bottom: 1px solid #d9e0e8;
}

.brand { display: flex; align-items: center; min-width: 0; }

.brand h1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  color: var(--green);
  white-space: nowrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink-soft);
  font-size: var(--tx-sm);
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--green); color: var(--green); background: var(--surface-sunken); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

/* ---------------- 工作区 ---------------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(344px, 418px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 20px 24px 40px;
  max-width: 1440px;
  margin: 0 auto;
}

.stack { display: grid; gap: 16px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 56px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fcfefd, var(--surface-head));
}
.panel-head h2 {
  margin: 0;
  font-size: var(--tx-lg);
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--ink);
  display: flex;
  align-items: center;
  line-height: 1.4;
}
/* 步骤序号：沿用「光伏小超人」面板标题的写法 */
.step {
  display: inline-flex;
  justify-content: flex-start;
  width: 30px;
  flex: 0 0 auto;
  font-size: var(--tx-lg);
  font-weight: 700;
  color: #2b4a5e;
  opacity: 0.62;
  font-variant-numeric: tabular-nums;
}
.panel-head .hint { font-size: var(--tx-xs); color: var(--faint); }

.panel-body { padding: 14px 16px 16px; }

/* ---------------- 电缆清单 ---------------- */
.rows { display: grid; gap: 8px; }

.row {
  display: grid;
  grid-template-columns: 3px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 9px 9px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-sunken);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  overflow: hidden;
}
.row:hover { border-color: var(--line-strong); background: #fbfdfc; }
.row.active {
  border-color: var(--green);
  background: #f6fdf9;
  box-shadow: 0 0 0 2.5px var(--green-soft);
}
.row.invalid { border-color: var(--red-line); background: var(--red-bg); }

.row-bar { width: 3px; height: 100%; min-height: 34px; border-radius: 0 2px 2px 0; }
.row-bar.pv { background: var(--green); }
.row-bar.ac { background: var(--ac); }

.row-fields {
  display: grid;
  grid-template-columns: 0.75fr 0.95fr 0.72fr 0.58fr;
  gap: 7px;
  min-width: 0;
}

.field { display: grid; gap: 3px; min-width: 0; }
.field label {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field select,
.field input {
  width: 100%;
  height: 34px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b9ca8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  padding-right: 20px;
}
.field select:hover, .field input:hover { border-color: #b6cbc0; }
.field input { font-variant-numeric: tabular-nums; text-align: right; padding-right: 9px; }
.field select:focus,
.field input:focus { border-color: var(--green); box-shadow: 0 0 0 2.5px var(--green-soft); }

.del {
  width: 26px;
  height: 26px;
  margin-right: 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.del:hover { background: var(--red-bg); color: var(--red); }

.row-actions { display: flex; gap: 8px; margin-top: 12px; }
.row-actions .btn { flex: 1; height: 34px; }

.row-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 14px;
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  font-size: var(--tx-sm);
  color: var(--muted);
  background: var(--surface-sunken);
}
.row-summary b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------- 参数 ---------------- */
.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.param { display: grid; gap: 5px; }
.param > label { font-size: var(--tx-sm); color: var(--muted); font-weight: 700; }
.param .unit { color: var(--faint); font-size: var(--tx-xs); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input {
  width: 100%;
  height: 40px;
  padding: 0 32px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: var(--tx-md);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-wrap input:focus { border-color: var(--green); box-shadow: 0 0 0 2.5px var(--green-soft); }
.input-wrap .suffix {
  position: absolute;
  right: 10px;
  font-size: var(--tx-sm);
  color: var(--faint);
  pointer-events: none;
}

.param select {
  width: 100%;
  height: 40px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b9ca8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.param select:focus { border-color: var(--green); box-shadow: 0 0 0 2.5px var(--green-soft); }

.param-note {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--green-soft);
  border: 1px solid var(--green-line);
  font-size: var(--tx-sm);
  line-height: 1.78;
  color: #38604f;
}
.param-note b { color: #1e4d3b; }
.param-note code {
  font-family: var(--mono);
  font-size: 12px;
  background: #fff;
  border-radius: 3px;
  padding: 0 4px;
  color: var(--green-deep);
}

/* ---------------- 画布 ---------------- */
.canvas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 18px 10px 15px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fcfefd, var(--surface-head));
  flex-wrap: wrap;
}
.head-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex-wrap: wrap; }
.canvas-title {
  display: flex;
  align-items: center;
  margin: 0;
  font-size: var(--tx-lg);
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--ink);
  line-height: 1.4;
  white-space: nowrap;
}
.canvas-title .step { width: 26px; }

.spec-tag {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 13px;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 3px 10px -6px rgba(11, 99, 73, 0.9);
}
.spec-tag small { font-size: var(--tx-xs); font-weight: 400; opacity: 0.85; letter-spacing: 0; }
.spec-tag.muted { background: var(--line-strong); color: var(--ink-soft); box-shadow: none; }
.spec-tag.fail { background: var(--red); box-shadow: 0 3px 10px -6px rgba(187, 58, 49, 0.9); }

.canvas-stage { position: relative; }

.canvas-wrap {
  position: relative;
  height: var(--canvas-h, clamp(300px, 38vh, 440px));
  background:
    linear-gradient(90deg, rgba(16, 122, 87, 0.032) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(0deg, rgba(16, 122, 87, 0.032) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--surface);
  overflow: hidden;
}

.canvas-wrap svg { display: block; width: 100%; height: 100%; user-select: none; }
.canvas-wrap .cbl { cursor: pointer; }

.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 7px;
  text-align: center;
  color: var(--faint);
  font-size: var(--tx-sm);
  pointer-events: none;
}
.canvas-empty b { color: var(--muted); font-size: var(--tx-md); font-weight: 700; }

/* SVG 内部元素 */
.tray-outline { fill: none; stroke: var(--ink); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.tray-fill { fill: #fcfdfc; }
.tray-over {
  fill: url(#hatch);
  stroke: none;
}
.over-line { stroke: var(--red); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }

.layer-line { stroke: #d7e5dd; stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.layer-label {
  fill: var(--faint);
  font-size: var(--fs-sm);
  font-family: var(--mono);
}

.band-divider { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 5; vector-effect: non-scaling-stroke; }

.cbl {
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: opacity 0.16s, stroke-width 0.12s;
}
.cbl.pv { fill: var(--green-soft); stroke: var(--green); }
.cbl.ac { fill: var(--ac-soft); stroke: var(--ac); }

.canvas-wrap[data-focus] .cbl { opacity: 0.2; }
.canvas-wrap[data-focus="hover"] .cbl.hot { opacity: 1; }
.canvas-wrap[data-focus="row"] .cbl.hot { opacity: 1; stroke-width: 2; }

.dim {
  stroke: var(--muted);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.dim-text {
  fill: var(--muted);
  font-size: var(--fs);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.dim-text.strong { fill: var(--ink-soft); font-weight: 700; }
.dim-text.over { fill: var(--red); font-weight: 700; }

/* tooltip */
.tip {
  position: absolute;
  z-index: 5;
  min-width: 130px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(21, 51, 77, 0.95);
  color: #fff;
  font-size: 12px;
  line-height: 1.62;
  pointer-events: none;
  box-shadow: 0 8px 22px -10px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.12s;
  white-space: nowrap;
}
.tip.show { opacity: 1; }
.tip b { color: #8fe0bd; font-variant-numeric: tabular-nums; }
.tip .k { color: #a9bcc8; }

/* ---------------- 结果指标 ---------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #fcfefd, #ffffff);
}
.metric { padding: 13px 16px 14px; min-width: 0; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric .k {
  font-size: var(--tx-xs);
  color: var(--faint);
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric .v {
  margin-top: 4px;
  font-size: clamp(22px, 1.75vw, 29px);
  font-weight: 700;
  line-height: 1.22;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.metric .v.hl { color: var(--green-deep); }
.metric .v small {
  font-size: var(--tx-xs);
  font-weight: 400;
  color: var(--faint);
  margin-left: 3px;
  letter-spacing: 0;
}
.metric .v .fallback { font-size: var(--tx-md); font-weight: 700; }
.metric .v.warn { color: var(--amber); }
.metric .v.fail { color: var(--red); }
.metric .sub {
  margin-top: 3px;
  font-size: var(--tx-xs);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track { position: relative; height: 5px; margin-top: 9px; border-radius: 3px; background: #e9f0eb; overflow: hidden; }
.track i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--green); transition: width 0.25s; }
.track i.warn { background: #d5a43a; }
.track i.fail { background: #d36b5f; }
.track .limit { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(95, 116, 132, 0.55); }

/* ---------------- 提示 ---------------- */
.alerts { display: grid; gap: 8px; padding: 12px 16px 0; }
/* 无告警时不占高度，避免右栏下方多出一条空白 */
.alerts:empty { display: none; }
.alert {
  display: grid;
  grid-template-columns: 17px 1fr;
  gap: 9px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid;
  font-size: var(--tx-sm);
  line-height: 1.72;
}
.alert .ico { font-weight: 800; line-height: 1.55; text-align: center; }
.alert .msg b { font-weight: 700; }
.alert .detail { margin-top: 2px; opacity: 0.88; font-size: var(--tx-xs); }
.alert.warn { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber); }
.alert.error { background: var(--red-bg); border-color: var(--red-line); color: var(--red); }
.alert.info { background: var(--green-soft); border-color: var(--green-line); color: #38604f; }

/* ---------------- 比选表 ---------------- */
.table-wrap { padding: 13px 16px 16px; }

table.cmp {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--tx-sm);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.cmp th, .cmp td {
  padding: 7px 8px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.cmp th {
  background: #edf6f0;
  color: #47695b;
  font-size: var(--tx-xs);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}
.cmp th:first-child, .cmp td:first-child { text-align: left; white-space: nowrap; }
.cmp td:first-child { font-weight: 700; color: var(--ink); }
.cmp tbody tr:last-child td { border-bottom: 0; }
.cmp tbody tr:hover td { background: #fbfdfc; }
.cmp tbody tr.pick td { background: #f2faf6; font-weight: 700; }
.cmp tbody tr.pick:hover td { background: #f2faf6; }
.cmp tbody tr.pick td:first-child { box-shadow: inset 3px 0 0 var(--green); color: var(--green-deep); }
.cmp td.miss { color: var(--faint); }
.cmp .no { color: var(--red); font-weight: 700; }
.cmp .yes { color: var(--green); font-weight: 700; }
.cmp .amber { color: var(--amber); font-weight: 700; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: var(--tx-xs);
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}
.legend .pv { background: var(--green-soft); border: 1px solid var(--green); }
.legend .ac { background: var(--ac-soft); border: 1px solid var(--ac); }

/* ---------------- 脚注 ---------------- */
.footnote {
  padding: 0 16px 16px;
  font-size: var(--tx-xs);
  line-height: 1.85;
  color: var(--faint);
}
.footnote code { font-family: var(--mono); color: var(--muted); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .canvas-wrap { height: clamp(300px, 36vh, 400px); }
  .metric .v { font-size: 26px; }
}

@media (max-width: 860px) {
  .topbar { height: auto; padding: 10px 16px; flex-wrap: wrap; row-gap: 10px; }
  .brand h1 { font-size: 18px; }
  .workspace { padding: 14px 14px 34px; gap: 14px; }
}

@media (max-width: 720px) {
  .row-fields { grid-template-columns: 1fr 1fr; row-gap: 7px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric { padding: 12px 14px 13px; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(1), .metric:nth-child(2) { border-bottom: 1px solid var(--line); }
  .metric .v { font-size: 21px; }
  .param-grid { grid-template-columns: 1fr; }
  .cmp th, .cmp td { padding: 6px 5px; }
  .cmp th { font-size: 10.5px; }
  .cmp { font-size: 11.5px; }
  .topbar-actions .btn { padding: 0 10px; font-size: var(--tx-xs); }
}

@media (max-width: 420px) {
  .brand h1 { font-size: 17px; }
  .canvas-head { padding: 9px 12px; }
  .spec-tag { font-size: 13.5px; padding: 4px 10px; }
}
