:root {
  --bg-color: #1e1e1e;
  --bg-color-light: #2a2a2a;
  --bg-color-lighter: #3c3c3c;
  --text-color: #d4d4d4;
  --primary-color: #118c38;
  --primary-color-hover: #096633;
  --accent-yellow: #dedb00;
  --accent-dark: #02293d;
  --accent-strong: #096633;
  --border-color: #4a4a4a;
  --error-color: #f44747;
  --success-color: #4caf50;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --focus-ring-color: #dedb00;
}

/* Hidden attribute support */
[hidden] {
  display: none !important;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* --- Toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background-color: var(--bg-color-light);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 16px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-group-right {
  margin-left: auto;
}

.mode-switcher,
.tab-switcher {
  display: flex;
  align-items: center;
  background-color: var(--bg-color);
  border-radius: 6px;
  padding: 4px;
}

/* Mode dropdown styles */
#mode-select {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
}

/* Mode icon badge next to the mode select */
.mode-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 14px;
  line-height: 1;
  user-select: none;
}

/* Subtle color hint per mode */
.mode-icon[data-mode="web"] { color: #4fc3f7; }
.mode-icon[data-mode="pascal"] { color: #ff7043; }
.mode-icon[data-mode="python"] { color: #ffd43b; }
.mode-icon[data-mode="nodejs"] { color: #21a366; }
.mode-icon[data-mode="nodets"] { color: #3178c6; }

.btn {
  background-color: var(--bg-color-lighter);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s, color 0.2s;
}

.btn:hover {
  background-color: #4f4f4f;
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring-color);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-mode,
.btn-tab {
  background: none;
  border: none;
  color: var(--text-color);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.btn-mode.active,
.btn-tab.active {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background-color: var(--primary-color-hover);
}

/* Prominent Run button */
#btn-run {
  background-color: #1fbf75; /* lighter, brighter green */
  border-color: #1fbf75;
  color: #0c1f14; /* dark text for contrast on light bg */
  font-size: 16px;
  font-weight: 600;
  padding: 8px 16px;
}

#btn-run:hover {
  background-color: #18a563;
  border-color: #18a563;
}

#btn-run svg {
  width: 20px;
  height: 20px;
}

#learner-notes {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px;
  font-family: inherit;
  font-size: 13px;
  height: 34px;
  width: 400px;
  resize: none;
}

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

.api-settings input {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  width: 100%;
}

#model-name {
  width: 100%;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.btn-icon {
  padding: 6px;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  box-sizing: border-box;
}

.modal-content {
  background-color: var(--bg-color-light);
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 300px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background-color 0.2s, color 0.2s;
}

.modal-close:hover {
  background-color: var(--bg-color);
  color: var(--error-color);
}

/* Dependencies Modal Styles */
.modal-description {
  color: var(--text-color);
  opacity: 0.8;
  font-size: 14px;
  margin-bottom: 8px;
}

/* Utility classes extracted from previous inline styles */
.token-usage-graph-box {
  height: 120px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(0, 0, 0, 0.02));
}

.flex-spread-center {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.text-right {
  text-align: right;
}

.dependency-section {
  margin-bottom: 20px;
}

.dependency-section h3 {
  color: var(--text-color);
  margin-bottom: 8px;
  font-size: 16px;
}

.quick-add-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.dependency-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.dependency-input-group input[type="url"] {
  flex: 1;
  padding: 8px 12px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-color);
  font-size: 14px;
}

.dependency-input-group input[type="url"]:focus {
  outline: none;
  border-color: var(--primary-color);
  /* subtle focus ring using primary with reduced alpha */
  box-shadow: 0 0 0 2px rgba(17, 140, 56, 0.14);
}

.dependencies-list {
  list-style: none;
  padding: 0;
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-color);
}

.dependencies-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
}

.dependencies-list li:last-child {
  border-bottom: none;
}

