/* ==========================================================================
   Hidrogen AI — app.css
   Tokens first, then layout, then components. Theme switches by setting
   data-theme on <html>. Every colour below is a variable, no raw hex in rules.
   ========================================================================== */

/* --- tokens: dark (default) ---------------------------------------------- */
:root,
:root[data-theme="dark"] {
  --bg:            #0A0B0E;
  --panel:         #0E1015;
  --surface:       #141721;
  --surface-2:     #1B1F2B;
  --line:          #242835;
  --line-soft:     #1A1E28;

  --text:          #E9EBF2;
  --text-dim:      #A8AEC0;
  --muted:         #767D91;
  --faint:         #4E5566;

  --accent:        #8477FF;   /* model, focus, primary action */
  --accent-soft:   rgba(132,119,255,0.14);
  --accent-line:   rgba(132,119,255,0.38);
  --tool:          #3ED4C8;   /* tools, search, retrieval */
  --tool-soft:     rgba(62,212,200,0.12);
  --warn:          #E8A64B;
  --danger:        #FF6B6B;
  --danger-soft:   rgba(255,107,107,0.12);

  --bubble-user:   #1D2130;
  --code-bg:       #0B0D12;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 28px rgba(0,0,0,.45);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
  color-scheme: dark;
}

/* --- tokens: light ------------------------------------------------------- */
:root[data-theme="light"] {
  --bg:            #FBFBFD;
  --panel:         #F4F5F9;
  --surface:       #FFFFFF;
  --surface-2:     #EEEFF5;
  --line:          #E1E3EC;
  --line-soft:     #EBECF3;

  --text:          #14161C;
  --text-dim:      #3D4250;
  --muted:         #6B7285;
  --faint:         #A2A8B8;

  --accent:        #5B4BE0;
  --accent-soft:   rgba(91,75,224,0.10);
  --accent-line:   rgba(91,75,224,0.32);
  --tool:          #12968D;
  --tool-soft:     rgba(18,150,141,0.10);
  --warn:          #B87514;
  --danger:        #D63B3B;
  --danger-soft:   rgba(214,59,59,0.10);

  --bubble-user:   #ECEDF4;
  --code-bg:       #F5F6FA;

  --shadow-sm: 0 1px 2px rgba(16,20,32,.06);
  --shadow-md: 0 8px 28px rgba(16,20,32,.10);
  --shadow-lg: 0 20px 60px rgba(16,20,32,.14);
  color-scheme: light;
}

/* --- shared sizing ------------------------------------------------------- */
:root {
  --font:      'Ubuntu', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Ubuntu Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --sidebar-w: 268px;
  --thread-w:  760px;
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --header-h:  56px;
  --ease: cubic-bezier(.22,.61,.36,1);
}

/* --- reset --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; flex: none; }
::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* scrollbars */
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid transparent; background-clip: content-box; border-radius: 8px; }
.scroll::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

/* ==========================================================================
   Shell
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns .28s var(--ease);
}
/* Grid children default to min-height:auto, which lets the column grow past
   the viewport instead of handing a bounded height to the scroller inside.
   Without this the thread never scrolls and long chats run off the screen. */
.app > * { min-height: 0; }
.app.is-collapsed { grid-template-columns: 0 1fr; }

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.sidebar__top {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
  padding: 0 10px 0 14px;
  flex: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}
.brand__orb {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  flex: none;
}
.brand__name {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand__name span { color: var(--muted); font-weight: 400; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

.sidebar__new {
  margin: 2px 10px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}
.sidebar__new:hover { background: var(--surface); border-color: var(--accent-line); }
.sidebar__new kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: .04em;
}

.sidebar__search {
  margin: 0 10px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
}
.sidebar__search:focus-within { border-color: var(--accent-line); }
.sidebar__search input {
  border: 0; background: none; outline: none;
  width: 100%; font-size: 13.5px; color: var(--text);
}
.sidebar__search input::placeholder { color: var(--faint); }

.chat-list { flex: 1; padding: 4px 8px 12px; min-height: 0; }
.chat-group {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 14px 8px 6px;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  position: relative;
  transition: background .13s, color .13s;
}
.chat-item:hover { background: var(--surface); color: var(--text); }
.chat-item.is-active { background: var(--surface-2); color: var(--text); }
.chat-item.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.chat-item__title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item__pin { color: var(--accent); opacity: .8; }
.chat-item__menu {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--muted);
  opacity: 0;
  flex: none;
}
.chat-item:hover .chat-item__menu,
.chat-item.is-open .chat-item__menu { opacity: 1; }
.chat-item__menu:hover { background: var(--surface-2); color: var(--text); }
.chat-item input.rename {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 13.5px;
  outline: none;
  min-width: 0;
}

