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

:root {
  --bg: #0a0a0c;
  --surface: #131316;
  --surface2: #1a1a1f;
  --border: #2a2a30;
  --text: #e4e4e7;
  --text-dim: #71717a;
  --accent: #6d5aff;
  --accent-hover: #7f6eff;
  --radius: 10px;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top bar ── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 16px;
  flex-shrink: 0;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.settings {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.key-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 13px;
  width: 240px;
  outline: none;
  transition: border-color .15s;
}
.key-field input:focus { border-color: var(--accent); }

#model {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

/* ── Workspace ── */
#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Chat panel ── */
#chat-panel {
  display: flex;
  flex-direction: column;
  width: 420px;
  min-width: 320px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

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

.msg {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px;
}

.msg.error {
  align-self: center;
  background: #2d1215;
  border: 1px solid #5c1a1f;
  color: #f87171;
  font-size: 12.5px;
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.3} 40%{opacity:1} }

.msg.streaming {
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  background: #0f0f12;
  border-color: #1e1e25;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--accent);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: cursor-blink .6s step-end infinite;
}
@keyframes cursor-blink { 0%,100%{opacity:1} 50%{opacity:0} }

#input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

#promptInput {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color .15s;
}
#promptInput:focus { border-color: var(--accent); }

#sendBtn {
  width: 38px; height: 38px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
#sendBtn:hover { background: var(--accent-hover); }
#sendBtn:disabled { opacity: .4; cursor: default; }

/* ── Preview panel ── */
#preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.preview-actions { display: flex; gap: 6px; }

.preview-actions button {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}
.preview-actions button:hover { background: var(--border); }

#preview-scroll {
  flex: 1;
  overflow: hidden;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
  padding: 40px;
  gap: 12px;
}
.empty-state h3 { font-size: 15px; color: var(--text); font-weight: 600; }
.empty-state p { font-size: 13px; line-height: 1.6; max-width: 340px; }
.empty-state .hints {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.empty-state .hint {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color .15s;
}
.empty-state .hint:hover { border-color: var(--accent); color: var(--text); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Responsive ── */
@media (max-width: 768px) {
  #workspace { flex-direction: column; }
  #chat-panel { width: 100%; height: 45%; border-right: none; border-bottom: 1px solid var(--border); }
  .key-field input { width: 140px; }
}
