/* Driftboard — product chat UI. Cool slate neutrals, one teal accent,
   Instrument Sans + IBM Plex Mono. Light & dark are both real themes. */

:root {
  --font-ui: "Instrument Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", monospace;

  --bg: #f2f3f5;            /* sidebar / app frame */
  --surface: #ffffff;       /* main thread */
  --raise: #ffffff;         /* composer, cards */
  --border: #e2e4e9;
  --border-strong: #cdd1d8;
  --text: #1a1d23;
  --text-mut: #667081;
  --text-faint: #8b93a2;
  --accent: #0d7a68;
  --accent-strong: #0a6355;
  --accent-soft: #e2f0ec;   /* user bubble */
  --accent-soft-text: #133c34;
  --hover: rgba(26, 29, 35, 0.055);
  --active-item: rgba(13, 122, 104, 0.09);
  --danger: #b3412f;
  --shadow: 0 1px 2px rgba(20, 24, 32, 0.05), 0 8px 24px -12px rgba(20, 24, 32, 0.18);

  --code-bg: #14161b;       /* code blocks stay dark in both themes (Claude's position) */
  --code-head: #1d2026;
  --code-text: #dee2e9;
  --code-border: #2a2e36;

  --tk-kw: #7dd3c8;
  --tk-str: #e3bb7d;
  --tk-com: #717c8c;
  --tk-num: #d98da1;
  --tk-fn: #a8b6fc;
  --tk-prop: #8fc7fd;

  --radius: 14px;
  --thread-w: 46rem;
}

[data-theme="dark"] {
  --bg: #101216;
  --surface: #17191f;
  --raise: #1d2027;
  --border: #272a32;
  --border-strong: #363a44;
  --text: #e7e9ee;
  --text-mut: #99a1b0;
  --text-faint: #6e7686;
  --accent: #3fcfb2;
  --accent-strong: #62dcc3;
  --accent-soft: #143732;
  --accent-soft-text: #c9ece4;
  --hover: rgba(231, 233, 238, 0.06);
  --active-item: rgba(63, 207, 178, 0.12);
  --danger: #e07a68;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --code-bg: #0d0f13;
  --code-head: #14171c;
  --code-border: #23262d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- layout ---------- */

.app { display: flex; height: 100dvh; }
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  position: relative;
}

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

.sidebar {
  width: 272px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  transition: margin-left 0.25s ease;
}
.app.sidebar-collapsed .sidebar { margin-left: -272px; }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand svg { display: block; border-radius: 8px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--text-mut);
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 4px 12px 10px;
  padding: 9px 13px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--raise);
  font-weight: 550;
  font-size: 14px;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.new-chat-btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.new-chat-btn svg { color: var(--accent); }

.conv-list { flex: 1; overflow-y: auto; padding: 2px 8px 12px; }
.conv-group-label {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 14px 10px 5px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
  transition: background 0.13s ease;
  position: relative;
}
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--active-item); }
.conv-item.active .conv-title { color: var(--text); font-weight: 550; }
.conv-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 8px 4px 8px 10px;
  font-size: 13.5px;
  color: var(--text-mut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 10px;
}
.conv-actions { display: none; align-items: center; padding-right: 4px; }
.conv-item:hover .conv-actions,
.conv-item.active .conv-actions,
.conv-item:focus-within .conv-actions { display: flex; }
.conv-actions .icon-btn { width: 26px; height: 26px; border-radius: 7px; }
.conv-actions .icon-btn:hover { color: var(--text); }
.conv-actions .icon-btn.confirm { color: var(--danger); background: var(--hover); }
.conv-rename-input {
  flex: 1;
  min-width: 0;
  margin: 4px 4px 4px 6px;
  padding: 4px 6px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--raise);
  border: 1px solid var(--accent);
  border-radius: 7px;
}
.conv-empty { padding: 18px 12px; font-size: 13px; color: var(--text-faint); line-height: 1.5; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.theme-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-mut);
  transition: background 0.15s ease, color 0.15s ease;
}
.theme-btn:hover { background: var(--hover); color: var(--text); }
.foot-colophon { font-size: 11.5px; color: var(--text-faint); text-align: right; line-height: 1.4; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  min-height: 54px;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-weight: 550;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-mut);
}
.topbar-title.named { color: var(--text); }

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

.thread-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.thread {
  max-width: var(--thread-w);
  margin: 0 auto;
  padding: 28px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.bubble {
  max-width: 82%;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  padding: 11px 16px;
  border-radius: 18px 18px 5px 18px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.msg.assistant { align-items: stretch; }
.md { font-size: 15.5px; line-height: 1.65; overflow-wrap: break-word; }
.md > * + * { margin-top: 0.85em; }
.md h3, .md h4, .md h5, .md h6 { line-height: 1.3; letter-spacing: -0.01em; }
.md h3 { font-size: 1.25em; margin-top: 1.3em; }
.md h4 { font-size: 1.1em; margin-top: 1.2em; }
.md ul, .md ol { padding-left: 1.5em; }
.md li { margin-top: 0.35em; }
.md li > ul, .md li > ol { margin-top: 0.35em; }
.md blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 2px 0 2px 14px;
  color: var(--text-mut);
}
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.md a { text-decoration-thickness: 1px; text-underline-offset: 2px; }
.md a:hover { color: var(--accent-strong); }

.inline-code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 0.93em; }
.md th, .md td { padding: 8px 13px; text-align: left; border-bottom: 1px solid var(--border); }
.md th { font-weight: 600; background: var(--hover); white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }

/* code blocks */
.code-block {
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid var(--code-border);
  background: var(--code-bg);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 6px 14px;
  background: var(--code-head);
  border-bottom: 1px solid var(--code-border);
}
.code-lang {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #8b95a6;
  text-transform: lowercase;
}
.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #a3adbd;
  padding: 4px 9px;
  border-radius: 7px;
  transition: background 0.15s ease, color 0.15s ease;
}
.code-copy:hover { background: rgba(255, 255, 255, 0.08); color: #e6eaf0; }
.code-copy.copied { color: var(--tk-kw); }
.code-block pre { overflow-x: auto; padding: 13px 15px; }
.code-block code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--code-text);
  display: block;
  min-width: max-content;
}
.tk-kw { color: var(--tk-kw); }
.tk-str { color: var(--tk-str); }
.tk-com { color: var(--tk-com); font-style: italic; }
.tk-num { color: var(--tk-num); }
.tk-fn { color: var(--tk-fn); }
.tk-prop { color: var(--tk-prop); }

/* message actions */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 7px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg.last .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 29px; height: 29px; border-radius: 8px; color: var(--text-faint); }
.msg-actions .icon-btn:hover { color: var(--text); }
.action-flash { font-size: 12px; color: var(--text-mut); padding: 0 4px; }

/* streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 15px;
  margin-left: 3px;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0.15; } }

/* thinking shimmer before first token */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mut);
  font-size: 14.5px;
}
.thinking .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { transform: scale(0.7); opacity: 0.4; } 50% { transform: scale(1); opacity: 1; } }

/* notices (errors, limits) */
.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  background: var(--hover);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-mut);
}
.notice.error { border-left-color: var(--danger); }
.notice.limit { border-left-color: var(--accent); }
.notice strong { color: var(--text); font-weight: 600; }
.notice .notice-body { flex: 1; }
.notice .retry-btn {
  margin-top: 8px;
  padding: 6px 13px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--raise);
  font-size: 13px;
  font-weight: 550;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.notice .retry-btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }

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

.empty-state {
  min-height: 52vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding-top: 4vh;
}
.empty-mark { margin-bottom: 8px; }
.empty-state h2 {
  font-size: 30px;
  font-weight: 640;
  letter-spacing: -0.022em;
  line-height: 1.15;
}
.empty-state p { color: var(--text-mut); font-size: 15px; max-width: 34rem; }
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 22px;
  width: 100%;
  max-width: 36rem;
}
.suggestion {
  text-align: left;
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--raise);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-mut);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}
.suggestion:hover { border-color: var(--accent); color: var(--text); box-shadow: var(--shadow); }
.suggestion .s-kicker {
  display: block;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  margin-bottom: 3px;
}

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

.composer-wrap {
  padding: 8px 20px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--surface) 75%, transparent);
}
.composer {
  max-width: var(--thread-w);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: var(--raise);
  padding: 9px 9px 9px 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  border: 0;
  background: none;
  resize: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  max-height: 190px;
  padding: 4px 0;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--text-faint); }
.composer textarea:disabled { color: var(--text-faint); }
.send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
[data-theme="dark"] .send-btn { color: #0c211d; }
.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.35; cursor: default; background: var(--accent); }
.send-btn .ic-stop { display: none; }
.send-btn.stop .ic-send { display: none; }
.send-btn.stop .ic-stop { display: block; }
.composer-note {
  max-width: var(--thread-w);
  margin: 7px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* jump to bottom */
.jump-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 108px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--raise);
  color: var(--text-mut);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
  z-index: 5;
}
.jump-bottom:hover { color: var(--text); border-color: var(--accent); }
.jump-bottom[hidden] { display: none; }

/* ---------- mobile ---------- */

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.45);
  z-index: 19;
  opacity: 0;
  transition: opacity 0.22s ease;
}
#sidebarClose { display: none; }

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(300px, 84vw);
    transform: translateX(-102%);
    transition: transform 0.25s ease;
    box-shadow: none;
    margin-left: 0 !important;
  }
  .app.drawer-open .sidebar { transform: translateX(0); box-shadow: 0 0 48px rgba(0, 0, 0, 0.3); }
  .app.drawer-open .scrim { display: block; opacity: 1; }
  #sidebarClose { display: inline-flex; }
  .thread { padding: 20px 16px 16px; gap: 22px; }
  .bubble { max-width: 88%; }
  .empty-state h2 { font-size: 24px; }
  .suggestions { grid-template-columns: 1fr; max-width: 100%; }
  .suggestion:nth-child(n+3) { display: none; } /* two chips on mobile — recomposed, not crammed */
  .composer-wrap { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); }
  .msg-actions { opacity: 1; } /* no hover on touch */
  .conv-actions { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .stream-cursor { animation: none; opacity: 0.8; }
}
