/* ============================================================
   投标报价测算工具 — 样式
   设计基调：专业、克制、数据密集（Navy + 中性灰 + 单色强调）
   ============================================================ */

:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #7c8798;
  --muted: #f1f3f5;
  --border: #e4e7eb;
  --border-strong: #d3d9e0;

  --primary: #1e3a5f;
  --primary-hover: #16304f;
  --secondary: #2563eb;
  --focus: #2563eb;

  --accent: #059669;
  --danger: #dc2626;
  --danger-text: #b91c1c;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --warn-text: #8a5a00;

  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #6250d6;

  --chart-grid: #e8edf3;
  --chart-axis: #c3c2b7;

  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.1);
  --font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { font-weight: 600; }
button, input, select, textarea { font-family: inherit; }

/* ---------------- Header ---------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.01em;
  line-height: 1.25;
}
.brand-text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions { display: flex; gap: 8px; flex: none; }

/* ---------------- Tabs ---------------- */

.tabs {
  position: sticky;
  top: 60px;
  z-index: 19;
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 15px 10px;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--ink); background: #f8fafc; }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -3px;
}

/* ---------------- Layout ---------------- */

main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 24px 72px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: panelIn 0.18s ease; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.panel-head { margin: 2px 0 16px; }
.panel-head h2 { margin: 0 0 3px; font-size: 18px; letter-spacing: -0.01em; }
.panel-head p { margin: 0; color: var(--ink-2); font-size: 13px; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr; }
}

/* ---------------- Card ---------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  min-width: 0;
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .sub {
  font-weight: 400;
  font-size: 11.5px;
  color: var(--ink-3);
}

.card-foot {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------------- Fields ---------------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.field-help { font-size: 11.5px; color: var(--ink-3); line-height: 1.45; }

.input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:hover:not(:disabled) { border-color: #b9c2ce; }
.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}
.input:disabled {
  background: var(--muted);
  color: var(--ink-3);
  cursor: not-allowed;
}
.input::placeholder { color: #a8b2c0; }

.textarea { height: auto; min-height: 66px; padding: 9px 10px; resize: vertical; line-height: 1.55; }

.input-unit { position: relative; display: flex; align-items: center; }
.input-unit .input { padding-right: 42px; }
.input-unit em {
  position: absolute;
  right: 10px;
  font-style: normal;
  font-size: 11.5px;
  color: var(--ink-3);
  pointer-events: none;
}

.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px 16px;
}
@media (max-width: 680px) {
  .param-grid { grid-template-columns: 1fr; }
}

.field-check { flex-direction: row; align-items: center; gap: 9px; }
.field-check input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  flex: none;
}

.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.form-row > .field { flex: 1 1 180px; }
.form-row > .field-action { flex: 0 0 auto; margin-top: 25px; margin-left: auto; }
.form-row-narrow > .field:not(.field-action) { flex: 0 1 240px; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.28); }
.btn:disabled { cursor: not-allowed; opacity: 0.6; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #1d4ed8; }

.btn-ghost { background: #fff; border-color: var(--border-strong); color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: #f8fafc; color: var(--ink); border-color: #c2cad4; }

.btn-danger-ghost { background: #fff; border-color: #f0c4c4; color: var(--danger-text); }
.btn-danger-ghost:hover:not(:disabled) { background: #fef2f2; }

.btn-lg { height: 40px; padding: 0 20px; font-size: 14px; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #fef2f2; color: var(--danger-text); }

/* ---------------- Notices ---------------- */

.notice {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.6;
  border: 1px solid;
  margin: 12px 0 0;
}
.notice strong { font-weight: 600; }
.notice-info { background: #eff6ff; border-color: #cfe0fb; color: #1e3a5f; }
.notice-warn { background: #fffbeb; border-color: #fde68a; color: #7a4d00; }
.notice-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.notice-ok { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.notice + .notice { margin-top: 8px; }

.hint { font-size: 12px; color: var(--ink-3); line-height: 1.6; margin: 9px 0 0; }
.hint strong { color: var(--ink-2); }

/* 键值网格 */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px 22px;
}
@media (max-width: 860px) {
  .kv-grid { grid-template-columns: 1fr 1fr; }
}
.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dotted #e4e7eb;
  font-size: 13px;
}
.kv span { color: var(--ink-3); }
.kv b { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }

/* ---------------- Tables ---------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.data-table th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 9px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #eef1f4;
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbfd; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

tr.is-best td { background: #f4f9ff; }
tr.is-best:hover td { background: #eef6ff; }
tr.is-best td:first-child { box-shadow: inset 3px 0 0 var(--secondary); }

.best-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--secondary);
  color: #fff;
  font-size: 10.5px;
  font-weight: 500;
  vertical-align: 1px;
}

.group-table td { padding: 6px 8px; }
.group-table th { padding: 8px; }
.group-table .input { height: 32px; font-size: 13px; }
.group-table .g-name { min-width: 108px; }
.group-table .g-prices { min-width: 190px; }
.group-table .g-num { width: 74px; }
.group-table .g-cv { width: 78px; }
.group-table .g-dist { width: 96px; }
.group-table .row-note { font-size: 11.5px; color: var(--ink-3); }

.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: #eef2f7;
  color: #475569;
  white-space: nowrap;
}
.type-badge.fixed { background: #e8f1fd; color: #1d4ed8; }
.type-badge.dist { background: #fdf0e8; color: #b45309; }
.type-badge.auto { background: #f3f0fd; color: #5b47c4; }

/* ---------------- KPI ---------------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 980px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.kpi {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 13px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.kpi-label { font-size: 12px; color: var(--ink-3); margin-bottom: 5px; }
.kpi-value {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
}
.kpi-unit { font-size: 12px; font-weight: 400; color: var(--ink-3); margin-left: 3px; }
.kpi-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; }
.kpi-sub b { color: var(--ink-2); font-weight: 600; }

.kpi.primary { border-color: #c9d8ea; background: linear-gradient(180deg, #f7fbff, #ffffff); }
.kpi.primary .kpi-value { color: var(--primary); }
.kpi.primary .kpi-label { color: #5b7a9d; }

/* ---------------- Chips & misc ---------------- */

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f7;
  font-size: 12px;
  color: #334155;
  font-variant-numeric: tabular-nums;
}
.chip b { font-weight: 600; }
.chip.bad { background: #fef2f2; color: #b91c1c; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}
.empty strong { display: block; color: var(--ink-2); font-size: 14px; margin-bottom: 4px; font-weight: 600; }

.progress { display: flex; align-items: center; gap: 10px; margin-top: 13px; }
.progress-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: #e8edf3;
  overflow: hidden;
}
.progress-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--secondary);
  transition: width 0.1s linear;
}
.progress-text { font-size: 12px; color: var(--ink-3); min-width: 92px; text-align: right; }

