@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c26;
  --border: #2a2a38;
  --text: #f0f0f8;
  --muted: #6b6b85;
  --accent: #6c63ff;
  --accent-dim: rgba(108,99,255,0.15);
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Layout ── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 100;
}

.logo { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }
.logo span { color: var(--accent); }

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

.main { flex: 1; max-width: 860px; margin: 0 auto; width: 100%; padding: 40px 24px; }

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #7c75ff; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.1); }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 14px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 15px; width: 100%;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="password"] { letter-spacing: 2px; }
textarea { resize: vertical; min-height: 120px; }
select option { background: var(--surface2); }
.hint { font-size: 12px; color: var(--muted); }

/* ── Setup screen ── */
.setup-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px;
  max-width: 520px; margin: 60px auto;
}
.setup-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.setup-card p { color: var(--muted); margin-bottom: 32px; }
.setup-fields { display: flex; flex-direction: column; gap: 20px; }
.setup-footer { margin-top: 28px; display: flex; justify-content: flex-end; }

/* ── Prompt screen ── */
.prompt-heading { margin-bottom: 32px; }
.prompt-heading h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }
.prompt-heading p { color: var(--muted); margin-top: 6px; }

.prompt-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  margin-bottom: 28px;
}
.prompt-box textarea {
  background: transparent; border: none; padding: 0;
  font-size: 17px; line-height: 1.7; min-height: 160px;
  resize: none;
}
.prompt-box textarea:focus { outline: none; }
.prompt-box textarea::placeholder { color: var(--muted); }

.prompt-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
}
.model-row { display: flex; align-items: center; gap: 10px; }
.model-row select { width: auto; font-size: 13px; padding: 6px 10px; }

/* ── Recent builds ── */
.recent-label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.build-list { display: flex; flex-direction: column; gap: 8px; }
.build-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.build-item-text { flex: 1; min-width: 0; }
.build-item-prompt {
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.build-item-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.build-item-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: 12px; }

/* ── Briefing screen ── */
.briefing-header { margin-bottom: 32px; }
.briefing-header h2 { font-size: 22px; font-weight: 700; }
.briefing-header p { color: var(--muted); margin-top: 4px; }

.briefing-cards { display: flex; flex-direction: column; gap: 20px; margin-bottom: 32px; }

.brief-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: border-color 0.2s;
}
.brief-card.loading { border-color: var(--accent); }
.brief-card.done { border-color: var(--border); }

.brief-card-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.brief-card-icon { font-size: 20px; }
.brief-card-title { font-weight: 600; font-size: 15px; }
.brief-card-subtitle { font-size: 12px; color: var(--muted); }
.brief-card-status { margin-left: auto; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); display: inline-block;
}
.status-dot.spinning {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.status-dot.done { background: var(--green); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.brief-card-body { padding: 20px; }
.brief-card-body.empty { min-height: 80px; display: flex; align-items: center; }
.waiting-text { color: var(--muted); font-size: 14px; }

/* Markdown content inside brief cards */
.brief-content h2 {
  font-size: 14px; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 20px 0 8px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.brief-content h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.brief-content p { font-size: 14px; line-height: 1.7; margin-bottom: 10px; color: #d0d0e0; }
.brief-content strong { color: var(--text); }
.brief-content ul, .brief-content ol { padding-left: 20px; margin-bottom: 10px; }
.brief-content li { font-size: 14px; line-height: 1.7; color: #d0d0e0; margin-bottom: 4px; }

/* Confidence badge */
.confidence-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: 600;
  margin-top: 12px;
}
.confidence-ready { background: rgba(34,197,94,0.15); color: var(--green); }
.confidence-minor { background: rgba(245,158,11,0.15); color: var(--amber); }
.confidence-rethink { background: rgba(239,68,68,0.15); color: var(--red); }

.briefing-actions {
  display: flex; gap: 12px; align-items: center;
  padding: 20px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.briefing-actions-text { flex: 1; }
.briefing-actions-text strong { display: block; }
.briefing-actions-text span { font-size: 13px; color: var(--muted); }

/* ── Building screen ── */
.building-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; text-align: center; gap: 20px;
}
.building-spinner {
  width: 56px; height: 56px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.building-screen h2 { font-size: 20px; font-weight: 600; }
.building-screen p { color: var(--muted); font-size: 14px; }

/* ── Result screen ── */
.result-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.result-header h2 { font-size: 20px; font-weight: 600; flex: 1; }

.preview-frame {
  width: 100%; height: 600px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; overflow: hidden;
}

.result-toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-top: 16px; flex-wrap: wrap;
}
.url-display {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 14px;
  font-size: 13px; color: var(--muted); font-family: monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Settings panel (slide-in) ── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 200; display: none;
}
.overlay.open { display: block; }
.settings-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: 420px;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 201; transform: translateX(100%);
  transition: transform 0.25s ease; overflow-y: auto; padding: 28px;
  display: flex; flex-direction: column; gap: 20px;
}
.settings-panel.open { transform: translateX(0); }
.settings-panel h3 { font-size: 17px; font-weight: 600; }
.panel-close { position: absolute; top: 20px; right: 20px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  padding: 12px 20px; border-radius: var(--radius-sm);
  font-size: 14px; z-index: 300; opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.toast.show { opacity: 1; }
.toast.error { border-color: var(--red); color: var(--red); }

/* ── Improve box ── */
.improve-box {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.improve-label {
  font-size: 13px; font-weight: 500; color: var(--muted);
  margin-bottom: 12px;
}
.improve-row {
  display: flex; gap: 12px; align-items: flex-start;
}
.improve-row textarea {
  flex: 1; min-height: 64px; resize: vertical; font-size: 14px;
}
.improve-row .btn { flex-shrink: 0; align-self: flex-end; }

/* ── Responsive ── */
@media (max-width: 600px) {
  .main { padding: 24px 16px; }
  .setup-card { padding: 24px; margin: 24px auto; }
  .settings-panel { width: 100%; }
  .preview-frame { height: 400px; }
  .briefing-actions { flex-direction: column; align-items: stretch; }
}

/* ── Project type toggle ── */
.type-toggle {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.type-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.type-btn:hover {
  border-color: var(--muted);
  color: var(--text);
}

.type-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.type-badge {
  font-size: 11px;
  font-weight: 400;
  color: inherit;
  opacity: 0.7;
}

/* ── Build progress bar ── */
.build-progress-bar {
  width: 280px;
  max-width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.build-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ── Build stages list ── */
.build-stages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  text-align: left;
  min-width: 200px;
}

.build-stage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.build-stage-item.done {
  color: var(--green);
}

.build-stage-item.active {
  color: var(--text);
}

.stage-icon {
  width: 16px;
  text-align: center;
  font-size: 12px;
  flex-shrink: 0;
}

.stage-icon.spinning {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}