.dependency-url {
  flex: 1;
  color: var(--text-color);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.dependency-remove {
  background: none;
  border: none;
  color: var(--error-color);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  margin-left: 8px;
}

.dependency-remove:hover {
  background-color: var(--error-color);
  color: white;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.btn-secondary {
  background-color: var(--bg-color-lighter);
  color: var(--text-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

/* === Settings Modal Specific Styles === */
#settings-modal .modal-content {
  /* increased width by 50%: was min-width 480px / max-width 600px */
  min-width: 720px;
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
}

#settings-modal h2 {
  color: var(--text-color);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 12px;
}

.settings-section {
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.settings-section h3 {
  color: var(--primary-color);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-section h3::before {
  content: "⚙️";
  font-size: 1rem;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-group label {
  display: block;
  color: var(--text-color);
  font-weight: 500;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

/* Flex variant for inline toggle style labels */
.flex-inline-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.setting-group input[type="password"],
.setting-group input[type="text"],
.setting-group input[type="url"],
.setting-group input[type="file"],
.setting-group select {
  width: 100%;
  background-color: var(--bg-color-lighter);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.setting-group input[type="password"]:focus,
.setting-group input[type="text"]:focus,
.setting-group input[type="url"]:focus,
.setting-group input[type="file"]:focus,
.setting-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(17, 140, 56, 0.08);
}

.setting-group input[type="password"]::placeholder,
.setting-group input[type="text"]::placeholder,
.setting-group input[type="url"]::placeholder {
  color: #888;
  opacity: 0.8;
}

.file-input-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-input-label {
  display: block;
  background-color: var(--bg-color-lighter);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.file-input-wrapper:hover .file-input-label {
  background-color: var(--bg-color);
  border-color: var(--primary-color);
}

.setting-description {
  display: block;
  color: #888;
  font-size: 0.85rem;
  margin-top: 6px;
  line-height: 1.4;
}

.setting-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.setting-actions .btn {
  flex: 1;
  justify-content: center;
  min-width: 80px;
}

.starters-status {
  padding: 12px;
  border-radius: 6px;
  background-color: var(--bg-color-lighter);
  border: 1px solid var(--border-color);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}

.status-indicator::before {
  content: "●";
  font-size: 1.2rem;
}

.status-indicator.default::before {
  color: var(--primary-color);
}

.status-indicator.custom::before {
  color: var(--success-color);
}

.status-indicator.error::before {
  color: var(--error-color);
}

/* Settings modal responsive adjustments */
@media (max-width: 640px) {
  #settings-modal .modal-content {
    min-width: 90vw;
    margin: 20px;
  }

  .setting-actions {
    flex-direction: column;
  }

  .setting-actions .btn {
    flex: none;
  }
}

/* --- Main Layout --- */
.main-container {
  display: flex;
  flex-grow: 1;
  overflow: hidden;
}

.editor-pane {
  flex: 1;
  min-width: 200px;
}

.resizer {
  width: 8px;
  background-color: var(--bg-color-light);
  cursor: col-resize;
  flex-shrink: 0;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

.resizer:hover {
  background-color: var(--primary-color);
}

.panel-container {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-color-light);
  height: 100%;
  min-height: 0; /* Allow flex item to shrink */
}

/* --- Panels --- */
.panel-tabs {
  display: flex;
  background-color: var(--bg-color);
  padding: 4px 8px 0;
  gap: 4px;
}

.panel-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-color);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

.panel-tab-btn.active {
  border-bottom-color: var(--primary-color);
  color: white;
}

.panel {
  display: none;
  flex-grow: 1;
  overflow-y: auto;
  padding: 16px;
  background-color: var(--bg-color-light);
}

.panel.active {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  height: 100%;
  min-height: 0; /* Allow flex item to shrink */
}

/* Files Panel */
#files-panel .files-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-color-light);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  min-height: 0;
}
#files-panel .files-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg-color-light);
  z-index: 1;
}
#files-panel .files-title { font-weight: 600; font-size: 13px; opacity: 0.9; }
#files-panel .file-tree {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow: auto;
  flex: 1 1 auto;
}
#files-panel .file-tree li { margin: 2px 0; }
#files-panel .file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
#files-panel .file-item:hover { background: var(--bg-color); }
#files-panel .file-item.active { background: var(--primary-color); color: #fff; }
#files-panel .file-item .icon { width: 14px; text-align: center; opacity: 0.85; }
#files-panel .file-folder { font-weight: 600; }

/* Chat Panel */
#chat-panel {
  padding: 0;
  overflow: hidden;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.01), rgba(0, 0, 0, 0));
}
.chat-toolbar .btn {
  font-size: 13px;
  padding: 6px 10px;
}
.chat-toolbar .chat-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Code toggle icon in chat toolbar */
.chat-toolbar-right .toggle-label svg {
  margin-left: 6px;
  display: inline-block;
  vertical-align: middle;
}

