/* Crux — "liquid glass" design system.
   Layers: an ambient drifting backdrop, translucent blurred surfaces on top, and
   content. Surfaces stay neutral; one accent, violet into a deep blue, draws every box
   edge and divider (--line, --line-2) and marks what is yours or live (the page you are
   on, your messages, focus, primary actions). Green / amber / red stay for status. */
:root {
  /* neutral ramp */
  --g-950: #08080a;
  --g-900: #0c0c0f;
  --g-850: #111114;
  --g-800: #16161a;
  --g-700: #1e1e23;
  --g-600: #2a2a31;
  --g-500: #3a3a43;
  --g-400: #5c5c68;
  --g-300: #8c8c99;
  --g-200: #b6b6c0;
  --g-100: #dcdce2;
  --g-50: #f2f2f5;

  --text: var(--g-50);
  --text-dim: var(--g-200);
  --muted: var(--g-300);
  --muted-2: var(--g-400);

  /* glass */
  --glass: rgba(255, 255, 255, 0.045);
  --glass-2: rgba(255, 255, 255, 0.075);
  --glass-3: rgba(255, 255, 255, 0.11);
  --line: rgba(157, 139, 251, 0.15);
  --line-2: rgba(157, 139, 251, 0.27);
  --sheen: inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --lift: 0 2px 8px rgba(0, 0, 0, 0.34), 0 12px 36px rgba(0, 0, 0, 0.3);
  --lift-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.22);
  --blur: saturate(150%) blur(22px);

  /* status only */
  --good: #8fcfa9;
  --warn: #d9bd85;
  --bad: #e39292;

  /* accent: violet into a deep blue */
  --violet-200: #d9d2ff;
  --violet-300: #bcb0ff;
  --violet-400: #9d8bfb;
  --violet-500: #7e69ef;
  --blue-400: #6f8cf0;
  --blue-500: #4a68d4;
  --accent: var(--violet-400);
  --accent-soft: rgba(126, 105, 239, 0.14);
  --accent-line: rgba(157, 139, 251, 0.36);
  --accent-glow: rgba(126, 105, 239, 0.38);
  --accent-grad: linear-gradient(135deg, #8b75f6 0%, #6470e4 52%, #3f5cc9 100%);
  --accent-wash: linear-gradient(135deg, rgba(139, 117, 246, 0.2), rgba(63, 92, 201, 0.12));

  --r: 14px;
  --r-sm: 10px;
  --r-xs: 7px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t: 0.19s var(--ease);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w: 248px;
  --sidebar-rail-w: 72px;
  --content-max: 1120px;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over the id `display` rules below (#app, #login),
   otherwise toggling `.hidden` does nothing and panels never disappear. */
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: #07070d;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---- ambient backdrop: slow drifting light, so the page is never quite static ---- */
body::before {
  content: "";
  position: fixed;
  inset: -30%;
  z-index: -2;
  background:
    radial-gradient(38% 42% at 20% 22%, rgba(126, 105, 239, 0.075), transparent 70%),
    radial-gradient(34% 38% at 78% 30%, rgba(63, 92, 201, 0.065), transparent 70%),
    radial-gradient(44% 46% at 55% 88%, rgba(98, 80, 214, 0.045), transparent 72%);
  animation: drift 48s var(--ease) infinite alternate;
  pointer-events: none;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(120% 100% at 50% 0%, transparent 40%, rgba(0, 0, 0, 0.5) 100%);
  pointer-events: none;
}
@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(2.5%, -2%, 0) scale(1.06); }
  100% { transform: translate3d(-2%, 2.5%, 0) scale(1.02); }
}
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.015em; margin: 0; }
a { color: var(--violet-300); text-decoration: none; border-bottom: 1px solid rgba(188, 176, 255, 0.3); }
a:hover { color: var(--violet-200); border-bottom-color: var(--violet-300); }
::selection { background: rgba(126, 105, 239, 0.42); color: #fff; }
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--glass-2);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: var(--r-xs);
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.row { display: flex; align-items: center; gap: 9px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.mono { font-family: var(--mono); }

/* ---- scrollbars ---- */
* { scrollbar-width: thin; scrollbar-color: var(--g-600) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--g-600); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(126, 105, 239, 0.55); background-clip: content-box; }

/* ---- buttons ---- */
button {
  cursor: pointer;
  border: 1px solid var(--line-2);
  background: var(--glass);
  color: var(--text-dim);
  padding: 8px 15px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--sheen);
  transition: background var(--t), border-color var(--t), color var(--t), transform var(--t), box-shadow var(--t), opacity var(--t);
}
button:hover:not(:disabled) { background: var(--glass-2); border-color: var(--accent-line); color: var(--text); transform: translateY(-1px); box-shadow: var(--sheen), var(--lift-sm); }
button:active:not(:disabled) { transform: translateY(0) scale(0.985); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: var(--sheen), 0 6px 18px -6px var(--accent-glow);
}
button.primary:hover:not(:disabled) { background: var(--accent-grad); color: #fff; filter: brightness(1.1); box-shadow: var(--sheen), 0 10px 26px -8px var(--accent-glow); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); box-shadow: none; }
button.ghost:hover:not(:disabled) { background: var(--glass); color: var(--text); box-shadow: var(--sheen); }
button.small { padding: 5px 11px; font-size: 12.5px; border-radius: var(--r-xs); }
button.danger { color: var(--bad); border-color: transparent; background: transparent; box-shadow: none; }
button.danger:hover:not(:disabled) { background: rgba(227, 146, 146, 0.12); border-color: rgba(227, 146, 146, 0.28); color: var(--bad); }
button.icon-btn { padding: 7px 10px; }
button.chip { border-radius: 99px; padding: 5px 13px; font-size: 12.5px; }
button.chip.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--violet-200); }

/* ---- inputs ---- */
input[type="text"], input[type="password"], input[type="search"], input[type="number"], input[type="url"], input[type="email"], textarea, select {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  width: 100%;
  outline: none;
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-line);
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 3px rgba(126, 105, 239, 0.16);
}
textarea { resize: vertical; font-family: inherit; }
select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 51%, calc(100% - 11px) 51%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select option { background: var(--g-800); color: var(--text); }
label.row { cursor: pointer; }
input[type="checkbox"] { width: auto; accent-color: var(--violet-400); }

/* ---- surfaces ---- */
.card, .glass {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--sheen), var(--lift);
}
.card { padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; overflow: hidden; }

.pill {
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--glass);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.pill.good { color: var(--good); border-color: rgba(143, 207, 169, 0.3); background: rgba(143, 207, 169, 0.1); }
.pill.bad { color: var(--bad); border-color: rgba(227, 146, 146, 0.3); background: rgba(227, 146, 146, 0.1); }
.pill.warn { color: var(--warn); border-color: rgba(217, 189, 133, 0.3); background: rgba(217, 189, 133, 0.1); }
.pill.accent { color: var(--violet-200); border-color: var(--accent-line); background: var(--accent-soft); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: var(--r-xs); background: var(--glass-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--g-500); flex: none; display: inline-block; transition: background var(--t), box-shadow var(--t); }
.dot.good { background: var(--good); box-shadow: 0 0 0 3px rgba(143, 207, 169, 0.14); animation: pulse 2.6s var(--ease) infinite; }
.dot.bad { background: var(--bad); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(143, 207, 169, 0.14); }
  50% { box-shadow: 0 0 0 5px rgba(143, 207, 169, 0.05); }
}

/* ---- login ---- */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 22px; overflow-y: auto; }
#login .card { max-width: 400px; width: 100%; animation: rise 0.45s var(--ease) both; }
.auth-links { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; }
button.link { background: none; border: none; box-shadow: none; padding: 2px 0; color: var(--muted); font-size: 12.5px; text-decoration: underline; text-underline-offset: 3px; }
button.link:hover:not(:disabled) { background: none; box-shadow: none; transform: none; color: var(--text); }

