/* ═══════════════════════════════════════════════════════
   CHAT AI — style.css  v4
   ═══════════════════════════════════════════════════════ */

/* ─── RESET ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  height: 100%;
  height: -webkit-fill-available;
  color-scheme: light;
}
html.dark { color-scheme: dark; }
body {
  min-height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* ─── DESIGN TOKENS  (light) ────────────────────────── */
:root {
  --c-bg:        #fafafa;
  --c-surface:   #ffffff;
  --c-surface-2: #f3f3f3;
  --c-border:    #e8e8e8;
  --c-border-2:  #d0d0d0;
  --c-ink:       #111111;
  --c-ink-2:     #3d3d3d;
  --c-ink-3:     #6b6b6b;
  --c-ink-4:     #9a9a9a;
  --c-accent:    #111111;
  --c-accent-inv:#ffffff;
  --c-accent-soft: rgba(17, 17, 17, .06);
  --c-brand:       #b8956b;
  --c-brand-soft:  rgba(184, 149, 107, .14);
  --c-focus-ring:  rgba(184, 149, 107, .35);
  --c-err:       #c62828;
  --c-ok:        #1b7a4a;
  --sidebar-bg:     #0d0d0d;
  --sidebar-ink:    #f2f2f2;
  --sidebar-ink-2:  #8a8a8a;
  --sidebar-border: rgba(255, 255, 255, .07);
  --chat-max:    44rem;
  --touch-min:   40px;
  --f-serif: Georgia, 'Times New Roman', 'Palatino Linotype', serif;
  --f-sans:  system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  --f-mono:  ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  --r-sm:  8px;  --r-md: 12px;  --r-lg: 18px;  --r-xl: 26px;  --r-full: 9999px;
  --sh-sm: 0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.04);
  --sh-md: 0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --sh-lg: 0 16px 48px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06);
  --sh-input: 0 8px 32px rgba(0,0,0,.06);
  --t-fast: 0.15s;  --t-base: 0.25s;  --t-slow: 0.45s;
}

/* ─── DARK MODE ──────────────────────────────────────── */
html.dark {
  --c-bg:        #090909;
  --c-surface:   #141414;
  --c-surface-2: #1c1c1c;
  --c-border:    #2a2a2a;
  --c-border-2:  #3d3d3d;
  --c-ink:       #ededed;
  --c-ink-2:     #c4c4c4;
  --c-ink-3:     #8a8a8a;
  --c-ink-4:     #5a5a5a;
  --c-accent:    #f0f0f0;
  --c-accent-inv:#0a0a0a;
  --c-accent-soft: rgba(255, 255, 255, .06);
  --c-brand:       #d4b896;
  --c-brand-soft:  rgba(212, 184, 150, .12);
  --c-focus-ring:  rgba(212, 184, 150, .28);
  --c-err:       #f87171;
  --c-ok:        #4ade80;
  --sh-sm: 0 1px 3px rgba(0,0,0,.35);
  --sh-md: 0 4px 20px rgba(0,0,0,.45);
  --sh-lg: 0 16px 56px rgba(0,0,0,.55);
  --sh-input: 0 8px 36px rgba(0,0,0,.35);
}

/* ─── BASE ───────────────────────────────────────────── */
body {
  font-family: var(--f-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--c-ink);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  transition: background var(--t-slow), color var(--t-slow);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
html { overflow-x: clip; }
img, svg, video, canvas { max-width: 100%; }
body.nav-open { overflow: hidden; }
a { color: var(--c-ink); }
a:hover { text-decoration: underline; }
button, select, textarea, input { font-family: inherit; }

/* scrollbars */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border-2); border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: var(--c-border-2) transparent; }

*:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }
::selection { background: var(--c-brand-soft); color: var(--c-ink); }

/* ─── LAYOUT ─────────────────────────────────────────── */
.shell {
  display: flex;
  height: 100vh;
  height: var(--app-height, 100vh);
  overflow: hidden;
}
@supports (height: 100dvh) {
  .shell { height: 100dvh; height: var(--app-height, 100dvh); }
}

/* ─── SIDEBAR ────────────────────────────────────────── */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
}
.sidebar-logo {
  font-family: var(--f-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .12em;
  color: var(--sidebar-ink);
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  text-transform: uppercase;
}
.sidebar-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: linear-gradient(145deg, rgba(212,184,150,.22), rgba(255,255,255,.06));
  border: 1px solid rgba(212,184,150,.25);
  color: #e8d4bc;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.sidebar-nav {
  flex-shrink: 0;
  padding: 12px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--sidebar-ink-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: rgba(255,255,255,.08); color: var(--sidebar-ink); }
.nav-item:active { background: rgba(255,255,255,.12); }
.nav-item--active {
  background: rgba(255,255,255,.11);
  color: var(--sidebar-ink);
  box-shadow: inset 3px 0 0 var(--c-brand);
}
.sidebar-bottom {
  padding: 14px 12px max(14px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mit-license {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--sidebar-ink-2);
}
.mit-license a { color: var(--sidebar-ink-2); text-decoration: underline; }
.mit-license a:hover { color: var(--sidebar-ink); }
.theme-switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-ink-2);
}

/* ─── TOGGLE SWITCH ──────────────────────────────────── */
.toggle-switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 36px; height: 20px;
  background: rgba(255,255,255,.15);
  border-radius: var(--r-full);
  position: relative;
  transition: background var(--t-base);
}
.toggle-switch input:checked + .toggle-track { background: rgba(255,255,255,.5); }
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: var(--r-full);
  background: var(--sidebar-ink);
  transition: transform var(--t-base);
}
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
/* mobile small variant */
.toggle-switch--sm .toggle-track { width: 30px; height: 17px; background: var(--c-border-2); }
.toggle-switch--sm input:checked + .toggle-track { background: var(--c-ink); }
.toggle-switch--sm .toggle-thumb { width: 11px; height: 11px; background: var(--c-bg); }
.toggle-switch--sm input:checked + .toggle-track .toggle-thumb { transform: translateX(13px); }

/* ─── CHAT MAIN ──────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: var(--c-bg);
  background-image:
    radial-gradient(ellipse 90% 60% at 50% -30%, var(--c-accent-soft), transparent 70%);
  position: relative;
  transition: background var(--t-slow);
}

/* ─── MOBILE HEADER ──────────────────────────────────── */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--c-border);
  background: color-mix(in srgb, var(--c-bg) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}
.mobile-header-start { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mobile-logo { font-family: var(--f-serif); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.mobile-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 1190;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.is-open {
  display: block;
  animation: backdropIn var(--t-base) ease;
}
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }

/* ─── DESKTOP TOPBAR ─────────────────────────────────── */
.chat-topbar {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  background: color-mix(in srgb, var(--c-bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.chat-topbar-start {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 14rem;
}
.active-chat-title {
  font-family: var(--f-serif);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--c-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.active-chat-title:empty { display: none; }

/* ─── ICON BUTTON ────────────────────────────────────── */
.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--c-border);
  border-radius: var(--r-full);
  background: var(--c-surface);
  color: var(--c-ink-3);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-ink); border-color: var(--c-border-2); }
.icon-btn:active { transform: scale(.92); }

/* ─── STATUS PILL ────────────────────────────────────── */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--f-mono); font-size: 11px; letter-spacing: .04em; color: var(--c-ink-3);
  padding: 4px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
}
.status::before { content:''; display:block; width:6px; height:6px; border-radius:50%; flex-shrink:0; }
.status.online::before { background: var(--c-ok);  animation: sPulse 2.4s ease-in-out infinite; }
.status.busy::before   { background: #e89400;       animation: sPulse 1.2s ease-in-out infinite; }
.status.offline::before { background: var(--c-ink-4); animation: none; }
.status.error::before  { background: var(--c-err); }
@keyframes sPulse { 0%,100%{opacity:1} 50%{opacity:.35} }
.status-label { display: none; max-width: 0; overflow: hidden; transition: max-width var(--t-base), opacity var(--t-fast); opacity: 0; }
.mobile-header .status-label { display: inline; max-width: 6rem; opacity: 1; }
.status:not(.online) .status-label { display: inline; max-width: 6rem; opacity: 1; }
.chat-topbar .status:hover .status-label,
.chat-topbar .status:focus-within .status-label { display: inline; max-width: 6rem; opacity: 1; }
.queue-badge {
  font-family: var(--f-mono);
  font-size: 9px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--r-full);
  background: rgba(245, 158, 11, .15);
  color: #b45309;
  margin-left: 4px;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
}
.queue-badge:not(.hidden):hover { background: rgba(245, 158, 11, .28); transform: scale(1.03); }
html.dark .queue-badge { color: #fbbf24; }
.queue-badge.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── MESSAGES AREA ──────────────────────────────────── */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 28px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  scroll-behavior: smooth;
}