.sidebar__foot {
  flex: none;
  border-top: 1px solid var(--line-soft);
  padding: 8px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  transition: background .15s;
  text-align: left;
}
.user-chip:hover { background: var(--surface); }
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  flex: none;
}
.user-chip__meta { min-width: 0; flex: 1; }
.user-chip__name { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip__sub { font-size: 11.5px; color: var(--muted); }

/* ==========================================================================
   Main column
   ========================================================================== */
/* Three fixed rows: bar, scrolling area, composer.
   A flex column works only if every ancestor also has min-height:0, and one
   missing link silently lets the column grow past the viewport, which is what
   stopped the thread scrolling. minmax(0, 1fr) cannot do that: the middle row
   is capped at the space left over, so the scroller always has a real height. */
.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
}
.topbar        { grid-row: 1; }
.empty         { grid-row: 2; }
.thread        { grid-row: 2; }
.composer-wrap { grid-row: 3; }

.topbar {
  height: var(--header-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid transparent;
  transition: border-color .2s, background .2s;
}
.topbar.is-stuck {
  border-bottom-color: var(--line-soft);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.topbar__title {
  font-size: 14px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.topbar__spacer { flex: 1; }

/* model picker ------------------------------------------------------------ */
.model-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: background .15s;
}
.model-btn:hover { background: var(--surface); }
.model-btn .tier {
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 5px;
}

.menu {
  position: absolute;
  z-index: 60;
  min-width: 250px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px;
  animation: pop .14s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.985); } }
.menu__label {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); padding: 8px 10px 4px;
}
.menu__item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text-dim);
  transition: background .12s, color .12s;
}
.menu__item:hover { background: var(--surface-2); color: var(--text); }
.menu__item.is-danger { color: var(--danger); }
.menu__item.is-danger:hover { background: var(--danger-soft); }
.menu__item .sub { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.menu__item .grow { flex: 1; min-width: 0; }
.menu__item .check { color: var(--accent); opacity: 0; }
.menu__item.is-on .check { opacity: 1; }
.menu__sep { height: 1px; background: var(--line-soft); margin: 5px 4px; }

/* ==========================================================================
   Thread
   ========================================================================== */
.thread {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  padding: 8px 0 0;
  overscroll-behavior: contain;
}
.thread__inner {
  max-width: var(--thread-w);
  margin: 0 auto;
  padding: 12px 22px 40px;
}

.msg { display: flex; gap: 14px; padding: 10px 0 18px; }
.msg__avatar { width: 28px; flex: none; padding-top: 2px; }
.msg__avatar .orb-slot { width: 28px; height: 28px; display: grid; place-items: center; }
.msg__body { min-width: 0; flex: 1; }

.msg--user { justify-content: flex-end; }
.msg--user .msg__body {
  background: var(--bubble-user);
  border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg);
  padding: 11px 15px;
  max-width: 78%;
  flex: 0 1 auto;
}

.msg__who {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 2px;
  letter-spacing: .01em;
}

/* prose ------------------------------------------------------------------- */
.prose { font-size: 15px; line-height: 1.68; overflow-wrap: anywhere; }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 12px; }
.prose h1, .prose h2, .prose h3 {
  margin: 22px 0 10px; line-height: 1.3; font-weight: 500; letter-spacing: -0.012em;
}
.prose h1 { font-size: 21px; }
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 16px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose blockquote {
  margin: 0 0 12px; padding: 2px 0 2px 14px;
  border-left: 2px solid var(--line); color: var(--text-dim);
}
.prose code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  background: var(--surface-2);
  padding: 1.5px 5px;
  border-radius: 5px;
}
.prose pre {
  margin: 0 0 14px;
  background: var(--code-bg);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}
.prose pre code { background: none; padding: 0; font-size: 13px; line-height: 1.62; }
.code-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px; color: var(--muted);
  font-family: var(--font-mono); letter-spacing: .04em;
}
.code-copy { margin-left: auto; color: var(--muted); display: flex; align-items: center; gap: 5px; font-size: 11.5px; }
.code-copy:hover { color: var(--text); }
.code-body { padding: 13px 14px; overflow-x: auto; }
.prose table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.prose th { background: var(--surface); font-weight: 500; }

