:root {
  --bg: #081229;
  --bg-2: #0d1b3a;
  --panel: rgba(11, 30, 61, 0.86);
  --line: rgba(131, 161, 233, 0.34);
  --text: #e8efff;
  --dim: #9fb2d8;
  --accent: #4fd1c5;
  --accent-2: #60a5fa;
  --warn: #fca5a5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(900px 600px at -5% -20%, rgba(96, 165, 250, 0.2), transparent 55%),
    radial-gradient(700px 500px at 110% -10%, rgba(79, 209, 197, 0.2), transparent 55%),
    linear-gradient(135deg, var(--bg), #0a1734 42%, #101c3a 100%);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
  background: rgba(7, 18, 39, 0.72);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 12px;
}

.controls {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 20, 45, 0.68);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
}

.label-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: #d6e6ff;
  font-size: 13px;
}

.label-check input {
  accent-color: var(--accent);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--dim);
}

button,
select,
input[type="number"],
input[type="text"],
textarea {
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(17, 35, 70, 0.9);
  color: var(--text);
  padding: 0 10px;
}

textarea {
  height: auto;
  padding: 8px 10px;
  resize: vertical;
  min-height: 72px;
  font: inherit;
}

button {
  cursor: pointer;
  font-weight: 600;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  color: #081229;
  border: none;
}

button:hover {
  filter: brightness(1.06);
}

.ghost-btn {
  background: rgba(96, 165, 250, 0.16);
  color: #cfe2ff;
  border: 1px solid rgba(96, 165, 250, 0.4);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-name {
  font-size: 12px;
  color: var(--dim);
}

.field-panel {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(11, 30, 61, 0.55);
  padding: 8px;
}

.field-panel.compact > summary {
  cursor: pointer;
  color: #cfe2ff;
  font-size: 12px;
  font-weight: 600;
}

.field-panel.compact:not([open]) {
  padding-bottom: 6px;
}

.field-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  margin-bottom: 8px;
}

.field-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
  max-height: 130px;
  overflow: auto;
  padding-right: 4px;
}

.field-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #d9e6ff;
  border: 1px solid rgba(131, 161, 233, 0.22);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(8, 20, 45, 0.7);
}

.field-item input {
  accent-color: var(--accent);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
}

.status {
  color: var(--dim);
}

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

.summary {
  color: #bfe4ff;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 12px;
  padding: 12px;
  height: max(calc(100vh - 240px), 900px);
  min-height: 900px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  min-height: 0;
}

.chart-panel {
  padding: 10px;
  display: grid;
  grid-template-rows: minmax(320px, 1fr) 260px 240px;
  gap: 10px;
}

.main-chart-wrap,
.osc-chart-wrap,
.resp-chart-wrap {
  min-height: 0;
}

#mainChart,
#oscChart,
#responseChart {
  width: 100%;
  height: 100%;
}

.osc-chart-wrap,
.resp-chart-wrap {
  border-top: 1px dashed rgba(131, 161, 233, 0.28);
  padding-top: 8px;
}

.osc-chart-title {
  font-size: 12px;
  color: #c5d8ff;
  margin-bottom: 6px;
}

.stats-panel {
  padding: 12px;
  overflow: auto;
}

.stats-panel h2 {
  margin: 2px 0 10px;
  font-size: 16px;
}

.oscillation-wrap {
  margin-top: 14px;
  border: 1px solid rgba(131, 161, 233, 0.25);
  border-radius: 10px;
  padding: 10px;
  background: rgba(10, 24, 49, 0.72);
}

.oscillation-wrap h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #c0d8ff;
}

.ai-wrap {
  margin-top: 14px;
  border: 1px solid rgba(131, 161, 233, 0.25);
  border-radius: 10px;
  padding: 10px;
  background: rgba(10, 24, 49, 0.72);
  display: grid;
  gap: 8px;
}

.ai-wrap h3 {
  margin: 0;
  font-size: 13px;
  color: #c0d8ff;
}

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

.ai-status {
  font-size: 12px;
  color: #d6e6ff;
}

