/* modern.css — v383: a quiet, modern layer for the main page.
 *
 * This is the beta facelift, promoted: the same file that ran on /beta/ for a week, loaded
 * after style.css. It changes no markup, no id and no script — every control keeps working
 * because only surfaces are restyled — and anything it does not name keeps the older styling
 * underneath. The beta-only wording in comments below is historical.
 *
 * The direction: deeper neutrals, one indigo-violet accent used sparingly, hairline borders
 * instead of heavy shadows, generous radii, a centred reading column, and motion that is
 * short enough to feel like a response rather than an animation.
 */

/* ---------- tokens ---------------------------------------------------------------- */
:root {
  --bg: #080a0f;
  --bg2: #0b0e14;
  --card: rgba(255, 255, 255, 0.028);
  --card2: rgba(255, 255, 255, 0.05);
  --card3: rgba(255, 255, 255, 0.08);
  --accent: #7c8cff;
  --accent-hover: #6a7bff;
  --accent-light: rgba(124, 140, 255, 0.13);
  --accent-grad: linear-gradient(135deg, #7c8cff 0%, #a17cff 55%, #c07cff 100%);
  --accent-soft: #b4a2ff;
  --text: #eef1f7;
  --text2: #a7b0c0;
  --text-muted: #6f7a8c;
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.14);
  --header-bg: rgba(8, 10, 15, 0.72);
  --scrim: rgba(4, 6, 10, 0.68);
  --radius: 1rem;
  --radius-sm: 0.65rem;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 6px 20px rgba(0, 0, 0, 0.28);
  /* v378: 40% wider than 282px, so a session name is readable without hovering the title. */
  --sidebar-w: 394px;
  --header-h: 56px;
  --reader-w: 1080px;
  --composer-w: 820px;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
             Roboto, system-ui, sans-serif;
  --font-display: var(--font-ui);
  --font-mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

html { color-scheme: dark; }

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(1100px 520px at 50% -220px, rgba(124, 140, 255, 0.16), transparent 70%),
    radial-gradient(900px 500px at 100% 110%, rgba(161, 124, 255, 0.07), transparent 60%),
    var(--bg);
  letter-spacing: 0.004em;
}

::selection { background: rgba(124, 140, 255, 0.32); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.10);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); background-clip: padding-box; }

