:root,
[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-raised: #ffffff;
  --bg-inset: #f0f1f3;
  --bg-hover: #eaebee;
  --ink: #1a1d23;
  --ink-secondary: #5f6571;
  --ink-tertiary: #8b8f99;
  --accent: #3b6cf5;
  --accent-hover: #2b5ad6;
  --accent-soft: rgba(59, 108, 245, 0.1);
  --accent-text: #2952c4;
  --danger: #d93b3b;
  --success: #1a9856;
  --warning: #c48b17;
  --border: #e2e4e9;
  --border-strong: #d0d3da;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "IBM Plex Mono", "Fira Code", monospace;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-raised: #1a1d27;
  --bg-inset: #141620;
  --bg-hover: #222532;
  --ink: #e4e6eb;
  --ink-secondary: #9498a5;
  --ink-tertiary: #6b6f7e;
  --accent: #5b8af5;
  --accent-hover: #7aa2ff;
  --accent-soft: rgba(91, 138, 245, 0.12);
  --accent-text: #7aa2ff;
  --danger: #ef5555;
  --success: #34c77b;
  --warning: #e5a520;
  --border: #2a2d3a;
  --border-strong: #3a3e4e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; }

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Top Bar ────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand { display: flex; align-items: center; gap: 12px; }

.topbar-logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 700; font-size: 16px;
  border-radius: var(--radius-sm);
}

.topbar-logo-img {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.topbar-title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.topbar-subtitle { font-size: 12px; color: var(--ink-tertiary); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 120ms;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--ink); }

/* ── Chips ──────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  font-size: 12px; font-weight: 600;
  border-radius: 99px;
  white-space: nowrap;
}
.chip-muted { background: var(--bg-inset); color: var(--ink-secondary); }
.chip-idle { background: var(--bg-inset); color: var(--ink-tertiary); }
.chip-running { background: var(--accent-soft); color: var(--accent-text); }
.chip-success { background: rgba(26,152,86,0.1); color: var(--success); }
.chip-error { background: rgba(217,59,59,0.1); color: var(--danger); }

/* ── 3-Panel Layout ─────────────────────────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.panels {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 280px;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.panel-left, .panel-right {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  height: calc(100vh - 61px);
  position: sticky;
  top: 61px;
}
.panel-right { border-right: none; border-left: 1px solid var(--border); }

.panel-center {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Panel Sections ─────────────────────────── */
.panel-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.section-header h2, .section-header h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-secondary); }

.text-btn {
  background: none; border: none; color: var(--accent-text);
  font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 2px 6px; border-radius: var(--radius-xs);
}
.text-btn:hover { background: var(--accent-soft); }

.muted-text { color: var(--ink-tertiary); font-size: 13px; }

/* ── Search ─────────────────────────────────── */
.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit; font-size: 13px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-input::placeholder { color: var(--ink-tertiary); }

/* ── Agent Grid ─────────────────────────────── */
.agent-grid {
  padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}

.agent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  font: inherit; color: var(--ink);
  transition: all 100ms;
}
.agent-item:hover { background: var(--bg-hover); }
.agent-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
}

.agent-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-xs);
  font-size: 12px; font-weight: 700;
  background: var(--bg-inset);
  color: var(--ink-secondary);
}
.agent-item.active .agent-icon { background: var(--accent); color: white; }
.agent-item.master-item .agent-icon { background: var(--accent); color: white; }

.agent-item-info { flex: 1; min-width: 0; }
.agent-item-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-item-meta { font-size: 11px; color: var(--ink-tertiary); }
.agent-item.active .agent-item-meta { color: var(--accent-text); opacity: 0.7; }

.agent-tool-count {
  flex-shrink: 0; font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 99px;
  background: var(--bg-inset); color: var(--ink-tertiary);
}
.agent-item.active .agent-tool-count { background: rgba(59,108,245,0.2); color: var(--accent-text); }

/* ── History ────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 2px; max-height: 200px; overflow-y: auto; }

.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer; border: none; background: none; text-align: left;
  font: inherit; color: var(--ink); width: 100%;
  transition: background 100ms;
}
.history-item:hover { background: var(--bg-hover); }
.history-item-service { font-size: 12px; font-weight: 600; flex-shrink: 0; }
.history-item-task { font-size: 11px; color: var(--ink-tertiary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item-time { font-size: 11px; color: var(--ink-tertiary); flex-shrink: 0; }

/* ── Composer ───────────────────────────────── */
.composer-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.composer-toolbar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-inset);
}

.toolbar-group { display: flex; flex-direction: column; gap: 3px; }
.toolbar-label { font-size: 11px; font-weight: 600; color: var(--ink-tertiary); text-transform: uppercase; letter-spacing: 0.04em; }
.toolbar-select {
  padding: 6px 10px; font: inherit; font-size: 13px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--ink);
  outline: none; cursor: pointer;
}
.toolbar-select:focus { border-color: var(--accent); }

.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-secondary); cursor: pointer;
  padding-bottom: 4px;
}
.toggle-label input { width: 16px; height: 16px; accent-color: var(--accent); }

.prompt-textarea {
  width: 100%;
  padding: 14px 16px;
  border: none; outline: none;
  background: var(--bg-raised);
  color: var(--ink);
  font: inherit; font-size: 14px; line-height: 1.6;
  resize: vertical; min-height: 100px;
}
.prompt-textarea::placeholder { color: var(--ink-tertiary); }

.composer-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.key-inputs { display: flex; gap: 8px; }
.key-input {
  padding: 6px 10px; font: inherit; font-size: 12px;
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--ink);
  outline: none; width: 160px;
}
.key-input:focus { border-color: var(--accent); }
.key-input::placeholder { color: var(--ink-tertiary); }

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

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  font: inherit; font-size: 13px; font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer; border: none;
  transition: all 120ms;
}
.btn-primary {
  background: var(--accent); color: white;
  box-shadow: 0 2px 8px rgba(59,108,245,0.3);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: var(--bg-inset); color: var(--ink-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--ink); }