/* ---- pairing, dialogs, account lists ---- */
.pair-code { font-family: var(--mono); font-size: 30px; letter-spacing: 0.12em; text-align: center; padding: 14px 10px; border-radius: var(--r-sm); background: rgba(0, 0, 0, 0.26); border: 1px dashed var(--accent-line); color: var(--violet-200); user-select: all; }
.modal-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 200; padding: 20px; overflow-y: auto; }
.modal { max-width: 560px; width: 100%; max-height: calc(100vh - 40px); overflow-y: auto; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; min-width: 0; }
.list-row:first-child { border-top: none; }
.list-row .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.connector-head { display: flex; align-items: center; gap: 10px; }
.connector-head .grow { font-weight: 600; }
.note { font-size: 12.5px; color: var(--muted); margin: 0; }
.note.warn { color: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.985); } }

/* ---- app shell ---- */
#app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100dvh; }

#sidebar {
  position: relative;
  isolation: isolate;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.065), rgba(255, 255, 255, 0.018) 62%);
  border-right: 1px solid var(--line);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 14px;
  gap: 10px;
  z-index: 30;
  overflow: hidden;
}
#sidebar::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: 220px;
  height: 220px;
  left: -90px;
  top: -110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  filter: blur(52px);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 11px; min-height: 46px; padding: 2px 8px 14px; }
.brand-mark { width: 30px; height: 30px; flex: none; border-radius: 8px; box-shadow: 0 0 0 1px var(--accent-line), 0 6px 18px -6px var(--accent-glow); }
.brand-name { min-width: 0; white-space: nowrap; font-size: 17px; font-weight: 650; letter-spacing: -0.025em; color: var(--text); }

/* Line icons for the sidebar: one weight, one size, coloured by the row they sit in. */
svg.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg.ico .ico-solid { fill: currentColor; stroke: none; }
svg.ico .ico-soft { opacity: 0.5; }

#nav { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 2px 0; }
/* Plain rows, not glass: the blurred backdrop every button inherits is what turned each
   item into a murky grey card. Only the page you are on gets a surface. */
#nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-start;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--g-300);
  font-size: 13.5px;
  font-weight: 550;
}
#nav button .ico { opacity: 0.85; transition: opacity var(--t); }
#nav button span, .side-signout span { min-width: 0; overflow: hidden; white-space: nowrap; }
#nav button:hover:not(.active) { background: rgba(255, 255, 255, 0.045); color: var(--g-100); transform: none; box-shadow: none; }
#nav button:active:not(:disabled) { transform: none; }
#nav button.active { background: var(--accent-wash); border-color: var(--accent-line); color: #fff; box-shadow: var(--sheen), 0 6px 18px -10px var(--accent-glow); }
#nav button.active .ico, #nav button:hover .ico { opacity: 1; }
#nav button.active .ico { color: var(--violet-200); }
.nav-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; color: var(--muted-2); font-size: 10px; text-transform: uppercase; letter-spacing: .07em; font-weight: 650; }
.nav-field select { height: 33px; min-width: 0; padding: 5px 26px 5px 9px; border-radius: 9px; font-size: 12px; text-transform: none; letter-spacing: 0; background-color: rgba(0,0,0,.22); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 12px; }
.fleet { display: flex; flex-direction: column; padding: 10px 8px 7px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.025); box-shadow: var(--sheen); }
.fleet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 4px 5px; color: var(--muted-2); font-size: 10.5px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; }
#fleetCount { color: var(--muted); font-weight: 550; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
#deviceMini { display: flex; flex-direction: column; gap: 1px; font-size: 12.5px; }
#deviceMini .dev { display: flex; align-items: center; gap: 9px; min-height: 28px; padding: 0 4px; color: var(--text-dim); }
#deviceMini .dev.off, #deviceMini .dev.empty { color: var(--muted-2); }
/* Status, not decoration: a steady light rather than a pulse on every row. */
#deviceMini .dot { width: 7px; height: 7px; animation: none; box-shadow: none; }
#deviceMini .dot.good { box-shadow: 0 0 6px rgba(143, 207, 169, 0.45); }
.dev-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-kind { flex: none; color: var(--muted-2); font-size: 10.5px; }
#sidebar .side-signout { display: flex; align-items: center; gap: 12px; justify-content: flex-start; width: 100%; min-height: 36px; padding: 0 12px; background: transparent; border-color: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; color: var(--muted); font-size: 13px; }
#sidebar .side-signout:hover:not(:disabled) { background: rgba(255, 255, 255, 0.045); color: var(--text); transform: none; box-shadow: none; }
.side-signout .ico { width: 17px; height: 17px; }

@media (min-width: 861px) {
  #app { grid-template-columns: var(--sidebar-rail-w) minmax(0, 1fr); }
  #sidebar { width: var(--sidebar-rail-w); height: 100%; transition: width var(--t), box-shadow var(--t); }
  /* Expand over the page so hovering the rail never shifts the current workspace.
     Only keyboard focus holds it open; a mouse click must still collapse on leaving. */
  #sidebar:hover,
  #sidebar:has(:focus-visible) { width: var(--sidebar-w); background-color: var(--g-850); box-shadow: var(--lift); }
  #sidebar:not(:hover):not(:has(:focus-visible)) :is(.brand-name, #nav button span, .side-signout span) { visibility: hidden; width: 0; }
  #sidebar:not(:hover):not(:has(:focus-visible)) .fleet { display: none; }
}

.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand img { border-radius: 10px; box-shadow: 0 0 0 1px var(--accent-line), var(--lift-sm); }

#main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 11px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 10, 12, 0.55);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  z-index: 10;
}
#topbar h1 { font-size: 16px; flex: 1; font-weight: 650; }
#menuBtn { display: none; }
#view { flex: 1; overflow: auto; min-height: 0; overscroll-behavior: contain; }
/* `backwards`, not `both`: a transform that stays filled after the animation makes the view the
   containing block of its position:fixed children, so the chat's off-canvas settings drawer
   scrolled with the page and widened it sideways. */
#view > * { animation: fadeUp 0.3s var(--ease) backwards; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }

#scrim { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); z-index: 20; }

/* ---- layout helpers ---- */
.pane { width: 100%; padding: 26px clamp(18px, 3vw, 34px) 38px; max-width: var(--content-max); margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.device-connect { display: flex; flex-direction: column; gap: 18px; margin-top: 12px; padding-top: 24px; border-top: 1px solid var(--line); scroll-margin-top: 22px; }
.device-connect-heading { font-size: 18px; }
#add-device { scroll-margin-top: 22px; }
.section-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-2); font-weight: 600; }
.page-stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.page-empty { min-height: 180px; align-items: center; justify-content: center; gap: 5px; }
.page-empty strong { color: var(--text-dim); }
.settings-field { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: center; }
.route-row { cursor: default; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
.route-note { grid-column: 2 / -1; margin-top: 2px; }
.command-row { font-family: var(--mono); font-size: 12px; background: rgba(0,0,0,.2); border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 10px; }
.command-row > .grow { word-break: break-all; }
.grid { display: grid; gap: 12px; }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.empty { color: var(--muted); text-align: center; padding: 48px 20px; font-size: 13.5px; }
.kv { display: grid; grid-template-columns: minmax(76px, max-content) minmax(0, 1fr); gap: 6px 16px; font-size: 12.5px; }
.kv dt { color: var(--muted-2); }
.kv dd { margin: 0; word-break: break-word; color: var(--text-dim); }

/* ---- workspace and file browser ---- */
.files-pane { max-width: 980px; }
.file-routing { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.3fr) auto; align-items: end; gap: 12px; padding: 16px; }
.file-routing select { width: 100%; }
.file-routing > button { min-height: 34px; }
.file-path { min-height: 38px; }
.file-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; background: rgba(255,255,255,.018); }
.file-row { width: 100%; min-height: 46px; display: flex; align-items: center; gap: 10px; padding: 9px 13px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--text-dim); text-align: left; box-shadow: none; }
.file-row:last-child { border-bottom: 0; }
.file-row:hover { transform: none; background: var(--glass-2); box-shadow: none; }
.file-icon { width: 18px; color: var(--g-100); text-align: center; }
.file-preview { display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line-2); border-radius: 15px; padding: 14px; background: rgba(255,255,255,.025); }
.file-preview[hidden] { display: none; }
.file-preview pre { max-height: 420px; overflow: auto; margin: 0; padding: 13px; border-radius: 10px; background: rgba(0,0,0,.26); color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.55 var(--mono); }
@media (max-width: 720px) { .file-routing { grid-template-columns: 1fr; align-items: stretch; } }

