/* ============================================================
   Essomen Prism v1 - css/style.css
   Dark charcoal + red, modern motion. Zero dependencies.
   Signature motif: .prism-sweep (diagonal light band sweep).
   ============================================================ */

:root {
  --bg: #101014;
  --bg2: #17171c;
  --panel: #1e1e24;
  --panel2: #24242c;
  --line: #2a2a32;
  --line-soft: #222228;
  --red: #e5484d;
  --red-deep: #8f2428;
  --red-soft: rgba(229, 72, 77, 0.12);
  --text: #ececf1;
  --muted: #9a9aa3;
  --muted-dim: #6e6e78;
  --green: #3fb96f;
  --amber: #e0a63f;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --red-glow: 0 0 0 1px rgba(229, 72, 77, 0.35), 0 4px 18px rgba(229, 72, 77, 0.28);
  --ease: cubic-bezier(0.22, 0.8, 0.32, 1);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
::selection { background: rgba(229, 72, 77, 0.4); }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: 16px; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.view { height: 100dvh; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: transform 180ms var(--ease), box-shadow 180ms var(--ease),
              background 180ms var(--ease), border-color 180ms var(--ease);
}
.btn:hover { transform: translateY(-1px); border-color: #3a3a44; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-deep) 130%);
  border-color: rgba(229, 72, 77, 0.6);
  color: #fff;
  box-shadow: var(--red-glow);
}
.btn-primary:hover { box-shadow: 0 0 0 1px rgba(229, 72, 77, 0.5), 0 8px 26px rgba(229, 72, 77, 0.4); }
.btn-danger { background: rgba(229, 72, 77, 0.14); border-color: var(--red); color: #ff8a8e; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 7px 10px; }
.btn-ghost:hover { color: var(--text); background: var(--panel2); border-color: var(--line); }
.btn-block { width: 100%; }
.judge-cta { display: flex; justify-content: center; padding: 10px 0 4px; animation: msgIn 220ms ease-out; }
.btn-judge {
  background: linear-gradient(135deg, rgba(229, 72, 77, 0.18), rgba(229, 72, 77, 0.07));
  border: 1px solid rgba(229, 72, 77, 0.55);
  color: #ffb3b6;
  border-radius: 999px;
  padding: 9px 22px;
  font-weight: 600;
}
.btn-judge:hover { box-shadow: 0 0 18px rgba(229, 72, 77, 0.35); color: #fff; }
.btn-small { padding: 6px 10px; font-size: 13px; }

.icon-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.icon-btn span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }

/* ---------- login view ---------- */
#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px 300px at 50% -80px, rgba(229, 72, 77, 0.16), transparent 70%),
    var(--bg);
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 40px 36px 32px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: card-in 320ms var(--ease);
}
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.99); } }
.login-logo { display: flex; justify-content: center; margin-bottom: 10px; position: relative; }
.login-logo::before {
  content: ""; position: absolute; top: 50%; left: 50%; width: 230px; height: 230px;
  transform: translate(-50%, -58%); border-radius: 50%;
  background: radial-gradient(circle, rgba(229, 72, 77, 0.22) 0%, transparent 70%);
  filter: blur(12px); pointer-events: none;
}
.prism-wrap { position: relative; display: inline-block; }
.prism-wrap::before {
  content: ""; position: absolute; inset: -32%; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(229, 72, 77, 0.30) 70deg, transparent 140deg, rgba(255, 125, 156, 0.20) 210deg, transparent 280deg);
  filter: blur(30px);
  animation: aura-spin 9s linear infinite;
}
.brand-mini .prism-wrap::before { display: none; }
.prism-logo {
  width: 118px; height: auto; display: block; position: relative;
  animation: prism-float 5.2s ease-in-out infinite, prism-breathe 4.4s ease-in-out infinite;
}
.prism-logo.small {
  width: 30px;
  animation: none;
  filter: none;
}
.prism-logo.welcome-logo { width: 84px; margin: 0 auto 6px; }
@keyframes prism-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
@keyframes prism-breathe {
  0%, 100% { filter: drop-shadow(0 0 14px rgba(229, 72, 77, 0.45)) drop-shadow(0 8px 30px rgba(229, 72, 77, 0.22)); }
  50% { filter: drop-shadow(0 0 30px rgba(229, 72, 77, 0.80)) drop-shadow(0 8px 46px rgba(229, 72, 77, 0.42)); }
}
@keyframes aura-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .prism-logo, .prism-wrap::before { animation: none; }
  .prism-logo { filter: drop-shadow(0 0 18px rgba(229, 72, 77, 0.55)); }
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 0.2px; }
.tagline { color: var(--muted); margin: 0 0 26px; font-size: 14px; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input, .field select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 12px;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.field input:focus, .field select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.18);
  outline: none;
}
.form-error {
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.5);
  color: #ff9a9d;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin: 4px 0 14px;
  text-align: left;
}
.login-note { color: var(--muted-dim); font-size: 12px; margin: 16px 0 0; }

/* ---------- app layout ---------- */
#view-app { display: flex; }
#view-login[hidden], #view-app[hidden] { display: none !important; }
#sidebar {
  width: 284px;
  flex: 0 0 284px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.sidebar-top { padding: 16px 14px 10px; border-bottom: 1px solid var(--line-soft); }
