:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #182033;
  --muted: #667085;
  --line: #d8dee8;
  --grid: #edf1f6;
  --blue: #1267b8;
  --orange: #e36d24;
  --green: #128763;
  --red: #c13f39;
  --purple: #6d5bd0;
  --shadow: 0 10px 28px rgba(24, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
.file-btn {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
.file-btn:hover {
  border-color: #aeb8c8;
}

button.active,
button.primary {
  border-color: #0c579d;
  background: var(--blue);
  color: #fff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 250, 0.94);
  backdrop-filter: blur(10px);
}

.brand {
  min-width: 250px;
}

.brand h1 {
  margin: 0 0 4px;
  font-size: 21px;
  line-height: 1.2;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.path-input,
.search {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.path-input {
  width: min(420px, 34vw);
}

.app {
  display: grid;
  grid-template-columns: 310px minmax(620px, 1fr) 360px;
  gap: 14px;
  padding: 14px;
}

.sidebar,
.rightbar {
  position: sticky;
  top: 90px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.workspace {
  min-width: 0;
}

.panel,
.measurebar,
.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0;
  padding: 12px 13px;
  border-bottom: 1px solid var(--grid);
  font-size: 14px;
  line-height: 1.2;
}

.status {
  padding: 12px 13px 14px;
  color: var(--muted);
  line-height: 1.45;
}

.search {
  width: calc(100% - 24px);
  margin: 12px;
}

.selector-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 0 12px 10px;
}

.selector-actions select {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 8px;
}

.variable-list {
  max-height: 440px;
  overflow: auto;
  padding: 0 8px 10px;
}

.formula-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.formula-box input,
.formula-box textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.formula-box textarea {
  min-height: 72px;
  resize: vertical;
  line-height: 1.4;
}

.formula-actions {
  display: flex;
  justify-content: flex-end;
}

.formula-help,
.formula-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.formula-status.error {
  color: var(--red);
}

.formula-status.ok {
  color: var(--green);
}

.type-block {
  border-top: 1px solid var(--grid);
}

.type-title {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px;
  border: 0;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.type-title:hover {
  color: var(--text);
}

.type-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.type-chevron {
  width: 12px;
  color: var(--blue);
  font-size: 15px;
  line-height: 1;
}

.type-vars.collapsed {
  display: none;
}

.var-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 30px;
  padding: 4px;
  border-radius: 5px;
}

.var-row:hover {
  background: #f3f6fa;
}

.var-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.var-meta {
  color: var(--muted);
  font-size: 11px;
}

.var-row button {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
}

.measurebar {
  position: sticky;
  top: 90px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 10px 12px;
}

.cursor-controls {
  display: flex;
  gap: 8px;
}

.measure-summary {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.delta-time {
  color: var(--red);
  font-weight: 700;
}

.charts {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.chart-card {
  overflow: hidden;
}

.chart-card.collapsed canvas {
  display: none;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--grid);
}

.chart-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.chart-title strong {
  white-space: nowrap;
}

.chart-title span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 260px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 11px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.swatch {
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
}

.small-btn {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

canvas {
  display: block;
  width: 100%;
  height: 210px;
  cursor: crosshair;
}

.group-editor {
  padding: 10px;
}

.group-cache-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px 10px 0;
}

.group-cache-actions button {
  height: 30px;
  font-size: 12px;
}

.group-row {
  border-bottom: 1px solid var(--grid);
  padding: 9px 0;
}

.group-row:last-child {
  border-bottom: 0;
}

.group-row header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
}

.group-row input {
  min-width: 0;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  font-size: 12px;
}

.chip button {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  color: var(--muted);
}

.measure-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.measure-table th,
.measure-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--grid);
  text-align: right;
  white-space: nowrap;
}

.measure-table th:first-child,
.measure-table td:first-child {
  text-align: left;
}

.measure-table thead th {
  color: var(--muted);
  font-weight: 700;
}

.param-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 6px 0;
}

.param {
  min-width: 0;
  padding: 7px 10px;
  border-bottom: 1px solid var(--grid);
  font-size: 12px;
}

.param b {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.param span {
  color: var(--ink);
}

@media (max-width: 1180px) {
  .app {
    grid-template-columns: 280px minmax(520px, 1fr);
  }

  .rightbar {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }
}

@media (max-width: 860px) {
  .topbar,
  .app {
    display: block;
  }

  .actions,
  .sidebar,
  .rightbar {
    margin-top: 12px;
  }

  .path-input {
    width: 100%;
  }

  .sidebar,
  .rightbar,
  .measurebar {
    position: static;
    max-height: none;
  }
}