.ai-status.error {
  color: #fca5a5;
}

.ai-queue-meta {
  font-size: 12px;
  color: #a7bee8;
}

.ai-result {
  margin: 0;
  border: 1px dashed rgba(131, 161, 233, 0.28);
  border-radius: 8px;
  background: rgba(8, 20, 45, 0.7);
  padding: 8px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.6;
}

.ai-result h1,
.ai-result h2,
.ai-result h3,
.ai-result h4 {
  margin: 8px 0 6px;
  color: #dbe9ff;
  line-height: 1.4;
}

.ai-result h1 { font-size: 16px; }
.ai-result h2 { font-size: 14px; }
.ai-result h3,
.ai-result h4 { font-size: 13px; }

.ai-result p {
  margin: 0 0 8px;
}

.ai-result ul,
.ai-result ol {
  margin: 0 0 8px 18px;
  padding: 0;
}

.ai-result li {
  margin: 2px 0;
}

.ai-result code {
  font-family: "Consolas", "Monaco", monospace;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 6px;
  background: rgba(96, 165, 250, 0.16);
  color: #d5e7ff;
}

.ai-result pre {
  margin: 8px 0;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(131, 161, 233, 0.3);
  background: rgba(6, 15, 33, 0.85);
  overflow: auto;
}

.ai-result pre code {
  background: transparent;
  padding: 0;
}

.ai-result table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.ai-result th,
.ai-result td {
  border: 1px dashed rgba(131, 161, 233, 0.28);
  padding: 4px 6px;
  text-align: left;
}

.ai-result a {
  color: #8bc8ff;
}

.ai-history-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ai-history-limit-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #b9d3ff;
  font-size: 12px;
}

#aiHistoryLimitInput {
  width: 64px;
  padding: 4px 6px;
}

.ai-history-list {
  border: 1px dashed rgba(131, 161, 233, 0.28);
  border-radius: 8px;
  background: rgba(8, 20, 45, 0.65);
  max-height: 240px;
  overflow: auto;
  display: grid;
  gap: 6px;
  padding: 8px;
}

.ai-history-item {
  border: 1px solid rgba(131, 161, 233, 0.24);
  border-radius: 8px;
  padding: 7px;
  background: rgba(10, 24, 49, 0.82);
  display: grid;
  gap: 6px;
}

.ai-history-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #d7e7ff;
}

.ai-history-title .meta {
  color: #a3bfec;
}

.ai-history-question {
  font-size: 12px;
  color: #b5d2ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-history-actions {
  display: flex;
  gap: 8px;
}

.ai-history-actions button {
  padding: 4px 8px;
  font-size: 12px;
}

.oscillation-stats {
  display: grid;
  gap: 8px;
}

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

.osc-item {
  border: 1px solid rgba(131, 161, 233, 0.2);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(8, 20, 45, 0.7);
  font-size: 12px;
}

.osc-item b {
  color: #9bd8ff;
}

.osc-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.osc-mini-table th,
.osc-mini-table td {
  padding: 4px 6px;
  border-bottom: 1px dashed rgba(131, 161, 233, 0.22);
  text-align: left;
}

.osc-mini-table th {
  color: #bfe4ff;
}

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

thead th {
  text-align: left;
  color: #c0d8ff;
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
}

tbody td {
  padding: 6px 4px;
  border-bottom: 1px dashed rgba(131, 161, 233, 0.2);
}

.empty {
  color: var(--dim);
  text-align: center;
}

.tips {
  margin-top: 14px;
  padding: 10px;
  border: 1px dashed rgba(131, 161, 233, 0.35);
  border-radius: 10px;
  color: var(--dim);
}

.tips h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #c0d8ff;
}

.tips ul {
  margin: 0;
  padding-left: 16px;
  line-height: 1.6;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .chart-panel {
    min-height: 760px;
  }

  .control-row.grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

/* ════════════════════════════════════════════════════════════
   3D 车辆姿态回放
   ════════════════════════════════════════════════════════════ */
.replay3d-wrap {
  padding: 12px;
  padding-top: 0;
}

.replay3d-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  overflow: hidden;
}

