:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --border: #e2e2e6;
  --text: #1c1c1f;
  --muted: #6b6b74;
  --accent: #3b5bfd;
  --accent-text: #ffffff;
  --user-bubble: #3b5bfd;
  --agent-bubble: #ececef;
  --tool-bubble: #fff8e6;
  --tool-border: #eecb6b;
  --error-bubble: #fdecec;
  --error-border: #e57373;
  --confirm-bg: #fffdf4;
  --confirm-border: #e0b84b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --panel: #1e1f23;
    --border: #303136;
    --text: #eaeaec;
    --muted: #9a9aa2;
    --accent: #6d85ff;
    --accent-text: #0d0d10;
    --user-bubble: #6d85ff;
    --agent-bubble: #2a2b30;
    --tool-bubble: #2c2716;
    --tool-border: #7a5f18;
    --error-bubble: #3a1f1f;
    --error-border: #a34a4a;
    --confirm-bg: #221f13;
    --confirm-border: #8a6a1e;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

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

.topbar-title {
  font-weight: 600;
}

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

.topbar-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-controls input {
  font: inherit;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 130px;
}

.session-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* A "turn" is one labeled request/response entry: a small sender/time
   caption above its bubble, so which side said what is never ambiguous —
   the thing every other chat/prompt tool does and this one was missing. */
.turn {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  gap: 3px;
}

.turn.tool { max-width: 85%; }

.turn.user { align-self: flex-end; align-items: flex-end; }
.turn.agent, .turn.tool, .turn.error { align-self: flex-start; align-items: flex-start; }

.meta {
  font-size: 11px;
  color: var(--muted);
  padding: 0 6px;
}

.msg {
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  background: var(--user-bubble);
  color: var(--accent-text);
  border-bottom-right-radius: 3px;
}

.msg.agent {
  background: var(--agent-bubble);
  border-bottom-left-radius: 3px;
}

.msg.tool {
  background: var(--tool-bubble);
  border: 1px solid var(--tool-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.msg.error {
  background: var(--error-bubble);
  border: 1px solid var(--error-border);
}

.msg.agent.thinking {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.msg.agent.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: thinking-bounce 1.2s infinite ease-in-out both;
}

.msg.agent.thinking span:nth-child(1) { animation-delay: -0.32s; }
.msg.agent.thinking span:nth-child(2) { animation-delay: -0.16s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.msg.system {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  background: none;
  padding: 2px;
}

.pending-confirmations {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px;
}

.confirmation-card {
  background: var(--confirm-bg);
  border: 1px solid var(--confirm-border);
  border-radius: 10px;
  padding: 10px 14px;
}

.confirmation-card .tool-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.confirmation-card .tool-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}

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

.confirmation-card .status {
  font-size: 12px;
  margin-top: 6px;
  color: var(--muted);
}

.confirmation-card .actions button.deny {
  background: transparent;
  color: var(--error-border);
  border: 1px solid var(--error-border);
}

.confirmation-card.resolved {
  opacity: 0.6;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.composer button {
  align-self: flex-end;
}