/* Screen reader only helper */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.toggle-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text-color);
  font-size: 13px;
}

/* User bubble matching assistant style */
.chat-message.user {
  justify-content: flex-end;
}
.chat-message.user .chat-bubble {
  background: #0f1720;
  color: #e6eef6;
  border-color: #14202a;
  padding: 12px 18px;
  border-radius: 12px;
  max-width: 80%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeIn 0.2s ease;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: #2e2e2e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.chat-bubble {
  width: fit-content;
  max-width: 100%;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.25; /* tighter lines */
  position: relative;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}

.chat-message.assistant .chat-bubble {
  background: #f4f6f8;
  color: #1b2730;
  border-color: #d0d7de;
  flex: 1;
  width: 100%;
  padding: 22px 34px 22px 34px; /* increased padding for breathing room */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
  line-height: 1.25; /* ensure assistant bubble uses tighter lines */
}

/* Dark mode contrast tweak (if body retains dark bg) */
@media (prefers-color-scheme: dark) {
  .chat-message.assistant .chat-bubble {
    background: #e1e7ec;
    color: #12181d;
    border-color: #b8c2ca;
  }
}

.chat-message.user .chat-bubble {
  background: #2d2d2d;
  border-color: #444;
}

.chat-bubble markdown,
.chat-bubble p {
  margin: 0 0 6px;
}
.chat-bubble p:last-child {
  margin-bottom: 0;
}
.chat-bubble pre {
  background: #1e1e1e;
  color: #f5f7fa;
  padding: 10px 14px;
  border-radius: 8px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.3;
  position: relative; /* allow positioning the copy button */
  padding-right: 40px; /* space for copy button */
}
.chat-bubble code {
  background: #272d33;
  color: #f5f7fa;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 12.5px;
}

/* Inline code in assistant bubble (light background) */
.chat-message.assistant .chat-bubble code:not(pre code) {
  background: #e6eaef;
  color: #0f1a22;
}
.chat-message.assistant .chat-bubble pre code {
  background: transparent;
  color: #f5f7fa;
  padding: 0;
}

/* Copy button for code blocks in chat */
.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f7fa;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.copy-code-btn:hover,
.chat-bubble pre:hover .copy-code-btn,
.chat-bubble pre:focus-within .copy-code-btn {
  opacity: 1;
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.28);
}
.copy-code-btn svg { pointer-events: none; }
.copy-code-btn.copied {
  background: #2e7d32;
  border-color: #2e7d32;
  color: #fff;
  opacity: 1;
}

/* Mark/highlight readability */
.chat-bubble mark,
.chat-message.assistant .chat-bubble mark {
  background: #fff3b0;
  color: #222;
  padding: 2px 4px;
  border-radius: 4px;
}

/* Tighten vertical edges */
.chat-message.assistant .chat-bubble > :first-child {
  margin-top: 0;
}
.chat-message.assistant .chat-bubble > :last-child {
  margin-bottom: 0;
}

.chat-input-row {
  padding: 12px 16px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-color-light);
}

/* Typing / thinking indicator */
.chat-bubble.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
}