/* ── Response ───────────────────────────────── */
.response-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.response-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.response-header h2 { font-size: 15px; font-weight: 700; }
.response-meta { display: flex; gap: 6px; }

.summary-strip {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 14px;
}
.summary-item {
  padding: 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.summary-label { font-size: 11px; font-weight: 600; color: var(--ink-tertiary); text-transform: uppercase; letter-spacing: 0.04em; display: block; margin-bottom: 6px; }
.summary-value { font-size: 14px; display: block; }

.readiness-group { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.readiness-ring {
  --ring-color: var(--danger);
  --ring-fill: 0deg;
  width: 48px; height: 48px; flex-shrink: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background:
    radial-gradient(circle closest-side, var(--bg-inset) 68%, transparent 69%),
    conic-gradient(var(--ring-color) var(--ring-fill), var(--border) 0deg);
}
.readiness-score { font-family: var(--mono); font-size: 11px; font-weight: 700; }

.response-body {
  font-family: var(--mono);
  font-size: 13px; line-height: 1.7;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  min-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.response-body h1, .response-body h2, .response-body h3, .response-body h4 {
  font-family: var(--font);
  margin: 16px 0 6px;
  color: var(--ink);
}
.response-body h1 { font-size: 18px; }
.response-body h2 { font-size: 16px; }
.response-body h3 { font-size: 14px; }
.response-body ul, .response-body ol { padding-left: 20px; margin: 6px 0; }
.response-body li { margin: 3px 0; }
.response-body code {
  background: var(--bg-hover); padding: 2px 5px;
  border-radius: 3px; font-size: 12px;
}
.response-body pre {
  background: var(--bg-hover); padding: 12px;
  border-radius: var(--radius-sm); overflow-x: auto;
  margin: 8px 0;
}
.response-body pre code { background: none; padding: 0; }
.response-body strong { color: var(--ink); }
.response-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 8px 0;
  color: var(--ink-secondary);
}
.response-body table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12px; }
.response-body th, .response-body td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.response-body th { background: var(--bg-hover); font-weight: 600; }

/* ── Tools Section ──────────────────────────── */
.tools-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 14px 18px;
}
.tools-body { display: flex; flex-direction: column; gap: 8px; }

.tool-result {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.tool-result-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
}
.tool-result-name { font-size: 12px; font-weight: 700; font-family: var(--mono); }
.tool-result-status { font-size: 11px; font-weight: 700; }
.tool-result-status.ok { color: var(--success); }
.tool-result-status.err { color: var(--danger); }
.tool-result-body {
  padding: 10px 12px; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; line-height: 1.5; max-height: 300px; overflow-y: auto;
}

/* ── Intel Panel ────────────────────────────── */
.intel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.intel-header h3 { font-size: 14px; font-weight: 700; }

.intel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.intel-tab {
  flex: 1;
  padding: 8px 0;
  font: inherit; font-size: 12px; font-weight: 600;
  text-align: center;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--ink-tertiary); cursor: pointer;
  transition: all 100ms;
}
.intel-tab:hover { color: var(--ink); }
.intel-tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

.intel-content { display: none; padding: 14px 16px; }
.intel-content.active { display: block; }

.intel-block { margin-bottom: 14px; }
.intel-block h4 { font-size: 11px; font-weight: 700; color: var(--ink-tertiary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.intel-block p, .intel-block li { font-size: 13px; line-height: 1.5; }
.intel-block ul { padding-left: 16px; margin: 0; }
.intel-block li { margin: 3px 0; color: var(--ink-secondary); }

.intel-tools-list { display: flex; flex-direction: column; gap: 8px; }
.intel-tool {
  padding: 10px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.intel-tool-name { font-size: 12px; font-weight: 700; font-family: var(--mono); color: var(--accent-text); }
.intel-tool-desc { font-size: 12px; color: var(--ink-secondary); margin-top: 2px; }

.specialty-tag {
  display: inline-block;
  padding: 3px 8px;
  margin: 2px;
  font-size: 11px; font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 99px;
}

.config-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.config-label { color: var(--ink-tertiary); }
.config-value { font-weight: 600; }

.guardrail-item {
  padding: 8px 10px;
  background: rgba(217,59,59,0.05);
  border: 1px solid rgba(217,59,59,0.15);
  border-radius: var(--radius-xs);
  font-size: 12px;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

[data-theme="dark"] .guardrail-item {
  background: rgba(239,85,85,0.08);
  border-color: rgba(239,85,85,0.2);
}

.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 1200px) {
  .panels { grid-template-columns: 220px minmax(0, 1fr) 240px; }
}

@media (max-width: 900px) {
  .panels { grid-template-columns: 1fr; }
  .panel-left, .panel-right {
    position: static; height: auto;
    border-right: none; border-left: none;
    border-bottom: 1px solid var(--border);
  }
  .panel-right { border-bottom: none; border-top: 1px solid var(--border); }
  .agent-grid { flex-direction: row; flex-wrap: wrap; }
  .agent-item { width: auto; flex-shrink: 0; }
  .composer-toolbar { flex-wrap: wrap; }
  .key-inputs { flex-wrap: wrap; }
  .key-input { width: 130px; }
  .summary-strip { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .composer-footer { flex-direction: column; }
  .composer-actions { width: 100%; justify-content: flex-end; }
  .key-inputs { width: 100%; }
  .key-input { flex: 1; width: auto; }
}

/* ── Topbar Nav Links ───────────────────────── */
.topbar-nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: var(--accent);
}