/* ---- chat ---- */
/* History rail and the conversation. Crux adds its info column only while it is open. */
#chatWrap { display: grid; grid-template-columns: 270px minmax(0, 1fr); height: 100%; min-height: 0; position: relative; }
#threadList {
  border-right: 1px solid var(--line);
  overflow: auto;
  background: linear-gradient(180deg, rgba(255,255,255,.025), rgba(255,255,255,.01));
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  display: flex;
  flex-direction: column;
  z-index: 5;
  min-height: 0;
}
#chatOptions {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.028), rgba(255,255,255,.012));
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  z-index: 5;
}
.chat-rail-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 14px 12px; }
.chat-rail-head > div { display: flex; flex-direction: column; line-height: 1.25; }
.chat-rail-head strong { font-size: 13px; font-weight: 650; }
.chat-rail-head .small { font-size: 10.5px; margin-top: 3px; }
.conversation-routing { display: flex; flex-direction: column; gap: 9px; margin: 0 10px 11px; padding: 11px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.022); box-shadow: var(--sheen); }
.conversation-routing .nav-field select { width: 100%; }
.chat-options-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 14px 12px; }
.chat-options-head > div { display: flex; flex-direction: column; line-height: 1.25; }
.chat-options-head strong { font-size: 13px; font-weight: 650; }
.chat-options-head .small { font-size: 10.5px; margin-top: 3px; }
.options-close { display: grid; place-items: center; font-size: 20px; line-height: 1; }
.rail-new { width: 31px; height: 31px; padding: 0; border-radius: 10px; font-size: 19px; line-height: 1; }
.chat-settings { margin: 0 12px 10px; padding: 13px; display: flex; flex-direction: column; gap: 12px; background: rgba(255,255,255,.025); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--sheen), var(--lift-sm); }
.rail-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; color: var(--muted-2); font-size: 10px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.rail-field select, .rail-field input, .chat-settings > .model-input { height: 34px; padding: 5px 27px 5px 9px; font-size: 12px; text-transform: none; letter-spacing: 0; }
.rail-field input { padding-right: 9px; }
.system-field input { min-height: 34px; }
.rail-actions { display: flex; padding: 0 12px 14px; }
.rail-actions button { width: 100%; }
.thread-rows { flex: 1; min-height: 0; overflow-y: auto; }
/* Rail actions: New chat and Models, one height, one shape. */
.ic { display: inline-grid; place-items: center; flex: none; line-height: 0; }
.chat-rail-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 14px 12px 4px; }
button.rail-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 13px; border-radius: 12px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); background: rgba(255,255,255,.035); border: 1px solid var(--line); box-shadow: var(--sheen); }
button.rail-btn:hover:not(:disabled) { color: var(--text); background: rgba(255,255,255,.06); border-color: var(--accent-line); transform: none; }
button.rail-btn .ic { color: var(--muted); }
button.rail-newchat { justify-content: flex-start; color: var(--text); background: var(--accent-wash); border-color: var(--accent-line); }
button.rail-newchat .ic { color: var(--violet-200); }
button.rail-newchat:hover:not(:disabled) { background: linear-gradient(135deg, rgba(139,117,246,.3), rgba(63,92,201,.18)); }
/* History groups: workspace, then the computer it is on. */
.history-group { padding-bottom: 2px; margin-top: 5px; }
.history-group-head { display: flex; align-items: center; gap: 3px; margin: 0 8px 3px; padding: 3px 4px 3px 5px; border-radius: 9px; cursor: grab; }
.history-group-head:active { cursor: grabbing; }
.history-group-head:hover { background: var(--glass); }
button.history-group-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 5px; padding: 5px 0; border: 0; border-radius: 5px; background: transparent; box-shadow: none; text-align: left; color: var(--text); }
button.history-group-toggle:hover:not(:disabled) { background: transparent; transform: none; box-shadow: none; }
.history-drag-handle { flex: none; color: var(--muted-2); font-size: 10px; letter-spacing: -2px; padding-right: 3px; user-select: none; }
button.history-group-new { flex: none; display: grid; place-items: center; width: 23px; height: 23px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); box-shadow: none; }
button.history-group-new:hover:not(:disabled) { background: var(--accent-wash); color: var(--violet-200); transform: none; box-shadow: none; }
.history-group.dragging { opacity: .45; }
.history-group.drag-over-before > .history-group-head { box-shadow: 0 -3px 0 var(--violet-300); }
.history-group.drag-over-after { box-shadow: 0 3px 0 var(--violet-300); }
.history-caret { color: var(--muted-2); transition: transform var(--t); transform: rotate(90deg); }
.history-group.closed .history-caret { transform: none; }
.history-group-name { display: flex; align-items: center; gap: 5px; min-width: 0; flex: 0 1 auto; max-width: 65%; font-size: 12px; font-weight: 650; }
.history-group-name .ic { color: var(--violet-300); }
.history-group-name > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-group-device { flex: 0 100 auto; min-width: 0; font-size: 10.5px; color: var(--muted-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-group-count { flex: none; margin-left: auto; min-width: 18px; padding: 0 5px; border-radius: 99px; background: rgba(255,255,255,.05); font-size: 10.5px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.thread-rows .thread { padding-left: 33px; }
.history-group + .thread, .thread + .history-group { margin-top: 0; }
.chat-scrim { display: none; }
.thread-rows .empty { padding: 32px 14px; }
.thread {
  padding: 6px 14px;
  cursor: pointer;
  transition: background var(--t);
  position: relative;
}
.thread:hover { background: var(--glass); }
.thread.active { background: var(--accent-soft); }
.thread.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--accent-grad); }
.thread .t1 { font-size: 12.5px; font-weight: 500; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
.thread { padding-right: 38px; }
.thread-more { position: absolute; right: 6px; top: 50%; margin-top: -12px; width: 24px; height: 24px; padding: 0; border-radius: 8px; opacity: 0; transition: opacity var(--t); }
.thread:hover .thread-more, .thread.active .thread-more, .thread-more:focus-visible { opacity: 1; }
@media (hover: none) { .thread-more { opacity: 1; } }
.folder-bar { display: flex; align-items: center; gap: 6px; padding: 0 12px 10px; }
.folder-bar .folder-filter { flex: 1; min-width: 0; height: 32px; font-size: 12px; padding: 4px 26px 4px 9px; }
.folder-bar button { flex: none; }
.pop-menu { position: fixed; z-index: 60; min-width: 190px; max-width: 260px; max-height: 60vh; overflow-y: auto; padding: 5px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--g-900); box-shadow: 0 14px 40px rgba(0,0,0,.45); display: flex; flex-direction: column; }
.pop-item { text-align: left; padding: 8px 10px; border-radius: 8px; background: transparent; border: 0; color: var(--text); font-size: 13px; cursor: pointer; }
.pop-item:hover, .pop-item:focus-visible { background: var(--glass); }
.pop-item.danger { color: var(--bad); }

#chatMain { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.chat-main-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line); color: var(--text-dim); font-size: 13px; font-weight: 650; }
.chat-main-head > div { display: flex; gap: 8px; }
#messages { flex: 1; overflow: auto; padding: 30px 24px 14px; display: flex; flex-direction: column; gap: 20px; scroll-behavior: smooth; background: radial-gradient(70% 55% at 50% 100%, rgba(255,255,255,.018), transparent 72%); }
.msg { max-width: min(800px, 85%); width: fit-content; margin: 0 auto 0 0; display: flex; flex-direction: column; align-items: flex-start; animation: fadeUp 0.28s var(--ease) both; }
.msg.user { margin-left: auto; margin-right: 0; align-items: flex-end; }
.msg > * { min-width: 0; max-width: 100%; }
.msg .who { font-size: 11.5px; color: var(--muted-2); margin-bottom: 6px; display: flex; align-items: center; flex-wrap: wrap; gap: 9px; overflow-wrap: anywhere; }
.msg .who .meta { margin-left: auto; font-variant-numeric: tabular-nums; }
.msg .bubble {
  width: fit-content;
  border-radius: var(--r);
  padding: 13px 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--sheen);
}
.msg.user .bubble { background: var(--accent-wash); border-color: var(--accent-line); }
.msg.assistant .bubble { background: var(--glass); }
.msg .reasoning { width: 100%; margin-bottom: 8px; color: var(--muted); font-size: 12.5px; }
.reasoning > summary { width: fit-content; cursor: pointer; padding: 5px 2px; border-radius: 5px; }
.reasoning > summary:hover { color: var(--text); }
.reasoning > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.reasoning-count { font-size: 11px; }
.reasoning-body { max-height: 360px; overflow: auto; padding: 4px 0 8px 12px; border-left: 1px solid var(--line); }
.reasoning-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.reasoning-text + .reasoning-text { margin-top: 9px; }
.reasoning .tool + .reasoning-text { margin-top: 9px; }
.msg-actions { display: flex; gap: 4px; margin-top: 7px; opacity: 0; transition: opacity var(--t); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }

.msg .tool { font-family: var(--mono); font-size: 11.5px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: var(--r-sm); margin-top: 9px; overflow: hidden; }
.msg .tool .tool-head { width: 100%; padding: 7px 11px; display: flex; gap: 9px; align-items: center; text-align: left; font: inherit; border: 0; border-radius: 0; background: transparent; box-shadow: none; cursor: pointer; transition: background var(--t); }
.msg .tool .tool-head:hover { background: var(--glass); }
.msg .tool .tool-head:hover:not(:disabled) { transform: none; box-shadow: none; }
.msg .tool .tool-name { color: var(--violet-200); font-weight: 600; }
.msg .tool .tool-body { padding: 9px 11px; white-space: pre-wrap; word-break: break-word; color: var(--muted); border-top: 1px solid var(--line); max-height: 320px; overflow: auto; }
.msg .tool.err .tool-name { color: var(--bad); }
.cursor-blink::after { content: "▍"; color: var(--accent); animation: blink 1.05s steps(2) infinite; }
/* While the typing dots show, they are the cursor. */
.cursor-blink:has(.typing)::after { content: none; }
@keyframes blink { 50% { opacity: 0; } }

#composer {
  position: relative;
  z-index: 4;
  padding: 10px 24px 26px;
  background: linear-gradient(180deg, transparent, rgba(8,8,10,.86) 28%, rgba(8,8,10,.96));
  display: flex;
  flex-direction: column;
  gap: 7px;
}
#composer .inner { max-width: 860px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 7px; }
/* The composer is one card: the message on top, a toolbar of chips under it. */
#composer .inner { position: relative; }
#composer .composer-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 10px 10px 14px;
  background: rgba(24, 24, 28, 0.9);
  border: 1px solid var(--line-2);
  border-radius: 22px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--sheen), 0 12px 34px rgba(0,0,0,.34);
  transition: border-color var(--t), box-shadow var(--t);
}
#composer .composer-card:focus-within { border-color: var(--accent-line); box-shadow: var(--sheen), 0 0 0 3px rgba(126, 105, 239, 0.14), 0 16px 40px rgba(0,0,0,.38); }
#promptInput { min-height: 26px; max-height: 220px; background: transparent; border: none; padding: 2px 4px 2px 0; box-shadow: none; resize: none; line-height: 1.5; }
#promptInput:focus { box-shadow: none; background: transparent; }
.composer-bar { display: flex; align-items: center; gap: 6px; min-width: 0; margin-left: -4px; }
.composer-bar .grow { flex: 1; min-width: 0; }
.composer-note { display: flex; justify-content: space-between; gap: 12px; padding: 0 7px; color: var(--muted-2); font-size: 10.5px; }