/* ─── WELCOME STATE ──────────────────────────────────── */
.welcome-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
  width: 100%;
  max-width: 36rem;
}
.welcome-state.hidden { display: none; }
.welcome-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--r-lg);
  font-family: var(--f-serif);
  font-size: 28px;
  color: var(--c-brand);
  background: linear-gradient(160deg, var(--c-surface), var(--c-surface-2));
  border: 1px solid var(--c-border);
  box-shadow: var(--sh-md), inset 0 1px 0 rgba(255,255,255,.6);
  animation: breathe 3.5s ease-in-out infinite;
  margin-bottom: 4px;
}
html.dark .welcome-glyph { box-shadow: var(--sh-md), inset 0 1px 0 rgba(255,255,255,.04); }
@keyframes breathe { 0%,100%{opacity:1;transform:scale(1) translateY(0)} 50%{opacity:.85;transform:scale(.97) translateY(2px)} }
.welcome-title {
  font-family: var(--f-serif);
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.25;
  color: var(--c-ink);
  background: linear-gradient(135deg, var(--c-ink) 40%, var(--c-brand) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
html.dark .welcome-title {
  background: linear-gradient(135deg, var(--c-ink) 30%, var(--c-brand) 95%);
  -webkit-background-clip: text;
  background-clip: text;
}
.welcome-sub {
  font-size: 15px;
  color: var(--c-ink-3);
  max-width: 26rem;
  line-height: 1.6;
}
.welcome-hints {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--c-ink-4);
  letter-spacing: .02em;
  margin-top: 2px;
}
.welcome-hints kbd {
  font-family: inherit;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 9px;
  color: var(--c-ink-3);
}
.welcome-features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.welcome-feature {
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: var(--r-full);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-ink-3);
}
.welcome-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  width: 100%;
  max-width: 28rem;
}

/* ─── MESSAGE ROWS ───────────────────────────────────── */
.message-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 6px 0;
  width: 100%;
  max-width: var(--chat-max);
  animation: fadeUp .22s ease both;
}
.message-row + .message-row { margin-top: 4px; }
.user-row { flex-direction: row-reverse; }
@keyframes fadeUp { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }

/* avatar */
.msg-avatar {
  width: 28px; height: 28px; border-radius: var(--r-md);
  background: linear-gradient(145deg, var(--c-ink), color-mix(in srgb, var(--c-ink) 80%, var(--c-ink-3)));
  color: var(--c-bg);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--f-mono); font-size: 9px; font-weight: 600; letter-spacing: .04em;
  flex-shrink: 0; margin-top: 3px;
  box-shadow: var(--sh-sm);
}
.user-row .msg-avatar { display: none; }

/* column holding bubble + meta + actions */
.msg-col { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.user-row .msg-col { align-items: flex-end; }

/* bubble */
.message {
  padding: 12px 16px;
  border-radius: var(--r-lg);
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: min(68ch, 100%);
  position: relative;
  box-shadow: var(--sh-sm);
}
.message.user {
  background: linear-gradient(145deg, var(--c-ink), color-mix(in srgb, var(--c-ink) 82%, var(--c-brand)));
  color: var(--c-bg);
  font-family: var(--f-sans);
  font-size: 14px;
  line-height: 1.55;
  border-radius: var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg);
  box-shadow: var(--sh-sm), 0 1px 0 rgba(255,255,255,.06) inset;
}
.message.bot {
  background: color-mix(in srgb, var(--c-surface) 96%, var(--c-brand-soft));
  color: var(--c-ink);
  font-family: var(--f-serif);
  font-size: 15px;
  line-height: 1.75;
  border: 1px solid color-mix(in srgb, var(--c-border) 80%, var(--c-brand-soft));
  border-radius: var(--r-sm) var(--r-lg) var(--r-lg) var(--r-lg);
}
.message.error-msg {
  background: #fff4f4; border: 1px solid #ffc8c8; color: var(--c-err);
  font-family: var(--f-sans); font-size: 13px; border-radius: var(--r-md);
}
html.dark .message.error-msg { background: #1e0a0a; border-color: #4a1010; }

/* streaming cursor */
.msg-content.streaming::after {
  content: '▋';
  animation: blink .9s step-end infinite;
  color: var(--c-ink-3); margin-left: 1px;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ─── MSG CONTENT (markdown) ─────────────────────────── */
.msg-content h1,.msg-content h2,.msg-content h3,
.msg-content h4,.msg-content h5,.msg-content h6 {
  font-family: var(--f-serif); font-weight: 700; letter-spacing: -.02em;
  margin: 1.1em 0 .4em; line-height: 1.25; color: var(--c-ink);
}
.msg-content h1{font-size:1.4em} .msg-content h2{font-size:1.2em} .msg-content h3{font-size:1.05em}
.msg-content p { margin: .5em 0; }
.msg-content p:first-child { margin-top: 0; }
.msg-content p:last-child  { margin-bottom: 0; }
.msg-content strong { font-weight: 700; }
.msg-content em     { font-style: italic; }
.msg-content del    { text-decoration: line-through; }
.msg-content hr     { border: none; border-top: 1px solid var(--c-border); margin: 1em 0; }
.msg-content blockquote {
  border-left: 3px solid var(--c-border-2); padding-left: 12px;
  color: var(--c-ink-3); margin: .6em 0;
}
.msg-content a {
  color: var(--c-ink); text-decoration: underline;
  text-decoration-color: var(--c-border-2); text-underline-offset: 2px;
  transition: text-decoration-color var(--t-fast);
}
.msg-content a:hover { text-decoration-color: var(--c-ink); }
.msg-content ul,.msg-content ol { padding-left: 1.4em; margin: .5em 0; }
.msg-content li { margin: .2em 0; }
.msg-content code {
  font-family: var(--f-mono); font-size: .88em;
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: 3px; padding: 1px 5px;
}
.msg-content pre.code-block {
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: var(--r-sm); padding: 12px 14px;
  overflow-x: auto; margin: .8em 0; position: relative;
}
.msg-content pre.code-block .code-lang {
  position: absolute; top: 6px; right: 10px;
  font-family: var(--f-mono); font-size: 9px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--c-ink-4);
}
.msg-content pre.code-block code {
  font-family: var(--f-mono); font-size: 12.5px; line-height: 1.55;
  background: none; border: none; padding: 0;
}

/* ─── MESSAGE ACTIONS ────────────────────────────────── */
.message-actions {
  display: flex; gap: 4px; margin-top: 6px;
  opacity: 0; transition: opacity var(--t-fast);
}
.message-row:hover .message-actions,
.message-row:focus-within .message-actions { opacity: 1; }
@media (hover:none) { .message-actions { opacity: 1; } }

.msg-action-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border: 1px solid var(--c-border);
  border-radius: var(--r-full); background: var(--c-surface);
  color: var(--c-ink-3); font-size: 11px; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.msg-action-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }
.msg-action-btn:active { transform: scale(.92); }
.msg-action-btn.danger:hover { background: #fff0f0; color: var(--c-err); border-color: #ffc8c8; }
html.dark .msg-action-btn.danger:hover { background: #1e0a0a; border-color: #4a1010; }
.msg-action-btn.liked { color: var(--c-ok); border-color: var(--c-ok); }

/* ─── MSG META ───────────────────────────────────────── */
.msg-meta {
  display: none; gap: 6px; align-items: center; margin-top: 5px;
  font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-4); letter-spacing: .03em;
}
.message-row:hover .msg-meta { display: flex; }
@media (hover:none) { .msg-meta { display: flex; } }
.msg-time {
  opacity: .85;
  cursor: default;
  white-space: nowrap;
}
.msg-time:hover { opacity: 1; color: var(--c-ink-3); }
.msg-provider {
  text-transform: uppercase; font-size: 9px; letter-spacing: .07em;
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: var(--r-sm); padding: 1px 5px;
}
.msg-provider--cached {
  background: rgba(74, 109, 220, .12);
  border-color: rgba(74, 109, 220, .28);
  color: var(--c-accent);
}
.msg-cache-src {
  font-size: 9px;
  color: var(--c-ink-3);
  text-transform: lowercase;
}

.mermaid-figure {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  overflow-x: auto;
}
.mermaid-figure--rendered .mermaid-diagram svg { max-width: 100%; height: auto; }
.mermaid-source { margin-top: 8px; font-size: 11px; color: var(--c-ink-3); }
.mermaid-source summary { cursor: pointer; user-select: none; }
.mermaid-source-code {
  margin-top: 6px; padding: 8px; font-size: 11px;
  background: var(--c-surface-2); border-radius: var(--r-sm);
  white-space: pre-wrap; overflow-x: auto;
}
.mermaid-error { font-size: 12px; color: var(--c-err); margin: 0; }

.conv-virtual-window { display: flex; flex-direction: column; gap: 2px; }
.conv-virtual-top, .conv-virtual-bottom { flex-shrink: 0; pointer-events: none; }

/* ─── PROCESS STRIP (above input) ────────────────────── */
.process-strip {
  margin-bottom: 8px;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-brand);
  border-radius: var(--r-md);
  background: var(--c-surface);
  animation: processEnter var(--t-base) ease;
}
.process-strip.hidden { display: none !important; }
@keyframes processEnter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.process-phases {
  display: flex;
  align-items: center;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.process-phases::-webkit-scrollbar { display: none; }

.process-phase {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  scroll-snap-align: start;
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--c-ink-4);
  padding: 4px 0;
  transition: color var(--t-fast);
}
.process-phase + .process-phase::before {
  content: '';
  display: block;
  width: 14px;
  height: 1px;
  margin: 0 6px;
  background: var(--c-border);
  flex-shrink: 0;
}
.process-phase.is-done { color: var(--c-ink-3); }
.process-phase.is-done .process-phase-dot { background: var(--c-ink); border-color: var(--c-ink); }
.process-phase.is-active { color: var(--c-ink); }
.process-phase.is-active .process-phase-dot {
  border-color: var(--c-ink);
  background: var(--c-ink);
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}
html.dark .process-phase.is-active .process-phase-dot { box-shadow: 0 0 0 3px rgba(255,255,255,.08); }