.typing-dots {
  display: inline-flex;
  gap: 6px;
  height: 14px;
  align-items: flex-end;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: #5da9d9;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
  opacity: 0.7;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Shimmer bar for thinking */
.thinking-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background: linear-gradient(90deg, rgba(0, 150, 255, 0) 0%, rgba(0, 150, 255, 0.6) 50%, rgba(0, 150, 255, 0) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-color);
  line-height: 1.4;
}

.chat-input:focus-visible {
  outline: 2px solid var(--focus-ring-color);
  outline-offset: 2px;
}

.chat-send-ing .dot-typing {
  display: inline-block;
  position: relative;
  width: 46px;
  height: 16px;
}

.dot-typing span {
  position: absolute;
  top: 0;
  width: 8px;
  height: 8px;
  background: #5da9d9;
  border-radius: 50%;
  animation: dotPulse 1.4s infinite ease-in-out;
}

.dot-typing span:nth-child(2) {
  left: 14px;
  animation-delay: 0.2s;
}
.dot-typing span:nth-child(3) {
  left: 28px;
  animation-delay: 0.4s;
}
.dot-typing span:first-child {
  left: 0;
}

@keyframes dotPulse {
  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-meta {
  font-size: 11px;
  opacity: 0.65;
  margin-top: 4px;
}

.included-code {
  font-size: 11px;
  color: #6b7280;
  margin-left: 8px;
}

.chat-error {
  color: var(--error-color);
  font-size: 13px;
}

.chat-message.assistant .chat-bubble .chat-meta {
  color: #7fb7d6;
}
.chat-message.user .chat-bubble .chat-meta {
  color: #888;
}

/* Review panel specific scrolling */
#review-panel {
  padding: 0; /* Remove default padding to let card handle spacing */
  /* Let .panel/.panel.active control display; avoid forcing it visible */
  overflow-y: hidden; /* Avoid double scrollbars; inner content will scroll */
  height: 100%;
  min-height: 0; /* Allow flex item to shrink */
}

#review-panel::-webkit-scrollbar {
  width: 8px;
}

#review-panel::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-radius: 4px;
}

#review-panel::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

#review-panel::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

.panel-toolbar {
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
}

.panel-toolbar .mobile-controls {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.panel-toolbar .select-sm {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-color);
}

.panel-toolbar .btn[aria-pressed="true"] {
  background-color: var(--bg-color);
  border-color: var(--focus-ring-color);
}

#result-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background-color: white;
}

/* Mobile viewport mode for result iframe */
.result-output.mobile-mode {
  align-items: center;
  justify-content: flex-start;
  overflow: auto;
  padding: 8px;
  background: var(--bg-color-lighter);
}

.result-output.mobile-mode { --mobile-scale: 1; }

.result-output.mobile-mode .mobile-viewport {
  width: calc(var(--mobile-w, 390px) * var(--mobile-scale));
  height: calc(var(--mobile-h, 844px) * var(--mobile-scale));
  display: block;
}

.result-output.mobile-mode .mobile-viewport #result-iframe {
  width: var(--mobile-w, 390px);
  height: var(--mobile-h, 844px);
  max-width: none;
  max-height: none;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.25);
  transform: scale(var(--mobile-scale));
  transform-origin: top center;
}

/* Result panel split layout */
.result-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.result-output {
  flex: 1 1 auto;
  min-height: 0; /* allow flex children to shrink and not force parent growth */
  display: flex;
  flex-direction: column;
}

.result-resizer {
  flex: 0 0 6px;
  background-color: var(--bg-color-light);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  cursor: row-resize;
}

.result-console {
  flex: 0 0 200px; /* fixed console height */
  min-height: 0; /* ensure the flexbox can constrain children */
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-color-lighter);
}

.console-header {
  padding: 8px 12px;
  background-color: var(--bg-color-light);
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.console-zoom-controls {
  display: flex;
  gap: 6px;
}

.console-zoom-controls .btn.btn-sm {
  padding: 2px 8px;
}

/* Git terminal toolbar (font controls) */
.git-terminal-toolbar {
  padding: 6px 12px;
  background-color: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

/* Editor zoom controls inside the main toolbar */
.editor-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
}

#result-console-output {
  font-family: "Courier New", Courier, monospace;
  font-size: var(--console-font-size, 13px);
  white-space: pre-wrap;
  word-break: break-all;
  /* fill the console area's height and scroll internally */
  height: 100%;
  box-sizing: border-box;
  padding: 8px;
  overflow-y: auto;
}