/* Toolbar chips: the same 32px pill for the model, the folder, Crux info and icon buttons. */
.tool-chip, button.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  min-width: 0;
  padding: 0 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255,255,255,.045);
  box-shadow: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--t), border-color var(--t), color var(--t);
}
button.tool-chip:hover:not(:disabled), .tool-chip:hover { background: rgba(255,255,255,.08); border-color: var(--line-2); color: var(--text); transform: none; box-shadow: none; }
button.tool-chip.on, button.tool-chip[aria-expanded="true"] { background: var(--accent-wash); border-color: var(--accent-line); color: var(--violet-200); }
.tool-chip .ic { color: var(--muted); }
.tool-chip:hover .ic, .tool-chip.on .ic, .tool-chip[aria-expanded="true"] .ic { color: var(--violet-200); }
button.tool-chip.icon-only { width: 32px; padding: 0; justify-content: center; }
button.composer-tool { display: none; }
/* Chat and Crux share a themed, searchable model menu rather than an OS popup. */
.tool-chip.model-pick { flex: 0 1 auto; width: fit-content; max-width: 300px; text-align: left; }
.model-pick-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.model-pick .ic { flex: none; }
.tool-chip.model-pick.reasoning-pick { flex: 0 0 54px; width: 54px; min-width: 54px; max-width: 54px; padding: 0 8px; justify-content: center; }
.reasoning-pick > .ic { display: none; }
.reasoning-meter { display: flex; gap: 3px; width: 36px; height: 10px; }
.reasoning-segment { flex: 1; min-width: 0; border-radius: 2px; background: rgba(255,255,255,.16); }
.reasoning-segment.filled { background: var(--violet-300); }
.model-pop.reasoning-pop { width: min(240px, calc(100vw - 24px)); }
.reasoning-pop .model-group-title { display: none; }
.reasoning-pop p { margin: 0 4px; }
.model-reasoning-select { width: 135px; flex: none; font-size: 11px; padding: 6px 8px; }
.model-pop, .route-pop { max-width: 100%; }
.model-pop { position: absolute; bottom: calc(100% + 10px); z-index: 31; width: min(440px, calc(100vw - 24px)); max-height: min(70vh, 560px); display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--line-2); border-radius: 18px; color: var(--text); background: #16161c; box-shadow: 0 24px 60px rgba(0,0,0,.55), var(--sheen); animation: popIn .16s var(--ease) backwards; }
.model-pop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-left: 4px; }
.model-pop-head strong { margin-right: auto; font-size: 13.5px; }
.model-pop-actions { display: flex; align-items: center; gap: 6px; }
.model-search { flex: none; width: 100%; height: 38px; border-radius: 10px; background: var(--g-900); font-size: 12.5px; }
.model-options { min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding: 1px 2px 2px; }
.model-group-title { padding: 7px 10px; color: var(--violet-300); font-size: 10.5px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; }
.model-option-group + .model-option-group { border-top: 1px solid var(--line); padding-top: 4px; }
button.model-option { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 11px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text-dim); text-align: left; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
button.model-option:hover:not(:disabled), button.model-option:focus-visible { background: var(--glass-2); color: var(--text); transform: none; box-shadow: none; border-color: var(--line-2); }
button.model-option[aria-selected="true"] { background: var(--accent-wash); border-color: var(--accent-line); color: var(--text); }
.model-option-copy { display: flex; flex: 1; flex-direction: column; gap: 3px; min-width: 0; }
.model-option-name { font-size: 12.5px; font-weight: 550; overflow-wrap: anywhere; }
.model-option-detail { color: var(--muted); font-size: 11px; }
.model-option-check { width: 16px; flex: none; color: var(--violet-300); font-size: 15px; }
.model-empty { padding: 24px 12px; color: var(--muted); font-size: 12.5px; text-align: center; }
.folder-btn { flex: 0 1 auto; width: fit-content; max-width: 300px; }
.folder-btn .ic:first-child { color: var(--violet-300); }
.folder-label { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
button.default-star { font-size: 15px; line-height: 1; color: var(--muted); }
button.default-star.on { color: var(--warn); background: rgba(217, 189, 133, .1); }
button.default-star:disabled { visibility: hidden; }
#sendBtn { width: 34px; height: 34px; padding: 0; flex: none; border-radius: 11px; font-size: 17px; font-weight: 700; line-height: 1; margin-left: 2px; }

/* The folder menu: computers as rows, access as a switch, the workspace as a picker. */
.route-pop { position: absolute; bottom: calc(100% + 10px); z-index: 30; width: min(400px, calc(100vw - 24px)); max-height: min(70vh, 560px); overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 8px; border-radius: 18px; border: 1px solid var(--line-2); background: rgba(20, 20, 25, 0.98); box-shadow: 0 24px 60px rgba(0,0,0,.55), var(--sheen); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); animation: popIn 0.16s var(--ease) backwards; }
@keyframes popIn { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.route-pop[hidden] { display: none; }
.route-pop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 6px 6px 6px 10px; }
.route-pop-head > div { display: flex; flex-direction: column; gap: 2px; }
.route-pop-head strong { font-size: 13.5px; }
button.route-close { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 9px; }
.route-sec { display: flex; flex-direction: column; gap: 7px; padding: 10px; border-radius: 13px; background: rgba(255,255,255,.025); }
.route-sec[hidden], .route-field:has(> .route-sec[hidden]) { display: none; }
.route-sec-head { display: flex; align-items: center; gap: 6px; color: var(--muted-2); font-size: 10.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.route-native { display: none !important; }
.route-choices { display: flex; flex-direction: column; gap: 3px; }
button.route-choice { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid transparent; background: transparent; box-shadow: none; text-align: left; color: var(--text-dim); font-size: 13px; }
button.route-choice:hover:not(:disabled) { background: rgba(255,255,255,.05); border-color: transparent; transform: none; box-shadow: none; color: var(--text); }
button.route-choice.on { background: var(--accent-wash); border-color: var(--accent-line); color: var(--text); }
.route-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); opacity: .6; }
.route-dot.online { background: var(--good); opacity: 1; box-shadow: 0 0 0 3px rgba(143, 207, 169, .14); }
.route-choice-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-choice-meta { font-size: 11px; color: var(--muted-2); }
.route-seg { display: flex; padding: 3px; gap: 3px; border-radius: 11px; background: rgba(0,0,0,.28); border: 1px solid var(--line); }
button.seg { flex: 1; min-width: 0; height: 30px; padding: 0 8px; border-radius: 8px; border: 0; background: transparent; box-shadow: none; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.seg:hover:not(:disabled) { background: rgba(255,255,255,.05); color: var(--text); transform: none; box-shadow: none; border: 0; }
button.seg.on { background: var(--accent-grad); color: #fff; box-shadow: 0 4px 14px -6px var(--accent-glow); }
.route-select { position: relative; display: flex; align-items: center; }
.route-select select { width: 100%; height: 38px; padding: 0 34px 0 12px; border-radius: 10px; appearance: none; -webkit-appearance: none; background-image: none; font-size: 13px; }
.route-select .ic { position: absolute; right: 12px; pointer-events: none; color: var(--muted); }
.route-more { border-radius: 13px; padding: 2px 10px; }
.route-more summary { display: flex; align-items: center; gap: 6px; padding: 8px 0; list-style: none; cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 600; }
.route-more summary::-webkit-details-marker { display: none; }
.route-more summary .ic { transition: transform var(--t); }
.route-more[open] summary .ic { transform: rotate(90deg); }
.route-more summary:hover { color: var(--text); }
.route-more[open] { display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px; background: rgba(255,255,255,.025); }
.route-more .rail-field select, .route-more .rail-field input { width: 100%; }
.route-more .rail-field[hidden] { display: none; }
button.route-export { align-self: flex-start; }

/* Crux info chip: text at width, the icon alone when the bar is tight. */
@media (max-width: 600px) { .crux-info-btn .chip-text { display: none; } button.crux-info-btn { width: 32px; padding: 0; justify-content: center; } }
.attachment-tray, .message-attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-tray[hidden] { display: none; }
.message-attachments { margin-top: 10px; }
.attachment-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 8px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--glass-2); color: var(--text-dim); font-size: 11px; overflow-wrap: anywhere; }
.attachment-chip button { border: 0; background: transparent; color: var(--muted); padding: 0 2px; box-shadow: none; font-size: 16px; }
.chat-model-dialog { width: min(1120px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior-y: contain; padding: 22px; color: var(--text); background: #202024; border: 1px solid var(--line-2); border-radius: 20px; box-shadow: 0 24px 80px #000a; }
.chat-model-dialog::backdrop { background: #000a; }
.model-dialog-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 10px; }
.model-dialog-head h3 { margin: 0 0 4px; font-size: 17px; }
.model-dialog-head p { margin: 0; }
.model-dialog-nav { position: sticky; top: -22px; z-index: 2; display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 0 12px; margin-bottom: 16px; background: #202024; border-bottom: 1px solid var(--line); }
.model-dialog-nav button { border-radius: 999px; }
.model-settings-grid { display: grid; grid-template-columns: minmax(0, .94fr) minmax(0, 1.06fr); align-items: start; gap: 16px; }
.model-settings-column { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.model-settings-panel, .model-connections { min-width: 0; padding: 17px; border: 1px solid var(--line-2); border-radius: 16px; background: rgba(255,255,255,.025); scroll-margin-top: 58px; }
.model-panel-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 12px; }
.model-panel-head h4 { margin: 0; font-size: 14px; }
.model-local-list { display: flex; flex-direction: column; gap: 5px; }
.model-local-row { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--glass); }
.model-local-info { display: flex; flex: 1; flex-direction: column; min-width: 0; line-height: 1.3; }
.model-local-info strong { font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.model-local-info .muted { overflow-wrap: anywhere; }
.model-settings-list { display: flex; flex-direction: column; gap: 5px; padding: 0 4px 2px 0; }
.model-settings-row { position: relative; display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 12px; font-size: 12px; cursor: grab; transition: border-color var(--t), background var(--t); }
.model-settings-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.model-settings-row.drag-over-before, .model-settings-row.drag-over-after { border-color: var(--accent-line); background: var(--glass-2); }
.model-settings-row.drag-over-before::before, .model-settings-row.drag-over-after::after { content: ''; position: absolute; left: 8px; right: 8px; height: 3px; border-radius: 3px; background: var(--accent); pointer-events: none; }
.model-settings-row.drag-over-before::before { top: -5px; }
.model-settings-row.drag-over-after::after { bottom: -5px; }
.model-settings-row.dragging { opacity: .48; }
.model-settings-row.dragging, .model-settings-row:active { cursor: grabbing; }
.model-drag-handle { flex: none; width: 18px; color: var(--muted); user-select: none; font-size: 15px; letter-spacing: -3px; }
.model-settings-name { flex: 1; min-width: 90px; overflow-wrap: anywhere; }
.model-settings-row code { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }
.model-settings-subhead { margin: 16px 0 5px; font-size: 12px; }
.model-settings-add { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.model-settings-add select, .model-settings-add input { min-width: 120px; flex: 1; }
.model-settings-add:has(input) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.model-settings-add:has(input) select, .model-settings-add:has(input) input { min-width: 0; width: 100%; }
.model-settings-add:has(input) button { grid-column: 1 / -1; justify-self: end; }
.model-connections { margin-top: 16px; }
.model-connections h4 { margin: 0 0 6px; font-size: 14px; }
.model-connections h5 { margin: 18px 0 8px; font-size: 12px; color: var(--text-dim); }
.model-connections p { margin: 0 0 14px; }
.model-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.model-field select { min-width: 180px; }
.model-connection-row { display: flex; align-items: center; gap: 7px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.model-connection-row > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.model-connection-row .muted { margin-top: 3px; }
.model-connection-form { display: grid; gap: 10px; margin-top: 12px; padding: 14px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--glass-2); }
.model-connection-form > input { width: 100%; }
.model-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.model-form-grid input, .model-form-grid select { min-width: 0; width: 100%; }
.model-form-actions { display: flex; gap: 7px; }
@media (max-width: 760px) { .model-settings-grid { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .chat-model-dialog { width: calc(100vw - 16px); padding: 14px; } .model-dialog-nav { top: -14px; } .model-settings-panel, .model-connections { padding: 12px; } .model-form-grid { grid-template-columns: 1fr; } .model-settings-row { flex-wrap: wrap; } }
.quick-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* chat empty state */
.chat-hero { max-width: 640px; margin: auto; text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; padding: 30px 20px; }
.chat-hero .crux-mark { filter: drop-shadow(0 14px 40px rgba(126, 105, 239, 0.32)); animation: fadeUp 0.5s var(--ease) both; }
.hero-route { letter-spacing: 0.01em; }

/* ---- device cards ---- */
.dev-card {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 17px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--sheen), var(--lift-sm);
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
.dev-card:hover { transform: translateY(-2px); box-shadow: var(--sheen), var(--lift); border-color: var(--line-2); }
.dev-card .dc-head { display: flex; align-items: center; gap: 10px; }
.dev-card .dc-title { font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; }
.dev-card .caps { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.cap { display: flex; align-items: center; gap: 9px; min-width: 0; }
.cap .cap-label { width: 74px; color: var(--muted-2); flex: none; }
.dev-card .dc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

/* ---- history rows ---- */
.sess-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--glass);
  cursor: pointer;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  transition: background var(--t), border-color var(--t), transform var(--t);
  min-width: 0;
}
.sess-row:hover { background: var(--glass-2); border-color: var(--line-2); transform: translateX(2px); }
.sess-row .s-main { min-width: 0; flex: 1; }
/* History: one group per workspace (folder) and computer. */
.sess-group { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sess-group-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; padding: 0 4px; }
.sess-group-name { font-weight: 650; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess-group-device { font-size: 11.5px; color: var(--violet-200); white-space: nowrap; }
.sess-group-path { padding: 0 4px; margin-top: -4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 10.5px; }
.sess-row .s-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
.sess-row .s-meta { font-size: 11.5px; color: var(--muted-2); display: flex; gap: 8px; margin-top: 2px; flex-wrap: wrap; }

/* ---- control ---- */
#controlPane { padding: 20px; max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; height: 100%; }
.control-launcher { max-width: 520px; margin: auto; text-align: center; align-items: center; }
.control-launcher .lede { color: var(--muted); font-size: 13.5px; }
#screenWrap {
  position: relative;
  background: #000;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  overflow: hidden;
  flex: 1;
  min-height: 300px;
  display: grid;
  place-items: center;
  box-shadow: var(--lift);
}
#screenImg { max-width: 100%; max-height: 100%; display: block; cursor: crosshair; }
#screenWrap .hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; padding: 20px; text-align: center; }
.control-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kbd-bar { display: flex; gap: 8px; align-items: center; min-width: 0; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--bad); display: inline-block; margin-right: 6px; animation: pulse-live 1.4s var(--ease) infinite; }
@keyframes pulse-live { 50% { opacity: 0.3; } }

/* ---- toasts ---- */
#toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 9px; z-index: 100; }
.toast {
  background: rgba(22, 22, 26, 0.86);
  border: 1px solid var(--line-2);
  border-left: 2px solid var(--accent);
  padding: 11px 16px;
  border-radius: var(--r-sm);
  max-width: 340px;
  font-size: 13px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--lift);
  animation: slidein 0.26s var(--ease);
}
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--good); }
@keyframes slidein { from { transform: translateX(16px); opacity: 0; } }