/* thinking block ---------------------------------------------------------- */
.think {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  margin: 0 0 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.think__head {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 9px 12px;
  font-size: 13px; color: var(--muted);
}
.think__head:hover { color: var(--text-dim); }
.think__chev { margin-left: auto; transition: transform .2s var(--ease); }
.think.is-open .think__chev { transform: rotate(180deg); }
.think__body {
  display: none;
  padding: 2px 14px 13px 34px;
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--muted);
  border-top: 1px solid var(--line-soft);
  white-space: pre-wrap;
}
.think.is-open .think__body { display: block; }

/* tool / status chips ----------------------------------------------------- */
.steps { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; }
.step {
  display: inline-flex; align-items: center; gap: 9px;
  align-self: flex-start;
  padding: 6px 12px 6px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--surface);
  max-width: 100%;
}
.step .dot { width: 14px; height: 14px; display: grid; place-items: center; }
.step .what { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step .arg { color: var(--muted); font-family: var(--font-mono); font-size: 11.5px; }
.step .ms  { color: var(--faint); font-size: 11px; font-family: var(--font-mono); }
.step.is-tool { border-color: color-mix(in srgb, var(--tool) 30%, transparent); background: var(--tool-soft); }
.step.is-tool .what { color: var(--tool); }
.step.is-error { border-color: color-mix(in srgb, var(--danger) 30%, transparent); background: var(--danger-soft); color: var(--danger); }
.step.is-live .what { color: var(--text); }

/* live status line while generating --------------------------------------- */
.live {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; color: var(--muted);
  padding: 2px 0 6px;
}
.live__text { position: relative; }
.live__text::after {
  content: "";
  display: inline-block;
  width: 7px; height: 15px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--accent);
  border-radius: 1px;
  animation: caret 1.05s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.live.is-done .live__text::after { display: none; }

/* sources ----------------------------------------------------------------- */
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 12px; }
.source {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px; color: var(--text-dim);
  max-width: 260px;
}
.source:hover { border-color: var(--accent-line); text-decoration: none; }
.source .n { color: var(--faint); font-family: var(--font-mono); }
.source .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* message actions --------------------------------------------------------- */
.msg__actions {
  display: flex; align-items: center; gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.msg:hover .msg__actions, .msg__actions:focus-within { opacity: 1; }
.act {
  width: 30px; height: 28px;
  display: grid; place-items: center;
  border-radius: 7px;
  color: var(--muted);
  transition: background .13s, color .13s;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act.is-on { color: var(--accent); }
.act--text { width: auto; padding: 0 9px; gap: 6px; display: inline-flex; font-size: 12.5px; }
.msg__meta { font-size: 11.5px; color: var(--faint); font-family: var(--font-mono); margin-left: 4px; }

/* attachments in a message ------------------------------------------------ */
.attachs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 11px 7px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  max-width: 240px;
}
.attach .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach .sz { color: var(--faint); font-size: 11px; flex: none; }
.attach img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.attach .x { color: var(--muted); }
.attach .x:hover { color: var(--danger); }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 22px 0;
  text-align: center;
}
.empty__orb { margin-bottom: 20px; animation: rise .6s var(--ease) both; }
.empty__title {
  font-size: 27px;
  font-weight: 400;
  letter-spacing: -0.025em;
  margin: 0 0 8px;
  animation: rise .6s .06s var(--ease) both;
}
.empty__title b { font-weight: 500; }
.empty__sub {
  color: var(--muted);
  font-size: 14.5px;
  margin: 0 0 28px;
  max-width: 440px;
  animation: rise .6s .12s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.starters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  width: 100%;
  max-width: var(--thread-w);
  animation: rise .6s .18s var(--ease) both;
}
.starter {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  text-align: left;
  transition: border-color .16s, background .16s, transform .16s var(--ease);
}
.starter:hover { border-color: var(--accent-line); background: var(--surface); transform: translateY(-1px); }
.starter__ico { color: var(--accent); padding-top: 2px; }
.starter__ttl { font-size: 13.8px; }
.starter__sub { font-size: 12.3px; color: var(--muted); line-height: 1.45; }

/* ==========================================================================
   Composer
   ========================================================================== */
.composer-wrap {
  flex: none;
  padding: 0 22px 14px;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}
.composer {
  max-width: var(--thread-w);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .18s, box-shadow .18s;
}
.composer.is-focus { border-color: var(--accent-line); box-shadow: var(--shadow-md); }
.composer.is-drag { border-color: var(--accent); background: var(--accent-soft); }

