/* Fx. Nippy. v3.1 — lightweight, transparent
   Perplexity-like grammar: centred wordmark, single composer, generous whitespace.
   teal #0E7A82 · ink #1C1C1C · muted #5A5A5A · page #F7F4EC · paper #FBFAF5 */

:root {
  --teal: #0E7A82;
  --teal-deep: #0a5f66;
  --teal-bright: #14959F;
  --teal-light: #E6F3F4;
  --ink: #1C1C1C;
  --ink-soft: #2c2c2c;
  --muted: #5A5A5A;
  --muted-2: #8a8a8a;
  --row-alt: #F5F8F8;
  --page: #F7F4EC;
  --paper: #FBFAF5;
  --hairline: rgba(28, 28, 28, 0.08);
  --hairline-strong: rgba(28, 28, 28, 0.14);
  --rust: #8b2a2a;
  --radius: 4px;
  --radius-soft: 12px;
  --radius-pill: 999px;
  --topbar-h: 56px;
  --composer-h: 120px;
  --max-w: 760px;
  --font-display: "DM Sans", system-ui, sans-serif;
  --font-body: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: var(--page); }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- topbar (minimal) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  padding: 0 18px;
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
}
.brand { display: none; }
.threadbar { display: flex; gap: 2px; margin-left: auto; }
.iconbtn {
  background: transparent;
  color: var(--muted-2);
  border: 0;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 120ms ease;
  border-radius: var(--radius);
}
.iconbtn:hover, .iconbtn:focus-visible {
  color: var(--ink);
  outline: none;
}

/* ---------- chat ---------- */
.chat {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 22px calc(var(--composer-h) + 28px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.empty {
  margin-top: 18vh;
  text-align: center;
  padding: 0;
}
.mark {
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 700;
  font-size: 56px;
  letter-spacing: -0.04em;
  color: var(--ink);
  margin: 0 0 36px;
  line-height: 1;
}
.mark-fx { color: var(--teal); }
.mark-nippy { color: var(--ink); margin-left: 6px; }

/* inline API key box (only when no key) */
.empty-keybox {
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-soft);
  text-align: left;
}
.empty-keybox-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.empty-keybox-row input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
}
.empty-keybox-row input:focus { border-color: var(--teal); }
.empty-keybox-row button { white-space: nowrap; }
.empty-keybox-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- messages ---------- */
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg .role {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.msg.user .role { color: var(--teal); }
.msg.assistant .role { color: var(--muted); }
.msg.system .role { color: var(--rust); }

.bubble {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .bubble {
  background: transparent;
  border-left: 2px solid var(--teal);
  padding: 0 0 0 14px;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--ink-soft);
}
.msg.assistant .bubble { background: transparent; padding: 0; }
.msg.assistant .bubble p:first-child { margin-top: 0; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }

.bubble h1, .bubble h2, .bubble h3 {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 1.3em 0 0.4em;
}
.bubble h1 { font-size: 22px; }
.bubble h2 { font-size: 18px; }
.bubble h3 { font-size: 15.5px; color: var(--ink); }
.bubble a {
  color: var(--teal);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.bubble a:hover { color: var(--teal-bright); }
.bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--paper);
  padding: 1px 5px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.bubble pre {
  background: var(--paper);
  border: 1px solid var(--hairline);
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  border-radius: var(--radius);
}
.bubble pre code { background: transparent; border: 0; padding: 0; }
.bubble blockquote {
  border-left: 2px solid var(--hairline-strong);
  margin: 0.6em 0;
  padding: 0.2em 0 0.2em 14px;
  color: var(--muted);
}
.bubble ul, .bubble ol { padding-left: 22px; }
.bubble li { margin: 0.25em 0; }
.bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin: 0.8em 0;
}
.bubble th, .bubble td {
  border: 1px solid var(--hairline-strong);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.bubble th {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 12px;
}
.bubble tr:nth-child(even) td { background: var(--row-alt); }

/* citations */
.citations {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.citations .head {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 4px;
}
.citations a {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  display: flex;
  gap: 8px;
}
.citations a:hover { color: var(--teal); }
.citations .num {
  color: var(--teal);
  font-family: var(--font-mono);
  font-size: 11.5px;
  flex-shrink: 0;
  min-width: 22px;
}
.citation-ref {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--teal-light);
  border: 1px solid var(--hairline);
  color: var(--teal);
  padding: 0 4px;
  margin: 0 1px;
  text-decoration: none;
  vertical-align: super;
  line-height: 1.4;
  border-radius: var(--radius);
}
.citation-ref:hover { background: var(--teal); color: #fff; }

/* streaming cursor */
.cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  background: var(--teal);
  vertical-align: -0.15em;
  margin-left: 2px;
  animation: blink 0.9s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- composer (Perplexity-style ask box) ---------- */
.composer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  background: linear-gradient(to top, var(--page) 78%, rgba(247,244,236,0));
  padding: 18px 16px calc(10px + env(safe-area-inset-bottom));
}
.composer-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-soft);
  padding: 14px 16px 10px;
  box-shadow: 0 1px 0 rgba(28,28,28,0.02), 0 8px 24px rgba(28,28,28,0.04);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.composer-inner:focus-within {
  border-color: var(--hairline-strong);
  box-shadow: 0 1px 0 rgba(28,28,28,0.02), 0 12px 32px rgba(28,28,28,0.08);
}
.composer textarea {
  width: 100%;
  resize: none;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  padding: 2px 2px;
  max-height: 220px;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--muted-2); }