#result-console-output .log-error {
  color: var(--error-color);
}
#result-console-output .log-warn {
  color: #f0ad4e;
}
#result-console-output .log-info {
  color: #5bc0de;
}
#result-console-output .log-time {
  color: #888;
  margin-right: 8px;
}

/* --- Review Panel Card --- */
.review-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  color: #212529;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.05);
  margin: 16px;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  max-width: 100%;
  word-wrap: break-word;
  /* Allow the card to fill the review panel and stack header/content/footer */
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.review-card.error-card {
  background: linear-gradient(135deg, #fee 0%, #fdd 100%);
  border-left: 4px solid #dc3545;
}

.review-header {
  background: linear-gradient(135deg, #ffffff 0%, #f1f3f4 100%);
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.review-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a202c;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.025em;
}

.review-icon {
  width: 22px;
  height: 22px;
  color: #059669;
  flex-shrink: 0;
}

.review-icon.error-icon {
  color: #dc3545;
}

.review-timestamp {
  font-size: 0.875rem;
  color: #6b7280;
  font-weight: 500;
  background: rgba(107, 114, 128, 0.1);
  padding: 4px 12px;
  border-radius: 20px;
}

.review-content {
  padding: 24px; /* Extra bottom padding for comfortable scroll end */
  color: #374151;
  font-size: 0.95rem;
  line-height: 1.7;
  /* Let content area take remaining height and be the scroll container */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.review-footer {
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  padding: 16px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: flex-end;
}

.review-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.badge-text {
  background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
  color: #3730a3;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

/* --- Review Content Typography --- */
.review-content h1,
.review-content h2,
.review-content h3,
.review-content h4 {
  color: #1f2937;
  font-weight: 600;
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  line-height: 1.4;
}

.review-content h1 {
  font-size: 1.5rem;
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: 0.5em;
}

.review-content h2 {
  font-size: 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.4em;
}

.review-content h3 {
  font-size: 1.125rem;
  color: #374151;
}

.review-content h4 {
  font-size: 1rem;
  color: #4b5563;
}

.review-content p {
  margin-bottom: 1.25em;
  color: #374151;
}

.review-content strong {
  font-weight: 600;
  color: #1f2937;
}

.review-content em {
  font-style: italic;
  color: #4b5563;
}

.review-content ul,
.review-content ol {
  margin: 1em 0 1.25em 1.5em;
  color: #374151;
}

.review-content li {
  margin-bottom: 0.5em;
  padding-left: 0.25em;
}

.review-content ul li {
  list-style-type: disc;
}

.review-content ol li {
  list-style-type: decimal;
}

.review-content blockquote {
  background: #f9fafb;
  border-left: 4px solid #6366f1;
  padding: 1em 1.5em;
  margin: 1.5em 0;
  border-radius: 0 8px 8px 0;
  color: #4b5563;
  font-style: italic;
}

.review-content code {
  background: #f3f4f6;
  color: #dc2626;
  padding: 0.25em 0.5em;
  border-radius: 4px;
  font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", "Consolas", monospace;
  font-size: 0.875em;
  font-weight: 500;
  border: 1px solid #e5e7eb;
}

/* Override any red text with better visibility - black text on light yellow background */
.review-content *[style*="color: red"],
.review-content *[style*="color:#ff"],
.review-content *[style*="color: #ff"],
.review-content *[style*="color:#red"],
.review-content span[style*="color: red"],
.review-content div[style*="color: red"],
.review-content .error,
.review-content .warning {
  background-color: #fff3cd !important;
  color: #000000 !important;
  padding: 4px 6px !important;
  border-radius: 3px !important;
  font-weight: 500 !important;
}

.review-content pre {
  background: #1f2937;
  color: #f9fafb;
  padding: 1.5em;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.5em 0;
  border: 1px solid #374151;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.review-content pre code {
  background: none;
  color: inherit;
  padding: 0;
  border: none;
  font-size: 0.875rem;
}

.review-content a {
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
}

.review-content a:hover {
  color: #1d4ed8;
  border-bottom-color: #2563eb;
}

.review-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.review-content th,
.review-content td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.review-content th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.review-content td {
  color: #4b5563;
}

.review-content tr:last-child td {
  border-bottom: none;
}

.error-content {
  background: #fee2e2;
  color: #991b1b;
  padding: 1em;
  border-radius: 6px;
  border: 1px solid #fecaca;
  font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", "Consolas", monospace;
  font-size: 0.875rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Loading state for review card */
.review-card.loading {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  opacity: 0.8;
}

.review-card.loading .review-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px; /* Increased to ensure loading text is visible */
  color: #6b7280;
  font-weight: 500;
}

.review-card.loading .review-icon {
  animation: spin 2s linear infinite;
  color: #6366f1;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* --- Legacy Review Panel Markdown (keeping for compatibility) --- */
#review-panel h1,
#review-panel h2,
#review-panel h3 {
  margin-top: 1.2em;
  margin-bottom: 0.6em;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.3em;
}
#review-panel h1 {
  font-size: 1.6em;
}
#review-panel h2 {
  font-size: 1.4em;
}
#review-panel h3 {
  font-size: 1.2em;
}
#review-panel p {
  line-height: 1.6;
  margin-bottom: 1em;
}
#review-panel ul,
#review-panel ol {
  margin-left: 20px;
  margin-bottom: 1em;
}
#review-panel li {
  margin-bottom: 0.5em;
}
#review-panel a {
  color: #4aa3ff;
  text-decoration: none;
}
#review-panel a:hover {
  text-decoration: underline;
}
#review-panel code {
  background-color: var(--bg-color);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
}
#review-panel pre {
  background-color: var(--bg-color);
  padding: 1em;
  border-radius: 6px;
  overflow-x: auto;
}
#review-panel pre code {
  padding: 0;
  background: none;
}
#review-panel blockquote {
  border-left: 4px solid var(--border-color);
  padding-left: 1em;
  margin-left: 0;
  color: #aaa;
}
#review-panel table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}
#review-panel th,
#review-panel td {
  border: 1px solid var(--border-color);
  padding: 8px;
}
#review-panel th {
  background: var(--bg-color);
}

