:root {
  --bg: #0a0b0f;
  --panel: #15171f;
  --panel-hover: #1b1e28;
  --border: #262a35;
  --border-soft: #1c1f28;
  --text: #eef0f4;
  --muted: #8991a4;
  --muted-soft: #666d80;
  --accent: #7aa2ff;
  --accent-strong: #5b86ff;
  --accent-contrast: #0a0b0f;
  --danger: #ff7070;
  --danger-soft: rgba(255, 112, 112, 0.12);
  --success: #52d18a;
  --user-bubble: #212739;
  --assistant-bubble: #171a24;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.28);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}
::selection { background: rgba(122, 162, 255, 0.35); }
header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, rgba(122,162,255,0.05), transparent);
}
header .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(122, 162, 255, 0.15);
}
header h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: 0.2px; }
header .tagline { color: var(--muted); font-size: 13px; }
header .backLink {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  transition: color 0.15s, border-color 0.15s;
}
header .backLink:hover { color: var(--text); border-color: var(--accent); }
header .spacer { flex: 1; }
#balance {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
}
#adminLink, #logoutBtn {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#adminLink:hover, #logoutBtn:hover { color: var(--text); border-color: var(--accent); background: var(--panel); }
main {
  flex: 1;
  display: flex;
  min-height: 0;
}
#historyColumn {
  flex: 0 0 240px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: rgba(255,255,255,0.012);
}
#historyColumn .newChatBtn {
  margin: 12px;
  background: var(--accent);
  border: none;
  color: var(--accent-contrast);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: background 0.15s, transform 0.1s;
}
#historyColumn .newChatBtn:hover { background: var(--accent-strong); }
#historyColumn .newChatBtn:active { transform: scale(0.98); }
#historyList { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.historyItem {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.historyItem:hover { color: var(--text); background: var(--panel-hover); }
.historyItem.active { color: var(--text); background: var(--panel); box-shadow: inset 2px 0 0 var(--accent); }
.historyItem .historyItemTitle {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.historyItem .deleteBtn {
  flex-shrink: 0;
  opacity: 0;
  background: none;
  border: none;
  color: var(--muted-soft);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  transition: opacity 0.1s, color 0.15s, background 0.15s;
}
.historyItem:hover .deleteBtn, .historyItem.active .deleteBtn { opacity: 1; }
.historyItem .deleteBtn:hover { color: var(--danger); background: var(--danger-soft); }
#chatColumn {
  flex: 1 1 420px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#chatColumn.withPreview {
  border-right: 1px solid var(--border);
}
#previewColumn {
  flex: 1 1 480px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#previewColumn .placeholder {
  margin: auto;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px;
  max-width: 320px;
  line-height: 1.5;
}
#previewBar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#previewFrame {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
}
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  font-size: 14.5px;
  box-shadow: var(--shadow-soft);
}
.bubbleText { white-space: pre-wrap; word-break: break-word; }
.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}
.bubble.pending {
  color: var(--muted);
  font-style: italic;
}
.bubble.error {
  align-self: flex-start;
  background: var(--danger-soft);
  color: var(--danger);
}
.messageMedia {
  margin-top: 8px;
}
.messageMedia img, .messageMedia video {
  display: block;
  max-width: 100%;
  max-height: 340px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
}
.messageMedia img { cursor: zoom-in; }
.messageMedia.fileChip a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.messageMedia.fileChip a:hover { border-color: var(--accent); }
.mediaStatus {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  width: fit-content;
}
.logPanel {
  margin-top: 8px;
  max-height: 160px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: rgba(0,0,0,0.15);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.logLine { white-space: pre-wrap; word-break: break-word; }
.logLine.thought { color: #a996ff; }
.logLine.tool_call { color: #7aa2ff; }
.logLine.code { color: #6fe89c; }
.logLine.retry { color: #f5a742; font-weight: 600; }
.inputRequest {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.inlineTextInput {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  min-width: 200px;
}
.inlineTextInput:focus { outline: none; border-color: var(--accent); }
.choiceBtn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.choiceBtn:hover { background: var(--accent-strong); }
.choiceBtn.secondary {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
}
.choiceBtn.secondary:hover { border-color: var(--accent); }
#composer {
  border-top: 1px solid var(--border);
  padding: 14px;
  display: flex;
  gap: 10px;
  background: rgba(255,255,255,0.012);
}
#composerColumn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#attachBtn, #sendBtn {
  flex-shrink: 0;
  align-self: flex-end;
}
#attachChip {
  max-width: 100%;
}
#attachChipName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#textInput {
  width: 100%;
  resize: none;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}
#textInput:focus { outline: none; border-color: var(--accent); }
#attachChip {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  width: fit-content;
}
#attachChip::before {
  content: "📎";
  font-size: 12px;
}
#attachChip button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
#attachChip button:hover { color: var(--danger); }
#attachBtn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-md);
  padding: 0 16px;
  height: 42px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}
#attachBtn:hover { color: var(--text); border-color: var(--accent); }
#sendBtn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-md);
  padding: 0 22px;
  height: 42px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
#sendBtn:hover:not(:disabled) { background: var(--accent-strong); }
#sendBtn:disabled {
  opacity: 0.5;
  cursor: default;
}
#runBtn, #runFromPlaceholderBtn, #shareBtn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
#runBtn:hover:not(:disabled), #runFromPlaceholderBtn:hover:not(:disabled), #shareBtn:hover:not(:disabled) {
  background: var(--accent-strong);
}
#runBtn:disabled, #runFromPlaceholderBtn:disabled, #shareBtn:disabled {
  opacity: 0.5;
  cursor: default;
}
#previewPlaceholder {
  display: flex;
  flex-direction: column;
  align-items: center;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-soft); }