.composer__files { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 8px; }

.composer__row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1;
  border: 0;
  background: none;
  outline: none;
  resize: none;
  padding: 8px 0;
  max-height: 220px;
  min-height: 24px;
  line-height: 1.6;
  font-size: 15px;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--faint); }

.send {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  flex: none;
  transition: opacity .16s, transform .16s var(--ease), background .16s;
}
.send:disabled { opacity: .32; cursor: default; }
.send:not(:disabled):hover { transform: scale(1.05); }
.send.is-stop { background: var(--surface-2); color: var(--text); }

.composer__tools { display: flex; align-items: center; gap: 4px; padding-right: 2px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  transition: color .14s, border-color .14s, background .14s;
}
.chip-btn:hover { color: var(--text); border-color: var(--faint); }
.chip-btn.is-on { color: var(--tool); border-color: color-mix(in srgb, var(--tool) 42%, transparent); background: var(--tool-soft); }

.composer__hint {
  max-width: var(--thread-w);
  margin: 7px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--faint);
}

/* ==========================================================================
   Bits
   ========================================================================== */
.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  animation: rise .22s var(--ease);
}
.toast.is-error { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }

.scrim { position: fixed; inset: 0; z-index: 50; }

.backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.5);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .16s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  animation: rise .2s var(--ease);
}
.dialog h3 { margin: 0 0 6px; font-size: 17px; font-weight: 500; }
.dialog p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.dialog__row { display: flex; gap: 8px; justify-content: flex-end; }
.btn {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid var(--line);
  color: var(--text);
  transition: background .14s, border-color .14s;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }

.jump {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 128px;
  z-index: 20;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.jump[hidden] { display: none; }

.hidden { display: none !important; }

/* ==========================================================================
   Mobile
   ========================================================================== */
.sidebar__scrim { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: 120;
    transform: translateX(-100%);
    transition: transform .26s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .app.is-open-mobile .sidebar { transform: none; }
  .app.is-open-mobile .sidebar__scrim {
    display: block;
    position: fixed; inset: 0; z-index: 110;
    background: rgba(0,0,0,.5);
  }
  .thread__inner { padding: 10px 15px 30px; }
  .composer-wrap { padding: 0 12px 10px; }
  .starters { grid-template-columns: 1fr; }
  .empty__title { font-size: 22px; }
  .msg--user .msg__body { max-width: 88%; }
  .composer__hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ==========================================================================
   Streaming additions (Part 2)
   ========================================================================== */

/* A reasoning trace can run long. Cap it and let it scroll instead of
   pushing the answer off screen while it streams. */
.think__body {
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.think__body::-webkit-scrollbar { width: 8px; }
.think__body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }

/* The head reads "Thinking" while it streams and "Thought it through" after,
   so give the live state a moving accent. */
.msg.is-pending .think__head { color: var(--accent); }

/* Text arriving token by token should not make the layout jump. */
.msg.is-pending .prose { min-height: 22px; }

/* Stop marker on a halted answer. */
.step .what { color: inherit; }

/* ==========================================================================
   Files and message editing (Part 3)
   ========================================================================== */

/* attachment chips ---------------------------------------------------------- */
.attach { transition: border-color .15s, opacity .15s; }
.attach--img {
  padding: 6px 12px 6px 6px;
  cursor: zoom-in;
  text-align: left;
}
.attach--img:hover { border-color: var(--accent-line); }
.attach img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; flex: none; }
a.attach:hover { border-color: var(--accent-line); text-decoration: none; }

/* an upload in flight reads as busy without a spinner competing with the orb */
.attach.is-busy { opacity: .6; }
.attach.is-busy .sz { color: var(--accent); }

.composer__warn {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--warn);
}