.process-phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--c-border-2);
  flex-shrink: 0;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.process-phase.is-active .process-phase-dot {
  animation: phasePulse 1.2s ease-in-out infinite;
}
@keyframes phasePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: .75; }
}

.process-phase-label { white-space: nowrap; }

.process-strip-detail {
  margin: 6px 0 0;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--c-ink-3);
  line-height: 1.4;
  min-height: 1.4em;
}

/* ─── IN-CHAT PROCESS ACTIVITY ───────────────────────── */
.process-activity-row .message.bot {
  padding: 10px 14px;
  min-width: min(280px, 100%);
}
.process-activity-panel { display: flex; flex-direction: column; gap: 8px; }
.process-activity-panel.collapsed .process-activity-head,
.process-activity-panel.collapsed .typing-indicator,
.process-activity-panel.collapsed .reasoning-panel,
.process-activity-panel.collapsed .processing-panel--inline { display: none; }
.process-activity-row.exit { animation: pExit var(--t-base) ease forwards; }
.processing-panel--inline {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  max-width: 100%;
}

.process-activity-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-ink-3);
}
.process-activity-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--c-ink);
  color: var(--c-bg);
  font-size: 8px;
  padding: 2px 6px;
  border-radius: var(--r-full);
  letter-spacing: .06em;
  animation: badgePulse 1.5s ease-in-out infinite;
}
.process-activity-badge::before {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.reasoning-panel {
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  overflow: hidden;
}
.reasoning-panel summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  cursor: pointer;
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-ink-2);
  list-style: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.reasoning-panel summary::-webkit-details-marker { display: none; }
.reasoning-panel summary::after {
  content: '▾';
  margin-left: auto;
  font-size: 10px;
  color: var(--c-ink-4);
  transition: transform var(--t-fast);
}
.reasoning-panel[open] summary::after { transform: rotate(180deg); }
.loader-circle {
  width: 12px;
  height: 12px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
.loader-circle--md { width: 18px; height: 18px; border-width: 2px; }
.reasoning-loader { width: 10px; height: 10px; }

.reasoning-panel.is-loading summary { color: var(--c-ink); }
.reasoning-panel.is-loading .reasoning-loader {
  border-color: color-mix(in srgb, var(--c-ink) 18%, var(--c-border));
  border-top-color: var(--c-ink);
}

.reasoning-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 2px;
  color: var(--c-ink-3);
  font-size: 12px;
  line-height: 1.4;
}
.reasoning-loading-text {
  font-style: italic;
  animation: reasoningTextPulse 2s ease-in-out infinite;
}
@keyframes reasoningTextPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

.reasoning-content {
  padding: 0 10px 8px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--c-ink-3);
  max-height: 120px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  word-break: break-word;
}
.reasoning-panel.is-loading .reasoning-content {
  min-height: 44px;
  display: flex;
  align-items: center;
}
.reasoning-content:not(:empty):not(:has(.reasoning-loading)) {
  padding-top: 2px;
}

.process-phase.is-active[data-phase="reason"] .process-phase-dot,
.process-phase.is-active[data-phase="think"] .process-phase-dot {
  background: transparent;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-ink);
  box-shadow: none;
  animation: spin .8s linear infinite;
}

.stream-cursor::after {
  content: '▋';
  display: inline;
  margin-left: 1px;
  color: var(--c-ink-3);
  animation: cursorBlink 1s step-end infinite;
}
@keyframes cursorBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

@media (max-width: 720px) {
  .process-strip { padding: 8px 10px; margin-bottom: 6px; }
  .process-phase { font-size: 9px; }
  .process-phase + .process-phase::before { width: 10px; margin: 0 4px; }
  .process-strip-detail { font-size: 10px; }
  .reasoning-content { max-height: 96px; font-size: 11px; }
}

/* ─── PIPELINE PANEL ─────────────────────────────────── */
.processing-panel {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: 12px 14px; margin: 6px 0;
  max-width: min(70ch, 100%);
}
.pipeline-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  font-family: var(--f-mono); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--c-ink-3);
}
.pipeline-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--c-ink); color: var(--c-bg);
  font-size: 8px; padding: 2px 6px; border-radius: var(--r-full);
  letter-spacing: .06em; animation: badgePulse 1.5s ease-in-out infinite;
}
.pipeline-badge::before { content:''; display:block; width:4px; height:4px; border-radius:50%; background:currentColor; }
@keyframes badgePulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.pstep {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 4px 0; font-family: var(--f-mono); font-size: 11px; color: var(--c-ink-3);
}
.pstep+.pstep { border-top: 1px solid var(--c-border); }
.pstep-icon {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--c-border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 8px; margin-top: 1px;
}
.pstep.done  .pstep-icon { background: var(--c-ink); border-color: var(--c-ink); color: var(--c-bg); }
.pstep.error .pstep-icon { background: var(--c-err); border-color: var(--c-err); color: #fff; }
.pstep.processing .pstep-icon {
  border-color: var(--c-ink-3); border-top-color: var(--c-ink);
  animation: spin .8s linear infinite;
}
@keyframes spin { to{transform:rotate(360deg)} }
.pstep-body  { flex:1; min-width:0; }
.pstep-name  { color: var(--c-ink-2); font-weight: 500; }
.pstep-detail{ font-size:10px; color:var(--c-ink-4); margin-top:1px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.processing-panel.collapsed { padding: 7px 12px; }
.processing-panel.collapsed .pstep { display: none; }
.processing-panel.collapsed .pipeline-header { margin-bottom: 0; }
.processing-panel.exit { animation: pExit var(--t-base) ease forwards; }
@keyframes pExit { to{opacity:0;transform:translateY(-4px);max-height:0;padding:0;margin:0;overflow:hidden} }

/* ─── TYPING INDICATOR ───────────────────────────────── */
.typing-indicator { display:flex; gap:5px; align-items:center; padding:4px 0; }
.typing-indicator span {
  width:7px; height:7px; border-radius:50%; background:var(--c-ink-4);
  animation: tBounce 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2){animation-delay:.18s}
.typing-indicator span:nth-child(3){animation-delay:.36s}
@keyframes tBounce { 0%,80%,100%{transform:translateY(0);opacity:.4} 40%{transform:translateY(-6px);opacity:1} }

/* ─── SUGGESTION CHIPS ───────────────────────────────── */
.suggestion-chip {
  padding: 10px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-ink-2);
  font-family: var(--f-sans);
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--sh-sm);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.suggestion-chip:hover {
  background: var(--c-ink);
  color: var(--c-bg);
  border-color: var(--c-ink);
  box-shadow: var(--sh-md);
  transform: translateY(-1px);
}
.suggestion-chip:active { transform: scale(.98) translateY(0); }

/* ─── SCROLL-TO-BOTTOM ───────────────────────────────── */
.scroll-bottom-btn {
  position: absolute;
  bottom: calc(108px + env(safe-area-inset-bottom, 0px));
  right: max(22px, calc(50% - var(--chat-max) / 2 - 2rem));
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-full); border: 1px solid var(--c-border);
  background: var(--c-surface); color: var(--c-ink-3);
  cursor: pointer; z-index: 5; box-shadow: var(--sh-md);
  transition: opacity var(--t-base), background var(--t-fast), transform var(--t-fast), border-color var(--t-fast);
  animation: fabIn var(--t-base) ease;
}
@keyframes fabIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.scroll-bottom-btn:hover {
  background: var(--c-surface-2);
  color: var(--c-ink);
  border-color: var(--c-brand);
  transform: translateY(-2px);
}
.scroll-bottom-btn.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* ─── CHAT INPUT ─────────────────────────────────────── */
.chat-input {
  padding: 12px 28px max(20px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--c-border);
  background: color-mix(in srgb, var(--c-bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
  position: relative;
  z-index: 1100;
}
.chat-input-inner {
  width: 100%;
  max-width: calc(var(--chat-max) + 4rem);
  margin: 0 auto;
}
.composer-attachments:has(.file-card),
.composer-attachments:has(.tool-card),
.composer-attachments:has(.rag-chip-bar:not(.hidden)) {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed color-mix(in srgb, var(--c-border) 70%, transparent);
}
body.cookie-visible .chat-input {
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  padding: 8px 10px 8px 12px;
  box-shadow: var(--sh-input);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.input-wrap:focus-within {
  border-color: color-mix(in srgb, var(--c-brand) 45%, var(--c-border-2));
  box-shadow: var(--sh-input), 0 0 0 3px var(--c-focus-ring);
  transform: translateY(-1px);
}
html.dark .input-wrap:focus-within { box-shadow: var(--sh-input), 0 0 0 3px var(--c-focus-ring); }
#messageInput {
  flex: 1; min-width: 0; border: none; background: transparent; resize: none;
  font-size: 16px; color: var(--c-ink); line-height: 1.55;
  max-height: 120px; padding: 4px 0; outline: none; overflow-y: auto;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}
#messageInput::placeholder { color: var(--c-ink-4); }
.input-icon-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--r-full);
  background: transparent; color: var(--c-ink-3); cursor: pointer;
  flex-shrink: 0; margin-bottom: 1px;
  transition: background var(--t-fast), color var(--t-fast);
}
.input-icon-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }
.input-icon-btn.listening { color: var(--c-err); background: rgba(204,34,34,.08); animation: mPulse 1s ease-in-out infinite; }
@keyframes mPulse { 0%,100%{box-shadow:0 0 0 0 rgba(204,34,34,.25)} 50%{box-shadow:0 0 0 6px rgba(204,34,34,0)} }
.send-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--r-full);
  background: var(--c-border); color: var(--c-ink-4); cursor: pointer; flex-shrink: 0;
  transition: opacity var(--t-fast), transform var(--t-fast), background var(--t-fast), color var(--t-fast);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.send-btn.is-ready,
