/* Atlas — a light "workbench" identity: dense, monospace accents, a sidebar to
 * come. Deliberately not the same look as Relay; with two AI chats in the zoo,
 * distinct identities are the only thing that stops a visitor conflating them.
 *
 * The custom properties below are an intentional copy of the ones in the other
 * demos' stylesheets. See ../../../README.md § "No shared code" -- a token file
 * that four projects import is exactly what makes a project un-liftable.
 */

:root {
  --bg: #fbfaf8;
  --panel: #ffffff;
  --ink: #1a1a18;
  --muted: #6b6a66;
  --faint: #97958f;
  --line: #e5e2dc;
  --accent: #3d5afe;
  --user-bg: #eef1ff;
  --code-bg: #f4f2ee;
  --danger: #c0392b;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f;
    --panel: #1c1c19;
    --ink: #f2f0eb;
    --muted: #9c9a93;
    --faint: #6e6c66;
    --line: #2d2d28;
    --user-bg: #23273d;
    --code-bg: #232320;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  height: 100%;
}

.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  position: relative;
}

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

/* -------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  width: 15.5rem;
  flex: 0 0 15.5rem;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-decoration: none;
}

.brand:hover { color: var(--accent); }

.new {
  padding: 0.28rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
}

.new:hover { border-color: var(--accent); color: var(--accent); }

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.sidebar-foot {
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--faint);
}

.convo-empty {
  margin: 0.5rem 0.4rem;
  color: var(--faint);
  font-size: 0.8rem;
}

.convo {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  border-radius: 8px;
}

.convo:hover { background: color-mix(in oklab, var(--ink) 5%, transparent); }
.convo.active { background: color-mix(in oklab, var(--accent) 12%, transparent); }

.convo-open {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  padding: 0.42rem 0.55rem;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
}

.convo-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.convo-count {
  flex: none;
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--faint);
}

.convo-tools {
  display: flex;
  gap: 0.1rem;
  padding-right: 0.3rem;
  opacity: 0;
}

.convo:hover .convo-tools,
.convo:focus-within .convo-tools { opacity: 1; }

.icon {
  padding: 0.1rem 0.3rem;
  border: none;
  border-radius: 5px;
  background: none;
  color: var(--faint);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.icon:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 8%, transparent); }
.icon.danger:hover { color: var(--danger); }
.icon.armed { color: var(--danger); font-size: 0.62rem; }

.convo-rename {
  flex: 1;
  padding: 0.2rem 0.3rem;
}

.convo-rename input {
  width: 100%;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
}

.hamburger {
  display: none;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: 0 0 40px -10px rgb(0 0 0 / 0.4);
  }
  .sidebar.open { transform: none; }
  .hamburger { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* -------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.title strong {
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.title .sub {
  margin-left: 0.6rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--faint);
}

.home {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
}

.home:hover { border-color: var(--accent); color: var(--accent); }

/* -------------------------------------------------- thread */