.brand-mini {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; margin-bottom: 12px;
}
#thread-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.thread-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 160ms var(--ease), border-color 160ms var(--ease);
}
.thread-item:hover { background: var(--panel2); }
.thread-item.active { background: var(--red-soft); border-color: rgba(229, 72, 77, 0.35); }
.mode-ico {
  flex: 0 0 26px; width: 26px; height: 26px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.thread-item.active .mode-ico { color: var(--red); border-color: rgba(229, 72, 77, 0.5); }
.thread-title-text {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px;
}
.thread-item .mini-btn {
  background: transparent; border: none; color: var(--muted-dim);
  cursor: pointer; font-size: 15px; padding: 2px 5px; border-radius: 6px;
  opacity: 0; transition: opacity 150ms, color 150ms, background 150ms;
}
.thread-item:hover .mini-btn, .thread-item:focus-within .mini-btn { opacity: 1; }
.thread-item .mini-btn:hover { color: var(--red); background: rgba(229, 72, 77, 0.12); }
.thread-rename-input {
  flex: 1; min-width: 0;
  background: var(--bg2); border: 1px solid var(--red); border-radius: 6px;
  color: var(--text); font-size: 13.5px; padding: 4px 8px;
}
.threads-empty { color: var(--muted-dim); font-size: 13px; text-align: center; padding: 26px 12px; line-height: 1.6; }
.sidebar-foot { border-top: 1px solid var(--line-soft); padding: 12px 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; min-width: 0; }
.user-chip .email { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.demo-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(232, 180, 74, 0.15);
  color: #e8b44a;
  border: 1px solid rgba(232, 180, 74, 0.3);
  margin-left: 4px;
  vertical-align: middle;
}
.admin-badge {
  font-size: 10px; font-weight: 800; letter-spacing: 0.8px;
  color: #fff; background: linear-gradient(135deg, var(--red), var(--red-deep));
  border-radius: 5px; padding: 2px 7px;
  box-shadow: 0 0 10px rgba(229, 72, 77, 0.5);
}
.sidebar-actions { display: flex; gap: 4px; }

#drawer-scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  z-index: 150; backdrop-filter: blur(2px);
}

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- topbar + mode tabs ---------- */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(23, 23, 28, 0.85);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 100;
}
#mode-tabs {
  display: flex; gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  position: relative;
}
/* Fade indicator for horizontal scroll on mobile */
@media (max-width: 700px) {
  #mode-tabs::after {
    content: "";
    position: absolute;
    right: 0; top: 4px; bottom: 4px;
    width: 32px;
    background: linear-gradient(to right, transparent, var(--bg2));
    pointer-events: none;
    border-radius: 0 8px 8px 0;
  }
  #mode-tabs.scrolled-end::after {
    display: none;
  }
}
.mode-tab {
  border: none; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 13.5px;
  padding: 10px 18px; border-radius: 8px; cursor: pointer;
  min-height: 38px;
  transition: color 180ms var(--ease), background 180ms var(--ease), box-shadow 180ms var(--ease), transform 180ms var(--ease);
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--red) 0%, var(--red-deep) 140%);
  box-shadow: var(--red-glow);
  transform: translateY(-1px);
}
.thread-title {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--muted); font-size: 13.5px; text-align: right;
}

/* ---------- messages ---------- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 12px;
  scroll-behavior: smooth;
}
.msg-column { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg { animation: msg-in 220ms var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } }
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }
.bubble {
  max-width: min(78%, 640px);
  border-radius: 16px;
  padding: 12px 15px;
  position: relative;
  overflow-wrap: break-word;
}
.msg-row.user .bubble {
  background: linear-gradient(135deg, #2b2b34 0%, #232329 100%);
  border: 1px solid var(--line);
  border-bottom-right-radius: 5px;
}
.msg-row.assistant .bubble {
  background: linear-gradient(180deg, var(--panel2) 0%, var(--panel) 100%);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  max-width: min(92%, 760px);
}
.bubble-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.bubble-head .model-name { color: var(--text); }
.msg-text { font-size: 14.5px; }
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text h1, .msg-text h2, .msg-text h3 { margin: 14px 0 8px; font-size: 15px; }
.msg-text ul, .msg-text ol { margin: 6px 0 10px; padding-left: 22px; }
.msg-text li { margin-bottom: 4px; }
.msg-text code {
  font-family: var(--mono); font-size: 13px;
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px;
}
.msg-text pre {
  font-family: var(--mono); font-size: 13px;
  background: rgba(0, 0, 0, 0.4); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px; overflow-x: auto;
  margin: 8px 0 10px;
}
.msg-text pre code { background: none; border: none; padding: 0; }
.msg-text blockquote {
  margin: 8px 0; padding: 6px 12px;
  border-left: 3px solid var(--red); color: var(--muted);
  background: rgba(229, 72, 77, 0.06); border-radius: 0 8px 8px 0;
}
.msg-text strong { color: #fff; }

/* reasoning collapsible */
details.reasoning { margin-top: 8px; font-size: 13px; }
details.reasoning summary { cursor: pointer; color: var(--muted); font-weight: 600; }
details.reasoning summary:hover { color: var(--text); }
details.reasoning .reasoning-body {
  margin-top: 6px; padding: 10px 12px;
  background: rgba(0, 0, 0, 0.25); border: 1px dashed var(--line);
  border-radius: var(--radius-sm); color: var(--muted);
  white-space: pre-wrap; max-height: 220px; overflow-y: auto;
}

/* ---------- signature: prism sweep ---------- */
.prism-sweep { position: relative; overflow: hidden; }
.prism-sweep::after {
  content: "";
  position: absolute; top: -10%; bottom: -10%; left: 0;
  width: 45%;
  background: linear-gradient(100deg,
    transparent 0%,
    rgba(229, 72, 77, 0.22) 30%,
    rgba(255, 255, 255, 0.38) 50%,
    rgba(255, 140, 160, 0.22) 70%,
    transparent 100%);
  transform: translateX(-160%) skewX(-12deg);
  animation: prism-sweep-move 1.7s ease-in-out infinite;
  pointer-events: none;
  mix-blend-mode: screen;
}
@keyframes prism-sweep-move {
  0% { transform: translateX(-160%) skewX(-12deg); }
  100% { transform: translateX(340%) skewX(-12deg); }
}

/* ---------- skeleton shimmer ---------- */
.skeleton {
  position: relative; overflow: hidden;
  background: var(--panel2);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,0.08) 50%, transparent 70%);
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skeleton-line { height: 14px; margin: 8px 0; }
.skeleton-line.short { width: 55%; }

/* ---------- run groups (compare / panel) ---------- */
.run-group { display: flex; flex-direction: column; gap: 12px; }
.run-group.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 12px;
  max-width: none;
}
.compare-col {
  display: flex; flex-direction: column; min-width: 0;
  background: linear-gradient(180deg, var(--panel2) 0%, var(--panel) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  animation: msg-in 220ms var(--ease);
}
.compare-col .bubble {
  max-width: none; border: none; background: transparent;
  box-shadow: none; border-radius: 0; flex: 1;
}
.compare-col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px; font-weight: 700;
  min-width: 0;
}
.compare-col-head .model-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- status pills ---------- */
.pill {
  flex: 0 0 auto;
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase;
  border-radius: 20px; padding: 3px 10px;
  border: 1px solid var(--line);
  color: var(--muted); background: var(--bg2);
  transition: all 200ms var(--ease);
}
.pill.waiting { color: var(--muted); }
.pill.answering {
  color: var(--amber); border-color: rgba(224, 166, 63, 0.55);
  background: rgba(224, 166, 63, 0.1);
  animation: pill-pulse 1.1s ease-in-out infinite;
}
.pill.done { color: var(--green); border-color: rgba(63, 185, 111, 0.5); background: rgba(63, 185, 111, 0.08); }
.pill.error { color: #ff9a9d; border-color: rgba(229, 72, 77, 0.6); background: rgba(229, 72, 77, 0.1); }
@keyframes pill-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- route receipt cards ---------- */
.receipt { margin-top: 10px; }
.receipt summary {
  cursor: pointer; font-size: 12px; color: var(--muted-dim); font-weight: 600;
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
.receipt summary::before { content: "+"; color: var(--red); font-weight: 800; }
.receipt[open] summary::before { content: "-"; }
.receipt summary:hover { color: var(--muted); }
.receipt-card {
  margin-top: 6px;
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--muted);
  overflow-x: auto;
  white-space: pre;
}
.receipt-card .rk { color: var(--muted-dim); }
.receipt-card .rv-cost { color: var(--green); }

/* ---------- verdict card ---------- */
.verdict-card {
  border: 1px solid rgba(229, 72, 77, 0.45);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(229, 72, 77, 0.1) 0%, var(--panel) 60%);
  box-shadow: var(--red-glow);
  padding: 16px 18px;
  animation: msg-in 240ms var(--ease);
  grid-column: 1 / -1;
}
.verdict-title { font-weight: 800; font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.verdict-title::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 10px var(--red); }