.spinner { width: 14px; height: 14px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- responsive ---- */
@media (min-width: 1181px) {
  #chatWrap.options-open { grid-template-columns: 270px minmax(0, 1fr) 380px; }
  #chatWrap:not(.options-open) #chatOptions { display: none; }
  #chatWrap.options-open #chatOptions { animation: fadeUp 0.2s var(--ease) both; }
}
@media (max-width: 1180px) {
  #chatOptions {
    position: fixed;
    top: 58px;
    right: 0;
    bottom: 0;
    width: min(94vw, 420px);
    z-index: 26;
    transform: translateX(105%);
    transition: transform 0.26s var(--ease);
    box-shadow: -24px 0 70px rgba(0,0,0,.48);
  }
  #chatWrap.options-open #chatOptions { transform: translateX(0); }
  #chatWrap.options-open .chat-scrim { display: block; position: fixed; inset: 0; z-index: 24; background: rgba(0,0,0,.58); backdrop-filter: blur(3px); }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(86vw, 286px); padding-top: max(14px, env(safe-area-inset-top)); transform: translateX(-105%); transition: transform 0.26s var(--ease); box-shadow: 24px 0 70px rgba(0,0,0,.42); }
  #app.menu-open #sidebar { transform: translateX(0); }
  #app.menu-open #scrim { display: block; }
  #menuBtn { display: inline-flex; }
  #chatWrap { grid-template-columns: 1fr; }
  #threadList { position: fixed; left: 0; top: 0; bottom: 0; width: min(88vw, 330px); z-index: 26; transform: translateX(-105%); transition: transform 0.26s var(--ease); box-shadow: 24px 0 70px rgba(0,0,0,.48); padding-top: env(safe-area-inset-top); }
  #chatWrap.threads-open #threadList { transform: translateX(0); }
  #chatOptions { top: 0; padding-top: env(safe-area-inset-top); }
  #chatWrap.threads-open .chat-scrim, #chatWrap.options-open .chat-scrim { display: block; position: fixed; inset: 0; z-index: 24; background: rgba(0,0,0,.58); backdrop-filter: blur(3px); }
  button.composer-tool { display: inline-flex; }
  .pane { padding: 20px 16px 32px; }
  #messages { padding: 22px 18px 10px; }
  #composer { padding: 8px 18px 22px; }
  #topbar { padding-inline: 16px; }
}
@media (max-width: 600px) {
  body { font-size: 13.5px; }
  #topbar { min-height: 54px; padding: max(9px, env(safe-area-inset-top)) 12px 9px; }
  #topbar h1 { font-size: 15px; }
  #topSummary { display: none; }
  #connState { max-width: 112px; overflow: hidden; text-overflow: ellipsis; }
  .pane { padding: 16px 12px 28px; gap: 16px; }
  .card { padding: 16px; border-radius: 13px; }
  .page-stack { gap: 16px; }
  .pane .row { min-width: 0; }
  .pane .row.wrap { align-items: stretch; }
  .pane .row.wrap > select { flex: 1 1 130px; width: 100% !important; }
  .pane .row.wrap > .grow { flex-basis: 100%; }
  .cap { align-items: flex-start; flex-wrap: wrap; gap: 6px 8px; }
  .cap .cap-label { width: 72px; }
  .cap > .grow { display: none; }
  .kv { grid-template-columns: 76px minmax(0, 1fr); gap: 7px 10px; }
  .dev-card { padding: 15px; }
  .dev-card .dc-head { align-items: flex-start; flex-wrap: wrap; }
  .dev-card .dc-head > .pill { margin-left: 26px; }
  .sess-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; padding: 11px 12px; }
  .sess-row .s-meta { gap: 4px 6px; }
  #sessionDetail .card > .row { align-items: flex-start; flex-wrap: wrap; }
  #sessionDetail .card > .row > .grow { flex-basis: calc(100% - 80px); }
  .route-row { grid-template-columns: auto minmax(0, 1fr); }
  .route-row > button { grid-column: 2; justify-self: end; }
  .route-note { grid-column: 2; }
  .command-row { flex-wrap: wrap; }
  .command-row > .grow { flex-basis: calc(100% - 58px); }
  #messages { padding: 18px 12px 8px; gap: 16px; }
  .msg .bubble { padding: 12px 13px; }
  .msg-actions { opacity: 1; }
  #composer { padding: 7px 10px calc(16px + env(safe-area-inset-bottom)); }
  #composer .composer-card { padding: 10px 8px 8px 12px; border-radius: 20px; }
  .composer-note { padding: 0 5px; }
  .composer-note > span:first-child { display: none; }
  #composerRoute { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: auto; }
  .chat-hero { padding: 22px 4px; }
  #controlPane { padding: 14px 10px 24px; }
  .control-launcher { width: 100%; }
  .control-launcher .row { flex-direction: column; width: 100%; }
  .control-launcher select, .control-launcher button { width: 100% !important; }
  #screenWrap { min-height: 220px; }
  .control-bar { gap: 6px; }
  .control-bar > .grow { display: none; }
  .kbd-bar { flex-wrap: wrap; }
  .kbd-bar input { flex: 1 1 180px; max-width: none !important; }
  .card .row > input[type="password"] { min-width: 0; }
  .settings-field { grid-template-columns: 1fr; gap: 5px; }
  #toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
