:root {
  --bg: #0e0f13;
  --bg-elev: #15171d;
  --bg-soft: #1c1f27;
  --border: #2a2e3a;
  --text: #e6e8ee;
  --text-dim: #9aa0ad;
  --text-muted: #6c7280;
  --accent: #ff9333;
  --accent-soft: #ff933322;
  --user: #5e7cff;
  --user-soft: #5e7cff22;
  --tool: #58c79a;
  --tool-soft: #58c79a18;
  --error: #ff6b7a;
  --error-soft: #ff6b7a22;
  --code-bg: #0a0b0f;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font-ui:
    "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono:
    "JetBrains Mono", "Fira Code", "SF Mono", Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #c2580f);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #1a0f00;
}

.sidebar-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
}

.sidebar-section:last-child {
  flex: 0 0 auto;
}

.sidebar > .sidebar-section:nth-child(2) {
  flex: 1 1 auto;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  text-align: left;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.12s ease, color 0.12s ease;
}

.session-item:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.session-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.session-item .session-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item .session-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.empty-state {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
}

.settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.settings input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12px;
}

.settings input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.toggle {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 12px;
}

.toggle input {
  margin: 0;
  accent-color: var(--accent);
}

/* ---------------- Buttons ---------------- */
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-send {
  cursor: pointer;
  font: inherit;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn-primary {
  background: var(--accent);
  color: #1a0f00;
  font-weight: 600;
}

.btn-primary:hover {
  background: #ffa64d;
}

.btn-secondary {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: transparent;
  padding: 6px 10px;
  font-size: 14px;
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
}

.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.btn-send {
  background: var(--accent);
  color: #1a0f00;
  font-weight: 600;
  align-self: flex-end;
  padding: 9px 18px;
  height: 36px;
}

.btn-send:hover:not(:disabled) {
  background: #ffa64d;
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------------- Main pane ---------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex: 0 0 auto;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tool);
  box-shadow: 0 0 0 3px rgba(88, 199, 154, 0.15);
}

.status-dot.busy {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.error {
  background: var(--error);
  box-shadow: 0 0 0 3px var(--error-soft);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
  }
}

/* ---------------- Chat ---------------- */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 780px;
  margin: 60px auto;
  padding: 0 24px;
  text-align: center;
  color: var(--text-dim);
}

.welcome h1 {
  font-size: 32px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent), #ffd089);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.welcome code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.message {
  max-width: 820px;
  margin: 0 auto 18px;
  padding: 0 24px;
  display: flex;
  gap: 12px;
}

.message .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}

.message.user .avatar {
  background: var(--user-soft);
  color: var(--user);
  border: 1px solid var(--user);
}

.message.assistant .avatar {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.message.tool .avatar {
  background: var(--tool-soft);
  color: var(--tool);
  border: 1px solid var(--tool);
  font-size: 14px;
}

.message.error .avatar {
  background: var(--error-soft);
  color: var(--error);
  border: 1px solid var(--error);
}

.message .body {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  overflow-wrap: anywhere;
}

.message.user .body {
  background: var(--bg-soft);
  border-color: var(--user);
}

.message.error .body {
  border-color: var(--error);
  background: var(--error-soft);
}

.message .body :first-child {
  margin-top: 0;
}

.message .body :last-child {
  margin-bottom: 0;
}

.message .body p {
  margin: 8px 0;
}

.message .body h1,
.message .body h2,
.message .body h3 {
  margin: 14px 0 8px;
}

.message .body ul,
.message .body ol {
  padding-left: 22px;
  margin: 8px 0;
}

.message .body code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
  color: #ffcd91;
}

.message .body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}

.message .body pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
}

.message .body a {
  color: var(--accent);
}

/* Tool call card */
.tool-call {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tool);
  border-radius: var(--radius-sm);
  margin: 6px 0;
  font-family: var(--font-mono);
  font-size: 12px;
}

.tool-call summary {
  cursor: pointer;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  user-select: none;
  color: var(--text-dim);
}

.tool-call summary::-webkit-details-marker {
  display: none;
}

.tool-call summary::before {
  content: "▶";
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.tool-call[open] summary::before {
  transform: rotate(90deg);
}

.tool-call .tool-name {
  color: var(--tool);
  font-weight: 600;
}

.tool-call .tool-args {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.tool-call .tool-body {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-call .tool-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  margin: 0;
  font-size: 11.5px;
  overflow-x: auto;
  max-height: 240px;
  overflow-y: auto;
}

.tool-call .label {
  color: var(--text-muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Composer */
.composer {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 12px 16px 14px;
  flex: 0 0 auto;
}

.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.12s ease;
}

.composer-inner:focus-within {
  border-color: var(--accent);
}

#prompt-input {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 6px 0;
  outline: none;
  min-height: 22px;
  max-height: 200px;
}

.composer-meta {
  max-width: 820px;
  margin: 6px auto 0;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* Palette */
.palette {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: start center;
  padding-top: 12vh;
  z-index: 50;
}

.palette.hidden {
  display: none;
}

.palette-card {
  width: min(560px, 92vw);
  max-height: 70vh;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.palette-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.palette-head input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.palette-list {
  overflow-y: auto;
  padding: 6px;
}

.palette-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  font: inherit;
}

.palette-item:hover,
.palette-item.active {
  background: var(--bg-soft);
}

.palette-item .palette-name {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 13px;
  margin-right: 8px;
}

.palette-item .palette-desc {
  color: var(--text-dim);
  font-size: 12px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3b414f;
}

/* Mobile-ish narrow screens */
@media (max-width: 720px) {
  #app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
}