/* ---------- keyless notice ---------- */
.notice-card {
  border: 1px dashed rgba(229, 72, 77, 0.55);
  background: rgba(229, 72, 77, 0.07);
  border-radius: var(--radius);
  padding: 16px 18px;
  animation: msg-in 220ms var(--ease);
}
.notice-card p { margin: 0 0 12px; font-size: 14px; }
.notice-card .notice-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- mode options row ---------- */
#mode-options {
  border-top: 1px solid var(--line-soft);
  background: var(--bg2);
  padding: 10px 18px;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
#mode-options.switching { opacity: 0; transform: translateY(5px); }
.opt-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 1100px; margin: 0 auto; }
.opt-label { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.opt-select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 10px; max-width: 100%;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.opt-select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.16); outline: none; }
.opt-search {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 12px; flex: 1; min-width: 200px; max-width: 100%;
  font-size: 14px; transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.opt-search:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.16); outline: none; }
.opt-search::placeholder { color: var(--muted); opacity: 0.6; }
.chip-list { display: flex; gap: 7px; flex-wrap: wrap; flex: 1; min-width: 0; }
.model-chip {
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); border-radius: 20px;
  padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: all 170ms var(--ease);
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 260px;
}
.model-chip span.nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-chip:hover { border-color: #3d3d48; color: var(--text); transform: translateY(-1px); }
.model-chip.selected {
  border-color: var(--red); color: #fff;
  background: linear-gradient(135deg, rgba(229,72,77,0.28), rgba(143,36,40,0.28));
  box-shadow: var(--red-glow);
}
.free-badge {
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.5px;
  color: var(--green); border: 1px solid rgba(63, 185, 111, 0.5);
  border-radius: 4px; padding: 1px 5px; flex: 0 0 auto;
}
.squad-lock-note { font-size: 12.5px; color: var(--muted-dim); display: inline-flex; align-items: center; gap: 6px; }
.opt-count { font-size: 12.5px; color: var(--muted); }
.opt-hint { font-size: 12px; color: var(--muted-dim); width: 100%; }

/* ---------- prompt bar ---------- */
#promptbar {
  border-top: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(23,23,28,0.6) 0%, var(--bg2) 40%);
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
}
.prompt-row { display: flex; gap: 10px; align-items: flex-end; max-width: 1100px; margin: 0 auto; }
#prompt-input {
  flex: 1; resize: none;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; color: var(--text);
  padding: 12px 15px; max-height: 180px; line-height: 1.5;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
  scrollbar-width: none;
}
#prompt-input::-webkit-scrollbar { display: none; }
#prompt-input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.16); outline: none; }
#prompt-input::placeholder { color: var(--muted-dim); }
#btn-send { border-radius: 14px; padding: 12px 16px; display: inline-flex; align-items: center; }
#btn-stop { border-radius: 14px; padding: 12px 16px; }
.prompt-meta {
  display: flex; align-items: center; gap: 14px;
  max-width: 1100px; margin: 8px auto 0;
}
.key-hint { font-size: 12px; color: var(--muted-dim); }
.key-hint.ok { color: var(--green); }
.key-hint.missing { color: var(--amber); }