@media (display-mode: standalone) {
  #topbar { padding-top: max(13px, env(safe-area-inset-top)); }
  #composer { padding-bottom: max(22px, calc(14px + env(safe-area-inset-bottom))); }
}

/* ---- brain settings, inside the chat options panel ---- */
.brain-settings { display: flex; flex-direction: column; gap: 8px; margin: 0 12px 14px; }
.set-section { border: 1px solid var(--line-2); border-radius: 12px; background: rgba(255,255,255,.022); overflow: hidden; }
.set-row { display: flex; align-items: center; gap: 6px; padding-right: 8px; }
.set-head { flex: 1; display: flex; align-items: center; gap: 7px; padding: 9px 10px; background: none; border: 0; color: var(--text); font-size: 11px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; text-align: left; cursor: pointer; }
.set-head:hover { color: var(--violet-200); }
.set-caret { font-size: 9px; color: var(--muted-2); }
.set-body { display: flex; flex-direction: column; gap: 7px; padding: 2px 10px 11px; font-size: 11.5px; }
/* Same box as the rail fields above: a fixed height with the global 9px padding left no
   room for the text, which rendered cut in half. */
.set-body input:not([type='checkbox']), .set-body select { width: 100%; height: 34px; padding: 5px 9px; font-size: 12px; }
.set-body select { padding-right: 27px; text-overflow: ellipsis; }
.set-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.set-line.wrap { padding: 7px 0; border-top: 1px solid var(--line); }
.set-line:first-child.wrap { border-top: 0; }
.set-line b { font-weight: 650; }
.set-line .full { flex: 0 0 100%; line-height: 1.4; word-break: break-word; }
.set-line input[type='number'] { max-width: 76px; }
.set-check { display: flex; align-items: center; gap: 5px; }
.set-check input { width: auto; height: auto; }
.set-form { display: flex; flex-direction: column; gap: 7px; padding: 10px; margin-top: 6px; border: 1px solid var(--line-2); border-radius: 11px; background: rgba(255,255,255,.03); }
.brain-settings .danger { color: var(--bad); }

/* ---- Crux: which model answers at each tier ---- */
.tier-list { display: flex; flex-direction: column; }
.tier-block { display: flex; flex-direction: column; gap: 5px; padding: 8px 0 9px; border-top: 1px solid var(--line); }
.tier-list .tier-block:first-child { border-top: 0; padding-top: 2px; }
.tier-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
.tier-head .pill { max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; }
.tier-row { display: grid; grid-template-columns: 14px minmax(0, 1fr); align-items: center; gap: 5px; }
.tier-row.many { grid-template-columns: 14px minmax(0, 1fr) 28px 28px; }
.tier-rank { font-size: 11px; color: var(--muted-2); text-align: center; font-variant-numeric: tabular-nums; }
.brain-settings button.tier-btn { width: 28px; height: 28px; padding: 0; display: grid; place-items: center; font-size: 14px; line-height: 1; border-radius: var(--r-xs); }
/* The first model cannot move up; keep its slot so the pickers line up. */
.brain-settings button.tier-btn:disabled { visibility: hidden; }
.tier-add { align-self: flex-start; }
.tier-hand { display: flex; flex-direction: column; gap: 6px; }

/* ---- Crux: API keys and what they have left ---- */
.prov-card { display: flex; flex-direction: column; gap: 6px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.02); }
.prov-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.meter { display: flex; flex-direction: column; gap: 3px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-dim); }
.meter-val { font-variant-numeric: tabular-nums; color: var(--text); }
.meter-bar { height: 6px; border-radius: 99px; background: rgba(255,255,255,.07); overflow: hidden; }
.meter-bar > i { display: block; height: 100%; border-radius: inherit; background: var(--good); transition: width var(--t); }
.meter-bar.warn > i { background: var(--warn); }
.meter-bar.bad > i { background: var(--bad); }
.meter-note { font-size: 10.5px; }
.rate-head { margin-top: 2px; }

/* ---- motion: the Crux mark, typing dots, shimmer rows (web/lib/motion.js) ---- */
.crux-mark { position: relative; flex: none; }
.crux-mark svg { display: block; width: 100%; height: 100%; overflow: visible; }
/* SVG transforms default to the drawing's origin; turn about the mark's centre instead. */
.crux-mark .cm-spin, .crux-mark .cm-halo { transform-box: view-box; transform-origin: 50% 50%; }
.crux-mark .cm-spin { animation: cm-spin 40s linear infinite; }
.crux-mark .cm-halo { animation: cm-breathe 6s var(--ease) infinite; }
.crux-mark .cm-lines { opacity: 0.6; }
.crux-mark .cm-glow { animation: cm-twinkle 3.6s ease-in-out infinite; }
.crux-mark .s2 .cm-glow { animation-delay: -0.9s; }
.crux-mark .s3 .cm-glow { animation-delay: -1.8s; }
.crux-mark .s4 .cm-glow { animation-delay: -2.7s; }
.crux-mark .s5 .cm-glow { animation-delay: -1.3s; }
/* The loader is the same mark in a hurry: a turn in seconds, stars flickering faster. */
.crux-mark.busy .cm-spin { animation-duration: 2.4s; animation-timing-function: cubic-bezier(0.55, 0.1, 0.45, 0.9); }
.crux-mark.busy .cm-glow { animation-duration: 1.4s; }
@keyframes cm-spin { to { transform: rotate(360deg); } }
@keyframes cm-breathe { 0%, 100% { opacity: 0.7; transform: scale(0.94); } 50% { opacity: 1; transform: scale(1.04); } }
@keyframes cm-twinkle { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.msg .who .crux-mark { margin: -3px 0; }

.loading-state { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 20px; animation: fadeUp 0.3s var(--ease) both; }

.typing { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-grad); opacity: 0.35; animation: typing 1.25s var(--ease) infinite; }
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.35; } 30% { transform: translateY(-5px); opacity: 1; } }

.skel-row { display: flex; flex-direction: column; gap: 8px; padding: 13px 14px; }
.skel { display: block; height: 10px; border-radius: 6px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.045) 0%, rgba(157, 139, 251, 0.16) 50%, rgba(255, 255, 255, 0.045) 100%); background-size: 200% 100%; animation: shimmer 1.5s linear infinite; }
.skel.thin { width: 38%; height: 8px; opacity: 0.7; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  .crux-mark *, .typing i, .skel { animation: none !important; }
  .typing i { opacity: 0.7; }
}

/* The chat's one row is the page's height, so a long conversation (or a setup interview)
   scrolls inside #messages instead of pushing the header and composer off the page. */
#chatWrap { grid-template-rows: minmax(0, 1fr); }
#chatMain { min-height: 0; }

/* ---- Crux as a personal assistant: default model, context, setups (ADR 0014) ---- */
.chat-main-head .agents-btn { display: inline-flex; align-items: center; gap: 7px; border-radius: 99px; padding: 4px 12px 4px 7px; background: var(--accent-wash); border-color: var(--accent-line); color: var(--violet-200); }
.chat-main-head .agents-btn .crux-mark { margin: -2px 0; }

.hero-extras { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 4px; }
.hero-context { font-size: 12.5px; }
.setup-chips { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 7px; max-width: 560px; }
.setup-chips > .muted { flex-basis: 100%; text-align: center; }
.setup-chip.done { border-color: rgba(143, 207, 169, 0.3); }

