:root {
  --bg: #1e1e1e;
  --bg-deep: #181818;
  --bg-editor: #1e1e1e;
  --bg-sidebar: #252526;
  --bg-hover: #2a2d2e;
  --bg-active: #094771;
  --bg-tab: #2d2d2d;
  --border: #3c3c3c;
  --border-soft: #2b2b2b;
  --text: #cccccc;
  --text-dim: #9d9d9d;
  --text-bright: #e8e8e8;
  --accent: #007acc;
  --accent-soft: #264f78;
  --err: #f14c4c;
  --warn: #cca700;
  --kw: #c586c0;
  --type: #4ec9b0;
  --fn: #dcdcaa;
  --str: #ce9178;
  --num: #b5cea8;
  --cmt: #6a9955;
  --plain: #d4d4d4;
  --md-h: #e8e8e8;
  --md-muted: #8b949e;
  --font-ui: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "Consolas", "Sarasa Mono SC", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: default;
}

.ide {
  display: grid;
  grid-template-rows: 30px 1fr 22px;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

/* —— 顶栏 —— */
.titlebar {
  display: grid;
  grid-template-columns: 1fr minmax(160px, 320px) 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-soft);
  user-select: none;
}

.menubar {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}

.menubar button {
  padding: 2px 7px;
  border-radius: 3px;
  color: var(--text);
  white-space: nowrap;
}

.menubar button:hover {
  background: var(--bg-hover);
}

.title-pill {
  justify-self: center;
  width: 100%;
  max-width: 280px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 999px;
  background: #2b2b2b;
  border: 1px solid #3a3a3a;
  color: var(--text-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 12px;
}

.title-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
}

.ico,
.win {
  display: inline-block;
  width: 12px;
  height: 12px;
  opacity: 0.75;
  position: relative;
}

.ico.layout::before {
  content: "";
  position: absolute;
  inset: 1px;
  border: 1px solid currentColor;
  border-radius: 1px;
}
.ico.layout::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  bottom: 1px;
  width: 1px;
  background: currentColor;
}

.ico.gear::before {
  content: "⚙";
  font-size: 11px;
  line-height: 12px;
}

.win.min::before {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  top: 6px;
  height: 1px;
  background: currentColor;
}
.win.max::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px solid currentColor;
}
.win.close::before,
.win.close::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 5px;
  height: 1px;
  background: currentColor;
}
.win.close::before {
  transform: rotate(45deg);
}
.win.close::after {
  transform: rotate(-45deg);
}

/* —— 工作区 —— */
.workspace {
  display: grid;
  grid-template-columns: minmax(140px, 18%) 4px minmax(0, 1fr) 4px minmax(220px, 28%);
  min-height: 0;
  background: var(--bg);
}

.split-v,
.split-h {
  background: var(--bg);
  position: relative;
}
.split-v::after {
  content: "";
  position: absolute;
  inset: 0 1px;
  background: var(--border-soft);
}
.split-h {
  height: 4px;
}
.split-h::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 1px;
  height: 1px;
  background: var(--border);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 35px;
  padding: 0 12px;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: none;
  user-select: none;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.panel-tools {
  display: flex;
  gap: 8px;
  color: var(--text-dim);
}
.panel-tools .dot {
  opacity: 0.7;
  font-size: 12px;
}

/* 左栏 */
.sidebar-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-sidebar);
  overflow: hidden;
}

.explorer {
  flex: 1;
  overflow: auto;
  padding: 4px 0 12px;
  scrollbar-width: thin;
  scrollbar-color: #424242 transparent;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding-right: 8px;
  color: var(--text);
  white-space: nowrap;
  cursor: default;
}
.tree-item:hover {
  background: var(--bg-hover);
}
.tree-item.active {
  background: var(--bg-active);
  color: #fff;
}
.tree-item .twist {
  width: 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 9px;
  flex-shrink: 0;
}
.tree-item .fi {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border-radius: 2px;
}
.fi.folder {
  color: #dcb67a;
  position: relative;
}
.fi.folder::before {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  top: 4px;
  bottom: 1px;
  border: 1.5px solid currentColor;
  border-radius: 1px;
}
.fi.folder::after {
  content: "";
  position: absolute;
  left: 1px;
  top: 2px;
  width: 6px;
  height: 3px;
  border: 1.5px solid currentColor;
  border-bottom: 0;
  border-radius: 1px 1px 0 0;
}
.fi.ets {
  background: #3178c6;
  color: #fff;
  font-weight: 700;
  font-size: 8px;
}
.fi.json {
  background: #cbcb41;
  color: #1e1e1e;
  font-weight: 700;
  font-size: 7px;
}
.fi.ts {
  background: #3178c6;
  color: #fff;
  font-weight: 700;
  font-size: 7px;
}
.fi.file {
  border: 1.5px solid var(--text-dim);
  border-radius: 1px;
}
.tree-item .mark {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--err);
  margin-left: auto;
  flex-shrink: 0;
}

