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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0a0a0f;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========== Login View ========== */

#login-view {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 100vh;
}

.login-container {
  width: 100%;
  max-width: 380px;
  padding: 0 24px;
}

.login-card {
  background: #111118;
  border: 1px solid #1e1e2e;
  border-radius: 12px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.login-card h1 { font-size: 22px; color: #c4b5fd; font-weight: 700; }

.login-subtitle { font-size: 13px; color: #666; }

/* GitHub Login Button */
.github-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  background: #24292e;
  color: white;
  border: 1px solid #444;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}

.github-btn:hover { background: #2f363d; }
.github-btn svg { flex-shrink: 0; }

#logout-btn {
  padding: 8px 16px;
  background: transparent;
  color: #888;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

#logout-btn:hover { border-color: #ef4444; color: #ef4444; }

/* ========== Sessions View ========== */

#sessions-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 32px 24px;
  overflow-y: auto;
}

.sessions-container {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.sessions-header h1 { font-size: 22px; color: #c4b5fd; font-weight: 700; }

#new-session-toggle {
  padding: 8px 16px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

#new-session-toggle:hover { background: #4f46e5; }

/* ========== User Info ========== */

#user-info {
  display: none;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #333;
}

#user-name {
  font-size: 13px;
  color: #aaa;
}

/* ========== Searchable Select ========== */

.searchable-select {
  position: relative;
  width: 100%;
}

.ss-trigger {
  display: flex;
  align-items: center;
  background: #1a1a2e;
  border: 1px solid #2e2e4e;
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.ss-trigger:focus-within { border-color: #6366f1; }

.ss-search {
  flex: 1;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: #e0e0e0;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.ss-search::placeholder { color: #555; }
.ss-search:disabled { color: #444; cursor: not-allowed; }

.ss-arrow {
  padding: 0 12px;
  color: #555;
  font-size: 12px;
  flex-shrink: 0;
}

.ss-clear {
  padding: 0 8px;
  color: #888;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.ss-clear:hover { color: #ef4444; }

.ss-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #1a1a2e;
  border: 1px solid #2e2e4e;
  border-radius: 8px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.ss-dropdown.open { display: block; }

.ss-dropdown::-webkit-scrollbar { width: 6px; }
.ss-dropdown::-webkit-scrollbar-track { background: transparent; }
.ss-dropdown::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.ss-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #e0e0e0;
  border-bottom: 1px solid #151525;
}

.ss-item:last-child { border-bottom: none; }
.ss-item:hover, .ss-item.highlighted { background: #252540; }
.ss-item.selected { background: #6366f1; color: white; }

.ss-loading, .ss-empty {
  padding: 16px;
  text-align: center;
  color: #555;
  font-size: 13px;
}

.ss-loading .spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #333;
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

/* Repo item custom rendering */
.repo-item strong { display: block; }
.repo-desc { font-size: 12px; color: #666; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo-lock { font-size: 12px; }

/* ========== Create Form ========== */

.create-card {
  background: #111118;
  border: 1px solid #1e1e2e;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.create-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn-secondary {
  padding: 10px 16px;
  background: transparent;
  color: #888;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.btn-secondary:hover { border-color: #666; color: #ccc; }

/* ========== Session Cards ========== */

.session-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #111118;
  border: 1px solid #1e1e2e;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.session-card:hover { border-color: #333; }

.session-info { flex: 1; min-width: 0; }

.session-repo {
  font-size: 15px;
  font-weight: 600;
  color: #e0e0e0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 12px;
  color: #666;
}

.session-branch {
  background: #1a1a2e;
  padding: 2px 8px;
  border-radius: 4px;
  color: #888;
}

.session-status {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
}

.session-status.running { background: #0a2e1a; color: #22c55e; }
.session-status.completed { background: #1a0f2e; color: #a78bfa; }
.session-status.error { background: #2e0f0f; color: #ef4444; }
.session-status.stopped { background: #1e1e2e; color: #666; }

.session-id {
  font-size: 11px;
  color: #444;
  margin-top: 4px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.session-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 16px;
}

.btn-enter {
  padding: 6px 14px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.btn-enter:hover { background: #4f46e5; }

.btn-delete {
  padding: 6px 14px;
  background: transparent;
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.btn-delete:hover { background: #ef4444; color: white; }

.sessions-loading, .sessions-empty {
  text-align: center;
  color: #555;
  padding: 40px;
  font-size: 14px;
}

/* ========== Form Styles (shared) ========== */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label { font-size: 13px; color: #888; }

.form-group input {
  padding: 10px 14px;
  background: #1a1a2e;
  border: 1px solid #2e2e4e;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.form-group input:focus { border-color: #6366f1; }
.form-group input::placeholder { color: #555; }

#start-btn {
  padding: 12px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#start-btn:hover { background: #4f46e5; }
#start-btn:disabled { background: #333; cursor: not-allowed; color: #666; }

#landing-error { color: #ef4444; font-size: 13px; display: none; }

/* ========== Streaming View ========== */

#streaming-view {
  display: none;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ========== Preview Panel ========== */

#preview-panel {
  display: none;
  flex-direction: column;
  width: 50%;
  min-width: 320px;
  border-left: 1px solid #1e1e2e;
  background: #0a0a0f;
}

#streaming-view.with-preview #preview-panel {
  display: flex;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: #111118;
  border-bottom: 1px solid #1e1e2e;
  min-height: 40px;
}

.preview-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
}

.preview-tab {
  padding: 8px 14px;
  font-size: 12px;
  color: #888;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.preview-tab:hover { color: #c4b5fd; }
.preview-tab.active { color: #c4b5fd; border-bottom-color: #6366f1; }

#preview-close-btn {
  padding: 4px 8px;
  background: transparent;
  border: none;
  color: #666;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

#preview-close-btn:hover { color: #ef4444; }

#preview-iframe {
  flex: 1;
  border: none;
  background: #fff;
}

/* ========== Streaming Header ========== */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #111118;
  border-bottom: 1px solid #1e1e2e;
}

header h1 { font-size: 16px; font-weight: 600; color: #c4b5fd; }
#session-label { font-size: 12px; color: #666; font-weight: 400; margin-left: 8px; }

#status {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
}

#status.connected .dot { background: #22c55e; }

/* ========== Chat Output ========== */

#output {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#output::-webkit-scrollbar { width: 6px; }
#output::-webkit-scrollbar-track { background: transparent; }
#output::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* ========== Message Types ========== */

.msg {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant { background: #1a1a2e; border-left: 3px solid #c4b5fd; }

.msg.tool_use {
  background: #0f1a2e;
  border-left: 3px solid #38bdf8;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 13px;
}

.msg.tool_use .label {
  color: #38bdf8;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.msg.tool_result {
  background: #0f1a1a;
  border-left: 3px solid #2dd4bf;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 13px;
}

.msg.result { background: #1a0f2e; border-left: 3px solid #a78bfa; }
.msg.result .meta { margin-top: 6px; font-size: 12px; color: #888; }

.msg.system { background: #1e1e2e; border-left: 3px solid #6366f1; font-size: 12px; color: #aaa; }

.msg.error { background: #2e0f0f; border-left: 3px solid #ef4444; color: #fca5a5; }

.msg.health_check {
  border-left: 3px solid #f59e0b;
  background: #1a1708;
  color: #fbbf24;
  font-size: 12px;
  padding: 8px 14px;
}

.msg.health_check.recovered {
  border-left-color: #22c55e;
  background: #0f1a14;
  color: #86efac;
}

.msg.user-prompt {
  background: #1e1e2e;
  border-left: 3px solid #f59e0b;
  color: #fbbf24;
  align-self: flex-end;
  max-width: 80%;
}

.msg.setup_log {
  background: #0d1117;
  border-left: 3px solid #f59e0b;
  font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  font-size: 12px;
  color: #d4d4d4;
  padding: 6px 14px;
}

.msg.setup_log .step-icon { margin-right: 6px; }

.msg.history_complete {
  background: transparent;
  border: 1px dashed #333;
  color: #555;
  text-align: center;
  font-size: 12px;
}

.msg.tool_output {
  background: #0d1117;
  border-left: 3px solid #58a6ff;
  padding: 0;
  font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  font-size: 12px;
}

.msg.tool_output .tool-label {
  background: #161b22;
  padding: 6px 12px;
  font-size: 11px;
  color: #58a6ff;
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid #21262d;
}

.msg.tool_output .terminal {
  padding: 10px 14px;
  color: #c9d1d9;
  white-space: pre;
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.4;
}

.msg.tool_output .truncated {
  padding: 6px 12px;
  color: #8b949e;
  font-size: 11px;
  border-top: 1px solid #21262d;
}

/* ========== Setup Group ========== */

.setup-group {
  background: #111118;
  border: 1px solid #1e1e2e;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 4px;
}

.setup-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: #f59e0b;
  font-weight: 600;
}

.setup-group-header .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #333;
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.setup-group-header.done .spinner { display: none; }

.setup-group-header.done::before {
  content: '\2713';
  color: #22c55e;
  font-size: 14px;
  font-weight: bold;
}

.setup-group-lines {
  padding: 0 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setup-line {
  font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  font-size: 12px;
  color: #8b949e;
  line-height: 1.5;
}

.setup-line.highlight { color: #22c55e; }
.setup-line.warn { color: #f59e0b; }
.setup-line.error { color: #ef4444; }

/* ========== Compacting Banner ========== */

#compacting-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: #1a1a2e;
  border-bottom: 1px solid #2e2e4e;
  font-size: 12px;
  color: #a78bfa;
}

#compacting-banner .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #333;
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ========== Progress Badge ========== */

.progress-badge {
  font-size: 11px;
  color: #8b949e;
  font-weight: 400;
  margin-left: 8px;
}

.progress-badge.active {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ========== Input Area ========== */

#input-area {
  padding: 12px 20px;
  background: #111118;
  border-top: 1px solid #1e1e2e;
  display: flex;
  gap: 10px;
}

#prompt-input {
  flex: 1;
  padding: 10px 14px;
  background: #1a1a2e;
  border: 1px solid #2e2e4e;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
}

#prompt-input:focus { border-color: #6366f1; }
#prompt-input::placeholder { color: #555; }

#send-btn {
  padding: 10px 20px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#send-btn:hover { background: #4f46e5; }
#send-btn:disabled { background: #333; cursor: not-allowed; color: #666; }

/* ========== Session Controls ========== */

#stop-session-btn {
  padding: 6px 12px;
  background: transparent;
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: none;
}

#stop-session-btn:hover { background: #ef4444; color: white; }
#stop-session-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#new-session-btn {
  padding: 6px 12px;
  background: transparent;
  color: #888;
  border: 1px solid #333;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

#new-session-btn:hover { border-color: #ef4444; color: #ef4444; }

/* ========== Animations ========== */

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
