:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d9e1e8;
  --text: #1f2a33;
  --muted: #66788a;
  --accent: #0f7b8c;
  --accent2: #d9772b;
  --green: #2f8f5b;
  --red: #c0392b;
  --sidebar: #1e2a32;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, select, input {
  font: inherit;
}
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--sidebar);
  color: #e9eef2;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: 0; }
.brand-sub { color: #9fb0bd; margin: 4px 0 22px; font-size: 13px; }
.nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #c7d2da;
  padding: 10px 12px;
  margin: 4px 0;
  border-radius: 6px;
  cursor: pointer;
}
.nav-btn:hover { background: #2a3943; }
.nav-btn.active { background: var(--accent); color: #fff; }
.content { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.topbar h1 { font-size: 24px; margin: 0; }
.status-pill {
  background: #e8f3ef;
  color: var(--green);
  border: 1px solid #b9ddca;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.view { display: none; }
.view.active { display: block; }
h2 { margin: 0 0 14px; font-size: 20px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.card .num { font-size: 28px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar select, .toolbar input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fff;
  min-height: 36px;
}
.toolbar input { min-width: 260px; }
.toolbar button {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.calc-item { background: #f7fafc; border: 1px solid #e1e9ef; border-radius: 6px; padding: 10px; }
.calc-item .k { color: var(--muted); font-size: 12px; }
.calc-item .v { font-size: 18px; font-weight: 700; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
.chart-box { width: 100%; min-height: 340px; }
.chart-box svg { width: 100%; height: auto; }
.combined-chart { min-height: 620px; }
.curve-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 13px;
}
.curve-legend span { display: inline-flex; align-items: center; gap: 6px; }
.curve-legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }
.curve-label { stroke: #fff; stroke-width: 4px; paint-order: stroke; }
.mp-form-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }
.mp-form-legend span { display: inline-flex; align-items: center; gap: 6px; }
.mp-form-legend i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.mp-section-title { font-size: 14px; font-weight: 700; margin: 16px 0 8px; }
.mp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.mp-field {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fbfcfd;
}
.mp-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.mp-field input, .mp-field output {
  width: 100%;
  border: 1px solid #d5dee5;
  border-radius: 5px;
  padding: 6px 8px;
  font-size: 14px;
  min-height: 34px;
  box-sizing: border-box;
}
.mp-field input { background: #fffdf2; border-color: #e8cf6e; }
.mp-field output { background: #f7fafc; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-field.mp-alert input, .mp-field.mp-alert output { background: #fdecea; border-color: var(--red); color: var(--red); }
.mp-actions { margin-top: 14px; display: flex; gap: 10px; }
.mp-actions button { border: 0; border-radius: 6px; padding: 8px 16px; cursor: pointer; }
#mp-recalc { background: var(--accent); color: #fff; }
#mp-reset { background: #eef2f5; color: var(--text); }
.bp-count-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.bp-count-bar label { font-size: 12px; color: var(--muted); }
.bp-count-bar input {
  width: 100px;
  border: 1px solid #e8cf6e;
  border-radius: 5px;
  padding: 7px 8px;
  background: #fffdf2;
  font-size: 14px;
}
.bp-count-bar #bp-apply-count {
  border: 0;
  border-radius: 6px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.ci-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.ci-toolbar label { font-size: 12px; color: var(--muted); }
.ci-toolbar input {
  width: 110px;
  border: 1px solid #e8cf6e;
  border-radius: 5px;
  padding: 7px 8px;
  background: #fffdf2;
  font-size: 14px;
}
.ci-toolbar button {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.ci-toolbar button:nth-child(n+6) { background: #44525d; }
.ci-toolbar #ci-status { margin-left: auto; color: var(--muted); font-size: 12px; }
.ci-table-wrap { max-height: 560px; }
.ci-bottom-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.ci-bottom-actions button {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.ci-bottom-actions #ci-remove-row { background: #c0392b; }
.ci-bottom-actions #ci-restore { background: #44525d; }
#coordinates-input-table th { min-width: 96px; }
#coordinates-input-table td { min-width: 96px; }
#coordinates-input-table input {
  width: 120px;
  border: 1px solid #e8cf6e;
  border-radius: 4px;
  padding: 5px 6px;
  background: #fffdf2;
  font-size: 12px;
  box-sizing: border-box;
}
#coordinates-input-table .ci-out { font-variant-numeric: tabular-nums; }
.booster-matrix-wrap { max-height: 640px; }
.booster-matrix-table { border-collapse: separate; border-spacing: 0; min-width: max-content; }
.booster-matrix-table th, .booster-matrix-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  white-space: nowrap;
  text-align: left;
  background: #fff;
}
.booster-matrix-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef3f7;
}
.booster-matrix-table td.mp-field,
.booster-matrix-table td.mp-alert {
  border: 0;
  padding: 0;
  background: transparent;
}
.booster-matrix-table .mp-field input,
.booster-matrix-table .mp-field output {
  width: 110px;
  min-width: 110px;
  box-sizing: border-box;
}
.booster-matrix-table select {
  width: 170px;
  max-width: 220px;
  padding: 6px 8px;
  border: 1px solid #d5dee5;
  border-radius: 5px;
  background: #fff;
  font-size: 12px;
}
.hdg-formula {
  margin-bottom: 8px;
  color: var(--accent);
  font-weight: 600;
}
.curve-import-success {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 6px;
  background: #e8f3ef;
  color: var(--green);
}
.curve-import-error {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 6px;
  background: #fdecea;
  color: var(--red);
}
.curve-import-error ul { margin: 8px 0 0; padding-left: 20px; }
#curve-import-file { max-width: 320px; }
.table-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.pager { display: flex; gap: 8px; align-items: center; }
.pager button { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.table-wrap { overflow: auto; max-height: 620px; border: 1px solid var(--border); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { border-bottom: 1px solid #e8edf2; padding: 6px 8px; text-align: left; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
th { background: #eef3f7; position: sticky; top: 0; }
.muted { color: var(--muted); }

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .brand, .brand-sub { margin-right: 10px; }
  .nav-btn { width: auto; }
  .chart-grid { grid-template-columns: 1fr; }
}