/* --- Utils --- */
.info-note {
  padding: 16px;
  background-color: var(--bg-color);
  border-radius: 6px;
  text-align: center;
}

.spinner {
  border: 2px solid rgba(107, 114, 128, 0.3);
  border-radius: 50%;
  border-top: 2px solid #6366f1;
  width: 16px;
  height: 16px;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}

/* Dark theme spinner for toolbar */
.btn .spinner {
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  width: 14px;
  height: 14px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
}

.toast {
  background-color: var(--bg-color-lighter);
  color: var(--text-color);
  padding: 12px 20px;
  border-radius: 6px;
  margin-top: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  transform: translateY(20px);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background-color: var(--success-color);
  color: white;
}

.toast.error {
  background-color: var(--error-color);
  color: white;
}

/* --- Git Terminal Panel --- */
#git-panel {
  padding: 0;
}

.git-terminal {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.git-terminal-output {
  flex: 1;
  background: #0e0e0e;
  color: #e5e5e5;
  font-family: "SF Mono", "Menlo", "Monaco", Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: var(--terminal-font-size, 13px);
  line-height: 1.5;
  padding: 12px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.git-terminal-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-color);
}

.git-terminal-prompt {
  color: #22c55e;
  font-weight: 600;
  font-family: "SF Mono", monospace;
}

