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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a1a; color: #e0e0e0;
  height: 100dvh; display: flex; flex-direction: column;
}

#header {
  padding: 12px 16px; background: #282828; border-bottom: 1px solid #333;
  display: flex; align-items: center; justify-content: space-between;
}
#header h1 { font-size: 18px; color: #d79921; }
#header .session { font-size: 11px; color: #666; }
#header select {
  background: #333; color: #e0e0e0; border: 1px solid #444; padding: 5px 8px;
  border-radius: 6px; font-size: 12px; cursor: pointer; outline: none;
  max-width: 140px;
}
#header select:focus { border-color: #458588; }
#header button {
  background: #333; color: #aaa; border: none; padding: 6px 12px;
  border-radius: 6px; font-size: 12px; cursor: pointer;
}
#header button.icon-btn {
  font-size: 16px; padding: 4px 8px; line-height: 1; background: transparent;
}
#header button.icon-btn:hover { color: #e0e0e0; }

#messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 10px;
}

.exchange {
  display: flex; flex-direction: column; gap: 8px;
}

.msg {
  max-width: 85%; padding: 10px 14px; border-radius: 16px;
  line-height: 1.5; font-size: 15px; word-wrap: break-word;
}
.msg.user { align-self: flex-end; background: #458588; color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #333; color: #ebdbb2; border-bottom-left-radius: 4px; }
.msg.bot pre { background: #222; padding: 8px; border-radius: 6px; overflow-x: auto; margin: 6px 0; font-size: 13px; }
.msg.bot code { font-family: "JetBrains Mono", monospace; font-size: 13px; }
.msg.error { background: #cc241d; color: #fff; }
.msg .turns { font-size: 11px; color: #888; margin-top: 4px; }

/* Steps container — one per message, always visible */
.steps-container {
  align-self: flex-start; max-width: 90%;
  background: #252525; border: 1px solid #333; border-radius: 12px;
  padding: 8px 12px;
}
ol.turns {
  list-style: none; margin: 0; padding: 0;
  counter-reset: turn;
}

/* Per-step collapsible */
details.step {
  margin: 2px 0; padding: 0;
  border-left: 2px solid #3c3836;
}
details.step > summary {
  cursor: pointer; padding: 4px 8px;
  font-family: "JetBrains Mono", monospace; font-size: 12px;
  color: #b8bb26; list-style: none;
}
details.step > summary::before {
  content: '\25b6'; display: inline-block;
  transition: transform 0.15s; font-size: 10px; margin-right: 4px;
}
details.step[open] > summary::before { transform: rotate(90deg); }
details.step > summary::-webkit-details-marker { display: none; }
.step-result {
  padding: 4px 8px 4px 16px; font-size: 12px; color: #888;
}
.step-result pre {
  background: #1a1a1a; padding: 6px 8px; border-radius: 4px;
  overflow-x: auto; margin: 2px 0; max-height: 200px; overflow-y: auto;
}
.step-result code { font-family: "JetBrains Mono", monospace; font-size: 11px; }

.thinking {
  align-self: flex-start; padding: 10px 14px; color: #888; font-size: 14px;
}
.thinking::after { content: ''; animation: dots 1.5s infinite; }
@keyframes dots {
  0% { content: '.'; } 33% { content: '..'; } 66% { content: '...'; }
}

#input-bar {
  padding: 10px 12px; background: #282828; border-top: 1px solid #333;
  display: flex; gap: 8px;
}
#input-bar textarea {
  flex: 1; padding: 10px 14px; border-radius: 20px; border: 1px solid #444;
  background: #1a1a1a; color: #e0e0e0; font-size: 16px; outline: none;
  resize: none; max-height: 120px; overflow-y: auto;
  font-family: inherit; line-height: 1.4;
}
#input-bar textarea:focus { border-color: #458588; }

#scroll-down {
  position: fixed; bottom: 70px; right: 16px;
  width: 36px; height: 36px; border-radius: 50%;
  background: #458588; color: #fff; border: none;
  font-size: 18px; cursor: pointer; display: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  z-index: 100;
}
#scroll-down:active { background: #3a7072; }
#input-bar button {
  padding: 10px 18px; border-radius: 20px; border: none;
  background: #458588; color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer;
}
#input-bar button:disabled { opacity: 0.4; cursor: not-allowed; }