/* lightbox ------------------------------------------------------------------ */
.lightbox { cursor: zoom-out; padding: 34px; }
.lightbox__frame { margin: 0; max-width: 100%; max-height: 100%; text-align: center; }
.lightbox__frame img {
  max-width: 100%;
  max-height: calc(100vh - 110px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.lightbox__frame figcaption {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.lightbox__frame figcaption a { margin-left: 10px; cursor: pointer; }

/* code block controls ------------------------------------------------------- */
.code-head { gap: 6px; }
.code-head > span:first-child { margin-right: auto; }
.code-copy { margin-left: 0; }
pre.is-wrapped .code-body { overflow-x: hidden; }
pre.is-wrapped code { white-space: pre-wrap; overflow-wrap: anywhere; }

/* editing a question -------------------------------------------------------- */
.edit-box {
  width: 100%;
  min-height: 62px;
  background: var(--bg);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
  resize: vertical;
  line-height: 1.6;
}
.edit-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.msg--user .msg__body:has(.edit-box) { max-width: 100%; flex: 1; background: none; padding: 0; }
.msg--user .msg__actions { justify-content: flex-end; }

/* ==========================================================================
   Search, settings and memory (Part 5)
   ========================================================================== */

.sidebar__search input[readonly] { cursor: pointer; }
.sidebar__kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: .04em;
  flex: none;
}

/* found-by-search flash --------------------------------------------------- */
.msg.is-found .msg__body {
  animation: found 2.2s var(--ease);
  border-radius: var(--radius);
}
@keyframes found {
  0%, 70% { box-shadow: 0 0 0 2px var(--accent-line); background: var(--accent-soft); }
  100%    { box-shadow: 0 0 0 2px transparent; }
}

/* finder ------------------------------------------------------------------ */
.finder { align-items: flex-start; padding-top: 12vh; }
.finder__box {
  width: 100%;
  max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: rise .2s var(--ease);
}
.finder__head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
}
.finder__head input {
  flex: 1;
  border: 0;
  background: none;
  outline: none;
  font-size: 15.5px;
  color: var(--text);
}
.finder__head kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
}
.finder__results { max-height: 56vh; overflow-y: auto; padding: 6px; }
.finder__empty { padding: 26px 16px; text-align: center; color: var(--faint); font-size: 13.5px; margin: 0; }
.finder__hit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  position: relative;
}
.finder__hit:hover, .finder__hit.is-cursor { background: var(--surface-2); }
.finder__hit.is-cursor { box-shadow: inset 2px 0 0 var(--accent); }
.finder__title {
  display: block;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 60px;
}
.finder__snip {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 2px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.finder__snip b { color: var(--text-dim); font-weight: 500; }
.finder__ago {
  position: absolute;
  top: 10px; right: 12px;
  font-size: 11.5px;
  color: var(--faint);
}
.finder mark { background: var(--accent-soft); color: var(--text); border-radius: 3px; padding: 0 2px; }

/* settings sheet ---------------------------------------------------------- */
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: rise .2s var(--ease);
}
.sheet__head {
  display: flex;
  align-items: center;
  padding: 16px 14px 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.sheet__head h3 { margin: 0; flex: 1; font-size: 17px; font-weight: 500; }
.sheet__tabs { display: flex; gap: 2px; padding: 10px 14px 0; border-bottom: 1px solid var(--line-soft); }
.sheet__tab {
  padding: 8px 13px 11px;
  font-size: 13.5px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.sheet__tab:hover { color: var(--text-dim); }
.sheet__tab.is-on { color: var(--text); border-bottom-color: var(--accent); }
.sheet__body { padding: 18px 20px 22px; overflow-y: auto; }
.sheet__loading { color: var(--muted); font-size: 13.5px; margin: 8px 0; }
.sheet__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.sheet__note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 13px 15px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.55;
}

.field { display: block; margin-bottom: 18px; }
.field__label { display: block; font-size: 14px; margin-bottom: 3px; }
.field__hint { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-bottom: 8px; }
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  resize: vertical;
  line-height: 1.6;
}
.field textarea:focus { border-color: var(--accent-line); }

.switch {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}
.switch:last-of-type { border-bottom: 0; }
.switch > span:first-child { flex: 1; }
.switch b { display: block; font-size: 14px; font-weight: 400; margin-bottom: 2px; }
.switch .field__hint { margin-bottom: 0; }

.toggle {
  width: 42px; height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px;
  flex: none;
  transition: background .18s var(--ease), border-color .18s;
}
.toggle span {
  display: block;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .18s var(--ease), background .18s;
}
.toggle.is-on { background: var(--accent); border-color: var(--accent); }
.toggle.is-on span { transform: translateX(18px); background: #fff; }

.addnote { display: flex; gap: 8px; margin: 14px 0 10px; }
.addnote input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
}
.addnote input:focus { border-color: var(--accent-line); }

.notes { list-style: none; margin: 0; padding: 0; }
.note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
}
.note__text { flex: 1; line-height: 1.5; }
.note__ago { font-size: 11.5px; color: var(--faint); flex: none; }
.note__edit {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  padding: 5px 9px;
  outline: none;
}
.note--empty { color: var(--muted); border-bottom: 0; padding: 16px 0; }
.note .act { opacity: 0; }
.note:hover .act { opacity: 1; }