/* ---------- toggle switch ---------- */
.switch-wrap { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-ui {
  width: 40px; height: 22px; border-radius: 20px;
  background: var(--panel2); border: 1px solid var(--line);
  position: relative; flex: 0 0 auto;
  transition: background 200ms var(--ease), border-color 200ms var(--ease), box-shadow 200ms var(--ease);
}
.switch-ui::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted);
  transition: transform 200ms var(--ease), background 200ms var(--ease);
}
.switch:checked + .switch-ui {
  background: linear-gradient(135deg, var(--red), var(--red-deep));
  border-color: rgba(229, 72, 77, 0.6);
  box-shadow: 0 0 12px rgba(229, 72, 77, 0.45);
}
.switch:checked + .switch-ui::after { transform: translateX(18px); background: #fff; }
.switch:focus-visible + .switch-ui { outline: 2px solid var(--red); outline-offset: 2px; }
.switch-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.switch:checked ~ .switch-label { color: var(--text); }

/* ---------- web grounding toggle chip ---------- */
.toggle-chip {
  font-size: 12.5px; font-weight: 700;
  padding: 10px 13px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  min-height: 38px;
  transition: background 180ms var(--ease), color 180ms var(--ease),
    border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.toggle-chip:hover { color: var(--text); border-color: var(--muted-dim); }
.toggle-chip.on {
  background: linear-gradient(135deg, var(--red), var(--red-deep));
  border-color: rgba(229, 72, 77, 0.6);
  color: #fff;
  box-shadow: 0 0 10px rgba(229, 72, 77, 0.4);
}
.toggle-chip:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------- image attach ---------- */
.attach-btn {
  flex: 0 0 auto;
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color 180ms var(--ease), border-color 180ms var(--ease),
    transform 180ms var(--ease);
}
.attach-btn:hover:not(:disabled) { color: var(--text); border-color: var(--red); transform: translateY(-1px); }
.attach-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.attach-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
#attach-preview { display: flex; align-items: flex-end; }
#attach-preview:empty { display: none; }
.attach-thumb {
  position: relative; width: 56px; height: 56px;
  border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line);
  animation: msg-in 220ms var(--ease);
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-remove {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(8, 8, 10, 0.82); color: #fff;
  border: 1px solid var(--line);
  font-size: 12px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.attach-remove:hover { border-color: var(--red); color: #ffb3b5; }

/* ---------- vision-model heads-up ---------- */
.vision-warn {
  max-width: 1100px; margin: 8px auto 0;
  font-size: 12.5px; color: var(--amber);
}
.vision-warn[hidden] { display: none; }

/* ---------- sources card (web-grounded runs) ---------- */
.sources-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 16px;
  animation: msg-in 220ms var(--ease);
}
.sources-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px;
}
.sources-card ol { margin: 0; padding-left: 20px; font-size: 13.5px; }
.sources-card li { margin-bottom: 6px; }
.sources-card a { color: var(--text); text-decoration: underline; text-decoration-color: var(--muted-dim); }
.sources-card a:hover { color: var(--red); text-decoration-color: var(--red); }

/* ---------- modal ---------- */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(5, 5, 8, 0.72);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  animation: fade-in 180ms var(--ease);
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 620px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: modal-in 220ms var(--ease);
  overflow: hidden;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-x {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
  transition: all 160ms var(--ease);
}
.modal-x:hover { color: var(--red); border-color: var(--red); }
.modal-body { padding: 20px 22px 26px; display: flex; flex-direction: column; gap: 24px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 10px; }
/* Variable fill dialog */
.var-dialog { max-width: 440px; }
.var-dialog .modal-body { gap: 14px; }
.var-dialog .field span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.var-dialog .field input {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.var-dialog .field input:focus { outline: none; border-color: var(--red); }
/* Chat folders */
.thread-folder { margin-bottom: 4px; }
.folder-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
  font-size: 13px; font-weight: 700; color: var(--text);
  transition: background 160ms var(--ease);
}
.folder-head:hover { background: var(--hover); }
.folder-toggle { font-size: 10px; color: var(--muted); width: 14px; }
.folder-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count { font-size: 11px; color: var(--muted); background: var(--surface); border-radius: 10px; padding: 1px 8px; }
.thread-folder .thread-item { margin-left: 16px; }
.thread-folder.collapsed .thread-item { display: none; }
.folder-picker { gap: 8px; }
.folder-picker .folder-dot { display: inline-block; margin-right: 4px; }
/* @ mention dropdown */
.mention-dropdown {
  position: absolute; bottom: 100%; left: 0; right: 0;
  margin-bottom: 8px; z-index: 50;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden;
  max-height: 280px; overflow-y: auto;
}
.mention-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; padding: 10px 14px; background: none; border: none;
  color: var(--text); cursor: pointer; text-align: left;
  transition: background 140ms var(--ease);
}
.mention-item:hover { background: var(--hover); }
.mention-name { font-size: 13.5px; font-weight: 600; }
.mention-id { font-size: 11.5px; color: var(--muted); font-family: monospace; }
/* Disagreement card */
.disagreement-card {
  margin: 12px 0; padding: 14px 16px;
  background: rgba(232, 180, 74, 0.08);
  border: 1px solid rgba(232, 180, 74, 0.3);
  border-radius: 12px;
}
.disagreement-head { font-size: 13px; font-weight: 700; color: var(--gold, #e8b44a); margin-bottom: 8px; }
.disagreement-body { font-size: 13.5px; color: var(--text); line-height: 1.6; white-space: pre-wrap; }
/* Model picker collapse */
.opt-collapse-btn {
  display: block; width: 100%; padding: 6px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: all 160ms var(--ease);
}
.opt-collapse-btn:hover { color: var(--text); border-color: var(--red); }
#mode-options.options-collapsed > *:not(.opt-collapse-btn) { display: none; }
#mode-options.options-collapsed { padding: 4px 0; }
/* Temporary mode toggle */
#temp-toggle.active {
  background: rgba(232, 180, 74, 0.15);
  border-color: var(--gold, #e8b44a);
  color: var(--gold, #e8b44a);
}
.set-section h3 {
  margin: 0 0 4px; font-size: 14px; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--muted);
}
.set-section > p.desc { margin: 0 0 12px; font-size: 13px; color: var(--muted-dim); }
.key-row { display: flex; gap: 8px; }
.key-row .field { flex: 1; margin: 0; }
.key-status { font-size: 13px; margin-top: 8px; min-height: 20px; }
.key-status.ok { color: var(--green); }
.key-status.fail { color: #ff9a9d; }
.key-status.working { color: var(--amber); }
.set-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.danger-zone { border: 1px solid rgba(229, 72, 77, 0.35); border-radius: var(--radius); padding: 16px; }
.danger-zone h3 { color: #ff9a9d; }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); }
.admin-table th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px; }
.admin-table td.email { word-break: break-all; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 6px; margin-top: 6px; }
.inline-form input {
  flex: 1; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 6px; color: var(--text); padding: 6px 9px; font-size: 13px; min-width: 0;
}
.create-user-form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.create-user-form .field { margin: 0; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.check-row input { width: 17px; height: 17px; accent-color: var(--red); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 200;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  max-width: min(92vw, 520px); text-align: center;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-ok { border-color: rgba(63, 185, 111, 0.55); }
#toast.toast-error { border-color: rgba(229, 72, 77, 0.6); box-shadow: var(--red-glow); }
#toast.toast-warn { border-color: rgba(224, 166, 63, 0.55); }

/* ---------- welcome / empty state ---------- */
.welcome { text-align: center; padding: 8vh 20px 30px; animation: msg-in 260ms var(--ease); }
.welcome .prism-logo { margin: 0 auto 18px; }
.welcome h2 { margin: 0 0 8px; font-size: 22px; }
.welcome p { color: var(--muted); max-width: 480px; margin: 0 auto 6px; font-size: 14px; }
.welcome .mode-hint { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.welcome .hint-chip {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 8px 13px; font-size: 13px; color: var(--muted);
}

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #33333c; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #44444e; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-105%);
    transition: transform 240ms var(--ease);
    box-shadow: var(--shadow);
    width: min(300px, 84vw); flex-basis: auto;
    z-index: 200;
  }
  body.drawer-open #sidebar { transform: translateX(0); }
  .icon-btn { display: inline-flex; }
  #topbar { padding: 8px 12px; gap: 8px; }
  .mode-tab { padding: 7px 12px; font-size: 12.5px; }
  .thread-title { display: none; }
  /* The thread menu (export) joins the topbar on mobile: let the tabs
     shrink and scroll horizontally instead of squeezing. */
  #mode-tabs { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  #mode-tabs::-webkit-scrollbar { display: none; }
  .mode-tab { flex: 0 0 auto; }
  .thread-menu-wrap { margin-left: auto; }
  #messages { padding: 16px 12px 8px; }
  .msg-row.assistant .bubble, .msg-row.user .bubble { max-width: 94%; }
  .run-group.compare { grid-template-columns: 1fr; }
  #mode-options { padding: 8px 12px; }
  #promptbar { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .prompt-meta { gap: 10px; }
  .modal-backdrop { padding: 20px 10px; align-items: flex-start; }
  .thread-item .mini-btn { opacity: 1; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #messages { scroll-behavior: auto; }
  .prism-sweep::after { display: none; }
  .skeleton::after { display: none; }
  .skeleton { background: var(--line); }
}

/* ---------- image generation mode ---------- */
.img-bubble { display: flex; flex-direction: column; gap: 10px; }
.img-bubble img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  animation: msg-in 220ms var(--ease);
}
.img-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.img-actions .btn[disabled] { opacity: 0.6; cursor: wait; }
.img-actions a.btn { text-decoration: none; }
.img-meta { font-size: 12px; color: var(--muted-dim); }
.img-error {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.img-error p { margin: 0 0 12px; font-size: 14px; color: var(--text); }

/* ---------- spend tracker ---------- */
.spend-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.spend-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.spend-card-label {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px;
}
.spend-card-value {
  font-size: 22px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.spend-empty {
  text-align: center; color: var(--muted); font-size: 14px;
  padding: 24px 12px; background: var(--bg2);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.spend-table-head {
  display: flex; justify-content: space-between;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
  padding: 0 2px 8px; margin-top: 4px;
}
.spend-list { display: flex; flex-direction: column; gap: 12px; }
.spend-row {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 12px;
}
.spend-row-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.spend-model {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: ui-monospace, Consolas, monospace;
}
.spend-cost { font-size: 13.5px; color: var(--green); font-variant-numeric: tabular-nums; }
.spend-bar {
  height: 6px; border-radius: 3px; background: var(--line);
  margin: 8px 0 6px; overflow: hidden;
}
.spend-bar-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--red-deep), var(--red));
  transition: width 400ms var(--ease);
}
.spend-row-meta { font-size: 12px; color: var(--muted-dim); }
.spend-note { margin: 0; }
@media (max-width: 560px) {
  .spend-cards { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .spend-card-value { font-size: 17px; }
}

/* ---------- personas + library + custom squads (Features 4, 5, 9) ---------- */
.field textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.field textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.18);
  outline: none;
}

.prompt-meta { flex-wrap: wrap; row-gap: 8px; }

.persona-select {
  font-size: 12.5px; font-weight: 600;
  padding: 6px 8px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  max-width: 170px;
  transition: border-color 180ms var(--ease), color 180ms var(--ease);
}
.persona-select:hover { color: var(--text); border-color: var(--muted-dim); }
.persona-select:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.persona-chip {
  font-size: 12px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  background: rgba(229, 72, 77, 0.1);
  border: 1px solid rgba(229, 72, 77, 0.45);
  color: #ff9a9d; cursor: pointer;
  max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 180ms var(--ease), border-color 180ms var(--ease);
}
.persona-chip[hidden] { display: none; }
.persona-chip:hover { background: rgba(229, 72, 77, 0.18); border-color: var(--red); }
.persona-chip:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.persona-list, .lib-list, .squad-list {
  display: flex; flex-direction: column; gap: 8px;
}
.persona-row, .lib-row, .squad-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  animation: msg-in 220ms var(--ease);
}
.persona-info, .lib-info, .squad-info {
  flex: 1; min-width: 0;
}
.persona-name, .lib-title, .squad-name {
  font-size: 14px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.persona-preview, .lib-preview {
  font-size: 12.5px; color: var(--muted-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.in-use {
  font-size: 12px; font-weight: 700; color: var(--green);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 6px 4px;
}
.inline-edit {
  border-top: 1px solid var(--line-soft);
  margin-top: 10px; padding-top: 12px;
  width: 100%;
}

.model-checklist {
  max-height: 260px; overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.check-group { margin-bottom: 12px; }
.check-group:last-child { margin-bottom: 0; }
.check-group-label {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
  margin-bottom: 6px;
}
.check-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text);
  padding: 3px 0; cursor: pointer;
}
.check-item input[type="checkbox"] {
  width: 15px; height: 15px; accent-color: var(--red);
  flex: 0 0 auto; cursor: pointer;
}
.check-item span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- regenerate + edit-and-rerun (Feature 10) ---------- */
.bubble-actions {
  display: flex; gap: 6px; margin-top: 10px;
  opacity: 0;
  transition: opacity 180ms var(--ease);
}
.bubble:hover .bubble-actions,
.bubble:focus-within .bubble-actions { opacity: 1; }
/* Touch devices have no hover: the buttons stay visible and tappable. */
@media (hover: none) {
  .bubble-actions { opacity: 1; }
}
.bubble-action {
  font-size: 12px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  background: var(--bg2); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.bubble-action:hover { color: var(--text); border-color: var(--red); }
.bubble-action:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.msg-edit-box {
  width: 100%; min-height: 90px;
  background: var(--bg2);
  border: 1px solid var(--red); border-radius: 8px;
  color: var(--text); padding: 10px 12px;
  font-size: 14px; line-height: 1.5; resize: vertical;
}
.msg-edit-box:focus { outline: none; box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.18); }
.edit-row-btns { display: flex; gap: 8px; margin-top: 8px; }

/* per-column regenerate button in compare headers */
.col-regen {
  flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 8px;
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.col-regen:hover { color: #fff; border-color: var(--red); }
.col-regen:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* panel "re-run verdict" row */
.rerun-verdict-row {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: center;
  gap: 10px; flex-wrap: wrap;
  padding: 6px 0 2px;
  animation: msg-in 220ms var(--ease);
}

/* ---------- thread menu / export (Feature 6) ---------- */
.thread-menu-wrap { position: relative; flex: 0 0 auto; }
.menu-dots {
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer;
  font-size: 15px; letter-spacing: 1px; line-height: 1; padding: 0 0 4px 1px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.menu-dots:hover { color: var(--text); border-color: var(--red); }
.menu-dots:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 220px; z-index: 500;
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px;
  animation: msg-in 160ms var(--ease);
}
.dropdown[hidden] { display: none; }
.dropdown button {
  display: block; width: 100%; text-align: left;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text); padding: 10px 12px;
  font-size: 14px; cursor: pointer;
  transition: background 140ms var(--ease);
}
.dropdown button:hover { background: var(--panel); }
.dropdown button:focus-visible { outline: 2px solid var(--red); outline-offset: -2px; }

/* ---------- voice input (Feature 7) ---------- */
.mic-btn {
  flex: 0 0 auto;
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color 180ms var(--ease), border-color 180ms var(--ease),
    transform 180ms var(--ease), background 180ms var(--ease);
}
.mic-btn:hover { color: var(--text); border-color: var(--red); transform: translateY(-1px); }
.mic-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
/* Prompt optimizer (magic wand) */
.optimize-btn {
  flex: 0 0 auto;
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color 180ms var(--ease), border-color 180ms var(--ease),
    transform 180ms var(--ease), background 180ms var(--ease);
}
.optimize-btn:hover { color: var(--gold, #e8b44a); border-color: var(--gold, #e8b44a); transform: translateY(-1px); }
.optimize-btn:focus-visible { outline: 2px solid var(--gold, #e8b44a); outline-offset: 2px; }
.optimize-btn.working { animation: mic-pulse 1.2s ease-in-out infinite; pointer-events: none; }
.optimize-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.mic-btn.listening {
  color: #fff; border-color: var(--red);
  background: rgba(229, 72, 77, 0.16);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.5); }
  50% { box-shadow: 0 0 0 9px rgba(229, 72, 77, 0); }
}
.voice-preview {
  max-width: 1100px; margin: 8px auto 0;
  font-size: 13px; font-style: italic; color: var(--muted);
}
.voice-preview[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) {
  .mic-btn.listening { animation: none; box-shadow: 0 0 0 2px var(--red); }
}

/* ---------- print view (Feature 6) ---------- */
#print-root { display: none; }
.print-doc {
  background: #fff; color: #16161a;
  max-width: 740px; margin: 0 auto; padding: 28px 30px;
  font-size: 14px; line-height: 1.6;
}
.print-doc h1 { font-size: 22px; margin: 0 0 4px; color: #000; }
.print-meta { color: #555; font-size: 12.5px; margin: 0 0 20px; }
.print-msg {
  border: 1px solid #ddd; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px;
  page-break-inside: avoid;
}
.print-role { font-weight: 700; font-size: 13px; margin-bottom: 6px; color: #000; }
.print-time { font-weight: 400; color: #777; font-size: 12px; }
.print-body p { margin: 0 0 8px; }
.print-body pre {
  background: #f4f4f6; border: 1px solid #ddd; border-radius: 6px;
  padding: 10px; overflow-x: auto; font-size: 12.5px;
}
.print-body code { font-size: 12.5px; }
.print-receipt { margin-top: 8px; font-size: 12px; color: #555; font-style: italic; }
.print-img img { max-width: 100%; height: auto; border-radius: 8px; margin-top: 8px; }
@media print {
  body.printing { background: #fff; overflow: visible; }
  body.printing #view-app,
  body.printing #view-login,
  body.printing #modal-root,
  body.printing #toast { display: none !important; }
  body.printing #print-root { display: block !important; }
}

/* ============================================================
   UX tweaks (2026-10-09): pre-send cost estimate, latest pill,
   thread search + groups, picker recent label, free-mode hint,
   cost cap dialog, mode tab icons.
   NOTE: app.js creates #latest-pill, #thread-search(+clear),
   #freemode-hint and #costcap-dialog dynamically (ensure* guards
   with full event wiring). Static duplicates would break that
   wiring, so only #cost-estimate is static markup; the rest of
   this section styles the dynamically created elements.
   ============================================================ */

/* mode tab icons */
.mode-tab { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.tab-icon { width: 17px; height: 17px; flex: 0 0 auto; }

/* pre-send cost estimate line under the prompt bar */
#cost-estimate {
  max-width: 1100px; margin: 8px auto 0;
  font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#cost-estimate[hidden] { display: none; }
#cost-estimate .ce-free { color: var(--green); }
#cost-estimate .ce-warn { color: var(--amber); }

/* floating "latest" pill inside the message scroll area.
   Sticky to the bottom of the visible area; the JS module toggles [hidden]. */
#latest-pill {
  position: sticky; bottom: 16px; z-index: 30;
  display: block; width: fit-content; margin: 8px auto 0;
  background: rgba(30, 26, 28, 0.94);
  border: 1px solid rgba(229, 72, 77, 0.6);
  color: #ffb3b6; font-size: 13px; font-weight: 700;
  border-radius: 999px; padding: 8px 18px; cursor: pointer;
  box-shadow: 0 4px 18px rgba(229, 72, 77, 0.35);
  backdrop-filter: blur(6px);
  transition: color 160ms var(--ease), border-color 160ms var(--ease), transform 160ms var(--ease);
}
#latest-pill[hidden] { display: none; }
#latest-pill:hover { color: #fff; border-color: var(--red); transform: translateY(-1px); }
#latest-pill:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* thread search at the top of the sidebar list */
.thread-search-wrap { position: relative; padding: 10px 10px 2px; }

#thread-search {
  width: 100%;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 8px; color: var(--text);
  padding: 8px 30px 8px 12px; font-size: 13px;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
#thread-search::placeholder { color: var(--muted-dim); }
#thread-search:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.16); outline: none; }
#thread-search-clear {
  position: absolute; right: 16px; top: calc(50% + 4px); transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  background: transparent; border: none; color: var(--muted);
  font-size: 15px; line-height: 1; cursor: pointer; padding: 0;
}
#thread-search-clear:hover { color: var(--red); background: rgba(229, 72, 77, 0.12); }
#thread-search-clear[hidden] { display: none; }

/* thread groups */
.thread-group { margin: 2px 0 8px; display: flex; flex-direction: column; gap: 4px; }
.thread-group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--muted-dim);
  padding: 10px 10px 2px;
}
.thread-search-empty {
  color: var(--muted-dim); font-size: 13px; text-align: center;
  padding: 26px 12px; line-height: 1.6;
}

/* model picker "Recent" heading, matching the picker group label style */
.picker-recent-label {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
  margin-bottom: 6px;
}

/* first-run Free Mode hint tooltip, shown near the toggle.
   Created dynamically by app.js (once per user); this styles the container
   and its dismiss button. */
.prompt-meta { position: relative; }
#freemode-hint {
  position: absolute; bottom: calc(100% + 10px); left: 0;
  width: min(300px, calc(100vw - 40px));
  background: var(--panel);
  border: 1px solid rgba(229, 72, 77, 0.55);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex; gap: 10px; align-items: center;
  font-size: 12.5px; color: var(--text); line-height: 1.5;
  z-index: 50;
  animation: msg-in 200ms var(--ease);
}
#freemode-hint[hidden] { display: none; }
#freemode-hint button {
  flex: 0 0 auto;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 5px 12px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
#freemode-hint button:hover { color: var(--text); border-color: var(--red); }
#freemode-hint button:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* cost cap dialog. Created dynamically by app.js as
   #costcap-dialog > .costcap-box > #costcap-dialog-text + .costcap-btns
   (#costcap-send.btn.btn-primary, #costcap-cancel.btn). */
#costcap-dialog {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 5, 8, 0.72);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade-in 180ms var(--ease);
}
#costcap-dialog[hidden] { display: none; }
.costcap-box {
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  animation: modal-in 220ms var(--ease);
}
#costcap-dialog-text { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.6; }
.costcap-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- tour bot ---------- */
.tour-bot {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #2a0f12 0%, #1c1c24 100%);
  border: 2px solid var(--red); cursor: pointer; padding: 4px;
  box-shadow: var(--red-glow), 0 4px 16px rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform 180ms var(--ease);
}
.tour-bot:hover { transform: scale(1.08); }
.tour-bot img { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; }
.tour-bot[hidden] { display: none !important; }
.tour-bot-nudge { animation: tourNudge 1.6s var(--ease) 2; }
@keyframes tourNudge {
  0%, 100% { transform: scale(1) rotate(0); }
  25% { transform: scale(1.12) rotate(-6deg); }
  50% { transform: scale(1.12) rotate(6deg); }
  75% { transform: scale(1.06) rotate(0); }
}
#tour-overlay { position: fixed; inset: 0; z-index: 2000; pointer-events: none; }
#tour-overlay[hidden] { display: none !important; }
#tour-spotlight {
  position: absolute; border: 2px solid var(--red); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72);
  transition: all 300ms var(--ease); pointer-events: none;
}
#tour-tooltip {
  position: absolute; pointer-events: auto; width: 280px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; box-shadow: 0 12px 40px rgba(0,0,0,0.55);
}
#tour-tooltip p { font-size: 14px; line-height: 1.55; margin: 0 0 14px; }
.tour-controls { display: flex; align-items: center; justify-content: space-between; }
.tour-controls button {
  border: none; border-radius: 8px; padding: 8px 18px; min-height: 38px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
#tour-skip { background: transparent; color: var(--muted); }
#tour-skip:hover { color: var(--text); }
#tour-next { background: linear-gradient(135deg, var(--red), var(--red-deep)); color: #fff; }
#tour-count { font-size: 12px; color: var(--muted); }

/* ---------- compact model picker (compare/panel) ---------- */
.sel-chip-list { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; min-height: 38px; align-items: center; }
.sel-chip {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--red); background: rgba(229, 72, 77, 0.1);
  color: var(--text); border-radius: 20px; padding: 6px 8px 6px 14px;
  font-size: 13px; font-weight: 600;
}
.sel-chip .nm { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-chip-x {
  border: none; background: rgba(229, 72, 77, 0.2); color: var(--text);
  border-radius: 50%; width: 22px; height: 22px; min-width: 22px;
  font-size: 14px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 160ms var(--ease);
}
.sel-chip-x:hover { background: var(--red); color: #fff; }
.model-dropdown {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 500;
  width: min(480px, calc(100vw - 48px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  padding: 16px; max-height: min(420px, calc(100vh - 220px)); display: flex; flex-direction: column; gap: 12px;
}
.model-dropdown[hidden] { display: none; }
.provider-chips { display: flex; gap: 6px; flex-wrap: wrap; max-height: 76px; overflow-y: auto; }
.provider-chip {
  border: 1px solid var(--line); background: var(--raised); color: var(--muted);
  border-radius: 16px; padding: 5px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; min-height: 32px; transition: all 160ms var(--ease);
}
.provider-chip:hover { border-color: var(--muted); color: var(--text); }
.provider-chip.active { background: rgba(229, 72, 77, 0.15); border-color: var(--red); color: var(--text); }
.model-list { overflow-y: auto; max-height: 260px; border-top: 1px solid var(--line); padding-top: 8px; }
.model-group-label { font-size: 11px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted-dim); padding: 10px 8px 4px; }
.model-row {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: 8px; cursor: pointer; font-size: 13.5px;
  transition: background 120ms var(--ease);
}
.model-row:hover { background: var(--raised); }
.model-row.disabled { opacity: 0.4; cursor: not-allowed; }
.model-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--red); cursor: pointer; flex-shrink: 0; }
.model-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-list-empty { padding: 24px; text-align: center; color: var(--muted-dim); font-size: 13px; }

/* ---------- playground mode ---------- */
.pg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; padding: 16px; background: var(--raised); border: 1px solid var(--line); border-radius: 12px; }
.pg-grid .pg-full { grid-column: 1 / -1; }
.pg-grid .field span { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; display: block; }
.pg-grid .field input[type="number"], .pg-grid .field textarea, .pg-grid .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 8px 12px; font-size: 13.5px;
}
.pg-grid .field textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.pg-slider input[type="range"] { width: 100%; accent-color: var(--red); }
.pg-slider b { color: var(--text); font-weight: 700; }
.pg-reset { background: none; border: none; color: var(--muted-dim); cursor: pointer; font-size: 14px; padding: 2px 6px; }
.pg-reset:hover { color: var(--red); }
@media (max-width: 600px) { .pg-grid { grid-template-columns: 1fr; } }

/* ---------- squad picker ---------- */
#opt-squad-dropdown {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 500;
  width: 280px; max-width: calc(100vw - 48px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  padding: 8px; max-height: 320px; overflow-y: auto;
}
#opt-squad-dropdown[hidden] { display: none; }
.squad-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 10px 12px; border: none; background: none;
  color: var(--text); font-size: 13.5px; font-weight: 600;
  border-radius: 8px; cursor: pointer; text-align: left;
  transition: background 120ms var(--ease);
}
.squad-row:hover { background: var(--raised); }
.squad-row .squad-count { font-size: 12px; color: var(--muted-dim); font-weight: 400; }

/* ---------- Mobile promptbar redesign (Claude/Perplexity style) ---------- */
@media (max-width: 700px) {
  /* Hide persona, key hint from promptbar on mobile (moved to Settings) */
  #promptbar #persona-select,
  #promptbar #persona-chip,
  #promptbar #key-hint {
    display: none !important;
  }

  /* Main input row: large textarea + send only */
  #promptbar .prompt-row {
    gap: 8px;
  }
  #promptbar #prompt-input {
    min-height: 48px;
    font-size: 16px;
    border-radius: 16px;
  }
  /* Hide attach, mic, optimize from main row on mobile (moved to toolbar) */
  #promptbar .prompt-row #btn-attach,
  #promptbar .prompt-row #btn-mic,
  #promptbar .prompt-row #btn-optimize {
    display: none;
  }
  #promptbar .prompt-row #btn-send {
    min-width: 48px;
    min-height: 48px;
    border-radius: 16px;
  }

  /* Toolbar row: compact icon buttons */
  #promptbar .prompt-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 4px 0;
  }
  #promptbar .prompt-meta .toggle-chip,
  #promptbar .prompt-meta #temp-toggle {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
  }
  /* Mobile toolbar icons for attach/mic/optimize */
  .mobile-toolbar {
    display: flex;
    gap: 4px;
    align-items: center;
  }
  .mobile-toolbar button {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-toolbar button:active {
    background: rgba(255,255,255,0.08);
    color: var(--text);
  }
}
@media (min-width: 701px) {
  .mobile-toolbar { display: none !important; }
}