.thread {
  flex: 1;
  overflow-y: auto;
  /* Chrome's scroll anchoring adjusts scrollTop while content is appended, which
   * fights the pinning logic in app.js and produces a thread that judders as it
   * streams. */
  overflow-anchor: none;
  /* Generous bottom padding: the last message's usage line and action row sit
   * below the text, and a tight value clips them behind the composer. */
  padding: 1.5rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.msg {
  max-width: 46rem;
  width: 100%;
  margin: 0 auto;
}

.msg .body {
  /* Plain-text bodies (the user's own messages) keep their newlines. Rendered
   * markdown bodies opt out below -- with real block elements, pre-wrap would
   * turn every source newline into an extra blank line. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* -------------------------------------------------- rendered markdown */

.body.md { white-space: normal; }

.body.md > :first-child { margin-top: 0; }
.body.md > :last-child { margin-bottom: 0; }

.body.md p { margin: 0 0 0.85rem; }

.body.md h2,
.body.md h3,
.body.md h4,
.body.md h5,
.body.md h6 {
  margin: 1.4rem 0 0.5rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.body.md h2 { font-size: 1.15rem; }
.body.md h3 { font-size: 1rem; }
.body.md h4,
.body.md h5,
.body.md h6 { font-size: 0.92rem; }

.body.md ul,
.body.md ol {
  margin: 0 0 0.85rem;
  padding-left: 1.35rem;
}

.body.md li { margin: 0.2rem 0; }

.body.md blockquote {
  margin: 0 0 0.85rem;
  padding: 0.1rem 0 0.1rem 0.9rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.body.md hr {
  margin: 1.2rem 0;
  border: none;
  border-top: 1px solid var(--line);
}

.body.md a {
  color: var(--accent);
  text-underline-offset: 2px;
}

.body.md code {
  padding: 0.1rem 0.32rem;
  border-radius: 5px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.86em;
}

/* -------------------------------------------------- code blocks */

.code-block {
  position: relative;
  margin: 0 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--code-bg);
}

.code-block pre {
  margin: 0;
  padding: 0.75rem 0.9rem;
  /* Wide code scrolls inside its own box. The thread must never scroll
   * horizontally. */
  overflow-x: auto;
}

.code-block code {
  padding: 0;
  background: none;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
}

.code-lang {
  position: absolute;
  top: 0.4rem;
  left: 0.75rem;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  pointer-events: none;
}

.code-block:has(.code-lang) pre { padding-top: 1.5rem; }

.copy {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.62rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease;
}

.code-block:hover .copy,
.copy:focus-visible { opacity: 1; }

.copy:hover { color: var(--accent); border-color: var(--accent); }

/* A fence that has not closed yet: no copy button (it would copy half a
 * program), and a hint that more is coming. */
.code-block.streaming { border-style: dashed; }

.msg.user .body {
  margin-left: auto;
  max-width: 34rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  background: var(--user-bg);
}

.msg.error .body {
  padding: 0.6rem 0.85rem;
  border: 1px solid color-mix(in oklab, var(--danger) 40%, var(--line));
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.9rem;
  white-space: normal;
}

.extras:empty { display: none; }

.usage {
  margin-top: 0.4rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--faint);
}

/* -------------------------------------------------- per-message actions */

.row-tools {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.3rem;
  opacity: 0;
  transition: opacity 120ms ease;
}

.msg:hover .row-tools,
.msg:focus-within .row-tools { opacity: 1; }

.msg.user .row-tools { justify-content: flex-end; }

.link {
  padding: 0;
  border: none;
  background: none;
  color: var(--faint);
  font: inherit;
  font-size: 0.72rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.link:hover { color: var(--accent); }

.edit-form textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  resize: vertical;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.edit-actions button {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.edit-actions .ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

/* -------------------------------------------------- model picker */

.picker select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .row-tools { transition: none; }
}

/* -------------------------------------------------- reasoning */

.reasoning {
  display: block;
  margin-bottom: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-left: 2px solid var(--line);
  color: var(--faint);
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.reasoning-label {
  display: block;
  margin-bottom: 0.15rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* -------------------------------------------------- typing dots */

.dots {
  display: inline-flex;
  gap: 4px;
  padding: 0.55rem 0;
}

.dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  animation: blink 1.3s infinite ease-in-out both;
}

.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* -------------------------------------------------- empty state */

.empty {
  margin: auto;
  max-width: 34rem;
  text-align: center;
}

.empty h1 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.empty p {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.starters {
  display: grid;
  gap: 0.5rem;
}

.starters button {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
}

.starters button:hover { border-color: var(--accent); color: var(--accent); }

/* -------------------------------------------------- jump pill */

.jump {
  position: absolute;
  left: 50%;
  bottom: 6.5rem;
  transform: translateX(-50%);
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  box-shadow: 0 4px 16px -8px rgb(0 0 0 / 0.3);
}

.jump:hover { color: var(--accent); border-color: var(--accent); }

/* -------------------------------------------------- composer */

.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 0.75rem 1.25rem 1rem;
}

.composer textarea {
  display: block;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

.composer textarea:focus {
  outline: 2px solid color-mix(in oklab, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  max-width: 46rem;
  margin: 0.5rem auto 0;
}

.status {
  margin-right: auto;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--faint);
}

.actions button {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.actions .stop {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.actions .stop:hover { border-color: var(--danger); color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; opacity: 0.6; }
}
