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

/* ─── Tokens ─────────────────────────────────────────────────── */
:root {
  --bg:          #0a0a0a;
  --bg-card:     #111111;
  --bg-card-alt: #161616;
  --border:      #1e1e1e;
  --border-mid:  #2a2a2a;
  --text:        #e8e8e8;
  --text-muted:  #666;
  --text-dim:    #444;
  --accent:      #5b8def;
  --accent-glow: rgba(91, 141, 239, 0.15);
  --accent-dark: #3b6dcf;
  --green:       #3ecf8e;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 3px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.3);
  --font-sans:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  --max-w:       720px;
}

/* ─── Base ───────────────────────────────────────────────────── */
html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ─── Header ─────────────────────────────────────────────────── */
.header {
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.logo-icon {
  font-size: 18px;
  color: var(--accent);
}

.logo-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.byline {
  font-size: 12px;
  color: var(--text-muted);
}

.byline:hover { color: var(--text); text-decoration: none; }

/* ─── Main ───────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ─── Hero ───────────────────────────────────────────────────── */
.hero { margin-bottom: 8px; }

.hero-title {
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 12px;
}

.hero-sub {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 480px;
}

/* ─── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* ─── Fields ─────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.field-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.input, .textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
}

.input:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.textarea { line-height: 1.6; min-height: 80px; }

/* ─── API Key Row ─────────────────────────────────────────────── */
.api-key-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.api-key-row .input { flex: 1; }

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  white-space: nowrap;
  font-family: var(--font-sans);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-mid);
}
.btn-ghost:hover {
  background: var(--bg-card-alt);
  color: var(--text);
  border-color: var(--border-mid);
}

.btn-generate {
  background: linear-gradient(135deg, var(--accent), #7c5cbf);
  color: #fff;
  padding: 12px 28px;
  font-size: 14px;
  border-radius: var(--radius);
}
.btn-generate:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ─── Error ──────────────────────────────────────────────────── */
.error-msg {
  font-size: 12px;
  color: #e05a5a;
  margin-top: 8px;
}

/* ─── Conversation ───────────────────────────────────────────── */
.conversation-thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.bubble {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bubble-role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.bubble-ai .bubble-role { color: var(--accent); }
.bubble-user .bubble-role { color: var(--green); }

.bubble-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.bubble-ai .bubble-body {
  border-left: 3px solid var(--accent);
}

.bubble-user .bubble-body {
  border-left: 3px solid var(--green);
  background: var(--bg-card-alt);
  color: var(--text-muted);
  font-style: italic;
}

.answer-card { margin-top: 0; }

/* ─── Generate Prompt ────────────────────────────────────────── */
.generate-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  border: 1px dashed var(--border-mid);
  border-radius: var(--radius);
  text-align: center;
}

.generate-prompt p {
  font-size: 14px;
  color: var(--text-muted);
}

/* ─── Loading ─────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ─── Output ─────────────────────────────────────────────────── */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.output-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.output-content {
  font-size: 14px;
  line-height: 1.8;
}

/* Markdown output styling */
.output-content h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 20px;
  letter-spacing: -0.02em;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.output-content h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 24px 0 10px;
}

.output-content p {
  color: var(--text);
  margin-bottom: 12px;
}

.output-content ul, .output-content ol {
  padding-left: 20px;
  margin-bottom: 12px;
}

.output-content li {
  color: var(--text);
  margin-bottom: 4px;
}

.output-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 13px;
}

.output-content th {
  background: var(--bg-card-alt);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.output-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.output-content tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

.output-content strong {
  color: var(--text);
  font-weight: 600;
}

.output-content code {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.output-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ─── Footer ─────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

.footer a { color: var(--text-muted); }
.footer a:hover { color: var(--text); }

/* ─── Utility ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .main { padding: 32px 16px 48px; }
  .api-key-row { flex-direction: column; }
  .api-key-row .btn { width: 100%; }
  .hero-title { font-size: 24px; }
}