/* ---------------- Rule summary ---------------- */

.rule-list { display: grid; gap: 0; }
.rule-item {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 14px;
  align-items: start;
  padding: 11px 0;
  border-bottom: 1px solid #f1f4f7;
}
.rule-item:first-child { padding-top: 0; }
.rule-item:last-child { border-bottom: none; padding-bottom: 0; }
.rule-step { font-size: 12px; font-weight: 600; color: var(--primary); padding-top: 1px; }
.rule-text { font-size: 13px; color: var(--ink-2); line-height: 1.65; }
.rule-text b { color: var(--ink); font-weight: 600; }
.rule-text .formula {
  font-family: var(--mono);
  font-size: 12px;
  background: #f6f8fb;
  border: 1px solid #e8edf3;
  border-radius: 4px;
  padding: 1px 5px;
}

/* 规则图解 */
.sub-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 0 0 12px;
  letter-spacing: 0.01em;
}

.example-steps { display: flex; flex-direction: column; }
.example-step {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed #eef1f4;
}
.example-step:first-child { padding-top: 0; }
.example-step:last-child { border-bottom: none; padding-bottom: 0; }
.example-step .n {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #eef2f7;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}
.example-step .t {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.7;
  min-width: 0;
}
.example-step .t b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.example-step .t .hl {
  color: var(--secondary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.example-step .t .warn {
  color: var(--danger-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------------- Charts ---------------- */

.chart-host { position: relative; width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart-grid { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-row-sep { stroke: #f1f4f7; stroke-width: 1; }
.chart-tick { font-size: 11px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.chart-axis-title { font-size: 11.5px; fill: var(--ink-3); font-weight: 500; }
.chart-label { font-size: 12px; fill: var(--ink-2); }
.chart-label-strong { font-size: 12px; fill: var(--ink); font-weight: 600; }
.chart-value { font-size: 12px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.chart-value-strong { font-size: 12px; fill: var(--primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-flag { font-size: 10px; fill: var(--secondary); font-weight: 600; }
.chart-ref-label { font-size: 10.5px; font-weight: 500; }
.chart-marker-label { font-size: 11px; fill: var(--ink); font-weight: 600; }
.chart-band-label { font-size: 10.5px; fill: #4a6b93; }
.chart-ref-label, .chart-marker-label, .chart-band-label {
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-linejoin: round;
}
.chart-crosshair { stroke: #9aa7b8; stroke-width: 1; stroke-dasharray: 3 3; }

.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend-item i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  visibility: hidden;
  min-width: 150px;
  max-width: 260px;
  padding: 9px 11px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12);
  font-size: 12px;
}
.chart-tip.flip { transform: translateX(-100%); }
.tip-x { font-weight: 600; margin-bottom: 5px; color: var(--ink); }
.tip-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.tip-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: none; }
.tip-name { color: var(--ink-2); }
.tip-row b { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.tip-sub { color: var(--ink-3); font-size: 11px; margin-top: 4px; }

.chart-block { margin-top: 4px; }
.chart-block + .chart-block { margin-top: 18px; }
.chart-caption {
  font-size: 11.5px;
  color: var(--ink-3);
  margin: 8px 0 0;
  line-height: 1.55;
}

/* ---------------- Modal ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  max-height: 82vh;
  overflow: auto;
  background: #fff;
  border-radius: 10px;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal .modal-sub { margin: 0 0 16px; font-size: 12.5px; color: var(--ink-3); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.scenario-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.scenario-item:last-child { border-bottom: none; }
.scenario-meta { flex: 1; min-width: 0; }
.scenario-name { font-weight: 500; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; }
.scenario-date { font-size: 11.5px; color: var(--ink-3); }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  background: #1e3a5f;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Responsive ---------------- */

@media (max-width: 900px) {
  .app-header {
    position: static;
    height: auto;
    flex-wrap: wrap;
    padding: 10px 16px;
  }
  .tabs { top: 0; padding: 0 12px; }
  main { padding: 16px 14px 60px; }
  .header-actions { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .btn { height: 34px; padding: 0 11px; font-size: 13px; }
  .card { padding: 15px 14px; }
}

/* ---------------- Print ---------------- */
/* 打印样式在 styles.css 中统一处理：只打印右侧「报价计算」区域 */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