.send-btn[aria-disabled="false"] {
  background: linear-gradient(145deg, var(--c-ink), color-mix(in srgb, var(--c-ink) 78%, var(--c-brand)));
  color: var(--c-bg);
  box-shadow: 0 2px 10px var(--c-brand-soft);
}
.send-btn:hover.is-ready { opacity: .9; transform: translateY(-1px); }
.send-btn:active.is-ready { transform: scale(.9); }
html.dark .send-btn:not(.is-ready) { background: var(--c-surface-2); }
.send-btn-icon { display: block; flex-shrink: 0; pointer-events: none; }

.input-hint {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--c-ink-4);
  margin-top: 8px;
  padding: 0 6px;
  letter-spacing: .02em;
  text-align: center;
  opacity: 0;
  transition: opacity var(--t-base);
}
.chat-input:focus-within .input-hint,
.chat-input-inner:focus-within .input-hint { opacity: 1; }
.input-hint-mobile { display: none; }
@media (max-width: 720px) {
  .input-hint-desktop { display: none; }
  .input-hint-mobile { display: inline; }
}
.input-hint kbd {
  font-family: inherit; background: var(--c-surface-2);
  border: 1px solid var(--c-border); border-radius: 3px; padding: 1px 4px;
}

.rate-limit-notice {
  font-family: var(--f-mono); font-size: 11px; color: var(--c-err);
  margin-top: 6px; padding: 6px 10px; border-radius: var(--r-sm);
  background: rgba(204, 34, 34, .08); border: 1px solid rgba(204, 34, 34, .2);
}
.rate-limit-notice.hidden { display: none; }
.rate-limit-notice.warn { color: #9a6700; background: rgba(232, 148, 0, .08); border-color: rgba(232, 148, 0, .25); }
html.dark .rate-limit-notice.warn { color: #e89400; }

/* ─── STATUS BAR ─────────────────────────────────────── */
.status-bar {
  font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-4); letter-spacing: .03em;
  overflow: hidden; max-height: 0;
  transition: max-height var(--t-base), padding var(--t-base);
  padding: 0 28px; border-top: 1px solid transparent;
}
.status-bar.visible {
  max-height: 26px; padding: 5px 28px; border-top-color: var(--c-border);
}

/* ─── MODALS ─────────────────────────────────────────── */
.modal { position:fixed; inset:0; z-index:100; display:none; align-items:center; justify-content:center; }
.modal.open { display: flex; }
.modal-overlay {
  position:absolute; inset:0;
  background:rgba(0,0,0,.45); backdrop-filter:blur(4px);
  animation: mOver var(--t-base) ease;
}
@keyframes mOver{from{opacity:0}to{opacity:1}}
@keyframes mIn{from{opacity:0;transform:translateY(10px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
@keyframes panelIn{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:translateY(0)}}
.modal-panel {
  position: relative;
  z-index: 1;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 24px 24px 20px;
  width: min(480px, calc(100vw - 32px));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--sh-lg), 0 0 0 1px rgba(255,255,255,.04) inset;
  animation: mIn var(--t-base) ease;
}
.modal-panel--settings {
  width: min(520px, calc(100vw - 24px));
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-panel--settings .modal-head {
  margin: 0;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--c-bg) 94%, transparent);
  backdrop-filter: blur(8px);
  z-index: 1;
}
.modal-panel--settings .settings-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
}
.modal-panel--settings .modal-actions {
  margin: 0;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--c-border);
  position: sticky;
  bottom: 0;
  background: var(--c-bg);
}
.modal-panel--sm { width: min(360px, calc(100vw - 32px)); }
@keyframes mIn{from{opacity:0;transform:scale(.95) translateY(8px)}to{opacity:1;transform:scale(1) translateY(0)}}
.modal-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:20px; }
.modal-title { font-family:var(--f-serif); font-size:16px; font-weight:700; letter-spacing:-.015em; }
.modal-body-text { font-size:14px; color:var(--c-ink-3); line-height:1.6; margin-bottom:22px; }
.modal-close { border-color:transparent; background:transparent; }
.modal-close:hover { background:var(--c-surface-2); border-color:var(--c-border); }
.modal-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:22px; }
.setting-group {
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--c-border);
}
.setting-group:last-child,
.modal-panel--settings .settings-body > .setting-group:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}
.setting-group label {
  display:block; font-size:11px; font-weight:600; text-transform:uppercase;
  letter-spacing:.08em; color:var(--c-ink-3); margin-bottom:5px;
}
.setting-toggle {
  display: flex !important; align-items: flex-start; gap: 10px;
  font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0;
  color: var(--c-ink); cursor: pointer; margin-bottom: 0;
}
.setting-toggle input { margin-top: 3px; flex-shrink: 0; accent-color: var(--c-ink); }
.setting-hint {
  font-size: 11px; color: var(--c-ink-4); margin-top: 6px; line-height: 1.45;
}
.setting-group select {
  width:100%; appearance:none;
  background: var(--c-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6e6e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 10px center;
  border:1px solid var(--c-border); border-radius:var(--r-sm);
  padding:8px 30px 8px 10px; font-size:13px; color:var(--c-ink); cursor:pointer;
  transition:border-color var(--t-fast);
}
.setting-group select:focus { border-color:var(--c-border-2); outline:none; }
.setting-group input[type="text"],
.setting-group textarea {
  width:100%; background:var(--c-surface); border:1px solid var(--c-border);
  border-radius:var(--r-sm); padding:8px 10px; font-size:13px; color:var(--c-ink);
  line-height:1.55; resize:vertical; transition:border-color var(--t-fast);
}
.setting-group input[type="text"] { resize:none; }
.setting-group textarea:focus { border-color:var(--c-border-2); outline:none; }
.setting-group code {
  display:block; width:100%; font-family:var(--f-mono); font-size:11px; color:var(--c-ink-3);
  background:var(--c-surface-2); border:1px solid var(--c-border);
  border-radius:var(--r-sm); padding:7px 10px;
}
.btn-primary {
  padding:8px 20px; background:var(--c-ink); color:var(--c-bg);
  border:1px solid var(--c-ink); border-radius:var(--r-full);
  font-size:13px; font-weight:500; cursor:pointer; transition:opacity var(--t-fast);
}
.btn-primary:hover { opacity:.82; }
.btn-primary:active { transform:scale(.95); }
.btn-ghost {
  padding:8px 20px; background:transparent; color:var(--c-ink-2);
  border:1px solid var(--c-border); border-radius:var(--r-full);
  font-size:13px; font-weight:500; cursor:pointer;
  transition:background var(--t-fast),color var(--t-fast);
}
.btn-ghost:hover { background:var(--c-surface-2); color:var(--c-ink); }
.btn-ghost:active { transform:scale(.95); }
.btn-danger {
  padding:8px 20px; background:var(--c-err); color:#fff;
  border:1px solid var(--c-err); border-radius:var(--r-full);
  font-size:13px; font-weight:500; cursor:pointer; transition:opacity var(--t-fast);
}
.btn-danger:hover { opacity:.85; }
.btn-danger:active { transform:scale(.95); }

/* ─── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 720px) {
  .sidebar {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(300px, 92vw);
    z-index: 1200;
    transform: translateX(-105%);
    transition: transform var(--t-base);
    box-shadow: var(--sh-lg);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .chat-topbar {
    display: flex;
    padding: 6px max(12px, env(safe-area-inset-left, 0px)) 6px max(12px, env(safe-area-inset-right, 0px));
    gap: 8px;
    border-bottom: 1px solid var(--c-border);
    grid-template-columns: none;
  }
  .chat-topbar-start,
  .chat-topbar .status,
  .chat-topbar .icon-btn { display: none; }
  .message-search-wrap { flex: 1; max-width: none; }
  .message-search-field { max-width: none; }
  .message-search { font-size: 13px; }
  .message-search--mobile { display: block; }
  .sidebar-conversations { flex: 1; max-height: none; }
  .sidebar-tools { max-height: 32vh; }
  .analytics-main { padding: 20px max(16px, env(safe-area-inset-left, 0px)) 32px max(16px, env(safe-area-inset-right, 0px)); }
  .analytics-header { flex-direction: column; align-items: flex-start; }
  .analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-value { font-size: 22px; }
  .modal-panel {
    width: calc(100vw - 20px);
    max-height: calc(var(--app-height, 100vh) - 24px);
    margin: max(10px, env(safe-area-inset-top, 0px)) 0 max(10px, env(safe-area-inset-bottom, 0px));
  }
  .modal-panel--settings { width: calc(100vw - 16px); max-height: calc(var(--app-height, 100vh) - 16px); }
  .offline-queue-panel {
    top: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px) + var(--keyboard-inset, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    width: auto;
  }
  .cookie-banner {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    padding: 14px max(16px, env(safe-area-inset-left, 0px)) max(14px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-right, 0px));
  }
  .cookie-btn { width: 100%; min-height: var(--touch-min); }
  .scroll-bottom-btn {
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: calc(96px + env(safe-area-inset-bottom, 0px) + var(--keyboard-inset, 0px));
  }
  .welcome-hints { display: none; }
  .chat-messages{ padding: 14px 14px 6px; }
  .chat-input   {
    padding: 8px max(12px, env(safe-area-inset-left, 0px)) max(12px, calc(env(safe-area-inset-bottom, 0px) + var(--keyboard-inset, 0px))) max(12px, env(safe-area-inset-right, 0px));
  }
  body.cookie-visible .chat-input {
    padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px));
  }
  .input-wrap   { gap: 6px; padding: 6px 6px 6px 10px; }
  .input-icon-btn { width: 36px; height: 36px; }
  .send-btn {
    width: 40px; height: 40px;
    flex-shrink: 0;
    margin-left: 2px;
  }
  .send-btn.is-ready {
    background: var(--c-ink);
    box-shadow: var(--sh-sm);
  }
  .input-hint {
    opacity: 1;
    font-size: 11px;
    margin-top: 6px;
  }
  .status-bar   { padding: 0 14px; }
  .status-bar.visible { padding: 4px 14px; }
  .message      { max-width: 94%; }
  .welcome-chips { grid-template-columns: 1fr; }
  .suggestion-chip { max-width: 100%; }
  .welcome-features { gap: 6px; }
}
@media (min-width: 721px) and (max-width: 1024px) {
  .sidebar { width: 200px; }
  .chat-messages { padding: 16px 20px 8px; }
  .chat-input { padding: 10px 20px max(16px, env(safe-area-inset-bottom, 0px)); }
  .message { max-width: 90%; }
}
@media (min-width: 1280px) {
  .chat-messages{ padding: 28px 48px 8px; }
  .chat-input   { padding: 12px 48px 22px; }
  .status-bar   { padding: 0 48px; }
  .status-bar.visible { padding: 4px 48px; }
  .message.bot  { font-size: 15.5px; }
}
@media (min-width: 1600px) {
  .sidebar      { width: 260px; }
  .chat-messages{ padding: 36px 64px 8px; }
  .chat-input   { padding: 14px 64px 26px; }
  .welcome-title{ font-size: 28px; }
}
@media (min-width: 1920px) {
  :root { --chat-max: 50rem; }
  .chat-topbar { padding-left: 48px; padding-right: 48px; }
}
@media (min-width: 2560px) {
  :root { --chat-max: 56rem; }
  .sidebar { width: 280px; }
}

/* ─── SIDEBAR TOOLS ──────────────────────────────────── */
.sidebar-tools {
  flex-shrink: 0;
  max-height: min(36vh, 220px);
  overflow-y: auto;
  padding: 10px 10px 8px;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-tools-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--sidebar-ink-2);
  padding: 0 8px 8px;
}
.sidebar-tool-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--sidebar-ink-2);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-tool-btn:hover { background: rgba(255,255,255,.08); color: var(--sidebar-ink); }
.sidebar-advanced { margin-top: 6px; font-size: 12px; color: var(--sidebar-ink-2); }
.sidebar-advanced summary { cursor: pointer; padding: 6px 8px; list-style: none; }
.sidebar-advanced summary::-webkit-details-marker { display: none; }
.mode-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; font-size: 11px; color: var(--sidebar-ink-2); cursor: pointer;
}
.arena-providers { padding-left: 8px; }
.bookmarks-section { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.08); }
.bookmarks-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--sidebar-ink-2); margin-bottom: 4px; }
.bookmark-list { display: flex; flex-direction: column; gap: 2px; max-height: 120px; overflow-y: auto; }
.bookmark-item {
  background: rgba(255,255,255,.06); border: none; color: var(--sidebar-ink);
  font-size: 11px; text-align: left; padding: 5px 8px; border-radius: var(--r-sm); cursor: pointer;
}
.bookmark-item:hover { background: rgba(255,255,255,.12); }
.bookmark-item-wrap { display: flex; align-items: center; gap: 2px; }
.bookmark-remove {
  flex: none; width: 22px; height: 22px; border: none; border-radius: var(--r-sm);
  background: transparent; color: var(--sidebar-ink-2); cursor: pointer; font-size: 14px;
}
.bookmark-remove:hover { background: rgba(255,80,80,.2); color: #ff8080; }
.bookmarks-actions { display: flex; align-items: center; gap: 8px; }
.bookmark-clear-btn {
  border: none; background: transparent; color: var(--sidebar-ink-2); font-size: 10px;
  cursor: pointer; text-decoration: underline;
}
.bookmark-clear-btn:hover { color: var(--sidebar-ink); }

/* ─── FILE CARDS ─────────────────────────────────────── */
.file-cards { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 2px 8px; }
.file-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-full);
  padding: 6px 10px 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--c-ink-2);
  box-shadow: var(--sh-sm);
  max-width: 100%;
}
.file-size { color: var(--c-ink-4); font-size: 11px; font-weight: 400; }
.file-remove { background: none; border: none; color: var(--c-err); cursor: pointer; font-size: 14px; padding: 0; }