.git-terminal-input {
  flex: 1;
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

.git-line {
  display: block;
  padding: 2px 0;
}

.git-line.info {
  color: #93c5fd;
}
.git-line.success {
  color: #86efac;
}
.git-line.warn {
  color: #fde68a;
}
.git-line.error {
  color: #fca5a5;
}

.git-cmd {
  color: #60a5fa;
}
.git-time {
  color: #9ca3af;
  margin-right: 8px;
}

/* === Help Panel Styles === */
.help-content {
  padding: 16px;
  line-height: 1.6;
  overflow-y: auto;
  height: 100%;
}

/* Show AI Assistant only on the Review tab */
.help-content.ai-assistant {
  display: none;
}
#review-panel .help-content.ai-assistant {
  display: block;
}

.help-content details {
  background: var(--bg-color-light);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.help-content summary {
  padding: 16px;
  cursor: pointer;
  background: var(--bg-color-lighter);
  border-bottom: 1px solid var(--border-color);
  font-size: 1.1em;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 0.2s;
}

.help-content summary:hover {
  background: var(--bg-color);
}

.help-content details[open] summary {
  border-bottom: 1px solid var(--border-color);
}

.help-section {
  padding: 20px;
}

.help-intro,
.prerequisites,
.workflow-steps,
.important-notes {
  margin-bottom: 24px;
}

.help-content h4 {
  color: var(--primary-color);
  margin-bottom: 12px;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-content h5 {
  color: var(--text-color);
  margin-bottom: 8px;
  font-size: 1em;
  font-weight: 600;
}

.help-content h6 {
  color: var(--text-color);
  margin-bottom: 6px;
  font-size: 0.95em;
  font-weight: 500;
}

.info-box,
.warning-box,
.note-box {
  padding: 16px;
  border-radius: 6px;
  margin: 12px 0;
  border-left: 4px solid;
}

.info-box {
  background: rgba(59, 130, 246, 0.1);
  border-left-color: #3b82f6;
}

.warning-box {
  background: rgba(245, 158, 11, 0.1);
  border-left-color: #f59e0b;
}

.note-box {
  background: rgba(34, 197, 94, 0.1);
  border-left-color: #22c55e;
}

.step {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

.option {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-color-light);
  border-radius: 4px;
  border-left: 3px solid var(--primary-color);
}

.code-block {
  margin: 12px 0;
}

.code-block pre {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 12px;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 0.9em;
  overflow-x: auto;
  line-height: 1.4;
}

.code-block code {
  color: #e2e8f0;
}

.help-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.help-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.help-content li {
  margin: 4px 0;
}

.help-content li ul {
  margin-top: 4px;
  margin-bottom: 8px;
}

.help-content code {
  background: var(--bg-color-lighter);
  color: #fbbf24;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 0.9em;
}

.help-content p {
  margin: 8px 0;
}

.help-content strong {
  color: var(--primary-color-hover);
  font-weight: 600;
}

.help-content em {
  color: #94a3b8;
  font-style: italic;
}

/* === Review Panel Styles === */
.review-placeholder {
  padding: 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.review-features .help-content ul {
  margin-left: 0;
}

.review-features .help-content li ul {
  margin-left: 16px;
}

/* AI Review Highlighting Improvements */
.review-content mark,
.review-content .highlight,
.review-content .highlighted {
  background-color: #fff3cd !important;
  color: #000000 !important;
  padding: 4px 6px;
  border-radius: 3px;
  font-weight: 500;
}

/* Text selection in review area */
.review-content ::selection {
  background-color: #fff3cd;
  color: #000000;
}

/* Target red text specifically - make it black text on light yellow background */
.review-content *[style*="color: red"],
.review-content *[style*="color:#ff"],
.review-content *[style*="color: #ff"],
.review-content *[style*="color:#red"],
.review-content .error,
.review-content .error-text,
.review-content .warning,
.review-content .issue-text {
  background-color: #fff3cd !important;
  color: #000000 !important;
  padding: 4px 6px !important;
  border-radius: 3px !important;
  font-weight: 500 !important;
}

/* Starter controls */
.starter-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.starter-controls select {
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 10px;
}