@media (max-width: 860px) {
  .finder { padding-top: 6vh; }
  .sheet { max-height: 92vh; }
}

/* ==========================================================================
   Orb behaviour (Part 6.1)
   ========================================================================== */

.empty__orb { position: relative; }
.empty__orb hg-orb { transition: transform .25s var(--ease); }
.empty__orb hg-orb:hover { transform: scale(1.06); }

.empty__orblabel {
  margin: 8px 0 0;
  font-size: 11.5px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
  animation: rise .2s var(--ease);
}

/* The send button holds an orb while generating, so it needs to centre one. */
.send.is-stop { display: grid; place-items: center; }
.send.is-stop hg-orb { pointer-events: none; }

/* The brand mark is the global activity light. Give it a little presence
   when something is actually running. */
.brand__orb hg-orb { transition: opacity .25s; opacity: .75; }
.brand__orb hg-orb:not([paused]) { opacity: 1; }


/* ==========================================================================
   Pattern picker
   ========================================================================== */
.orbgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  margin-top: 6px;
}
.orbtile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 12px 6px 9px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  transition: border-color .15s, background .15s;
}
.orbtile:hover { border-color: var(--faint); background: var(--surface-2); }
.orbtile.is-on { border-color: var(--accent); background: var(--accent-soft); }
.orbtile__name {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.orbtile.is-on .orbtile__name { color: var(--accent); }
.orbtile__auto {
  display: grid;
  grid-template-columns: repeat(3, 20px);
  gap: 4px;
  height: 52px;
  align-content: center;
  justify-content: center;
}

/* The dot canvases are square and should never be squashed by a flex parent. */
hg-orb { flex: none; }

/* ==========================================================================
   Codebases (Part 8)
   ========================================================================== */

/* The attached project reads as a state, not a toggle, so it gets the accent
   rather than the tool colour. */
#btnProject.is-on {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
#projectLabel { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.note.is-on { background: var(--accent-soft); border-radius: var(--radius-sm); padding-left: 8px; }
.note .field__hint { margin-bottom: 0; }
.note__text b { display: block; font-weight: 500; }
.note a.act { display: grid; place-items: center; }

/* ==========================================================================
   Plans and credits (Part 9)
   ========================================================================== */

.credits-chip {
  margin-left: 10px;
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}
.credits-chip:hover { color: var(--text); text-decoration: underline; }
.credits-chip.is-low { color: var(--warn); }
.credits-chip:empty { display: none; }

.balance {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0 16px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 16px;
}
.balance__n { font-size: 34px; letter-spacing: -0.02em; color: var(--accent); }
.balance__l { font-size: 13px; color: var(--muted); line-height: 1.5; }
.balance__l b { color: var(--text); font-weight: 500; }

.plans { display: grid; gap: 10px; margin: 16px 0 6px; }
.plan {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.plan.is-on { border-color: var(--accent-line); background: var(--accent-soft); }
.plan__name { font-size: 15px; font-weight: 500; }
.plan__price { font-size: 20px; letter-spacing: -0.02em; }
.plan__price small { font-size: 12px; color: var(--muted); font-weight: 400; }
.plan__tag { font-size: 12.5px; color: var(--muted); }
.plan__list { list-style: none; margin: 6px 0 10px; padding: 0; font-size: 12.5px; color: var(--text-dim); }
.plan__list li { padding: 2px 0 2px 16px; position: relative; }
.plan__list li::before {
  content: ""; position: absolute; left: 3px; top: 10px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--faint);
}
.plan .btn { justify-self: start; }
.plan .btn--sm { margin-top: 6px; }

.linkish { color: var(--accent); text-decoration: underline; font: inherit; }

@media (min-width: 620px) {
  .plans { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================================
   Generated media (Part 10)
   ========================================================================== */

.media-slot:empty { display: none; }

.media {
  display: block;
  margin: 0 0 12px;
  max-width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.media--img { padding: 0; cursor: zoom-in; }
.media--img img {
  display: block;
  max-width: 100%;
  max-height: 460px;
  width: auto;
  border-radius: var(--radius);
}
.media video {
  display: block;
  width: 100%;
  max-height: 460px;
  background: #000;
}
.media--audio { padding: 12px 14px 10px; }
.media audio { width: 100%; display: block; }

.media__dl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 12px;
  color: var(--muted);
}
.media__dl:hover { color: var(--text); text-decoration: none; }
