:root {
  --bg: #0f1419;
  --bg2: #161d26;
  --bg3: #1e2836;
  --border: #2a3646;
  --text: #d4dee8;
  --text-dim: #7a8ba0;
  --accent: #4a9eff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
#app { display: flex; height: 100vh; }

/* 侧栏 */
#sidebar { width: 260px; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px; }
#sidebar h1 { font-size: 18px; margin-bottom: 16px; color: var(--accent); }
.banner { background: #3b2f1e; border: 1px solid var(--yellow); color: var(--yellow); font-size: 12px; padding: 9px; border-radius: 6px; margin-bottom: 12px; line-height: 1.7; }
.banner a { color: var(--accent); font-weight: bold; }
.new-project { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.new-project input, .new-project select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg3); color: var(--text); font-size: 12px; }
#btn-create-project { padding: 8px; background: var(--accent); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; }
#btn-create-project:hover { filter: brightness(1.15); }
#project-list { flex: 1; overflow-y: auto; list-style: none; }
#project-list li { padding: 10px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
#project-list li:hover { background: var(--bg3); }
#project-list li.active { background: var(--bg3); border-left: 3px solid var(--accent); }
#project-list .proj-name { font-size: 13px; }
#project-list .proj-state { font-size: 10px; padding: 2px 7px; border-radius: 10px; }
.state-idle { background: var(--bg); color: var(--text-dim); }
.state-running, .state-queued { background: #2d3b2d; color: var(--green); }
.state-compiled { background: #1e3a5f; color: var(--accent); }
.state-uploaded { background: #2d3b2d; color: var(--green); }
.state-failed, .state-aborted { background: #3b2d2d; color: var(--red); }
.sidebar-footer { padding-top: 10px; border-top: 1px solid var(--border); }

/* 主区 */
#main, #empty-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#empty-main { align-items: center; justify-content: center; }
.empty { color: var(--text-dim); font-size: 15px; }
#project-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--bg2); }
#project-title { font-size: 17px; }
#project-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
#project-state-badge { font-size: 12px; padding: 5px 14px; border-radius: 14px; }

/* tab */
#tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--bg2); border-bottom: 1px solid var(--border); }
#tabs button { background: none; border: none; color: var(--text-dim); padding: 10px 16px; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; }
#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; flex: 1; overflow-y: auto; padding: 16px 20px; }
.tab-panel.active { display: block; }

/* 卡片 */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 14px; margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

/* 上传 */
#drop-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 24px; text-align: center; color: var(--text-dim); cursor: pointer; font-size: 13px; }
#drop-zone.dragover { border-color: var(--accent); color: var(--accent); }
.file-label { color: var(--accent); cursor: pointer; }
.file-label input { display: none; }
#reference-files { margin-top: 8px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
#reference-files .file-chip { background: var(--bg3); padding: 3px 10px; border-radius: 10px; }
#upload-status { font-size: 12px; margin-top: 8px; color: var(--yellow); }

/* 运行控制 */
#prompt-input { width: 100%; background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 10px; font-size: 13px; resize: vertical; font-family: inherit; }
.run-controls { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.run-controls select { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 7px; font-size: 12px; }
.check { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }
button { font-size: 13px; padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; }
button.danger { background: var(--red); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* 时间线 */
#timeline { display: flex; flex-direction: column; gap: 2px; }
.stage-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--bg2); border-radius: 8px; }
.stage-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.stage-dot.start { background: var(--yellow); animation: pulse 1.2s infinite; }
.stage-dot.ok { background: var(--green); }
.stage-dot.fail { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.4; } }
.stage-name { font-size: 14px; width: 130px; }
.stage-detail { font-size: 12px; color: var(--text-dim); flex: 1; }
.stage-time { font-size: 12px; color: var(--text-dim); }

/* 日志 */
.log-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.log-tabs button { background: var(--bg3); color: var(--text-dim); font-size: 12px; padding: 6px 14px; }
.log-tabs button.active { color: var(--accent); border: 1px solid var(--accent); }
.log-view, .serial-view, .code-view { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; line-height: 1.7; white-space: pre-wrap; word-break: break-all; overflow-y: auto; }
.log-view { height: calc(100vh - 260px); }
.code-view { height: calc(100vh - 220px); }
#code-header { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.auto-scroll { margin-top: 8px; }

/* 串口 */
.serial-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.serial-controls select { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 7px; font-size: 12px; }
#serial-status { font-size: 12px; color: var(--text-dim); }
.serial-view { height: calc(100vh - 330px); }
.serial-send { display: flex; gap: 8px; margin-top: 10px; }
.serial-send input { flex: 1; background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 9px; font-size: 13px; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal[hidden] { display: none; }
.modal-body { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 24px; width: 560px; max-height: 85vh; overflow-y: auto; }
.modal-body h3 { margin-bottom: 14px; }
.modal-body h4 { margin: 16px 0 10px; font-size: 13px; }
.board-form { display: flex; flex-direction: column; gap: 7px; }
.board-form input, .board-form textarea { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: 12px; font-family: inherit; }
.board-item { display: flex; justify-content: space-between; align-items: center; padding: 9px; background: var(--bg3); border-radius: 6px; margin-bottom: 6px; font-size: 13px; }
.board-item button { padding: 4px 10px; font-size: 11px; }

/* 板卡信息 */
#board-info { font-size: 13px; line-height: 1.8; }
#board-info .pin-table { background: var(--bg3); border-radius: 6px; padding: 10px; font-family: Consolas, monospace; font-size: 12px; margin-top: 6px; white-space: pre-wrap; }

/* 烧录 tab */
.dl-link { color: var(--accent); font-size: 13px; text-decoration: none; }
.dl-link:hover { text-decoration: underline; }
#install-btn-slot { padding: 10px 0; }
esp-web-install-button { display: inline-block; }
.pulse-highlight { animation: pulseGlow 1.1s ease-in-out 4; }
@keyframes pulseGlow { 50% { filter: brightness(1.5) drop-shadow(0 0 10px var(--accent)); } }
#btn-serial-mode-browser, #btn-serial-mode-server { background: var(--bg3); color: var(--text-dim); font-size: 12px; padding: 6px 14px; }
#btn-serial-mode-browser.active, #btn-serial-mode-server.active { color: var(--accent); border: 1px solid var(--accent); }