/* ─── ARENA ──────────────────────────────────────────── */
.provider-caps {
  display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; min-height: 22px;
}
.cap-badge {
  font-family: var(--f-mono); font-size: 9px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: var(--r-full);
  border: 1px solid var(--c-border); background: var(--c-surface-2); color: var(--c-ink-3);
}
.cap-fast   { border-color: #b8e0c8; color: #1a6b3a; background: #f0faf4; }
.cap-vision { border-color: #c8d8f0; color: #2a5080; background: #f4f8fd; }
.cap-tools  { border-color: #e8d8b8; color: #7a5a10; background: #fdfaf4; }
.cap-code   { border-color: #d8c8e8; color: #5a3080; background: #faf6fd; }
.cap-large  { border-color: #e0c8c8; color: #803030; background: #fdf6f6; }
.cap-free   { border-color: #c8e8d8; color: #1a6040; background: #f4fdf8; }
html.dark .cap-fast   { color: #6fcf97; background: #0f1a14; border-color: #1e3a28; }
html.dark .cap-vision { color: #7eb8e8; background: #0f141a; border-color: #1e2a3a; }
html.dark .cap-tools  { color: #e8c878; background: #1a160f; border-color: #3a301e; }
html.dark .cap-code   { color: #c8a8e8; background: #160f1a; border-color: #2e1e3a; }
html.dark .cap-large  { color: #e8a0a0; background: #1a0f0f; border-color: #3a1e1e; }
html.dark .cap-free   { color: #88d8b0; background: #0f1a14; border-color: #1e3a28; }

.arena-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 8px; flex-wrap: wrap;
}
.arena-blind-label {
  font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-3); letter-spacing: .03em;
}
.arena-reveal {
  font-family: var(--f-mono); font-size: 10px; padding: 4px 10px;
  border: 1px solid var(--c-border); border-radius: var(--r-full);
  background: var(--c-surface); color: var(--c-ink-2); cursor: pointer;
}
.arena-reveal:hover { background: var(--c-surface-2); }
.arena-reveal.hidden { display: none; }

.arena-wrap { margin: 12px 0; max-width: 100%; }
.arena-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.arena-col { border: 1px solid var(--c-border); border-radius: var(--r-md); overflow: hidden; background: var(--c-surface); }
.arena-header { font-size: 11px; font-weight: 600; padding: 6px 10px; background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); text-transform: uppercase; }
.arena-body { padding: 8px 10px; min-height: 48px; font-size: 13px; }
.arena-status { font-size: 12px; color: var(--c-ink-3); }
.arena-pick {
  display: block; width: 100%; border: none; border-top: 1px solid var(--c-border);
  background: var(--c-ink); color: var(--c-accent-inv); padding: 6px; font-size: 12px; cursor: pointer;
}
.arena-pick.hidden { display: none; }

/* ─── ANALYTICS ──────────────────────────────────────── */
.analytics-main, .chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.analytics-main {
  overflow-y: auto;
  padding: 28px 32px 40px;
  background: var(--c-bg);
  background-image: radial-gradient(ellipse 70% 50% at 100% 0%, var(--c-brand-soft), transparent 55%);
}
.analytics-main.hidden, .chat-main.hidden { display: none !important; }
.analytics-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  max-width: 56rem;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
.analytics-header h1 {
  font-family: var(--f-serif);
  font-size: clamp(1.4rem, 2.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -.02em;
}
.analytics-header .btn-ghost { flex-shrink: 0; }
.analytics-sub {
  font-size: 13px;
  color: var(--c-ink-3);
  margin-top: 4px;
}
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
  max-width: 56rem;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
.stat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 16px 18px;
  box-shadow: var(--sh-sm);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }
.stat-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--c-ink-3);
  margin-bottom: 6px;
}
.stat-value { font-family: var(--f-serif); font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.analytics-section {
  margin-bottom: 28px;
  max-width: 56rem;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 16px 18px;
  box-shadow: var(--sh-sm);
}
.analytics-section h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 12px;
  color: var(--c-ink-3);
}
.provider-row, .elo-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  border-radius: var(--r-sm);
  transition: background var(--t-fast);
}
.provider-row:hover, .elo-row:hover { background: var(--c-surface-2); }
.provider-row:last-child, .elo-row:last-child { border-bottom: none; }
.elo-list, .provider-stats { border-radius: var(--r-sm); overflow: hidden; }
.analytics-empty { font-size: 13px; color: var(--c-ink-3); }
.export-btns { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

/* ─── TOAST ──────────────────────────────────────────── */
.app-toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--c-ink);
  color: var(--c-accent-inv);
  padding: 11px 20px;
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  box-shadow: var(--sh-lg);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.app-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.app-toast.error { background: var(--c-err); }
.app-toast.success { background: var(--c-ok); color: #fff; }

.hidden { display: none !important; }

/* ─── COOKIE CONSENT ─────────────────────────────────── */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1250;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px max(20px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  box-shadow: 0 -6px 32px rgba(0, 0, 0, .14);
  font-size: 14px;
  line-height: 1.45;
  color: var(--c-ink-2);
  transition: transform .35s ease, opacity .35s ease;
  pointer-events: auto;
}
.cookie-banner.open {
  transform: translateY(0);
  opacity: 1;
}
.cookie-banner.hide {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}
.cookie-text {
  flex: 1;
  min-width: 0;
}
.cookie-text a { color: var(--c-accent); text-decoration: underline; }
.cookie-text a:hover { text-decoration: none; }
.cookie-btn {
  flex-shrink: 0;
  background: var(--c-accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--r-full);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity .15s, transform .1s;
}
.cookie-btn:hover { opacity: .9; transform: scale(1.03); }

/* ─── CONVERSATIONS SIDEBAR ──────────────────────────── */
.sidebar-conversations {
  padding: 8px 10px;
  border-top: 1px solid var(--sidebar-border);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-conv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--sidebar-ink-2);
  margin-bottom: 8px;
}
.sidebar-conv-new {
  font-size: 10px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  border: 1px solid var(--sidebar-border);
  background: rgba(255,255,255,.04);
  color: var(--sidebar-ink-2);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-conv-new:hover { background: rgba(255,255,255,.1); color: var(--sidebar-ink); border-color: rgba(212,184,150,.35); }
.conv-search {
  width: 100%;
  margin: 6px 0 4px;
  padding: 6px 10px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--r-md);
  background: rgba(0,0,0,.18);
  color: var(--sidebar-ink);
  font-size: 11px;
  outline: none;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.conv-search::placeholder { color: var(--sidebar-ink-2); opacity: .7; }
.conv-search:focus {
  border-color: rgba(255,255,255,.22);
  background: rgba(0,0,0,.28);
}
.conv-search-empty {
  padding: 10px 8px;
  font-size: 11px;
  color: var(--sidebar-ink-2);
  text-align: center;
  font-style: italic;
}
.conversation-list {
  overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  -webkit-overflow-scrolling: touch;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--sidebar-ink-2);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.conv-item:hover { background: rgba(255,255,255,.07); color: var(--sidebar-ink); }
.conv-item.is-active {
  background: rgba(255,255,255,.11);
  color: var(--sidebar-ink);
  box-shadow: inset 3px 0 0 var(--c-brand);
}
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-pin {
  opacity: 0; flex-shrink: 0; font-size: 12px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.conv-item:hover .conv-pin, .conv-item--pinned .conv-pin { opacity: .55; }
.conv-pin:hover { opacity: 1 !important; color: #f59e0b; }
.conv-item--pinned .conv-title { font-weight: 600; }
.conv-dup {
  opacity: 0; flex-shrink: 0; font-size: 11px; line-height: 1; cursor: pointer; padding: 0 3px;
}
.conv-item:hover .conv-dup { opacity: .45; }
.conv-dup:hover { opacity: 1 !important; color: var(--sidebar-ink); }
.conv-delete {
  opacity: .5; font-size: 14px; line-height: 1; padding: 0 2px;
}
.conv-delete:hover { opacity: 1; color: var(--c-err); }
.conv-rename {
  opacity: 0; font-size: 11px; line-height: 1; padding: 0 2px;
}
.conv-item:hover .conv-rename { opacity: .5; }
.conv-rename:hover { opacity: 1 !important; color: var(--sidebar-ink); }
.conv-title-input {
  flex: 1; min-width: 0; padding: 2px 6px; border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--r-sm); background: rgba(0,0,0,.2); color: var(--sidebar-ink);
  font-size: 12px;
}

/* ─── MESSAGE SEARCH + CAPACITY ──────────────────────── */
.message-search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  max-width: 280px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-full);
  background: var(--c-surface);
  box-shadow: var(--sh-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.message-search-field:focus-within {
  border-color: color-mix(in srgb, var(--c-brand) 40%, var(--c-border-2));
  box-shadow: var(--sh-sm), 0 0 0 3px var(--c-focus-ring);
}
.message-search-icon { flex-shrink: 0; color: var(--c-ink-4); }
.message-search-field:focus-within .message-search-icon { color: var(--c-brand); }
.message-search {
  width: 100%;
  min-width: 0;
  padding: 7px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  font-size: 12px;
  color: var(--c-ink);
  box-shadow: none;
}
.message-search:focus {
  outline: none;
  box-shadow: none;
}
.message-row.search-miss { opacity: .25; }
.message-row.search-hit .message { box-shadow: 0 0 0 2px rgba(0,0,0,.08); }
.message-row.search-hit-active .message { box-shadow: 0 0 0 2px var(--c-brand); }
html.dark .message-row.search-hit .message { box-shadow: 0 0 0 2px rgba(255,255,255,.1); }
html.dark .message-row.search-hit-active .message { box-shadow: 0 0 0 2px var(--c-brand); }
.message-search-wrap { display: flex; align-items: center; gap: 6px; flex: 1; max-width: 360px; }
.message-search-wrap--mobile { flex-direction: column; align-items: stretch; max-width: none; }
.search-nav { display: flex; align-items: center; gap: 4px; flex: none; }
.search-nav.hidden { display: none; }
.search-count { font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-3); min-width: 3.5em; text-align: center; }
.search-nav-btn {
  width: 26px; height: 26px; border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface); color: var(--c-ink-2); cursor: pointer; font-size: 12px;
}
.search-nav-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }
.byok-more summary { cursor: pointer; font-size: 12px; color: var(--c-ink-3); margin-bottom: 6px; }
.byok-more input { margin-top: 6px; }
.btn-ghost--inline { width: 100%; text-align: left; padding: 8px 0; }
.persona-chip.is-active { background: var(--c-accent-soft); border-color: var(--c-brand); color: var(--c-brand); }
.hl-kw { color: #8250df; }
.hl-str { color: #0a3069; }
.hl-com { color: #6e7781; font-style: italic; }
.hl-num { color: #0550ae; }
html.dark .hl-kw { color: #d2a8ff; }
html.dark .hl-str { color: #a5d6ff; }
html.dark .hl-com { color: #8b949e; }
html.dark .hl-num { color: #79c0ff; }
.rag-chip--cloud { border-style: dashed; }
.auto-agent-wrap { margin: 12px 0; padding: 12px; border: 1px solid var(--c-border); border-radius: var(--r-md); background: var(--c-surface); }
.auto-plan-text { white-space: pre-wrap; font-family: var(--f-mono); font-size: 12px; max-height: 160px; overflow-y: auto; }
.auto-step { margin: 8px 0; font-size: 13px; }
.auto-step-status { font-family: var(--f-mono); font-size: 11px; color: var(--c-ink-3); margin: 4px 0; }
.conv-item--branch .conv-title { font-size: 11px; }
.anatomy-overlay { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--c-border); display: flex; flex-direction: column; gap: 6px; }
.anatomy-line { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.45; }
.anatomy-badge {
  flex: none; font-family: var(--f-mono); font-size: 9px; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 6px; border-radius: var(--r-full); border: 1px solid var(--c-border);
}
.anatomy-factual { background: rgba(46, 160, 67, .12); color: #1a7f37; }
.anatomy-opinion { background: rgba(74, 109, 220, .12); color: #3d5a80; }
.anatomy-suggestion { background: rgba(232, 148, 0, .12); color: #9a6700; }
.anatomy-hedge { background: rgba(140, 140, 140, .15); color: var(--c-ink-3); }
.anatomy-instruction { background: rgba(130, 80, 223, .12); color: #6e40c9; }
.anatomy-loading { opacity: .6; }
.regen-diff { margin-top: 8px; font-size: 12px; }
.regen-diff-body {
  font-family: var(--f-mono); font-size: 11px; line-height: 1.5;
  background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--r-sm);
  padding: 8px; max-height: 200px; overflow: auto;
}
.diff-add { color: #1a7f37; }
.diff-del { color: var(--c-err); }
.diff-same { color: var(--c-ink-3); }
.version-picker {
  margin-left: 4px; font-size: 10px; padding: 2px 6px; border: 1px solid var(--c-border);
  border-radius: var(--r-sm); background: var(--c-surface); color: var(--c-ink-2);
}

.capacity-banner {
  padding: 8px 16px; font-family: var(--f-mono); font-size: 11px;
  background: rgba(232, 148, 0, .12); color: #9a6700;
  border-bottom: 1px solid rgba(232, 148, 0, .25); text-align: center;
}
.capacity-banner--critical { background: rgba(204, 34, 34, .1); color: var(--c-err); border-color: rgba(204, 34, 34, .25); }
html.dark .capacity-banner { color: #e89400; }

.health-banner {
  padding: 8px 16px; font-family: var(--f-mono); font-size: 11px;
  background: rgba(232, 148, 0, .1); color: #9a6700;
  border-bottom: 1px solid rgba(232, 148, 0, .22); text-align: center;
}
html.dark .health-banner { color: #e89400; }

.offline-queue-panel {
  position: fixed; top: 56px; right: 16px; z-index: 850;
  animation: panelIn var(--t-base) ease;
  width: min(320px, calc(100vw - 32px));
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); box-shadow: var(--sh-lg);
  padding: 12px 14px; font-size: 13px;
}
.offline-queue-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 12px; margin-bottom: 8px;
}
.offline-queue-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.offline-queue-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--c-border);
}
.offline-queue-item:last-child { border-bottom: none; }
.offline-queue-body { flex: 1; min-width: 0; }
.offline-queue-text {
  flex: 1; min-width: 0; font-size: 12px; color: var(--c-ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.offline-queue-meta { font-size: 10px; color: var(--c-ink-3); font-family: var(--f-mono); }
.offline-queue-cancel {
  flex-shrink: 0; font-size: 11px; padding: 3px 8px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: transparent; color: var(--c-ink-2); cursor: pointer;
}
.offline-queue-cancel:hover { background: var(--c-surface-2); color: var(--c-err); border-color: rgba(204, 34, 34, .3); }
.offline-queue-empty { font-size: 12px; color: var(--c-ink-3); margin: 4px 0 0; text-align: center; }

.share-banner {
  padding: 8px 16px; font-family: var(--f-mono); font-size: 11px;
  background: rgba(74, 109, 220, .1); color: #3d5a80;
  border-bottom: 1px solid rgba(74, 109, 220, .2); text-align: center;
}
html.dark .share-banner { color: #9eb3e8; background: rgba(74, 109, 220, .15); }

.message-search--mobile { display: none; width: 100%; margin-bottom: 8px; }
.model-search {
  width: 100%; margin-bottom: 8px; padding: 8px 10px;
  border: 1px solid var(--c-border); border-radius: var(--r-md);
  font-size: 13px; background: var(--c-surface); color: var(--c-ink);
}
.model-search:focus {
  outline: none; border-color: var(--c-border-2);
  box-shadow: var(--sh-sm), 0 0 0 3px var(--c-accent-soft);
}
.label-hint { font-weight: 400; font-size: 11px; color: var(--c-ink-3); }

.active-mode-chip {
  font-family: var(--f-mono); font-size: 10px; font-weight: 600;
  padding: 4px 8px; border-radius: var(--r-full);
  background: var(--c-accent-soft); color: var(--c-ink-2);
  text-transform: uppercase; letter-spacing: .04em; flex-shrink: 0;
}
.active-mode-chip--heavy {
  background: rgba(245, 158, 11, .12);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, .25);
}
html.dark .active-mode-chip--heavy { color: #fbbf24; }
.mode-hint {
  margin: -2px 0 6px 22px;
  font-size: 10px;
  color: var(--sidebar-ink-2);
  line-height: 1.35;
}

.vision-warning {
  margin: 0 0 6px; padding: 8px 10px; font-size: 12px;
  background: rgba(232, 148, 0, .1); border: 1px solid rgba(232, 148, 0, .25);
  border-radius: var(--r-md); color: var(--c-ink-2);
}
.link-btn {
  background: none; border: none; padding: 0; margin-left: 4px;
  color: var(--c-brand, #3d5a80); text-decoration: underline; cursor: pointer; font: inherit;
}

.file-card--scanned { border-color: rgba(232, 148, 0, .35); }
.file-scan-tag {
  font-family: var(--f-mono); font-size: 9px; text-transform: uppercase;
  color: #9a6700; margin-left: 4px;
}
.file-vision-btn {
  margin-left: 6px; padding: 2px 8px; font-size: 10px; font-weight: 600;
  border: 1px solid var(--c-border); border-radius: var(--r-full);
  background: var(--c-surface); cursor: pointer;
}
.file-vision-btn:hover { background: var(--c-surface-2); }
.file-card--cloud { border-color: rgba(74, 109, 220, .3); }

.history-sentinel {
  height: 1px;
  width: 100%;
  pointer-events: none;
  flex-shrink: 0;
}

.history-load-more {
  display: block;
  width: 100%;
  margin: 8px 0 12px;
  padding: 10px 14px;
  border: 1px dashed var(--c-border-2);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  color: var(--c-ink-2);
  font-family: var(--f-mono);
  font-size: 11px;
  cursor: pointer;
  text-align: center;
}
.history-load-more:hover { background: var(--c-accent-soft); border-color: var(--c-border); }

.swarm-wrap {
  margin: 8px 0; padding: 12px; border: 1px solid var(--c-border);
  border-radius: var(--r-lg); background: var(--c-surface);
}
.swarm-status { font-family: var(--f-mono); font-size: 11px; color: var(--c-ink-3); margin-bottom: 8px; }
.swarm-steps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.swarm-step-card {
  padding: 8px 10px; border: 1px solid var(--c-border); border-radius: var(--r-md);
  background: var(--c-surface-2); font-size: 13px;
}
.swarm-step-label { font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-3); margin-bottom: 4px; }

.converter-preview {
  max-height: 220px; overflow: auto; margin: 10px 0 0;
  padding: 10px; font-family: var(--f-mono); font-size: 11px;
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: var(--r-md); white-space: pre-wrap; word-break: break-word;
}

/* ─── STOP BUTTON ────────────────────────────────────── */
.stop-btn {
  width: auto; min-width: 52px; height: 34px; padding: 0 12px;
  border: none; border-radius: var(--r-full); flex-shrink: 0;
  background: var(--c-err); color: #fff; font-size: 12px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(204, 34, 34, .25);
  transition: opacity var(--t-fast), transform var(--t-fast);
  animation: stopPulse 2s ease-in-out infinite;
}
@keyframes stopPulse { 0%,100%{box-shadow:0 2px 10px rgba(204,34,34,.25)} 50%{box-shadow:0 2px 16px rgba(204,34,34,.4)} }
.stop-btn:hover { opacity: .9; transform: scale(1.02); }
.stop-btn.hidden { animation: none; }

/* ─── PROVIDER HEALTH + SETTINGS SLIDERS ─────────────── */
.provider-health {
  display: flex; align-items: center; gap: 6px; margin-top: 6px;
  font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-3);
}
.health-dot { width: 8px; height: 8px; border-radius: 50%; }
.health-up { background: var(--c-ok); }
.health-degraded { background: #e89400; }
.health-down { background: var(--c-err); }
.health-unknown { background: var(--c-ink-4); }
.health-hint { font-size: 10px; color: var(--c-ink-4); }
.setting-val { float: right; font-family: var(--f-mono); color: var(--c-ink-3); }
.setting-group input[type="range"] { width: 100%; margin: 6px 0 12px; accent-color: var(--c-ink); }

/* ─── CODE COPY ──────────────────────────────────────── */
.code-copy-btn {
  position: absolute; top: 6px; right: 6px;
  padding: 2px 8px; font-size: 10px; border-radius: var(--r-sm);
  border: 1px solid var(--c-border); background: var(--c-surface);
  color: var(--c-ink-3); cursor: pointer;
}
.code-copy-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }

/* ─── SHORTCUTS + IMPORT + ONBOARDING ────────────────── */
.shortcuts-list { font-size: 13px; line-height: 2; color: var(--c-ink-2); }
.shortcuts-list kbd, .input-hint kbd {
  font-family: var(--f-mono); background: var(--c-surface-2);
  border: 1px solid var(--c-border); border-radius: 3px; padding: 1px 5px; font-size: 11px;
}
.import-file-input { width: 100%; font-size: 13px; margin: 8px 0; }

.onboarding-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.onboarding-overlay.hidden { display: none !important; }
.onboarding-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: 24px; max-width: 360px; width: 100%;
  box-shadow: var(--sh-lg);
}
.onboarding-card h3 { font-family: var(--f-serif); font-size: 18px; margin-bottom: 8px; }
.onboarding-card p { font-size: 14px; color: var(--c-ink-3); line-height: 1.55; }
.onboarding-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap;
}

/* ─── PRINT ──────────────────────────────────────────── */
@media print {
  .sidebar, .mobile-header, .chat-topbar, .chat-input, .scroll-bottom-btn,
  .process-strip, .message-actions, .cookie-banner, .capacity-banner, .health-banner, .offline-queue-panel,
  .sidebar-backdrop, .app-toast, .onboarding-overlay, .modal,
  .message-search, .conv-delete, #onboardingOverlay { display: none !important; }
  .shell { display: block; }
  .chat-main { overflow: visible; height: auto; }
  .chat-messages { overflow: visible; padding: 0; }
  .message { max-width: 100%; box-shadow: none; border: 1px solid #ccc; }
  .message.user { background: #f5f5f5; }
  body { background: #fff; color: #000; }
  .welcome-state { display: none !important; }
}

/* ─── EXTRA-SMALL PHONES ─────────────────────────────── */
@media (max-width: 380px) {
  .welcome-state { padding: 28px 14px; gap: 10px; }
  .welcome-glyph { width: 48px; height: 48px; font-size: 24px; }
  .welcome-title { font-size: 1.2rem; }
  .welcome-sub { font-size: 14px; }
  .welcome-features { display: none; }
  .mobile-logo { font-size: 11px; }
  .analytics-grid { grid-template-columns: 1fr; }
  .icon-btn { width: 36px; height: 36px; }
}

/* ─── LANDSCAPE PHONES ───────────────────────────────── */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .welcome-state { padding: 16px 20px; flex: 0; }
  .welcome-glyph { width: 40px; height: 40px; font-size: 20px; margin-bottom: 0; }
  .welcome-chips { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }
  .welcome-features, .welcome-hints { display: none; }
  .sidebar-tools { max-height: 40vh; }
  .chat-messages { padding-top: 10px; }
}

/* ─── TOUCH DEVICES (44px targets) ───────────────────── */
@media (hover: none) and (pointer: coarse) {
  :root { --touch-min: 44px; }
  .icon-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
  .input-icon-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
  .send-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
  .stop-btn { min-height: var(--touch-min); padding: 0 16px; }
  .conv-item { min-height: var(--touch-min); padding-top: 10px; padding-bottom: 10px; }
  .sidebar-tool-btn { min-height: var(--touch-min); display: flex; align-items: center; }
  .nav-item { min-height: var(--touch-min); }
  .msg-action-btn { min-height: 32px; padding: 6px 10px; }
  .search-nav-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
  .scroll-bottom-btn { width: var(--touch-min); height: var(--touch-min); }
  .cookie-btn { min-height: var(--touch-min); }
  .suggestion-chip { min-height: var(--touch-min); display: flex; align-items: center; }
  .message-actions { opacity: 1; }
  .msg-meta { display: flex; }
}

/* ─── TABLET PORTRAIT ────────────────────────────────── */
@media (min-width: 721px) and (max-width: 1024px) {
  .chat-topbar { padding-left: 20px; padding-right: 20px; }
  .active-chat-title { max-width: 10rem; }
  .message-search-field { max-width: 220px; }
}

/* ─── PERSONA CHIPS ──────────────────────────────────── */
.persona-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.persona-chip {
  padding: 5px 10px; border-radius: var(--r-full);
  border: 1px solid var(--c-border); background: var(--c-surface-2);
  color: var(--c-ink-2); font-size: 12px; cursor: pointer;
}
.persona-chip:hover { background: var(--c-surface); color: var(--c-ink); border-color: var(--c-border-2); }
.persona-chip.is-active,
.persona-chip:active {
  background: var(--c-brand-soft);
  border-color: var(--c-brand);
  color: var(--c-ink);
}

/* ─── CROSS-CHAT MEMORY ──────────────────────────────── */
.memory-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 160px; overflow-y: auto; margin-bottom: 8px;
}
.memory-empty { font-size: 12px; color: var(--c-ink-3); margin: 0; }
.memory-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--c-border);
  border-radius: var(--r-sm); background: var(--c-surface-2);
}
.memory-text { flex: 1; font-size: 13px; line-height: 1.4; }
.memory-del {
  border: none; background: none; color: var(--c-ink-3);
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px;
}
.memory-del:hover { color: var(--c-err); }
.memory-add-row { display: flex; gap: 8px; }
.memory-add-row input { flex: 1; }

/* ─── CONTEXT WINDOW BAR ─────────────────────────────── */
.context-window-bar {
  padding: 8px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  font-size: 11px;
}
.context-window-bar.hidden { display: none !important; }
.ctx-bar-legend {
  display: flex; flex-wrap: wrap; gap: 8px 12px;
  margin-bottom: 6px; color: var(--c-ink-3);
}
.ctx-legend-item { display: inline-flex; align-items: center; gap: 4px; }
.ctx-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 2px;
}
.ctx-dot.ctx-system, .ctx-seg.ctx-system { background: #6366f1; }
.ctx-dot.ctx-rag, .ctx-seg.ctx-rag { background: #8b5cf6; }
.ctx-dot.ctx-history, .ctx-seg.ctx-history { background: #0ea5e9; }
.ctx-dot.ctx-draft, .ctx-seg.ctx-draft { background: #f59e0b; }
.ctx-dot.ctx-free, .ctx-seg.ctx-free { background: var(--c-border); }
.ctx-bar-track {
  display: flex; height: 8px; border-radius: var(--r-full);
  overflow: hidden; background: var(--c-surface);
  border: 1px solid var(--c-border);
}
.ctx-seg { display: block; height: 100%; min-width: 0; transition: width .2s ease; }
.ctx-bar-label {
  display: block; margin-top: 5px;
  font-family: var(--f-mono); font-size: 10px; color: var(--c-ink-3);
}

/* ─── MERMAID DIAGRAMS ───────────────────────────────── */
.mermaid-diagram {
  margin: .8em 0; padding: 12px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface); overflow-x: auto;
}
.mermaid-diagram svg { max-width: 100%; height: auto; }
.mermaid-error {
  font-size: 12px; color: var(--c-danger, #c00); margin: 0;
}

/* ─── FINGERPRINT + COST ─────────────────────────────── */
.fingerprint-panel {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 16px; border: 1px solid var(--c-border);
  border-radius: var(--r-md); background: var(--c-surface);
}
#fingerprintCanvas { max-width: 100%; height: auto; }
.fingerprint-status { font-size: 12px; color: var(--c-ink-3); text-align: center; margin: 0; }
.cost-summary {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface-2); font-size: 13px; font-weight: 600;
}

/* ─── RAG CHIPS + TOOL CARDS ─────────────────────────── */
.rag-chip-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--c-ink-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
}
.rag-chip-bar.hidden { display: none !important; }
.rag-chip-label { font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 10px; }
.rag-chip {
  padding: 2px 8px; border-radius: var(--r-full);
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  font-family: var(--f-mono); font-size: 10px;
}

.tool-cards-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
  padding: 0 2px 8px;
}
.tool-cards-bar:empty { display: none; }
.tool-card {
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface-2); font-size: 12px;
}
.tool-card-head {
  padding: 4px 10px; cursor: pointer; font-weight: 600; color: var(--c-ink-2);
  list-style: none;
}
.tool-card-head::-webkit-details-marker { display: none; }
.tool-card-body {
  padding: 6px 10px 8px; font-family: var(--f-mono); font-size: 11px;
  color: var(--c-ink-3); border-top: 1px solid var(--c-border);
  white-space: pre-wrap; word-break: break-word;
}

/* ─── BYOK KEYS + PROVIDER STATS PANEL ───────────────── */
.setting-group--keys input[type="password"] {
  width: 100%; margin-top: 6px; padding: 8px 10px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface); color: var(--c-ink); font-size: 13px;
}
.setting-group--keys input[type="password"]:focus {
  outline: none; border-color: var(--c-border-2);
}

.provider-stats-panel {
  margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface-2); font-size: 11px;
}
.provider-stats-panel:empty { display: none; }
.prov-stat-row {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 3px 0; color: var(--c-ink-3);
  font-family: var(--f-mono);
}
.prov-stat-row + .prov-stat-row { border-top: 1px solid var(--c-border); }

/* ─── REDUCED MOTION ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after {
    animation-duration:.01ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.01ms !important;
  }
  .process-phase.is-active .process-phase-dot,
  .process-activity-badge,
  .pipeline-badge,
  .loader-circle,
  .reasoning-loading-text { animation: none !important; }
  .stream-cursor::after { animation: none; opacity: 1; }
}