.composer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.spacer { flex: 1; }

/* foot — minimal */
.composer-foot {
  max-width: var(--max-w);
  margin: 8px auto 0;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 11px;
  letter-spacing: 0;
  color: var(--muted-2);
}
.foot-mark { color: var(--muted); }
.foot-sep { color: var(--hairline-strong); }

/* ---------- pills ---------- */
.pill {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--hairline-strong);
  padding: 4px 10px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12.5px;
  letter-spacing: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--radius-pill);
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.pill:hover { color: var(--ink); border-color: var(--muted-2); }
.pill.toggle.on {
  color: var(--teal);
  border-color: var(--teal);
  background: var(--teal-light);
}
.pill.stop { color: var(--rust); border-color: var(--rust); }
.pill.ghost { background: transparent; }
.pill.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.pill.primary:hover { background: var(--ink-soft); border-color: var(--ink-soft); }
select.pill {
  padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  background-color: transparent;
}
.kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 1px 6px;
  background: var(--paper);
  border: 1px solid var(--hairline);
  color: var(--ink);
  border-radius: var(--radius);
}

.sendbtn {
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--ink);
  color: #fff;
  border: 1px solid var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease;
  border-radius: var(--radius-pill);
}
.sendbtn:hover { background: var(--ink-soft); border-color: var(--ink-soft); }
.sendbtn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- dialogs ---------- */
.dialog {
  display: none;
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(520px, 92vw);
  max-height: 86vh;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-soft);
  padding: 0;
  z-index: 1000;
  box-shadow: 0 24px 64px rgba(28, 28, 28, 0.24);
}
.dialog.is-open { display: block; }
.iconbtn svg, .pill svg, button svg { pointer-events: none; }
body.modal-open { overflow: hidden; }
body.modal-open::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(28, 28, 28, 0.45);
  backdrop-filter: blur(4px);
  z-index: 999;
  pointer-events: none;
}
.dialog-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 20px;
  overflow-y: auto;
  max-height: 86vh;
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog-head h2 {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.row { flex-direction: row; align-items: center; gap: 10px; cursor: pointer; }
.field-label {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input[type="password"],
.field input[type="text"],
.field textarea {
  background: #fff;
  border: 1px solid var(--hairline-strong);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 9px 12px;
  outline: 0;
  width: 100%;
  border-radius: var(--radius);
}
.field textarea {
  font-family: var(--font-sans);
  font-size: 14px;
  resize: vertical;
  line-height: 1.5;
}
.field input:focus, .field textarea:focus { border-color: var(--teal); }
.field-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.field-hint strong { color: var(--ink); font-weight: 600; }
.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.dialog-foot {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
}
.textbtn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}
.textbtn:hover { color: var(--ink); }
.textbtn.danger { color: var(--rust); }
.textbtn.danger:hover { color: #c04040; }

.threads { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.threads li { border-top: 1px solid var(--hairline); }
.threads li:last-child { border-bottom: 1px solid var(--hairline); }
.thread-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
}
.thread-row .ttitle { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-row .tdate { font-family: var(--font-mono); font-size: 11px; color: var(--muted-2); }
.thread-row.active { color: var(--teal); font-weight: 600; }
.thread-del { background: transparent; border: 0; color: var(--muted-2); cursor: pointer; padding: 4px 6px; }
.thread-del:hover { color: var(--rust); }

.errtoast {
  background: #fff;
  border-left: 2px solid var(--rust);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 13.5px;
  border-radius: var(--radius);
}

@media (min-width: 720px) {
  .mark { font-size: 72px; }
  .empty { margin-top: 22vh; }
}

/* --- Nippy additions (v3.3) --- */
.tagline {
  margin: 14px 0 0;
  font-size: 13px;
  color: #6b6b6b;
  letter-spacing: 0.01em;
  font-weight: 400;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: #5a5a5a;
  background: transparent;
  border: 1px solid rgba(0,0,0,0.08);
  user-select: none;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #c8c8c8;
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background 0.2s;
}
.status-dot[data-state="ok"]      { background: #16a34a; }
.status-dot[data-state="off"]     { background: #dc2626; }
.status-dot[data-state="probing"] { background: #f59e0b; }
.status-text { font-variant-numeric: tabular-nums; }