/* 标题栏 */
.replay3d-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 20, 50, 0.6);
}

.replay3d-title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.replay3d-title-row h2 {
  margin: 0;
  font-size: 16px;
  white-space: nowrap;
}

.replay3d-hint {
  font-size: 12px;
  color: var(--dim);
}

.replay3d-cam-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.replay3d-cam-btns .ghost-btn {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.r3d-cam-active {
  background: rgba(79, 209, 197, 0.22) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* 3D 视窗 */
.replay3d-viewport {
  position: relative;
  width: 100%;
  background: #0d1526;
  line-height: 0;
}

#replay3dCanvas {
  display: block;
  width: 100%;
  min-height: 500px;
}

/* HUD 覆盖层 */
.replay3d-hud {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(8, 18, 42, 0.78);
  border: 1px solid rgba(131, 161, 233, 0.3);
  border-radius: 10px;
  padding: 8px 12px;
  backdrop-filter: blur(4px);
  pointer-events: none;
  min-width: 280px;
  max-width: min(64vw, 560px);
  z-index: 3;
}

.r3d-hud-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  margin-bottom: 6px;
}

.r3d-hud-item {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.r3d-hud-label {
  font-size: 11px;
  color: #8ab0d8;
  white-space: nowrap;
}

.r3d-hud-val {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #69f0ae;
  min-width: 44px;
  text-align: right;
  transition: color 0.3s;
}

.r3d-hud-unit {
  font-size: 11px;
  color: #6a88b0;
}

.r3d-hud-time {
  font-size: 11px;
  color: #8ab0d8;
  border-top: 1px dashed rgba(131, 161, 233, 0.22);
  padding-top: 5px;
  margin-top: 2px;
}

/* 图例 */
.replay3d-legend {
  position: absolute;
  bottom: 78px;
  left: 10px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  pointer-events: none;
  z-index: 2;
}

.r3d-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #9ab8d8;
  background: rgba(8, 18, 42, 0.65);
  padding: 3px 7px;
  border-radius: 6px;
}

.r3d-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.r3d-dot.green  { background: #00e676; }
.r3d-dot.yellow { background: #ffd740; }
.r3d-dot.orange { background: #ff8a65; }
.r3d-dot.blue   { background: #1e88e5; }
.r3d-dot.white  { background: #ffffff; }
.r3d-dot.gold   { background: #ffd740; box-shadow: 0 0 3px #ffd740; }
.r3d-dot.cyan   { background: #00e5ff; }

.r3d-amp-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #c0d8ff;
  flex-shrink: 0;
}

/* 时间轴 */
.replay3d-timeline {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid rgba(131, 161, 233, 0.32);
  border-radius: 10px;
  background: rgba(8, 18, 42, 0.78);
  backdrop-filter: blur(4px);
  z-index: 3;
}

.r3d-play-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 14px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #081229;
  border: none;
}

.r3d-slider {
  flex: 1;
  min-width: 120px;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
}

.r3d-speed-select {
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
  width: auto;
  flex-shrink: 0;
}

.replay3d-timeline button[id="r3d-loadBtn"] {
  height: 30px;
  padding: 0 14px;
  font-size: 12px;
  flex-shrink: 0;
}

.replay3d-status {
  font-size: 11px;
  color: var(--dim);
  flex: 1;
  min-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 响应式 */
@media (max-width: 860px) {
  .replay3d-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .replay3d-hud {
    top: 6px;
    right: 6px;
    left: auto;
    min-width: 0;
    max-width: calc(100% - 12px);
  }

  .r3d-hud-grid {
    gap: 10px 14px;
  }

  .replay3d-legend {
    bottom: 106px;
    left: 6px;
    right: 6px;
    gap: 8px;
  }

  .replay3d-timeline {
    left: 6px;
    right: 6px;
    bottom: 6px;
    gap: 8px;
    padding: 8px;
  }

  .replay3d-status {
    min-width: 120px;
  }
}