.version-label {
  font-size: 0.6rem;
  opacity: 0.4;
  color: #888;
  margin-left: 0.3rem;
  font-family: monospace;
  letter-spacing: 0.02em;
  align-self: center;
}
details.steps-group { margin: 0; }
details.steps-group > summary {
  cursor: pointer;
  font-size: 12px;
  color: #a89984;
  padding: 4px 0;
  list-style: none;
}
details.steps-group > summary::-webkit-details-marker { display: none; }
details.steps-group > summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s;
}
details.steps-group[open] > summary::before { transform: rotate(90deg); }
li.turn-item { list-style: none; border-bottom: 1px solid #3c3836; padding: 0; }
li.turn-item:last-child { border-bottom: none; }
details.turn { margin: 0; }
details.turn > summary {
  cursor: pointer;
  font-size: 12px;
  color: #a89984;
  padding: 4px 0;
  list-style: none;
}
details.turn > summary::-webkit-details-marker { display: none; }
details.turn > summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s;
}
details.turn[open] > summary::before { transform: rotate(90deg); }
summary.thinking { display: list-item; }
summary.thinking::after { content: ''; animation: dots 1.5s infinite; display: inline; }

/* Version dialog */
#version-dialog {
  background: #282828; color: #e0e0e0; border: 1px solid #444;
  border-radius: 12px; padding: 0; max-width: 320px; width: 85vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#version-dialog::backdrop { background: rgba(0,0,0,0.5); }
.dialog-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid #333;
  font-size: 15px; font-weight: 600; color: #d79921;
}
.dialog-header button {
  background: none; border: none; color: #888; font-size: 22px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.dialog-header button:hover { color: #e0e0e0; }
.dialog-body { padding: 12px 16px; }
.dialog-row {
  display: flex; justify-content: space-between; padding: 6px 0;
  font-size: 13px; border-bottom: 1px solid #333;
}
.dialog-row:last-child { border-bottom: none; }
.dialog-label { color: #888; }
.dialog-row span:last-child {
  font-family: "JetBrains Mono", monospace; color: #b8bb26; font-size: 12px;
}
.version-label { cursor: pointer; }
.version-label:hover { opacity: 0.7 !important; }

/* Settings (inside version dialog) */
#version-dialog .settings-user {
  font-size: 12px; color: #a89984; font-weight: 400; margin-top: 2px;
}
#version-dialog .settings-user:empty { display: none; }
#version-dialog .settings-body {
  display: flex; flex-direction: column; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid #333;
}
#version-dialog .settings-action {
  background: #333; color: #e0e0e0; border: 1px solid #444;
  padding: 10px 14px; border-radius: 8px; font-size: 14px;
  cursor: pointer; text-align: left; transition: background 0.15s;
}
#version-dialog .settings-action:hover { background: #3c3c3c; }
#version-dialog .settings-action.danger { color: #fb4934; border-color: #cc241d; }
#version-dialog .settings-action.danger:hover { background: #3c2020; }

/* Error toasts */
#toast-container {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  width: 90vw; max-width: 400px; pointer-events: none;
}
.toast {
  background: #cc241d; color: #fff; padding: 12px 16px;
  border-radius: 10px; font-size: 13px; line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4); pointer-events: auto;
  animation: toast-in 0.25s ease-out;
  word-break: break-word;
}
.toast.warn { background: #d79921; color: #1a1a1a; }
.toast.info { background: #458588; }
.toast-dismiss {
  float: right; background: none; border: none; color: inherit;
  font-size: 18px; cursor: pointer; margin: -4px -4px 0 8px; line-height: 1;
  opacity: 0.7;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
