:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --panel: #141420;
  --panel-border: #232334;
  --accent: #7c9bff;
  --text: #f1f1f6;
  --muted: #a5a5b5;
  --success: #3ddc97;
  --error: #ff6b6b;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
}

#root {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#top-bar {
  padding: 16px 24px;
  background: #11111a;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#top-bar h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

#top-bar .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

#status-label {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #1c1c2b;
  color: var(--muted);
  border: 1px solid var(--panel-border);
}

#status-label.online {
  color: var(--success);
  border-color: rgba(61, 220, 151, 0.4);
}

#workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 64px);
}

#chat-panel {
  grid-row: 1;
}

#right-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 16px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 16px;
  padding: 6px;
}

.icon-button:hover {
  color: rgba(255, 255, 255, 0.9);
}

.icon-button.copied {
  color: #4ade80;
}

.panel-header-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.panel-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  gap: 12px;
  align-items: center;
}

#chat-form {
  align-items: flex-end;
}

.chat-input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#chat-input {
  width: 100%;
  min-height: 64px;
  max-height: 160px;
  resize: vertical;
  background: #0c0c15;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px;
  border-radius: 8px;
  font-family: inherit;
}

.credit-preview {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
  align-self: flex-end;
  min-height: 16px;
}

.credit-preview.warning {
  color: var(--error);
  opacity: 0.95;
}

#btn-mic {
  margin-right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1em;
  opacity: 0.7;
  padding: 0;
}

#btn-mic.listening {
  color: var(--error);
  opacity: 1;
}

#runCode {
  display: none;
}

#rollbackButton {
  display: none;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: #a1a1aa;
}

#promoteButton {
  display: none;
  background: transparent;
  border: 1px solid rgba(124, 155, 255, 0.4);
  color: #d8e2ff;
}

#rollbackButton:hover {
  border-color: rgba(124, 155, 255, 0.5);
  color: #e2e8f0;
}

#promoteButton:hover {
  border-color: rgba(124, 155, 255, 0.7);
  color: #ffffff;
}

.loading {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  opacity: 0.7;
}

.loading.hidden {
  display: none;
}

.dot {
  animation: fade 1.4s infinite both;
}

.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes fade {
  0% { opacity: 0.2; }
  20% { opacity: 1; }
  100% { opacity: 0.2; }
}

.timer {
  margin-left: 8px;
  font-size: 12px;
  opacity: 0.6;
}

button {
  background: var(--accent);
  border: none;
  color: #0b0b0f;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ghost-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--panel-border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.ghost-button:hover {
  border-color: rgba(124, 155, 255, 0.6);
  color: var(--accent);
}

.interface-status {
  font-size: 12px;
  opacity: 0.7;
  padding: 4px 8px;
}

.preview-status {
  font-size: 12px;
  opacity: 0.7;
  padding: 4px 8px;
  color: var(--muted);
}

.preview-execution-status {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-execution-status.idle {
  color: var(--muted);
  border-color: rgba(165, 165, 181, 0.3);
  background: rgba(165, 165, 181, 0.1);
}

.preview-execution-status.ready {
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.12);
}

.preview-execution-status.preparing {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.12);
}

.preview-execution-status.stale {
  color: #fb7185;
  border-color: rgba(251, 113, 133, 0.4);
  background: rgba(251, 113, 133, 0.12);
}

.preview-execution-status.running {
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.12);
}

.preview-execution-status.capped {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.12);
}

.preview-execution-status.heavy {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.12);
}

.preview-execution-status.stopped {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.12);
}

.preview-execution-status.completed {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.4);
  background: rgba(167, 139, 250, 0.12);
}

.execution-warnings {
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px dashed rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca;
  max-width: 260px;
  line-height: 1.3;
}

.execution-warnings.hidden {
  display: none;
}

.sandbox-controls {
  display: flex;
  gap: 8px;
  margin: 8px 0 12px;
}

.sandbox-controls.hidden {
  display: none;
}

.sandbox-controls .ghost-button {
  padding: 4px 10px;
}

.interface-status.updated {
  color: #4ade80;
}

.interface-status.unchanged {
  color: #a1a1aa;
}

#right-pane {
  position: relative;
}

#right-pane .splitter {
  height: 6px;
  cursor: row-resize;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

#right-pane .splitter:hover {
  background: rgba(255, 255, 255, 0.18);
}

#code-editor-wrapper {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
  font-family: "JetBrains Mono", "SFMono-Regular", Menlo, monospace;
  border-radius: 0 0 12px 12px;
  overflow: hidden;
  background: #07070d;
}

#line-numbers {
  user-select: none;
  pointer-events: none;
  text-align: right;
  padding: 16px 8px;
  color: rgba(255, 255, 255, 0.25);
  background: transparent;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  line-height: 1.5;
  font-size: 13px;
  white-space: pre;
  overflow: hidden;
}

#code-editor {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 16px 16px 16px 8px;
  font-family: "JetBrains Mono", "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  border-radius: 0;
  outline: none;
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.panel-footer.actions {
  justify-content: flex-end;
}

#code-footer {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-right: auto;
}

.code-editor,
.output-panel {
  flex: 1 1 50%;
  min-height: 0;
  overflow: hidden;
}

.console-output {
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
  cursor: zoom-in;
}

.console-output.preview-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: #000;
  display: flex;
  cursor: zoom-out;
}

.output-panel.preview-fullscreen #fullscreenToggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000000;
}

.fullscreen-exit {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #555;
}

.output-panel {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.output-panel .panel-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.console-output-log {
  overflow: auto;
  max-height: 40%;
}

.console-output iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.preview-frame-container {
  width: 100%;
  height: 100%;
  display: flex;
}

.preview-frame-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.output-panel iframe {
  flex: 1 1 auto;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.output-panel.loading iframe {
  opacity: 0;
  transform: scale(0.98);
}

.generation-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: #10101a;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.generation-indicator.active {
  color: var(--text);
  border-color: rgba(124, 155, 255, 0.6);
  background: rgba(124, 155, 255, 0.12);
}

.message {
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  position: relative;
}

.message.user {
  background: rgba(124, 155, 255, 0.2);
  border: 1px solid rgba(124, 155, 255, 0.4);
}

.message.assistant {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.message.assistant.thinking {
  opacity: 0.45;
  font-style: italic;
  transition: opacity 0.2s ease;
}

.message .assistant-meta {
  margin-top: 8px;
  font-size: 12px;
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.message .assistant-aside {
  font-style: italic;
  opacity: 0.7;
}

.message em {
  opacity: 0.6;
  font-style: italic;
}

.tts-btn {
  background: none;
  border: none;
  color: #9aa4ff;
  cursor: pointer;
  font-size: 0.85em;
  padding: 0;
}

.tts-btn:hover {
  opacity: 1;
}

.chat-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: none;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  cursor: pointer;
  color: white;
}

.chat-copy-btn.copied {
  background: rgba(34, 197, 94, 0.9);
}

@media (hover: hover) {
  .chat-copy-btn {
    opacity: 0;
  }

  .message:hover .chat-copy-btn {
    opacity: 1;
  }
}

@media (hover: none) {
  .chat-copy-btn {
    opacity: 0.9;
  }
}

.message.system {
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--error);
}

.output-line {
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: #0c0c15;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-family: "JetBrains Mono", "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
}

.output-line.error {
  color: var(--error);
  border-color: rgba(255, 107, 107, 0.3);
}

.output-line.success {
  color: var(--success);
  border-color: rgba(61, 220, 151, 0.3);
}

@media (max-width: 1000px) {
  #workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  #chat-panel {
    grid-row: auto;
  }
}