/* ---------- login ---------------------------------------------------------------- */
.login-page {
  background:
    radial-gradient(900px 460px at 50% -160px, rgba(124, 140, 255, 0.22), transparent 70%),
    var(--bg);
}
.login-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: 1.4rem;
  padding: 2.6rem 2.4rem 2.2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.login-card h1 {
  font-family: var(--font-display);
  font-weight: 750;
  letter-spacing: -0.02em;
  font-size: 1.55rem;
}
.login-card .subtitle { color: var(--text-muted); }
.login-card input {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.78rem 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.login-card input:focus {
  border-color: rgba(124, 140, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
}
.login-card button {
  border-radius: 0.7rem;
  padding: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: transform 0.12s, box-shadow 0.2s, filter 0.15s;
  box-shadow: 0 8px 24px rgba(124, 140, 255, 0.22);
}
.login-card button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.login-card button:active { transform: translateY(0); }

/* ---------- header --------------------------------------------------------------- */
.header {
  height: var(--header-h);
  padding: 0 1.1rem;
  background: var(--header-bg);
  backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.header .logo {
  font-family: var(--font-display);
  font-weight: 750;
  letter-spacing: -0.015em;
  font-size: 1.02rem;
}
.header .logo .material-symbols-outlined { color: var(--accent-soft); }
.header .user-info span:first-child { color: var(--text); font-weight: 550; }
.header .burger, .mobile-top-bar .burger {
  border-radius: 0.6rem;
  transition: background 0.15s;
}
.header .burger:hover { background: var(--card2); }
.header .user-info button, .mobile-top-bar button {
  border-radius: 0.6rem;
  transition: background 0.15s, color 0.15s;
}

/* ---------- shell ---------------------------------------------------------------- */
.main-layout { height: calc(100dvh - var(--header-h)); }

/* ---------- sidebar -------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 40%), var(--bg2);
  border-right: 1px solid var(--border);
}
.sidebar-top { padding: 0.9rem 0.9rem 0.6rem; }
.new-chat-btn {
  border-radius: 0.8rem;
  padding: 0.68rem 0.9rem;
  font-weight: 650;
  letter-spacing: 0.005em;
  box-shadow: 0 10px 28px rgba(124, 140, 255, 0.2);
  transition: filter 0.15s, transform 0.12s, box-shadow 0.2s;
}
.new-chat-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.new-chat-btn:active { transform: translateY(0); }

.sidebar-nav { gap: 0.35rem; padding: 0 0.9rem 0.7rem; border-bottom: 1px solid var(--border); }
.sidebar-nav .nav-item {
  border-radius: 0.65rem;
  padding: 0.52rem 0.45rem;
  font-size: 0.76rem;
  letter-spacing: 0.005em;
  white-space: nowrap;
  gap: 0.4rem;
}
.nav-item { border-radius: 0.65rem; font-size: 0.84rem; }
.nav-item.active {
  background: var(--accent-light);
  color: var(--accent-soft);
  font-weight: 600;
}

.conv-search {
  margin: 0.6rem 0.9rem 0.35rem;
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.conv-search:focus-within {
  border-color: rgba(124, 140, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.1);
}

.conv-list { padding: 0.45rem 0.55rem 0.6rem; gap: 1px; }
.session-tab {
  position: relative;
  border-radius: 0.7rem;
  padding: 0.55rem 0.65rem;
  transition: background 0.14s, color 0.14s;
}
.session-tab:hover { background: rgba(255, 255, 255, 0.045); }
.session-tab.active {
  background: linear-gradient(90deg, rgba(124, 140, 255, 0.16), rgba(124, 140, 255, 0.05));
  color: var(--text);
}
.session-tab.active::before {
  content: "";
  position: absolute;
  left: 0.15rem; top: 22%; bottom: 22%;
  width: 3px; border-radius: 999px;
  background: var(--accent-grad);
}
.session-tab .session-name { font-size: 0.83rem; letter-spacing: 0.002em; }

.sidebar-bottom { border-top: 1px solid var(--border); padding-top: 0.35rem; }
.credit-widget {
  border-radius: 0.7rem;
  margin: 0.35rem 0.6rem;
  transition: background 0.15s;
}
.credit-widget:hover { background: var(--card2); }
.sidebar-section { border-radius: 0.7rem; }

/* ---------- status bar ----------------------------------------------------------- */
.status-bar {
  background: rgba(255, 255, 255, 0.018);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 1rem;
  backdrop-filter: blur(8px);
}
.session-bar-actions { gap: 0.55rem; }
.toggle-tools-btn {
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  font-size: 0.73rem;
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.toggle-tools-btn:hover { background: var(--accent-light); border-color: rgba(124, 140, 255, 0.5); }
.session-search {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  padding: 0.16rem 0.4rem 0.16rem 0.6rem;
}
.session-search:focus-within {
  border-color: rgba(124, 140, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.1);
}
.session-files-btn {
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  font-size: 0.73rem;
}

/* ---------- reading column ------------------------------------------------------- */
.chat-messages {
  padding: 1.6rem max(1.25rem, calc((100% - var(--reader-w)) / 2)) 0.9rem;
  gap: 0.85rem;
  /* v384: NO scroll-behavior: smooth here. Every programmatic jump (send, poll, the mobile
     keyboard resizing the viewport) assigns scrollTop directly; with smooth behaviour on this
     container a phone animated through the whole history before the new bubble settled. */
}
.chat-msg {
  max-width: min(92%, 1000px);
  padding: 0.85rem 1.05rem;
  border-radius: 1.15rem;
  font-size: 0.925rem;
  line-height: 1.62;
}
.chat-msg.user {
  max-width: min(78%, 720px);
  border-radius: 1.15rem 1.15rem 0.35rem 1.15rem;
  box-shadow: 0 10px 26px rgba(124, 140, 255, 0.16);
  font-weight: 450;
}
.chat-msg.assistant {
  max-width: min(100%, 1000px);
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid var(--border);
  border-radius: 1.15rem 1.15rem 1.15rem 0.35rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}
.chat-msg.assistant pre {
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.85rem 1rem;
  font-size: 0.82rem;
}
.chat-msg.assistant :not(pre) > code {
  background: rgba(124, 140, 255, 0.10);
  border: 1px solid rgba(124, 140, 255, 0.14);
  border-radius: 0.4rem;
  padding: 0.08rem 0.32rem;
  font-size: 0.86em;
}
.chat-msg.auto-continuation,
.chat-msg.resume-chip { border-radius: 999px; }
.chat-msg.tool-bubble {
  background: rgba(255, 255, 255, 0.022);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 0.9rem;
  font-size: 0.82rem;
}
.chat-msg.tool-bubble:hover { background: rgba(255, 255, 255, 0.035); }
.chat-msg.tool-bubble.tool-done { border-left-color: rgba(34, 197, 94, 0.75); }
.chat-msg.tool-bubble.tool-error { border-left-color: rgba(239, 68, 68, 0.8); }
.chat-msg.search-match { outline-color: rgba(124, 140, 255, 0.6); }

.scroll-bottom-btn {
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

/* ---------- composer ------------------------------------------------------------- */
.chat-input-area {
  align-items: flex-end;
  gap: 0.45rem;
  /* The input is deliberately NARROWER than the reading column: the conversation can breathe
     wide, while a line of typing stays a comfortable measure. */
  max-width: var(--composer-w);
  width: calc(100% - 2rem);
  margin: 0.35rem auto 1.1rem;
  padding: 0.55rem 0.6rem 0.55rem 0.75rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.025));
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.32);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.chat-input-area:focus-within {
  border-color: rgba(124, 140, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.10), 0 14px 40px rgba(0, 0, 0, 0.32);
}
.chat-input-area.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(124, 140, 255, 0.35) inset;
}
.chat-input-area textarea {
  background: transparent;
  border: none;
  border-radius: 0.9rem;
  padding: 0.55rem 0.45rem;
  font-size: 0.93rem;
  min-height: 42px;
}
.chat-input-area textarea:focus { border: none; box-shadow: none; }
.chat-input-area select {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  font-size: 0.76rem;
}
.chat-input-area button {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  height: 42px;
  transition: background 0.15s, color 0.15s, transform 0.12s;
}
.chat-input-area button:hover { background: rgba(255, 255, 255, 0.08); }
.chat-input-area #sendBtn {
  border-radius: 0.8rem;
  padding: 0.5rem 1.15rem;
  font-weight: 650;
  box-shadow: 0 8px 22px rgba(124, 140, 255, 0.25);
}
.chat-input-area #sendBtn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.chat-input-area #sendBtn:active { transform: translateY(0); }
.chat-input-area #sendBtn.stop-btn {
  background: linear-gradient(135deg, #ef4444, #f97316);
  box-shadow: 0 8px 22px rgba(239, 68, 68, 0.25);
}

/* ---------- right panels --------------------------------------------------------- */
.right-panel {
  background: rgba(11, 14, 20, 0.92);
  backdrop-filter: blur(18px);
  border-left: 1px solid var(--border);
}
.right-panel h3 {
  font-family: var(--font-display);
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: 0.95rem;
}

/* ---------- modals --------------------------------------------------------------- */
.modal-overlay {
  background: var(--scrim);
  backdrop-filter: blur(8px);
}
.modal {
  position: relative;   /* an absolutely-placed close button belongs to the dialog, not the page */
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
              #0c1017;
  border: 1px solid var(--border);
  border-radius: 1.15rem;
  box-shadow: var(--shadow);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal h3 {
  font-family: var(--font-display);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.btn-primary, .btn-secondary {
  border-radius: 0.65rem;
  transition: filter 0.15s, background 0.15s;
}
.btn-primary { box-shadow: 0 8px 22px rgba(124, 140, 255, 0.2); }
.btn-primary:hover { filter: brightness(1.06); }

/* On a mouse, the three row actions are noise until the row is under the pointer. Their
   space is the name's space; touch keeps them visible (the old mobile rule does that). */
@media (hover: hover) and (min-width: 901px) {
  .session-tab .rename, .session-tab .share, .session-tab .del { opacity: 0; }
  .session-tab:hover .rename, .session-tab:hover .share,
  .session-tab:hover .del { opacity: 0.85; }
  .session-tab.active .rename, .session-tab.active .share,
  .session-tab.active .del { opacity: 0; }
  .session-tab.active:hover .rename, .session-tab.active:hover .share,
  .session-tab.active:hover .del { opacity: 0.85; }
}

/* v378 — the glyph's colour is its category, not decoration: boards amber, code blue,
   documents gold, sheets green, measurements violet, web teal, images pink, mail coral,
   plans indigo, research sky. A muted chip for a chat that fits no category. */
.session-tab > .sess-glyph.tone-amber   { color: #f0b86e; background: rgba(245, 158, 11, 0.13);  border-color: rgba(245, 158, 11, 0.28); }
.session-tab > .sess-glyph.tone-blue    { color: #8cc8ff; background: rgba(56, 139, 253, 0.13);  border-color: rgba(56, 139, 253, 0.28); }
.session-tab > .sess-glyph.tone-pink    { color: #ff9ecb; background: rgba(236, 72, 153, 0.13);  border-color: rgba(236, 72, 153, 0.26); }
.session-tab > .sess-glyph.tone-green   { color: #7fe3a6; background: rgba(34, 197, 94, 0.12);   border-color: rgba(34, 197, 94, 0.26); }
.session-tab > .sess-glyph.tone-gold    { color: #ffd479; background: rgba(234, 179, 8, 0.12);   border-color: rgba(234, 179, 8, 0.26); }
.session-tab > .sess-glyph.tone-teal    { color: #7ee0d2; background: rgba(20, 184, 166, 0.13);  border-color: rgba(20, 184, 166, 0.27); }
.session-tab > .sess-glyph.tone-violet  { color: #c4a7ff; background: rgba(139, 92, 246, 0.14);  border-color: rgba(139, 92, 246, 0.28); }
.session-tab > .sess-glyph.tone-coral   { color: #ffab9c; background: rgba(251, 113, 133, 0.13); border-color: rgba(251, 113, 133, 0.26); }
.session-tab > .sess-glyph.tone-indigo  { color: #a7b6ff; background: rgba(99, 102, 241, 0.15);  border-color: rgba(99, 102, 241, 0.28); }
.session-tab > .sess-glyph.tone-sky     { color: #9fd0ff; background: rgba(14, 165, 233, 0.13);  border-color: rgba(14, 165, 233, 0.27); }
.session-tab > .sess-glyph.tone-neutral { color: var(--text-muted); }
.session-tab.active > .sess-glyph { filter: brightness(1.12); }

/* ---------- User Management: the credit plan at a glance ---------------------------- */
/* v382: the rows carry two lines of credit detail now; 560px was a column, not a table. */
#userModal .modal { max-width: 1120px; width: 94vw; }
.user-list { list-style: none; margin: 0; padding: 0; }
.user-list li.user-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.65rem;
  margin-bottom: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.025);
  transition: background 0.14s, border-color 0.14s;
}
.user-list li.user-row:hover { background: rgba(255, 255, 255, 0.04); border-color: var(--border-strong); }
.user-main { flex: 1 1 250px; min-width: 0; }
.user-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 550;
}
.user-name .badge {
  padding: 0.08rem 0.36rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text2);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.user-name .badge-tier { color: var(--accent-soft); background: rgba(124, 140, 255, 0.12); border-color: rgba(124, 140, 255, 0.24); }
.user-name .badge-trial { color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }
.user-name .badge-exp { color: var(--text-muted); }
.user-credits { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.uc-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 0.68rem;
}
.uc-pill strong { color: var(--text2); font-weight: 600; }
.uc-pill .material-symbols-outlined { font-size: 12px; color: var(--accent-soft); }
.uc-pill.uc-reset { color: var(--text-muted); }
.user-actions { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }

/* ---------- TODO: status glyphs, not emoji ----------------------------------------- */
#todoList:empty::after {
  content: "No plan yet — the agent fills this panel while it works.";
  display: block;
  padding: 1rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
}
#todoList { display: flex; flex-direction: column; gap: 0.4rem; }
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.5rem 0.6rem;
  margin: 0;
  border: 1px solid var(--border);
  border-left: 1px solid var(--border);      /* the old 3px accent is gone */
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.025);
  color: var(--text2);
  font-size: 0.82rem;
  line-height: 1.5;
  text-decoration: none;
  transition: background 0.14s, border-color 0.14s;
}
/* A finished row is dimmed and its WORDS are struck — never the glyph. The old rule ran the
   line through the checkbox, which is what made a completed list look damaged. */
.todo-item.done, .todo-item.skipped { text-decoration: none; }
.todo-item:hover { background: rgba(255, 255, 255, 0.04); }
.todo-glyph {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  margin-top: 1px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}
.todo-glyph.plan    { color: #a7b6ff; background: rgba(99, 102, 241, 0.15); }
.todo-glyph.doing   { color: #f0b86e; background: rgba(245, 158, 11, 0.15); animation: todoSpin 1.8s linear infinite; }
.todo-glyph.done    { color: #7fe3a6; background: rgba(34, 197, 94, 0.12); }
.todo-glyph.skipped { color: #ff9a9a; background: rgba(239, 68, 68, 0.10); }
/* v382: a finished "doing" step is a check, not a turning ring; a stopped one pauses. */
.todo-glyph.finished { color: #7fe3a6; background: rgba(34, 197, 94, 0.12); }
.todo-glyph.paused { color: var(--text-muted); background: rgba(255, 255, 255, 0.05); }
@keyframes todoSpin { to { transform: rotate(360deg); } }
.todo-text { min-width: 0; overflow-wrap: anywhere; }
.todo-item.plan { border-color: rgba(124, 140, 255, 0.22); background: rgba(124, 140, 255, 0.045); color: var(--text); }
.todo-item.doing { border-color: rgba(245, 158, 11, 0.30); background: rgba(245, 158, 11, 0.055); color: var(--text); }
.todo-item.done { opacity: 0.86; }
.todo-item.finished { border-color: rgba(34, 197, 94, 0.22); background: rgba(34, 197, 94, 0.045); color: var(--text); }
.todo-item.paused { border-color: var(--border); background: rgba(255, 255, 255, 0.02); }
.todo-item.done .todo-text {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.28);
  text-decoration-thickness: 1px;
}
.todo-item.skipped .todo-text {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.16);
  opacity: 0.85;
}
.todo-label {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.08rem 0.4rem;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.todo-label.plan  { color: #a7b6ff; background: rgba(99, 102, 241, 0.18); }
.todo-label.doing { color: #f0b86e; background: rgba(245, 158, 11, 0.18); }
.todo-label.paused { color: var(--text-muted); background: rgba(255, 255, 255, 0.06); }

/* ---------- tool detail: a long number wraps, never scrolls sideways ---------------- */
.tool-detail-modal {
  max-width: min(900px, 94vw);
  overflow-x: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)), #0c1017;
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  box-shadow: var(--shadow);
}
.tool-detail-body { min-width: 0; overflow-wrap: anywhere; }
.tool-detail-body pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: hidden;
}
.code-block-wrapper {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
}
.code-block-gutter {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0.7rem 0.5rem;
  text-align: right;
  color: var(--text-muted);
  font: 0.72rem/1.55 var(--font-mono);
  background: rgba(255, 255, 255, 0.02);
  border-right: 1px solid var(--border);
  user-select: none;
}
.code-block-gutter span { display: block; }
.code-block-content { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.code-block-content pre {
  margin: 0;
  padding: 0.7rem 0.8rem;
  background: transparent;
  border: 0;
  border-radius: 0;
}

/* ---------- tool calls: chips in a wrapping cluster -------------------------------- */
.tool-cluster {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-width: min(100%, 1000px);
  padding: 0;
  margin: 0;
}
.chat-msg.tool-bubble {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: min(100%, 360px);
  height: 30px;
  padding: 0.2rem 0.65rem 0.28rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  border-left-width: 1px;
  background: rgba(255, 255, 255, 0.032);
  color: var(--text2);
  font-size: 0.74rem;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  animation: chipIn 0.16s ease;
  transition: background 0.14s, border-color 0.14s, transform 0.12s;
}
@keyframes chipIn {
  from { opacity: 0; transform: translateY(3px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.chat-msg.tool-bubble:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-strong);
  color: var(--text);
  transform: translateY(-1px);
}
.chat-msg.tool-bubble .tb-ic {
  flex: 0 0 auto;
  font-size: 0.86rem;
  filter: saturate(0.9);
}
.chat-msg.tool-bubble .tb-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 550;
  letter-spacing: 0.002em;
}
.chat-msg.tool-bubble .tb-mark {
  flex: 0 0 auto;
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 0.62rem;
  font-weight: 800;
}
.chat-msg.tool-bubble .tb-ok { color: #6ee7a8; background: rgba(34, 197, 94, 0.10); }
.chat-msg.tool-bubble .tb-err { color: #fca5a5; background: rgba(239, 68, 68, 0.12); }
.chat-msg.tool-bubble .tb-spin {
  flex: 0 0 auto;
  width: 11px; height: 11px;
  border: 1.6px solid rgba(124, 140, 255, 0.28);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.chat-msg.tool-bubble .tb-extra {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 210px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
/* The file name gives way before the two controls do: an ellipsised name is readable on
   hover, a clipped eye or arrow is a control the person cannot find. */
.chat-msg.tool-bubble .tb-extra .file-dl-link {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.file-dl-link {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  min-width: 0;
}
.file-dl-link .fdl-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-dl-link .fdl-ic,
.file-dl-link .fdl-arrow { flex: 0 0 auto; }

.chat-msg.tool-bubble .tb-extra .file-preview-btn {
  flex: 0 0 auto;
  width: 19px; height: 19px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.68rem;
  line-height: 1;
  cursor: pointer;
}
.chat-msg.tool-bubble .tb-extra .file-preview-btn:hover {
  background: rgba(124, 140, 255, 0.16);
  border-color: rgba(124, 140, 255, 0.4);
}
.chat-msg.tool-bubble .tb-extra a,
.chat-msg.tool-bubble .tb-extra button {
  font-size: 0.7rem;
  color: var(--accent-soft);
  background: none;
  border: 0;
  padding: 0 0.1rem;
  text-decoration: none;
}
.chat-msg.tool-bubble .ctx-progress {
  position: absolute;
  left: 10px; right: 10px; bottom: 2px;
  height: 2px; margin: 0;
}
.chat-msg.tool-bubble.running {
  border-color: rgba(124, 140, 255, 0.34);
  background: rgba(124, 140, 255, 0.07);
}
.chat-msg.tool-bubble.error,
.chat-msg.tool-bubble.tool-error {
  border-color: rgba(239, 68, 68, 0.32);
  background: rgba(239, 68, 68, 0.06);
}
.chat-msg.tool-bubble.done,
.chat-msg.tool-bubble.tool-done {
  border-color: rgba(255, 255, 255, 0.075);
}

/* ---------- session glyphs --------------------------------------------------------- */
.session-tab > .sess-glyph {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 0.42rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.035);
  color: var(--text-muted);
  font-size: 13px;
  transition: color 0.14s, background 0.14s, border-color 0.14s;
}
.session-tab:hover > .sess-glyph { color: var(--text2); border-color: var(--border-strong); }
.session-tab.active > .sess-glyph {
  color: var(--accent-soft);
  background: rgba(124, 140, 255, 0.12);
  border-color: rgba(124, 140, 255, 0.28);
}

/* ---------- mobile --------------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar {
    width: min(var(--sidebar-w), 88vw);
    background: #0b0e14;
    box-shadow: var(--shadow);
  }
  .chat-messages {
    padding: 1.1rem 0.85rem 0.6rem;
    gap: 0.7rem;
  }
  .chat-msg { max-width: 92%; font-size: 0.9rem; }
  .chat-input-area {
    margin: 0.25rem auto calc(0.6rem + env(safe-area-inset-bottom));
    width: calc(100% - 1.2rem);
    border-radius: 1.15rem;
    padding: 0.45rem 0.5rem 0.45rem 0.65rem;
  }
  .status-bar { padding: 0.45rem 0.65rem; }
}

@media (max-width: 600px) {
  .chat-msg { max-width: 94%; }
  .chat-msg.assistant { max-width: 100%; }
  .chat-msg.user { max-width: 88%; }
  .tool-cluster { gap: 0.3rem; }
  .chat-msg.tool-bubble { height: 28px; max-width: 100%; font-size: 0.72rem; }
  .chat-msg.tool-bubble .tb-name { max-width: 46vw; }
  /* style.css hides this label at 0 font-size; this layer loads later and had given the
     button a font-size again. Keep the phone's one-row status bar intact. */
  .session-files-btn { font-size: 0; padding: 0.3rem 0.45rem; }
  .session-files-btn .material-symbols-outlined { font-size: 1.1rem; }
  .toggle-tools-btn { white-space: nowrap; }
  .chat-input-area { gap: 0.35rem; }
  .chat-input-area #sendBtn { padding: 0.45rem 0.85rem; }
}

/* A user who asked the system to reduce motion gets none of the decorative kind. */
@media (prefers-reduced-motion: reduce) {
  .chat-msg, .modal, .new-chat-btn, .chat-input-area #sendBtn { animation: none !important; transition: none !important; }
}
