/*
 * EtPulse · 光电启停式电磁线圈炮模拟器 — 样式表
 * Copyright (c) 2026 雨晨_Ethan (YuchenEthann)
 * License: MIT (see LICENSE file in the project root)
 */

/* ========== 全局 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #0a1628;
  color: #d0e6ff;
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
#app { max-width: 1500px; margin: 0 auto; }

/* ========== 顶部 ========== */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(0,229,160,0.2);
}
#header h1 { font-size: 20px; color: #00e5a0; text-shadow: 0 0 12px rgba(0,229,160,0.4); }
.header-right { display: flex; align-items: center; gap: 10px; }
.phase-label { font-size: 13px; color: #8ab; }
.badge { padding: 4px 14px; border-radius: 20px; font-size: 13px; font-weight: bold; }
.badge-idle { background: #334; color: #889; }
.badge-running { background: rgba(0,229,160,0.2); color: #00e5a0; }
.badge-done { background: rgba(255,170,0,0.2); color: #ffaa00; }
.badge-sm { padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: bold; }
.badge-auto { background: rgba(0,229,160,0.15); color: #00e5a0; cursor: pointer; }
.badge-manual { background: rgba(255,170,0,0.15); color: #ffaa00; cursor: pointer; }

/* ========== 主布局 ========== */
#main { display: grid; grid-template-columns: 300px 6px 1fr 6px 320px; gap: 4px; padding: 12px; }

/* ========== 参数面板 ========== */
#params-panel {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 10px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.params-section {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.section-title { font-size: 14px; font-weight: bold; color: #00e5a0; margin-bottom: 8px; }
.params-section label { display: block; font-size: 12px; color: #8ab; margin-bottom: 6px; }
.params-section .unit { color: #567; font-size: 11px; }
.params-section input[type="number"],
.params-section input[type="text"],
.params-section select {
  width: 100%; margin-top: 3px; padding: 5px 8px;
  background: #0d1f3a; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px; color: #fff; font-size: 13px; outline: none;
}
.params-section input:focus, .params-section select:focus, .params-section input[type="text"]:focus { border-color: #00e5a0; }
.params-section input.invalid { border-color: #ff4444; }
.inline-field { display: flex; align-items: center; gap: 6px; }
.inline-field input { flex: 1; }
.check-label { display: flex !important; align-items: center; gap: 6px; font-size: 12px !important; cursor: pointer; }
.check-label input { width: auto !important; margin: 0 !important; }

/* ========== 预设自定义下拉（网页风格） ========== */
.preset-select-wrap { position: relative; margin-top: 3px; }
.preset-select-wrap input[type="text"] { padding-right: 28px; }
.preset-drop-btn {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #8ab; cursor: pointer;
  font-size: 12px; padding: 4px 8px; line-height: 1;
}
.preset-drop-btn:hover { color: #00e5a0; }
.preset-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: #12213f; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,0.55);
  max-height: 220px; overflow-y: auto;
}
.preset-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; font-size: 13px; color: #cfe;
  cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.preset-item:last-child { border-bottom: none; }
.preset-item:hover, .preset-item.active { background: rgba(0,229,160,0.12); color: #00e5a0; }
.preset-item .preset-tag { font-size: 10px; color: #567; flex-shrink: 0; margin-left: 8px; }
.preset-item:hover .preset-tag, .preset-item.active .preset-tag { color: #3a8f73; }
.preset-dropdown .dropdown-empty { padding: 10px; color: #567; font-size: 12px; text-align: center; }

/* ========== 线圈表格 ========== */
.coil-globals { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.coil-globals label { flex: 1; min-width: 96px; }
.coil-table {
  width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 6px;
}
.coil-table th {
  background: rgba(0,229,160,0.1); color: #00e5a0;
  padding: 5px 4px; text-align: center; font-weight: bold;
  border: 1px solid rgba(255,255,255,0.1);
}
.coil-table td {
  padding: 3px 4px; text-align: center;
  border: 1px solid rgba(255,255,255,0.08);
}
.coil-table td.row-idx { color: #567; font-size: 11px; cursor: pointer; }
.coil-table td.row-idx:hover { color: #ffaa00; }
.coil-table input {
  width: 100%; padding: 3px 4px; text-align: center;
  background: #0d1f3a; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px; color: #fff; font-size: 12px; outline: none;
}
.coil-table input:focus { border-color: #00e5a0; }
.coil-table input.invalid { border-color: #ff4444; }
.coil-table td.ro { color: #7ab; font-size: 11px; }
.coil-table td.ro span.mark { color: #ffaa00; font-size: 10px; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.btn-add { background: rgba(0,229,160,0.12); border-color: rgba(0,229,160,0.3); color: #00e5a0; }
.btn-remove { background: rgba(255,68,68,0.12); border-color: rgba(255,68,68,0.3); color: #ff6666; }
.coil-summary { font-size: 11px; color: #678; text-align: center; flex: 1; }
.coil-opt { margin-top: 6px; }

/* ========== 按钮 ========== */
.params-actions { display: flex; gap: 6px; padding: 6px 0; flex-wrap: wrap; }
.btn {
  flex: 1; min-width: 60px; padding: 10px 8px; border: none;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: bold;
  transition: all 0.2s;
}
.btn-primary { background: #00e5a0; color: #063; }
.btn-primary:hover { box-shadow: 0 0 14px rgba(0,229,160,0.5); }
.btn-secondary { background: #1a2a4a; color: #8ab; border: 1px solid rgba(255,255,255,0.15); }
.btn-secondary:hover { background: #243a60; }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm {
  flex: 1; padding: 6px 10px; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px; background: #1a2a4a; color: #8ab;
  font-size: 12px; cursor: pointer; transition: all 0.2s;
}
.btn-sm:hover { background: #243a60; color: #fff; }
.preset-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ========== 模拟区 ========== */
#sim-panel {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 10px;
}
.sim-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sim-label { font-size: 14px; font-weight: bold; color: #00e5a0; }
.sim-info { display: flex; gap: 18px; font-size: 13px; color: #8ab; }
.sim-info b { color: #fff; }
#sim-canvas, #chart-velocity, #chart-current, #chart-energy {
  background: #0d1f3a; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; display: block; width: 100%;
}
#sim-canvas { height: 320px; margin-bottom: 8px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: #8ab; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.dot { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.dot-coil-off { background: #334; }
.dot-coil-on { background: #00ff88; box-shadow: 0 0 8px #00ff88; }
.dot-proj { background: #b0b0b0; border-radius: 50%; }
.dot-sensor { background: #ffaa00; }

/* ========== 播放控制条 / 缩放条 / 回放条（滑块） ========== */
.replay-bar { margin-top: 4px; opacity: 0.9; }
.replay-bar .pb-slider:disabled { opacity: 0.4; }
.replay-bar .pb-value { min-width: 130px; color: #8ab; }
.playback-bar, .zoom-bar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px; padding: 6px 10px;
  background: rgba(255,255,255,0.04); border-radius: 8px;
}
.pb-label { font-size: 12px; color: #678; min-width: 70px; }
.pb-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, #1a2a4a, #00e5a0);
  outline: none;
  cursor: pointer;
}
.pb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #00e5a0;
  border: 2px solid #0a1628;
  box-shadow: 0 0 8px rgba(0,229,160,0.5);
  cursor: pointer;
}
.pb-slider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #00e5a0;
  border: 2px solid #0a1628;
  box-shadow: 0 0 8px rgba(0,229,160,0.5);
  cursor: pointer;
}
.pb-slider:disabled { opacity: 0.3; cursor: not-allowed; }
.pb-slider:disabled::-webkit-slider-thumb { background: #456; box-shadow: none; }
.pb-value {
  font-size: 12px; color: #00e5a0; font-weight: bold;
  min-width: 52px; text-align: right; font-family: 'Consolas', monospace;
}
.pb-input {
  width: 72px; padding: 3px 6px;
  background: #0d1f3a; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px; color: #fff; font-size: 12px; text-align: right;
  outline: none; font-family: 'Consolas', monospace;
}
.pb-input:focus { border-color: #00e5a0; }
.pb-input:disabled { opacity: 0.3; }
.zoom-col { flex-direction: column; align-items: stretch; }
.zoom-text-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.zoom-slider-row { display: flex; align-items: center; gap: 8px; }
/* 单轨道双滑块（图表X轴窗口）：一条轨道 + 两个可拖圆点 */
.dual-range {
  position: relative; width: 100%; height: 9px; margin: 2px 0;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.06) var(--lo, 0%),
      rgba(0,229,160,0.45) var(--lo, 0%), rgba(0,229,160,0.45) var(--hi, 100%),
      rgba(255,255,255,0.06) var(--hi, 100%));
  border-radius: 6px;
}
.dual-range input[type="range"] {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  -webkit-appearance: none; appearance: none; background: transparent; margin: 0;
  pointer-events: none;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track { background: transparent; height: 100%; }
.dual-range input[type="range"]::-moz-range-track { background: transparent; height: 100%; }
.dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #00e5a0; border: 2px solid #0a1628; box-shadow: 0 0 8px rgba(0,229,160,0.5);
  cursor: pointer; margin-top: -3.5px; pointer-events: auto;
}
.dual-range input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: #00e5a0; border: 2px solid #0a1628;
  box-shadow: 0 0 8px rgba(0,229,160,0.5); cursor: pointer; pointer-events: auto;
}
.dual-range .zoom-min-input { z-index: 3; }
.dual-range .zoom-max-input { z-index: 2; }
.dual-range input[type="range"]:disabled::-webkit-slider-thumb { background: #456; box-shadow: none; }
.dual-range input[type="range"]:disabled::-moz-range-thumb { background: #456; box-shadow: none; }

/* ========== 结果区 ========== */
#result-panel {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 10px;
  max-height: calc(100vh - 100px); overflow-y: auto;
}
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.result-item {
  background: rgba(0,229,160,0.06);
  border: 1px solid rgba(0,229,160,0.15);
  border-radius: 6px; padding: 6px 8px;
  display: flex; flex-direction: column;
}
.r-label { font-size: 10px; color: #67c; }
.r-value { font-size: 17px; font-weight: bold; color: #00ff88; text-shadow: 0 0 8px rgba(0,255,136,0.4); }
.r-unit { font-size: 10px; color: #567; }
.chart-section { margin-top: 12px; }
#chart-velocity, #chart-current { height: 150px; }
#chart-energy { height: 160px; }

/* ========== 各级贡献表 ========== */
#coil-contrib { font-size: 11px; color: #8ab; }
.contrib-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.contrib-table th {
  background: rgba(255,170,0,0.1); color: #ffaa00;
  padding: 4px; text-align: center; border: 1px solid rgba(255,255,255,0.1);
}
.contrib-table td {
  padding: 3px 4px; text-align: center;
  border: 1px solid rgba(255,255,255,0.08);
}


/* ========== 分隔条（三栏拖拽） ========== */
.divider {
  width: 6px;
  cursor: col-resize;
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
  transition: background 0.15s;
  touch-action: none;
  user-select: none;
}
.divider:hover, .divider.dragging {
  background: rgba(0,229,160,0.4);
  box-shadow: 0 0 8px rgba(0,229,160,0.3);
}
#main { grid-template-columns: 300px 6px 1fr 6px 320px; }
@media (max-width: 1100px) {
  #main { grid-template-columns: 1fr; }
  .divider { display: none; }
}

/* ========== 响应式 ========== */
@media (max-width: 1100px) {
  #main { grid-template-columns: 1fr !important; }
  #params-panel, #result-panel { max-height: none; }
  .divider { display: none; }
}

/* ========== 统一滚动条（深色主题） ========== */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 4px; }
*::-webkit-scrollbar-thumb { background: rgba(0,229,160,0.35); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(0,229,160,0.55); }
* { scrollbar-width: thin; scrollbar-color: rgba(0,229,160,0.35) rgba(255,255,255,0.05); }

/* ========== 删除按钮（危险操作） ========== */
.btn-danger {
  background: rgba(255,80,80,0.14); border-color: rgba(255,80,80,0.42); color: #ff6b6b;
}
.btn-danger:hover:not(:disabled) { background: rgba(255,80,80,0.24); }
.btn-danger:disabled { opacity: 0.35; cursor: not-allowed; }

/* ========== 能量横向条状图 ========== */
.energy-bar-wrap { margin-top: 12px; }
.energy-bar { display: flex; width: 100%; height: 14px; border-radius: 7px; overflow: hidden; background: rgba(255,255,255,0.06); }
.bar-seg { height: 100%; min-width: 0; transition: width 0.25s ease; }
.seg-kin   { background: #00ff88; }
.seg-loss  { background: #ffaa00; }
.seg-resid { background: #6a7f9f; }
.energy-legend { display: flex; flex-wrap: wrap; row-gap: 6px; column-gap: 16px; margin-top: 8px; font-size: 11px; color: #8ab6d6; }
.lg-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.lg-item b { color: #fff; font-family: 'Consolas', monospace; }
.lg-dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lg-kin   { background: #00ff88; }
.lg-loss  { background: #ffaa00; }
.lg-resid { background: #6a7f9f; }
.lg-total { font-weight: bold; color: #00e5a0; }
.lg-total b { color: #00e5a0; }

/* ========== 页脚声明 ========== */
#footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px;
  padding: 12px 4px 4px; margin-top: 16px;
  font-size: 12px; color: #6a7f9f;
  border-top: 1px solid rgba(255,255,255,0.06);
}
#footer a { color: #00e5a0; text-decoration: none; }
#footer a:hover { text-decoration: underline; }