/* ---------- Thread item context menu ---------- */
.thread-item { position: relative; }
.thread-menu-btn { opacity: 0; }
.thread-item:hover .thread-menu-btn,
.thread-item:focus-within .thread-menu-btn { opacity: 1; }
@media (hover: none) {
  .thread-menu-btn { opacity: 0.7; }
}
.thread-menu {
  position: absolute;
  right: 0; top: 100%;
  z-index: 500;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 160px;
  padding: 4px;
}
.thread-menu button {
  display: block; width: 100%;
  background: none; border: none;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px; text-align: left;
  border-radius: 6px; cursor: pointer;
}
.thread-menu button:hover { background: var(--raised); }
.thread-menu button.danger { color: var(--red); }







/* Folder dialog */
.folder-dialog-box { max-width: 380px !important; }
.folder-dialog-box h3 { margin: 0 0 16px; }
.folder-dialog-box label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.folder-dialog-box input[type="text"] {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  margin-bottom: 16px;
}
.folder-dialog-box input[type="text"]:focus {
  border-color: var(--red);
  outline: none;
}
.folder-color-picker {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.folder-color-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 150ms var(--ease), border-color 150ms var(--ease);
}
.folder-color-btn:hover { transform: scale(1.1); }
.folder-color-btn.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--bg);
}