/* 中栏 */
.center {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 4px minmax(120px, 32%);
  min-width: 0;
  min-height: 0;
  background: var(--bg-editor);
}

.editor-pane,
.terminal-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.tabs {
  display: flex;
  height: 35px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 12px;
  background: var(--bg-tab);
  border-right: 1px solid var(--border-soft);
  color: var(--text);
  max-width: 180px;
}
.tab.active {
  background: var(--bg-editor);
  border-top: 1px solid var(--accent);
}
.tab-icon.ets {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #3178c6;
  color: #fff;
  font-size: 7px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tab-icon.ets::before {
  content: "e";
}
.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-dirty {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--err);
  flex-shrink: 0;
}
.tab-close {
  opacity: 0.5;
  margin-left: 2px;
}

.editor {
  flex: 1;
  overflow: auto;
  background: var(--bg-editor);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  scrollbar-width: thin;
  scrollbar-color: #424242 transparent;
}

.code-row {
  display: grid;
  grid-template-columns: 48px 14px 1fr;
  min-height: 18px;
}
.code-row:hover {
  background: rgba(255, 255, 255, 0.03);
}
.ln {
  text-align: right;
  padding-right: 10px;
  color: #6e7681;
  user-select: none;
}
.bp {
  display: flex;
  align-items: center;
  justify-content: center;
}
.bp::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}
.bp.on::before {
  background: var(--err);
}
.code {
  padding-right: 16px;
  white-space: pre;
  color: var(--plain);
}
.code .kw {
  color: var(--kw);
}
.code .ty {
  color: var(--type);
}
.code .fn {
  color: var(--fn);
}
.code .st {
  color: var(--str);
}
.code .nu {
  color: var(--num);
}
.code .cm {
  color: var(--cmt);
}
.code .err {
  text-decoration: wavy underline var(--err);
}

.terminal-head {
  background: var(--bg-sidebar);
}
.term-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}
.term-tab {
  position: relative;
  color: var(--text-bright);
  padding-bottom: 2px;
}
.term-tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -10px;
  height: 1px;
  background: var(--accent);
}

.terminal {
  flex: 1;
  overflow: auto;
  padding: 8px 12px;
  background: #000;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: #d4d4d4;
}

.term-line.prompt {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.prompt-path {
  color: #cccccc;
}
.caret {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: #aeafad;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* 右栏 */
.sidebar-right {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-sidebar);
  overflow: hidden;
}

.chat-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px 8px;
  scrollbar-width: thin;
  scrollbar-color: #424242 transparent;
}

.md-view {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
}
.md-view h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 650;
  color: var(--md-h);
}
.md-view h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--md-h);
}
.md-view .tree-block {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #1b1b1b;
  border: 1px solid #303030;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  color: #c8c8c8;
  white-space: pre;
  overflow-x: auto;
}
.md-view .tree-block .ann {
  color: var(--md-muted);
}
.md-view table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 10px;
  font-size: 11.5px;
}
.md-view th,
.md-view td {
  border: 1px solid #3a3a3a;
  padding: 6px 8px;
  text-align: left;
}
.md-view th {
  background: #2a2a2a;
  color: var(--text-bright);
  font-weight: 600;
}
.md-view tr:nth-child(even) td {
  background: #222;
}
.md-view ul {
  margin: 4px 0 8px;
  padding-left: 1.2em;
}
.md-view li {
  margin: 3px 0;
}
.md-view li strong {
  color: var(--text-bright);
  font-weight: 600;
}

.chat-input {
  flex-shrink: 0;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border-soft);
  background: #1f1f1f;
}
.chat-input textarea {
  width: 100%;
  resize: none;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  background: #252526;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  outline: none;
}
.chat-input textarea::placeholder {
  color: #6e6e6e;
}
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}
.agent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px 0 4px;
  border-radius: 999px;
  background: #1a3a52;
  color: #cde7f7;
  font-size: 11px;
}
.agent-badge {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 10px;
}
.chev {
  opacity: 0.7;
  font-size: 10px;
}
.chat-tools {
  display: flex;
  gap: 10px;
  color: var(--text-dim);
}
.tool {
  opacity: 0.75;
}

/* 底栏 */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px;
  background: #007acc;
  color: #fff;
  font-size: 11px;
  user-select: none;
  overflow: hidden;
}
.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.status-left {
  overflow: hidden;
}
.crumb {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-ico {
  font-size: 8px;
  line-height: 1;
}
.status-ico.err {
  color: #ffb4b4;
}
.status-ico.warn {
  color: #ffe08a;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(110px, 22%) 3px minmax(0, 1fr) 3px minmax(160px, 30%);
  }
  .menubar button:nth-child(n + 6) {
    display: none;
  }
}

@media (max-width: 640px) {
  .workspace {
    grid-template-columns: 0 0 minmax(0, 1fr) 0 0;
  }
  .sidebar-left,
  .sidebar-right,
  .split-v {
    display: none;
  }
}
