:root {
  --bg: #0b0e14;
  --panel: #111622;
  --panel-2: #171d2c;
  --border: rgba(255, 255, 255, 0.09);
  --border-hi: rgba(96, 165, 250, 0.45);
  --ink: #e6edf7;
  --ink-dim: #94a3b8;
  --ink-faint: #64748b;
  --accent: #60a5fa;
  --cyan: #38bdf8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
}

.hidden { display: none !important; }

.ag-topbar {
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0 0.75rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.ag-topbar-left, .ag-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ag-brand { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; font-size: 0.9rem; }
.ag-logo { color: var(--cyan); font-size: 1.05rem; }
.ag-badge {
  font-family: var(--mono);
  font-size: 0.62rem;
  padding: 0.1rem 0.38rem;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, 0.35);
}
.ag-ws-pill {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.ag-btn, .ag-mini-btn, .ag-icon-btn {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.32rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}
.ag-btn:hover, .ag-mini-btn:hover { border-color: var(--border-hi); }
.ag-btn.primary {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--cyan);
  font-weight: 700;
}
.ag-mini-btn { font-size: 0.66rem; padding: 0.18rem 0.42rem; color: var(--ink-dim); }
.ag-icon-btn { padding: 0.25rem 0.5rem; }

.ag-key-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
.key-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.key-dot.ok { background: var(--green); }

.ag-workbench {
  height: calc(100vh - 46px);
  display: grid;
  grid-template-columns: 240px 1fr 370px;
}

.ag-sidebar-left, .ag-sidebar-right {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ag-sidebar-left { border-right: 1px solid var(--border); }
.ag-sidebar-right { border-left: 1px solid var(--border); }

.ag-pane-header {
  height: 36px;
  padding: 0 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--border);
}
.ag-pane-actions { display: flex; align-items: center; gap: 0.3rem; }
.ag-search-box { padding: 0.45rem 0.55rem; border-bottom: 1px solid var(--border); }
.ag-search-box input {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.72rem;
}

.ag-file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0;
  font-family: var(--mono);
  font-size: 0.74rem;
}
.ag-tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  cursor: pointer;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ag-tree-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--ink); }
.ag-tree-item.active { background: rgba(56, 189, 248, 0.14); color: var(--cyan); }
.ag-tree-del { opacity: 0; color: var(--red); background: none; border: 0; cursor: pointer; font-size: 0.85rem; }
.ag-tree-item:hover .ag-tree-del { opacity: 1; }

.ag-center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.ag-tabs-bar {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 0.4rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.ag-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-dim);
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 5px 5px 0 0;
  cursor: pointer;
}
.ag-tab.active {
  background: var(--bg);
  color: var(--ink);
  border-color: var(--border);
  border-bottom-color: var(--bg);
}
.ag-tab-close { background: none; border: 0; color: var(--ink-faint); cursor: pointer; font-size: 0.85rem; padding: 0; }

.ag-editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ag-editor-split {
  flex: 1;
  display: flex;
  min-height: 0;
}
.ag-code-pane, .ag-preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.ag-preview-pane { border-left: 1px solid var(--border); background: #fff; }
.ag-preview-pane .ag-editor-toolbar { background: var(--panel); }
.ag-preview-iframe { flex: 1; border: 0; width: 100%; height: 100%; background: #fff; }

.ag-editor-toolbar {
  height: 30px;
  padding: 0 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.ag-file-path { font-family: var(--mono); font-size: 0.7rem; color: var(--ink-dim); }
.ag-lang-badge { font-family: var(--mono); font-size: 0.64rem; color: var(--cyan); text-transform: uppercase; }

.ag-editor-surface {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}
.ag-gutter {
  margin: 0;
  padding: 0.75rem 0.55rem 0.75rem 0.75rem;
  min-width: 44px;
  text-align: right;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-faint);
  background: rgba(255, 255, 255, 0.015);
  border-right: 1px solid var(--border);
  user-select: none;
  overflow: hidden;
}
.ag-textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  border: 0;
  outline: none;
  resize: none;
  padding: 0.75rem;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.ag-terminal-pane {
  height: 145px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #080a0f;
}
.ag-terminal-head {
  height: 26px;
  padding: 0 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.64rem;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--border);
}
.ag-terminal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.45rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--ink-dim);
}
.ag-log-line.ok { color: var(--green); }
.ag-log-line.err { color: var(--red); }

.ag-select-sm {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.66rem;
  padding: 0.16rem 0.35rem;
}

.ag-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.ag-msg {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.ag-msg.user { background: rgba(96, 165, 250, 0.1); border-color: rgba(96, 165, 250, 0.3); align-self: flex-end; max-width: 92%; }
.ag-msg.assistant { background: var(--panel-2); }
.ag-msg.tool {
  font-family: var(--mono);
  font-size: 0.72rem;
  background: #0a0e16;
  border-color: rgba(52, 211, 153, 0.3);
  color: var(--green);
  padding: 0.45rem 0.65rem;
}

.ag-chat-composer {
  padding: 0.6rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.ag-chat-composer textarea {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  resize: none;
  outline: none;
}
.ag-chat-composer textarea:focus { border-color: var(--border-hi); }
.ag-composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ag-hint { font-family: var(--mono); font-size: 0.66rem; color: var(--ink-faint); }

.ag-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(4, 6, 10, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.ag-modal-backdrop.open { display: flex; }
.ag-modal {
  width: min(500px, 95vw);
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
}
.ag-modal-head {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.ag-modal-title { font-family: var(--mono); font-size: 0.9rem; font-weight: 700; color: var(--cyan); }
.ag-modal-sub { font-size: 0.74rem; color: var(--ink-dim); margin-top: 0.2rem; }
.ag-modal-close { background: none; border: 0; color: var(--ink-dim); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.ag-modal-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.ag-modal-foot {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.ag-field { display: flex; flex-direction: column; gap: 0.3rem; }
.ag-field label { font-family: var(--mono); font-size: 0.7rem; color: var(--ink-dim); }
.ag-input {
  width: 100%;
  padding: 0.48rem 0.6rem;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 0.76rem;
}
.ag-preset-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.25rem; }
.ag-chip {
  font-family: var(--mono);
  font-size: 0.66rem;
  padding: 0.16rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink-dim);
  cursor: pointer;
}
.ag-chip:hover { border-color: var(--cyan); color: var(--ink); }
.ag-test-status { font-family: var(--mono); font-size: 0.72rem; min-height: 1.2em; }

.ag-cmd-modal { width: min(540px, 95vw); }
.ag-cmd-input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  background: var(--bg);
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.84rem;
  outline: none;
}
.ag-cmd-list { max-height: 300px; overflow-y: auto; }
.ag-cmd-item {
  padding: 0.55rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.ag-cmd-item:hover { background: rgba(56, 189, 248, 0.12); }

.mobile-only { display: none; }
@media (max-width: 960px) {
  .mobile-only { display: inline-flex; }
  .ag-ws-pill, #btn-cmd-palette { display: none; }
  .ag-workbench { grid-template-columns: 1fr; position: relative; }
  .ag-sidebar-left, .ag-sidebar-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: min(340px, 90vw);
    z-index: 50;
    display: none;
  }
  .ag-sidebar-left.open, .ag-sidebar-right.open { display: flex; }
  .ag-sidebar-left { left: 0; }
  .ag-sidebar-right { right: 0; }
}