/* Chat selection mode */
.chat-select-cb {
  width: 18px;
  height: 18px;
  accent-color: var(--red);
  cursor: pointer;
  flex-shrink: 0;
}
.thread-item.chat-selected {
  background: rgba(229, 72, 77, 0.08);
  border-color: rgba(229, 72, 77, 0.3);
}
.select-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
}
.select-bar span { flex: 1; }
.select-bar .btn-sm { padding: 6px 14px; font-size: 13px; }

/* Folder edit/delete buttons */
.folder-head .mini-btn {
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 160ms var(--ease);
}
.folder-head .mini-btn:hover {
  background: var(--raised);
  color: var(--text);
  border-color: var(--line);
}
.folder-head .mini-btn[data-fact="delete"]:hover {
  background: rgba(229, 72, 77, 0.15);
  color: var(--red);
  border-color: var(--red);
}


.tab-beta {
  font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 3px;
  background: rgba(232, 180, 74, 0.15); color: #e8b44a;
  border: 1px solid rgba(232, 180, 74, 0.3); margin-left: 4px;
  vertical-align: middle; letter-spacing: 0.3px;
}


/* ---------- Image multi-model picker ---------- */
.img-models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.img-model-card {
  background: var(--bg2);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: all 160ms var(--ease);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.img-model-card:hover { border-color: var(--muted); }
.img-model-card.selected { border-color: var(--red); background: rgba(229, 72, 77, 0.05); }
.img-model-card input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--red);
  margin-top: 2px; flex-shrink: 0; cursor: pointer;
}
.img-model-info { flex: 1; min-width: 0; }
.img-model-name { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.img-model-desc { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.img-model-cost { font-size: 11px; font-weight: 700; }
.img-model-cost.free { color: #4ade80; }
.img-model-cost.paid { color: #e8b44a; }

/* ---------- Multi-image results ---------- */
.img-multi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.img-multi-grid.img-count-1 { grid-template-columns: 1fr; max-width: 512px; }
.img-multi-grid.img-count-2 { grid-template-columns: repeat(2, 1fr); }
.img-multi-grid.img-count-4,
.img-multi-grid.img-count-5,
.img-multi-grid.img-count-6 { grid-template-columns: repeat(3, 1fr); }
.img-result-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.img-result-card img {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block;
  background: var(--raised);
}
.img-result-meta { padding: 10px; }
.img-result-model { font-weight: 700; font-size: 12px; margin-bottom: 2px; }
.img-result-cost { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.img-result-cost.free { color: #4ade80; }
.img-result-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.img-error-card .img-error-msg { padding: 24px 16px; text-align: center; }
.img-error-card .img-error-msg p { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

@media (max-width: 700px) {
  .img-multi-grid,
  .img-multi-grid.img-count-2,
  .img-multi-grid.img-count-4,
  .img-multi-grid.img-count-5,
  .img-multi-grid.img-count-6 {
    grid-template-columns: 1fr;
  }
  .img-models-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 701px) and (max-width: 1024px) {
  .img-multi-grid.img-count-4,
  .img-multi-grid.img-count-5,
  .img-multi-grid.img-count-6 { grid-template-columns: repeat(2, 1fr); }
}


/* Mobile topbar temp toggle - hidden on desktop, shown on mobile */
#temp-toggle-top {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}
#temp-toggle-top.active {
  color: var(--crimson);
  background: rgba(229, 72, 77, 0.12);
  box-shadow: 0 0 8px rgba(229, 72, 77, 0.4);
}
@media (max-width: 700px) {
  #temp-toggle-top { display: inline-flex; margin-left: auto; }
  /* Hide bottom temp toggle on mobile (moved to topbar) */
  #temp-toggle { display: none; }
}

/* Floating label for topbar temp toggle (mobile only) */
#topbar { position: relative; }
.temp-float-label {
  display: none;
  position: absolute;
  top: 52px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
}
.temp-float-label.show { display: block; animation: tempFloatIn 200ms ease; }
.temp-float-label.warn { border-color: var(--crimson); color: var(--crimson); }
@keyframes tempFloatIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Mobile sidebar: modes nav + free card ---------- */
.mobile-modes { display: none; }
.mobile-free-card { display: none; }

@media (max-width: 700px) {
  /* Hide top mode tabs on mobile */
  #mode-tabs-wrap { display: none; }
  #mode-tabs { display: none; }

  /* Show sidebar modes */
  .mobile-modes {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 12px 0 4px;
    padding: 8px 0;
    border-top: 1px solid var(--line-soft);
    border-bottom: 1px solid var(--line-soft);
  }
  .mobile-mode-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: none;
    border: none;
    color: var(--muted);
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    width: 100%;
  }
  .mobile-mode-item:active { background: var(--raised); }
  .mobile-mode-item.active {
    background: rgba(229, 72, 77, 0.12);
    color: var(--red);
    font-weight: 700;
  }
  .mobile-mode-item svg { flex-shrink: 0; }

  /* Free models card */
  .mobile-free-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 8px 0;
  }
  .mobile-free-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
  }
  .mobile-free-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
  }
  .mobile-free-switch {
    width: 48px; height: 28px;
    background: var(--red);
    border: none;
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 200ms;
  }
  .mobile-free-switch[aria-pressed="false"] {
    background: var(--line);
  }
  .mobile-free-knob {
    position: absolute;
    top: 3px; right: 3px;
    width: 22px; height: 22px;
    background: #fff;
    border-radius: 50%;
    transition: transform 200ms;
  }
  .mobile-free-switch[aria-pressed="false"] .mobile-free-knob {
    transform: translateX(-20px);
  }
}

/* ---------- Sidebar bottom redesign ---------- */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
  margin-top: 8px;
}
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.sidebar-nav-item:hover { background: var(--raised); color: var(--text); }
.sidebar-nav-item svg { flex-shrink: 0; }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-top: 8px;
}
.user-card .admin-badge {
  font-size: 10px;
  padding: 2px 6px;
  white-space: nowrap;
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--red);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.user-info {
  flex: 1;
  min-width: 0;
}
.user-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout-icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.logout-icon-btn:hover {
  background: var(--raised);
  color: var(--red);
}

/* ---------- Mobile sidebar: single scroll ---------- */
@media (max-width: 700px) {
  #sidebar {
    display: block;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .sidebar-top,
  #thread-list,
  .sidebar-foot {
    overflow: visible;
    max-height: none;
    flex: none;
  }
  #thread-list {
    min-height: 100px;
  }
}
