/*
  Ask Qi — styles. Design tokens copied from the main portfolio (css/style.css) so this page
  matches the site and shares its "theme" localStorage key for dark mode.
  AI usage: written with Claude Code (CMU 15-113 HW4).
*/

/* ---------- Design tokens ---------- */
:root {
  --bg: #fafaf9;
  --bg-elevated: #ffffff;
  --text: #1c1c1e;
  --text-muted: #5b5b60;
  --border: #e6e6e4;
  --accent: #0f766e;
  --accent-hover: #0b5a54;
  --accent-soft: #e6f4f2;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --font-heading: "Poppins", "Segoe UI", sans-serif;
  --font-body: "Inter", "Segoe UI", sans-serif;

  --ok: #0f766e;
  --warn: #b45309;
  --bad: #c0392b;
  --user-bubble: #0f766e;
  --user-bubble-text: #ffffff;
}

[data-theme="dark"] {
  --bg: #0f1417;
  --bg-elevated: #171d21;
  --text: #f2f2f0;
  --text-muted: #a3a8ab;
  --border: #2a3237;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #16302c;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);

  --ok: #2dd4bf;
  --warn: #fbbf24;
  --bad: #f87171;
  --user-bubble: #14837a;
  --user-bubble-text: #f2fdfb;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

h1, h2, h3 { font-family: var(--font-heading); line-height: 1.2; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--accent-soft);
  color: var(--text);
  padding: 1px 5px;
  border-radius: 5px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.back-link { color: var(--text-muted); font-size: 0.9rem; font-weight: 500; }
.back-link:hover { color: var(--accent); }
.brand { flex: 1; text-align: center; font-size: 1.15rem; }

.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon { width: 18px; height: 18px; }
[data-theme="light"] .icon-moon, [data-theme="dark"] .icon-sun { display: none; }

/* ---------- Intro + status ---------- */
.intro { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 16px; }
.intro strong { color: var(--text); }

.status-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.82rem; font-weight: 500;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-muted);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); flex-shrink: 0;
}
.status-checking .status-dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status-ready   .status-dot { background: var(--ok); }
.status-ready   { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.status-down    .status-dot { background: var(--bad); }
.status-down    { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.quota-note { font-size: 0.78rem; color: var(--text-muted); }

/* ---------- Chat log ---------- */
.chat-log {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 300px;
  max-height: min(56vh, 520px);
  overflow-y: auto;
  padding: 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.msg { display: flex; flex-direction: column; gap: 4px; max-width: 86%; }
.msg-bot { align-self: flex-start; }
.msg-user { align-self: flex-end; align-items: flex-end; }

.msg-who {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-muted); padding: 0 4px;
}

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  white-space: pre-wrap;   /* keep the model's line breaks */
  overflow-wrap: anywhere; /* long URLs can't widen the layout */
}
.msg-bot .bubble { background: var(--accent-soft); border: 1px solid var(--border); }
.msg-user .bubble { background: var(--user-bubble); color: var(--user-bubble-text); }

/* An error is a message too — shown in the log so it can't be missed */
.msg-error .bubble {
  background: color-mix(in srgb, var(--bad) 12%, var(--bg-elevated));
  border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--border));
  color: var(--text);
}
.msg-error .msg-who { color: var(--bad); }

/* Typing indicator */
.typing .bubble { display: inline-flex; gap: 5px; align-items: center; padding: 14px; }
.typing span.dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: bounce 1.1s ease-in-out infinite;
}
.typing span.dot:nth-child(2) { animation-delay: 0.15s; }
.typing span.dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 100% { transform: translateY(0); opacity: 0.4; } 50% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Suggestions ---------- */
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip {
  font-family: inherit; font-size: 0.82rem;
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
  background: var(--bg-elevated); color: var(--text-muted);
  border: 1px solid var(--border);
}
.chip:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Composer ---------- */
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.composer textarea {
  flex: 1; min-width: 0;
  font-family: inherit; font-size: 0.95rem; line-height: 1.5;
  color: var(--text); background: transparent;
  border: none; resize: none; outline: none;
  max-height: 140px; padding: 6px 4px;
}
.composer textarea::placeholder { color: var(--text-muted); }
.composer-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.char-count { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.char-count.near-limit { color: var(--bad); font-weight: 600; }

.btn {
  font-family: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 9px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; transition: background 0.2s ease, opacity 0.2s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
[data-theme="dark"] .btn-primary { color: #06201d; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form-error { min-height: 1.2em; margin-top: 8px; font-size: 0.85rem; color: var(--bad); }

/* ---------- "How this works" ---------- */
.how-panel {
  margin-top: 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.how-panel summary {
  cursor: pointer; font-family: var(--font-heading); font-weight: 600; font-size: 0.95rem;
}
.how-body { margin-top: 12px; font-size: 0.9rem; color: var(--text-muted); }
.how-body p { margin-bottom: 10px; }
.how-body ol { margin: 0 0 10px 20px; }
.how-body li { margin-bottom: 8px; }
.how-body strong { color: var(--text); }
.endpoints, .repo-links { font-size: 0.85rem; }

/* ---------- Footer ---------- */
.footer {
  text-align: center; padding: 24px 16px 40px;
  font-size: 0.8rem; color: var(--text-muted);
}

/* ---------- Narrow screens ---------- */
@media (max-width: 560px) {
  .msg { max-width: 94%; }
  .brand { font-size: 1rem; }
  .back-link { font-size: 0.8rem; }
  .composer { flex-direction: column; align-items: stretch; }
  .composer-side { justify-content: space-between; }
}