.setup-flow { display: flex; flex-direction: column; gap: 16px; width: 100%; }
/* The interview is redrawn each step: only the newest answer and question move. */
.setup-flow > .setup-msg { animation: none; }
.setup-flow > .setup-msg:nth-last-child(-n+3) { animation: fadeUp 0.28s var(--ease) both; }
.setup-msg .bubble { display: flex; flex-direction: column; gap: 9px; white-space: normal; }
.setup-q { font-weight: 550; }
.setup-control { display: flex; flex-direction: column; gap: 9px; }
.setup-control input, .setup-control textarea { max-width: 460px; }
.setup-options { display: flex; flex-wrap: wrap; gap: 6px; }
.setup-options .chip { white-space: normal; text-align: left; }
.setup-nav { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.setup-help { max-width: 520px; }
.setup-known { color: var(--good); }
.setup-summary, .setup-saved { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }
.setup-exit { display: flex; justify-content: center; }

.memory-chip { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 9px; padding: 4px 11px; border-radius: 99px; border: 1px solid var(--accent-line); background: var(--accent-soft); color: var(--violet-200); font-size: 11.5px; }
.memory-chip .link { font-size: 11.5px; }
/* A session Crux started for a task: one line, with a way into that conversation. */
.session-card { display: flex; align-items: center; gap: 9px; margin-top: 9px; padding: 7px 12px; border-radius: 12px; border: 1px solid var(--line-2); background: rgba(255,255,255,.03); font-size: 12.5px; max-width: 100%; }
.session-card .grow { min-width: 0; overflow-wrap: anywhere; }
.session-card .session-icon { color: var(--violet-200); }
.crux-model-form { display: grid; gap: 8px; margin: 6px 0 12px; }
.crux-model-form .rail-actions { justify-content: flex-start; }

.context-dialog { width: min(820px, calc(100vw - 32px)); }
.ctx-toolbar { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-bottom: 8px; }
.ctx-toolbar input[type="search"] { flex: 1 1 220px; width: auto; }
.ctx-download { font-size: 12.5px; }
.ctx-meta { margin: 0 0 12px; }
.ctx-list { display: flex; flex-direction: column; gap: 14px; }
.ctx-section { border: 1px solid var(--line-2); border-radius: 14px; padding: 12px 14px; background: rgba(255,255,255,.02); }
.ctx-section-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.ctx-section-head h4 { margin: 0; font-size: 13.5px; }
.ctx-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.ctx-section .ctx-row:nth-child(2) { border-top: 0; }
.ctx-row.pinned .ctx-key::after { content: " \2605"; color: var(--warn); }
.ctx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ctx-key { font-weight: 650; font-size: 12px; color: var(--violet-200); }
.ctx-value { white-space: pre-wrap; overflow-wrap: anywhere; }
.ctx-actions { display: flex; gap: 2px; flex: none; }
.ctx-edit { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.ctx-edit .row > * { flex: 1; min-width: 0; }
.ctx-file { max-height: 60vh; overflow: auto; margin: 0; padding: 13px; border-radius: 10px; background: rgba(0,0,0,.3); color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; font: 11.5px/1.55 var(--mono); }
.ctx-add { margin-bottom: 4px; }

/* ---- Agents ---- */
.agents-pane { max-width: 920px; }
.agents-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.agents-title { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 220px; }
.agents-title h2 { font-size: 20px; }
.agents-list { display: flex; flex-direction: column; gap: 14px; }
.agent-card { gap: 10px; scroll-margin-top: 18px; }
.agent-card.status-draft { border-color: rgba(217, 189, 133, 0.35); }
.agent-head { display: flex; align-items: flex-start; gap: 10px; }
.agent-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.agent-task { color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.agent-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-create textarea { min-height: 92px; }
.agent-examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.agent-examples .chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; }
.agent-form-grid select, .agent-form-grid input { height: 36px; padding: 5px 27px 5px 10px; font-size: 12.5px; text-transform: none; letter-spacing: 0; }
.agent-form-grid input[type="time"], .agent-form-grid input[type="date"] { padding-right: 10px; }
.sched-fields { display: flex; flex-direction: column; gap: 6px; }
.sched-days { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--text-dim); font-weight: 500; }
.agent-questions { display: flex; flex-direction: column; gap: 12px; padding: 14px; border: 1px solid var(--accent-line); border-radius: 14px; background: var(--accent-wash); }
.agent-q-head { display: flex; align-items: center; gap: 10px; }
.agent-q-head > div { display: flex; flex-direction: column; }
.agent-q { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.agent-q legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.agent-opt { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text-dim); }
.agent-opt input { margin-top: 3px; flex: none; }
.agent-runs { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.run-row { display: flex; flex-direction: column; gap: 6px; }
.run-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; color: var(--text-dim); max-height: 240px; overflow: auto; padding: 9px 11px; border-radius: 10px; background: rgba(0,0,0,.22); border: 1px solid var(--line); }
.waiting-card { border-color: rgba(217, 189, 133, 0.35); }
.draft-row { display: flex; flex-direction: column; gap: 9px; padding: 10px 0; border-top: 1px solid var(--line); }
.waiting-card .draft-row:nth-child(2) { border-top: 0; }
.draft-editor { display: flex; flex-direction: column; gap: 8px; }
.draft-editor textarea { min-height: 150px; }

/* ---- notifications ---- */
.bell-btn { position: relative; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; }
.bell-count { position: absolute; top: 2px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; background: var(--accent-grad); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center; box-shadow: 0 0 0 2px #0c0c10; }
.notify-panel { position: fixed; top: 60px; right: 16px; width: min(380px, calc(100vw - 24px)); max-height: min(70vh, 560px); overflow-y: auto; z-index: 150; padding: 12px; border-radius: 16px; border: 1px solid var(--line-2); background: rgba(22, 22, 27, 0.97); box-shadow: var(--lift); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); animation: fadeUp 0.2s var(--ease) both; }
.notify-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 4px 10px; }
.notify-list { display: flex; flex-direction: column; gap: 2px; }
.notify-item { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 9px; align-items: start; width: 100%; text-align: left; padding: 9px 8px; border: 0; border-radius: 10px; background: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; color: var(--text-dim); }
.notify-item:hover:not(:disabled) { background: var(--glass-2); transform: none; box-shadow: none; }
.notify-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; }
.notify-item.unread .notify-dot { background: var(--accent); }
.notify-item.unread.attention .notify-dot { background: var(--warn); }
.notify-item.unread.error .notify-dot { background: var(--bad); }
.notify-item.unread.good .notify-dot { background: var(--good); }
.notify-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notify-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.notify-item:not(.unread) .notify-title { font-weight: 500; color: var(--text-dim); }
.notify-body { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.notify-time { font-size: 11px; color: var(--muted-2); white-space: nowrap; }

@media (max-width: 760px) {
  .agent-form-grid { grid-template-columns: 1fr; }
  .chat-main-head { padding: 10px 14px; flex-wrap: wrap; }
  .chat-main-head > div { flex-wrap: wrap; }
  .ctx-row { flex-wrap: wrap; }
  .ctx-actions { width: 100%; justify-content: flex-end; }
}
@media (max-width: 600px) {
  .notify-panel { top: calc(56px + env(safe-area-inset-top)); right: 12px; left: 12px; width: auto; }
  .agents-title h2 { font-size: 18px; }
  /* The top bar already names the page; the buttons get the row. */
  .chat-main-head > span:first-child { display: none; }
}

/* The toolbar answers to the conversation column's width, not the window's: Crux info and the
   history rail can leave it narrow on a wide screen. Labels give way first, then the model. */
#composer { container-type: inline-size; container-name: composer; }
@container composer (max-width: 640px) {
  .composer-bar { flex-wrap: wrap; }
  .crux-info-btn .chip-text { display: none; }
  button.crux-info-btn { width: 32px; padding: 0; justify-content: center; }
  .tool-chip.model-pick { flex: 0 1 auto; }
}
@container composer (max-width: 460px) {
  .folder-btn .folder-label, .folder-btn .ic:last-child { display: none; }
  button.folder-btn { width: 32px; padding: 0; justify-content: center; }
  .composer-bar .grow { display: none; }
  .composer-note > span:first-child { display: none; }
  #composerRoute { margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
