/* ===========================================================
   indie.chat — design system
   Swiss/editorial · terracotta accent · mono labels
   =========================================================== */

:root {
  /* canvas + surface */
  --canvas:      #e7e7e8;
  --surface:     #ffffff;
  --surface-2:   #f3f3f4;
  --surface-3:   #eaeaec;

  /* ink */
  --ink:         #18181a;
  --ink-2:       #4d4d51;
  --ink-3:       #88888d;
  --ink-4:       #b0b0b6;

  /* lines */
  --line:        #dbdbde;
  --line-2:      #c8c8cd;
  --line-strong: #18181a;

  /* brand */
  --terra:       #c2562d;
  --terra-ink:   #a8441f;
  --terra-wash:  #efe2db;
  --terra-line:  #ddc0b1;

  --green:       #4f7a5b;
  --green-wash:  #e4eae5;
  --green-line:  #c2d0c4;

  --maroon:      #8c3526;
  --gold:        #7c7c82;

  /* type */
  --sans: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* metrics */
  --rad:   3px;
  --rad-lg: 4px;
  --col:   42rem;   /* message column width */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#root { height: 100%; }

button { font-family: inherit; cursor: pointer; }
::selection { background: var(--terra-wash); }

/* mono label utility */
.mono {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ====================== app shell ====================== */
.app {
  display: grid;
  grid-template-columns: var(--side-w, 264px) 1fr;
  height: 100%;
  overflow: hidden;
}

.scrim { display: none; }

/* ====================== sidebar ====================== */
.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;        /* anchors the drag handle on its right edge */
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
}
.logo {
  width: 30px; height: 30px;
  background: var(--logo-img, url(/icons/logo.png)) center / contain no-repeat;
  flex: none;
}
.brand-name {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.brand-name b, .bd { color: var(--terra); font-weight: 800; }
.brand-tag {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin-top: 1px;
}

.new-chat {
  margin: 2px 14px 14px;
  padding: 11px 14px;
  background: var(--terra);
  color: #fff;
  border: none;
  border-radius: var(--rad);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background .14s ease;
}
.new-chat:hover { background: var(--terra-ink); }
.new-chat .plus { font-size: 14px; line-height: 1; display: inline-flex; }
.new-chat .plus svg { width: 15px; height: 15px; }

.conv-head {
  padding: 4px 18px 8px;
  border-top: 1px solid var(--line);
  margin-top: 2px;
}
.conv-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 8px 12px;
}
.conv-list::-webkit-scrollbar { width: 8px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }

.conv {
  position: relative;
  padding: 9px 11px 9px 12px;
  border-radius: var(--rad);
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.conv:hover { background: var(--surface-3); }
.conv.active {
  background: var(--surface);
  border-color: var(--line);
}
.conv.active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 2px;
  background: var(--terra);
}
.conv-title {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 18px;
}
.conv-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-4);
  text-transform: uppercase;
}
.conv-del {
  position: absolute;
  top: 7px; right: 6px;
  width: 22px; height: 22px;
  border: none; background: transparent;
  color: var(--ink-4);
  border-radius: var(--rad);
  display: none;
  align-items: center; justify-content: center;
  font-size: 14px;
}
.conv:hover .conv-del { display: flex; }
.conv-del:hover { background: var(--terra-wash); color: var(--maroon); }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  flex: none;
}
.dot.off { background: var(--maroon); }
.foot-txt { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; color: var(--ink-3); text-transform: uppercase; }
.foot-txt b { color: var(--ink); font-weight: 600; }
/* footer links — one consistent full-width row each (stacked) */
.admin-link, .install-link, .foot-link {
  width: 100%; box-sizing: border-box; margin: 0;
  display: inline-flex; align-items: center; gap: 7px; justify-content: flex-start;
  white-space: nowrap;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--rad); padding: 7px 10px;
  background: transparent; color: var(--ink-3);
}
.admin-link:hover, .foot-link:hover { color: var(--ink); border-color: var(--line-2); background: var(--surface); }
.admin-link svg, .install-link svg, .foot-link svg { width: 13px; height: 13px; flex: none; }
/* the install CTA keeps the terracotta accent */
.install-link { color: var(--terra-ink); border-color: var(--terra-line); background: var(--terra-wash); }
.install-link:hover { border-color: var(--terra); }

/* ====================== main ====================== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.topbar {
  height: 56px;
  flex: none;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--canvas) 86%, #fff);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
}
/* The kind label ("AGENT", "APP", "CHAT") is fixed width and the NAME is what
   truncates. Ellipsising the whole block instead left "A…" in a narrow pane —
   the label eating the space it was meant to caption. */
.topbar-title {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  min-width: 0;
}
.topbar-title .tt-kind {
  flex: none;
  color: var(--ink-4); font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.topbar-title .tt-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* model selector */
.model-sel { position: relative; }
.model-btn {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 7px 11px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink);
  text-transform: uppercase;
  white-space: nowrap;        /* never wrap the label onto multiple lines */
  min-width: 0;
}
.model-btn .sel-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 170px;
}
.model-btn:hover { border-color: var(--line-2); }
.model-btn .sq { width: 8px; height: 8px; background: var(--terra); flex: none; }
.model-btn .chev { color: var(--ink-4); font-size: 9px; margin-left: 2px; }
.model-menu {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  box-shadow: 0 12px 30px -12px rgba(0,0,0,.28);
  min-width: 248px;
  padding: 5px;
  z-index: 40;
}
.model-opt {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none; background: transparent;
  border-radius: var(--rad);
  text-align: left;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.03em;
  color: var(--ink);
}
.model-opt:hover { background: var(--surface-3); }
.model-opt .sq { width: 8px; height: 8px; background: var(--ink-4); flex: none; }
.model-opt.sel .sq { background: var(--terra); }
.model-opt .desc { display:block; font-family: var(--sans); font-size: 11px; letter-spacing: 0; color: var(--ink-3); text-transform: none; margin-top: 2px; }
.model-opt .label { flex: 1; }
.model-opt .check { color: var(--terra); font-size: 12px; }

/* caption row inside dropdown menus */
.menu-cap {
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-4); padding: 4px 10px 6px;
}

/* provider selector — live status dot (green = the chosen provider is the
   one that actually served the last response) */
.prov-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-4); flex: none; }
.prov-dot.on { background: var(--green); }
.prov-sel .model-btn .chev { margin-left: 2px; }

/* ====================== scroll / messages ====================== */
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.scroll::-webkit-scrollbar { width: 10px; }
.scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; }

.thread {
  max-width: var(--col);
  margin: 0 auto;
  padding: 30px 24px 24px;
}

.msg { padding: 14px 0 22px; }
.msg + .msg { border-top: 1px solid var(--line); }
.msg-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 9px;
}
.msg-sq { width: 9px; height: 9px; flex: none; }
.msg.user  .msg-sq { background: var(--ink); }
.msg.bot   .msg-sq { background: var(--terra); }
.msg-role {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-2);
}
.msg.bot .msg-role { color: var(--terra-ink); }
.msg-provider {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-4);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  white-space: nowrap;
}
.msg-time { font-family: var(--mono); font-size: 10px; color: var(--ink-4); letter-spacing: 0.05em; margin-left: auto; }

.msg-body {
  font-size: 15px;
  line-height: 1.62;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.msg.user .msg-body { white-space: pre-wrap; }

.msg-actions {
  display: flex; gap: 4px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity .14s;
}
.msg:hover .msg-actions { opacity: 1; }
.act-btn {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 4px 9px;
}
.act-btn:hover { border-color: var(--line-2); color: var(--ink); background: var(--surface); }
.act-btn:disabled { opacity: 0.45; cursor: default; }
.act-btn.primary { background: var(--terra); color: #fff; border-color: var(--terra); }
.act-btn.primary:hover { background: var(--terra-ink); border-color: var(--terra-ink); color: #fff; }

/* inline edit of a user message */
.msg-edit { display: flex; flex-direction: column; gap: 8px; }
.msg-edit textarea {
  width: 100%; resize: vertical; min-height: 60px;
  font-family: var(--sans); font-size: 15px; line-height: 1.55; color: var(--ink);
  background: var(--surface); border: 1px solid var(--terra-line); border-radius: var(--rad);
  padding: 10px 12px; outline: none;
}
.msg-edit .edit-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* cursor blink */
.caret {
  display: inline-block;
  width: 7px; height: 1.05em;
  background: var(--terra);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 0%,50%{opacity:1} 50.01%,100%{opacity:0} }

/* ====================== markdown ====================== */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1,.md h2,.md h3,.md h4 { font-weight: 700; line-height: 1.25; margin: 22px 0 10px; letter-spacing: -0.01em; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; } .md h4 { font-size: 14px; }
.md ul,.md ol { margin: 0 0 14px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--ink-4); }
.md a { color: var(--terra-ink); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.md strong { font-weight: 700; }
.md blockquote {
  margin: 0 0 14px; padding: 2px 0 2px 16px;
  border-left: 2px solid var(--terra-line);
  color: var(--ink-2);
}
.md hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.md code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
}
.md pre {
  background: #1b1b18;
  border: 1px solid #2c2c27;
  border-radius: var(--rad-lg);
  margin: 0 0 16px;
  overflow: hidden;
}
.md pre .code-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px solid #2c2c27;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: #8d8b83;
}
.md pre .code-copy {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  color: #b4b2a9; background: transparent; border: none; padding: 2px 4px;
}
.md pre .code-copy:hover { color: #fff; }
.md pre code {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: #ecebe6;
  background: transparent;
  border: none;
  padding: 13px 14px;
  overflow-x: auto;
}
.md table { border-collapse: collapse; width: 100%; margin: 0 0 16px; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.md th { background: var(--surface-3); font-weight: 600; }

/* ---- math (KaTeX) ---- */
.md .katex { font-size: 1.04em; }
.md .katex-display { margin: 12px 0; padding: 2px 0; overflow-x: auto; overflow-y: hidden; }

/* ====================== reasoning panel ====================== */
.reason {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--rad-lg);
  background: var(--surface-2);
  overflow: hidden;
}
.reason-toggle {
  display: flex; align-items: center; gap: 7px;
  width: 100%;
  padding: 8px 12px;
  background: transparent; border: none; cursor: pointer;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-4); text-align: left;
}
.reason-toggle:hover { color: var(--terra-ink); }
.reason-caret { font-size: 9px; width: 10px; }
.reason-body {
  padding: 2px 14px 12px;
  border-top: 1px solid var(--line);
  font-size: 13px; line-height: 1.6;
  color: var(--ink-3);
  white-space: pre-wrap; word-wrap: break-word;
  max-height: 360px; overflow-y: auto;
}

/* ====================== generated-file card ====================== */
.msg-files { margin-top: 10px; }
.msg-files .file-art { margin: 0 0 6px; }
.file-art {
  display: flex; align-items: center; gap: 12px;
  margin: 10px 0 4px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--rad-lg);
  background: var(--surface-2);
}
.file-art.pending { opacity: 0.7; }
.file-art .fa-ic {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 8px;
  background: var(--terra-wash, rgba(194,86,45,0.1));
  color: var(--terra-ink);
}
.file-art .fa-ic svg { width: 18px; height: 18px; }
.file-art .fa-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 auto; }
.file-art .fa-name { font-weight: 600; font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-art .fa-kind {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-4);
}
.file-art .fa-err { color: var(--maroon, #8c3526); text-transform: none; letter-spacing: 0; }
.file-art .fa-btn {
  flex: 0 0 auto;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.05em;
  padding: 7px 13px; border-radius: var(--rad);
  background: var(--terra); color: #fff; border: none; cursor: pointer;
}
.file-art .fa-btn:hover { filter: brightness(1.05); }
.file-art .fa-btn:disabled { opacity: 0.6; cursor: default; }

/* ====================== empty state ====================== */
.empty {
  max-width: var(--col);
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 24px 80px;
}
.empty-mark {
  width: 54px; height: 54px;
  /* --logo-img, like .logo above: a branded deployment sets ONE logo and the
     empty state honours it too, instead of showing indie.chat's mark. */
  background: var(--logo-img, url(/icons/logo.png)) center / contain no-repeat;
  margin-bottom: 22px;
}
.empty h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.025em; margin: 0 0 8px; }
.empty h1 b { color: var(--terra); }
.empty .sub { font-size: 15px; color: var(--ink-2); line-height: 1.55; margin: 0 0 28px; max-width: 30rem; }
.eyebrow {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-4); margin-bottom: 14px;
}
.prompts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.prompt {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 14px 15px;
  transition: border-color .14s, transform .14s;
}
.prompt:hover { border-color: var(--terra-line); transform: translateY(-1px); }
.prompt .p-k { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--terra); display: block; margin-bottom: 6px; }
.prompt .p-t { font-size: 13.5px; color: var(--ink); line-height: 1.4; }

/* ====================== composer ====================== */
.composer-wrap {
  flex: none;
  padding: 0 24px 20px;
  background: linear-gradient(to top, var(--canvas) 62%, transparent);
}
.composer {
  max-width: var(--col);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--rad-lg);
  box-shadow: 0 8px 26px -16px rgba(0,0,0,.3);
  transition: border-color .14s;
}
.composer.focus { border-color: var(--terra-line); }
.composer.drag { border-color: var(--terra); box-shadow: 0 0 0 3px var(--terra-wash); }

/* attachment chips */
.attach-row {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 11px 12px 2px;
}
.chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 5px 7px 5px 8px;
  max-width: 220px;
}
.chip .chip-ic { width: 8px; height: 8px; background: var(--ink-3); flex: none; }
.chip.bin .chip-ic { background: var(--gold); }
.chip .chip-thumb { width: 20px; height: 20px; object-fit: cover; border-radius: 3px; flex: none; }

/* image attachments shown in a message (vision) */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.msg-img { max-width: 220px; max-height: 220px; border-radius: var(--rad); border: 1px solid var(--line); }
.chip.loading .chip-ic { background: var(--terra); animation: chip-pulse 1s ease-in-out infinite; }
.chip.loading .chip-sz { color: var(--terra-ink); }
@keyframes chip-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.chip .chip-name { font-family: var(--mono); font-size: 10.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .chip-sz { font-family: var(--mono); font-size: 9.5px; color: var(--ink-4); flex: none; }
.chip .chip-x { border: none; background: transparent; color: var(--ink-4); font-size: 12px; line-height: 1; padding: 0 1px; flex: none; }
.chip .chip-x:hover { color: var(--maroon); }

/* attach + tool buttons in composer */
.attach-btn {
  flex: none;
  width: 34px; height: 40px;
  display: grid; place-items: center;
  background: transparent; border: none;
  color: var(--ink-3); border-radius: var(--rad);
  margin-left: -4px;
}
.attach-btn:hover { color: var(--ink); background: var(--surface-2); }
.attach-btn svg { width: 18px; height: 18px; }

.mic-btn {
  flex: none;
  width: 34px; height: 40px;
  display: grid; place-items: center;
  background: transparent; border: none;
  color: var(--ink-3); border-radius: var(--rad);
}
.mic-btn:hover { color: var(--ink); background: var(--surface-2); }
.mic-btn svg { width: 18px; height: 18px; }
.mic-btn.rec  { color: #fff; background: var(--maroon); animation: mic-pulse 1.1s ease-in-out infinite; }
.mic-btn.busy { color: var(--terra-ink); }
.mic-btn:disabled { cursor: default; }
@keyframes mic-pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(140,53,38,0.45) } 50%{ box-shadow: 0 0 0 5px rgba(140,53,38,0) } }

.voice-status {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3);
}
.voice-status.rec { color: var(--maroon); }
.voice-status.err { color: var(--maroon); text-transform: none; letter-spacing: 0; }
.voice-status .rec-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--maroon); flex: none; animation: chip-pulse 1s ease-in-out infinite; }
.voice-status .rec-dot.busy { background: var(--terra); }

.tool-toggle {
  display: flex; align-items: center; gap: 7px;
  flex: none; white-space: nowrap;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  padding: 5px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 100px;
  color: var(--ink-3);
}
.tool-toggle:hover { border-color: var(--line-2); color: var(--ink-2); }
.tool-toggle.on { border-color: var(--terra); background: var(--terra-wash); color: var(--terra-ink); }
.tool-toggle .tt-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-4); flex: none; }
.tool-toggle.on .tt-dot { background: var(--terra); }
.tool-toggle svg { width: 13px; height: 13px; flex: none; }
.tool-toggle .tt-sub { opacity: 0.6; letter-spacing: 0.04em; }

.composer-foot .foot-left { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; }

/* msg attachments display */
.msg-attach { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.search-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3); border: 1px solid var(--line); border-radius: 100px; padding: 3px 9px;
  margin-bottom: 9px;
}
.search-pill .tt-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--terra); }
/* prominent "what was redacted" note on a user message */
.redaction-note {
  display: flex; align-items: center; gap: 8px;
  background: var(--green-wash);
  border: 1px solid var(--green-line);
  border-left: 3px solid var(--green);
  border-radius: var(--rad);
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 12.5px; line-height: 1.4;
  color: var(--green);
}
.redaction-note .rn-ic { display: inline-flex; flex: none; }
.redaction-note .rn-ic svg { width: 15px; height: 15px; }
.redaction-note b { font-weight: 600; color: var(--ink); }
.stopped-note {
  margin-top: 10px; padding: 5px 10px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.04em;
  color: var(--ink-3); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--rad); display: inline-block;
}

/* Tool-call steps shown in an assistant message (agents + MCP chat).
   Collapsed = one line; click to expand the full arguments and result. */
.tool-steps { display: flex; flex-direction: column; gap: 6px; margin-bottom: 11px; }
.tool-step {
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--rad);
  overflow: hidden;
}
.tool-step.err { border-color: var(--terra-line); color: var(--maroon); }
.tool-step.open { background: var(--surface); border-color: var(--line-2); }
.tool-step .ts-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  font: inherit; color: inherit; text-align: left;
  background: none; border: 0; padding: 6px 10px; cursor: pointer;
}
.tool-step .ts-row:hover { background: var(--surface-3); }
.tool-step.open .ts-row { border-bottom: 1px solid var(--line); }
.tool-step .ts-ic { display: inline-flex; color: var(--terra); flex: none; }
.tool-step .ts-ic svg { width: 13px; height: 13px; }
.tool-step .ts-name { font-weight: 600; color: var(--ink); flex: none; }
.tool-step .ts-args { color: var(--ink-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30%; }
.tool-step .ts-res { color: var(--ink-3); margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.tool-step .ts-caret { flex: none; color: var(--ink-4); font-size: 9px; }
/* a result that ends in a link (an export, a report) gets a real chip */
.tool-step .ts-link {
  display: block; margin: 0 10px 8px; padding: 5px 9px;
  font-family: var(--mono); font-size: 11px; text-decoration: none;
  color: var(--terra-ink); background: var(--terra-wash);
  border: 1px solid var(--terra-line); border-radius: var(--rad);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-step .ts-link:hover { border-color: var(--terra); }
.tool-step.open .ts-res { display: none; }        /* the full result is right below */
.tool-step .ts-detail { padding: 9px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.tool-step .ts-lbl {
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-4);
  margin-top: 4px;
}
.tool-step .ts-lbl:first-child { margin-top: 0; }
.tool-step .ts-detail pre {
  margin: 0; padding: 8px 10px; max-height: 340px; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--rad);
  font-family: var(--mono); font-size: 11px; line-height: 1.55; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}
.tool-step.err .ts-detail pre { color: var(--maroon); }

/* the wiki maintainer can't be deleted — a quiet mark stands in for the ✕ */
.conv-locked { flex: none; font-size: 11px; color: var(--ink-4); padding: 0 4px; cursor: default; }

/* confirm-before-destroy */
.confirm-modal { max-width: 420px; }
.confirm-modal .modal-body p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
/* element+class, so it outranks the paragraph rule above */
.confirm-modal .modal-body p.warn-line { color: var(--maroon); }
.btn.danger { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.btn.danger:hover { background: #732c1f; border-color: #732c1f; }

/* which agent is docked to the open app (switch / disconnect) */
.app-agent-sel { position: relative; }
.app-agent-btn {
  display: inline-flex; align-items: center; gap: 6px; max-width: 190px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.04em;
  padding: 6px 9px; border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface); color: var(--ink-2);
}
.app-agent-btn:hover { border-color: var(--line-2); color: var(--ink); }
.app-agent-btn.none { color: var(--ink-4); border-style: dashed; }
.app-agent-btn svg { width: 13px; height: 13px; flex: none; }
.app-agent-btn .aa-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-agent-btn .aa-caret { flex: none; font-size: 9px; color: var(--ink-4); }
.app-agent-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  min-width: 244px; max-width: 300px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--rad);
  box-shadow: 0 10px 28px rgba(20,18,15,.14);
  padding: 5px; display: flex; flex-direction: column; gap: 2px;
}
.app-agent-menu .aam-head {
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-4); padding: 6px 8px 4px;
}
.app-agent-menu .aam-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.app-agent-menu button {
  display: flex; align-items: center; gap: 7px; width: 100%; text-align: left;
  font-size: 12.5px; padding: 7px 8px; border: 0; border-radius: var(--rad);
  background: none; color: var(--ink-2);
}
.app-agent-menu button:hover { background: var(--surface-2); color: var(--ink); }
.app-agent-menu button.on { background: var(--terra-wash); color: var(--terra-ink); font-weight: 600; }
.app-agent-menu button svg { width: 14px; height: 14px; flex: none; }
.app-agent-menu button .aa-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-agent-menu .aam-new { border-top: 1px solid var(--line); border-radius: 0; margin-top: 3px; padding-top: 9px; }
.app-agent-menu .aam-off { color: var(--maroon); font-family: var(--mono); font-size: 11px; }
.app-agent-menu .aam-off:hover { background: var(--terra-wash); color: var(--maroon); }

/* PWA install banner */
.pwa-banner {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  display: flex; align-items: center; gap: 11px;
  max-width: min(440px, calc(100vw - 24px));
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--rad-lg, 12px);
  box-shadow: 0 16px 40px -14px rgba(0,0,0,.42);
}
.pwa-banner .pwa-ic { width: 34px; height: 34px; border-radius: 8px; flex: none; }
.pwa-banner .pwa-txt { font-size: 13px; line-height: 1.4; color: var(--ink-2); flex: 1; min-width: 0; }
.pwa-banner .pwa-txt b { color: var(--ink); font-weight: 600; }
.pwa-banner .pwa-install {
  flex: none;
  background: var(--terra); color: #fff; border: none;
  border-radius: var(--rad); padding: 8px 14px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer;
}
.pwa-banner .pwa-install:hover { background: var(--terra-ink); }
.pwa-banner .pwa-x {
  flex: none; border: none; background: transparent; color: var(--ink-4);
  font-size: 14px; line-height: 1; padding: 2px 4px; cursor: pointer;
}
.pwa-banner .pwa-x:hover { color: var(--ink); }

.model-warn {
  display: block;
  font-size: 12px; line-height: 1.5;
  color: var(--maroon);
  background: var(--terra-wash);
  border: 1px solid var(--terra-line);
  border-radius: 7px;
  padding: 7px 11px;
  margin-bottom: 11px;
}
.model-warn b { font-weight: 600; }
.model-warn .warn-ic { margin-right: 6px; }

/* composer */
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 10px 10px 16px;
}
.composer textarea {
  flex: 1;
  border: none; outline: none; resize: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  max-height: 220px;
  padding: 6px 0;
}
.composer textarea::placeholder { color: var(--ink-4); }
.send {
  flex: none;
  width: 40px; height: 40px;
  background: var(--terra);
  border: none;
  border-radius: var(--rad);
  color: #fff;
  display: grid; place-items: center;
  transition: background .14s, opacity .14s;
}
.send:hover:not(:disabled) { background: var(--terra-ink); }
.send:disabled { background: var(--line-2); cursor: not-allowed; }
.send svg { width: 18px; height: 18px; }
.stop {
  flex: none;
  width: 40px; height: 40px;
  background: var(--ink);
  border: none; border-radius: var(--rad);
  display: grid; place-items: center;
}
.stop .sq { width: 12px; height: 12px; background: #fff; border-radius: 1px; }
.stop:hover { background: #000; }

.composer-foot {
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--line);
  padding: 8px 14px;
}
.composer-foot .hint {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.05em;
  color: var(--ink-4); text-transform: uppercase;
}
.composer-foot .hint b { color: var(--ink-3); }
.composer-foot .count { font-family: var(--mono); font-size: 10px; color: var(--ink-4); }

/* error banner */
.banner {
  max-width: var(--col);
  margin: 0 auto 10px;
  background: var(--terra-wash);
  border: 1px solid var(--terra-line);
  border-radius: var(--rad);
  padding: 9px 13px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.03em;
  color: var(--maroon);
  display: flex; align-items: center; gap: 8px;
}
.banner .x { margin-left: auto; cursor: pointer; border: none; background: transparent; color: var(--maroon); font-size: 14px; }

/* ====================== routines ====================== */
.routine-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.routine-grid .field { flex: 1 1 140px; min-width: 0; }
.routine-grid select, .routine-grid input { width: 100%; }
.routine-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.routine-row .hint { font-family: var(--mono); font-size: 11px; color: var(--ink-4); }
.routine-row code { font-family: var(--mono); background: var(--surface-3); padding: 1px 5px; border-radius: 3px; color: var(--ink-2); }
.push-row { display: flex; align-items: center; gap: 8px; }
.push-row .btn { display: inline-flex; align-items: center; gap: 7px; }
.push-row .btn svg, .push-on svg { width: 14px; height: 14px; }
.push-on { display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 11px; color: var(--green); letter-spacing: 0.03em; }
.routine-list { display: flex; flex-direction: column; gap: 8px; }
.routine-item {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--rad-lg);
  background: var(--surface-2); padding: 11px 13px;
}
.routine-item.off { opacity: 0.6; }
.routine-item .ri-main { flex: 1 1 auto; min-width: 0; }
.routine-item .ri-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.routine-item .ri-meta {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--ink-4); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
}
.routine-item .ri-meta.sub { text-transform: none; letter-spacing: 0; }
.routine-item .ri-dot { opacity: 0.5; }
.routine-item .ri-actions { display: flex; flex-direction: column; gap: 5px; flex: none; }
.routine-item .ri-actions .act-btn { white-space: nowrap; }
.act-btn.danger:hover { color: var(--maroon); border-color: var(--terra-line); }
/* the mode a routine runs in — the one thing that differs between them */
.routine-item .ri-title { display: flex; align-items: baseline; gap: 8px; }
.ri-mode {
  flex: none; font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  border-radius: 10px; padding: 2px 7px; border: 1px solid;
}
.ri-mode.chat  { color: var(--ink-3); background: var(--surface-3); border-color: var(--line-2); }
.ri-mode.agent { color: var(--green); background: var(--green-wash); border-color: var(--green-line); }
.routine-item .ri-prompt {
  margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--ink-3);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.routine-item .ri-confirm { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--maroon); align-self: center; }

/* filter tabs + the new-routine action above the list */
.routine-filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rf-tab {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface); color: var(--ink-3);
}
.rf-tab:hover { border-color: var(--line-2); color: var(--ink); }
.rf-tab.on { background: var(--terra-wash); border-color: var(--terra-line); color: var(--terra-ink); }
.rf-tab span { opacity: 0.6; margin-left: 4px; }

/* chat vs agent: the one choice that changes what everything else means */
.mode-seg { display: flex; gap: 8px; }
.mode-seg button {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 600; text-align: left;
}
.mode-seg button svg { width: 15px; height: 15px; }
.mode-seg button span { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.04em;
  font-weight: 400; color: var(--ink-4); text-transform: none; line-height: 1.35; }
.mode-seg button:hover:not(:disabled) { border-color: var(--line-2); }
.mode-seg button.on { border-color: var(--terra); background: var(--terra-wash); color: var(--terra-ink); }
.mode-seg button.on span { color: var(--terra-ink); opacity: 0.8; }
.mode-seg button:disabled { opacity: 0.5; cursor: default; }
.routines-modal { max-width: 620px; }

/* transient "reconnecting" hint — the run continues on the server */
.reconnect-banner {
  max-width: var(--col);
  margin: 0 auto 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 9px 13px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.03em;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 9px;
}

/* mobile */
.menu-btn { display: none; }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 60;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px -10px rgba(0,0,0,.4);
  }
  .app.nav-open .sidebar { transform: none; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 55; }
  .app.nav-open .scrim { display: block; }
  .menu-btn {
    display: grid; place-items: center;
    width: 36px; height: 36px; border: 1px solid var(--line); background: var(--surface);
    border-radius: var(--rad); margin-right: 12px;
  }
  .prompts { grid-template-columns: 1fr; }
  :root { --col: 100%; }
}

/* phones — keep the topbar and composer from getting cramped */
@media (max-width: 640px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title { display: none; }          /* sidebar already shows the chat */
  .menu-btn { flex: none; margin-right: 4px; }
  .tools { gap: 6px; min-width: 0; }         /* allow the tool row to shrink */
  .model-sel { min-width: 0; }
  .model-btn { padding: 7px 8px; gap: 6px; font-size: 10px; letter-spacing: 0.03em; min-width: 0; }
  .model-btn .sel-label { max-width: 88px; }
  .model-btn .chev { font-size: 8px; }
  .icon-btn { width: 34px; height: 34px; flex: none; }
  .icon-btn svg { width: 16px; height: 16px; }

  /* dropdown menus must never overflow the viewport */
  .model-menu { min-width: 0; width: max-content; max-width: calc(100vw - 24px); }

  /* the keyboard hint is desktop-only; reclaim the row on phones */
  .composer-foot .hint { display: none; }
  .composer-wrap { padding-left: 12px; padding-right: 12px; }
  .thread { padding-left: 16px; padding-right: 16px; }

  /* let the tool toggles wrap onto a second line instead of overflowing */
  .composer-foot { flex-wrap: wrap; row-gap: 8px; padding: 8px 12px; }
  .composer-foot .foot-left { gap: 6px; }
  .tool-toggle { padding: 6px 9px; }
}

/* very narrow phones (≤380px) — truncate the labels harder so the
   provider+model pickers never collide with the menu/gear buttons */
@media (max-width: 380px) {
  .topbar { padding: 0 8px; gap: 6px; }
  .tools { gap: 4px; }
  .model-btn { padding: 6px 7px; gap: 5px; }
  .model-btn .sel-label { max-width: 56px; }
}

/* ====================== topbar tools + modal ====================== */
.tools { display: flex; align-items: center; gap: 9px; }
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--line-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }

.modal-scrim {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(20,18,15,.34);
  display: grid; place-items: center;
  padding: 20px;
}
.modal {
  width: 100%; max-width: 460px;
  /* never taller than the viewport — head stays put, body scrolls (mobile fix).
     vh first, then dvh for browsers that support the dynamic viewport unit. */
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--rad-lg);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.45);
  overflow: hidden;
}
.modal-head, .modal-foot { flex: none; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.modal-head .eb { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--terra); display: block; margin-bottom: 3px; }
.modal-x { width: 28px; height: 28px; border: none; background: transparent; color: var(--ink-3); border-radius: var(--rad); font-size: 16px; }
.modal-x:hover { background: var(--surface-3); color: var(--ink); }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }

.preset-row { display: flex; gap: 6px; }
.preset {
  flex: 1;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 8px 6px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: var(--rad); color: var(--ink-2);
}
.preset.on { border-color: var(--terra); background: var(--terra-wash); color: var(--terra-ink); }
.preset:hover { border-color: var(--line-2); }

.field label {
  display: block;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%; box-sizing: border-box;
  font-family: var(--mono); font-size: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface-2); color: var(--ink);
  outline: none;
}
.field textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--terra-line); background: var(--surface); }
.adm-select {
  width: 100%; font-family: var(--mono); font-size: 12px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface-2); color: var(--ink); outline: none;
}
.adm-select:focus { border-color: var(--terra-line); background: var(--surface); }
.field .help { font-family: var(--sans); font-size: 11px; color: var(--ink-3); margin-top: 5px; line-height: 1.45; }
.field .help code { font-family: var(--mono); font-size: 10.5px; background: var(--surface-3); padding: 1px 4px; border-radius: 2px; }

.modal-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.test-status { flex: 1; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.03em; }
.test-status.ok { color: var(--green); }
.test-status.bad { color: var(--maroon); }
.test-status.run { color: var(--ink-3); }
.btn {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600;
  padding: 9px 15px; border-radius: var(--rad); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--terra); border-color: var(--terra); color: #fff; }
.btn.primary:hover { background: var(--terra-ink); border-color: var(--terra-ink); }

.note {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-left: 2px solid var(--terra);
  border-radius: var(--rad);
  padding: 10px 12px;
  font-size: 12px; line-height: 1.5; color: var(--ink-2);
}
.note b { color: var(--ink); }
.note code { font-family: var(--mono); font-size: 11px; background: var(--surface); padding: 1px 4px; border-radius: 3px; }

.settings-sep { border-top: 1px solid var(--line); margin: 2px 0; }
.field-label-row { font-size: 13px; color: var(--ink); }
.mcp-list { display: flex; flex-direction: column; gap: 6px; }
.mcp-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--rad);
  padding: 7px 10px; font-family: var(--mono); font-size: 11px;
}
.mcp-row .mcp-name { font-weight: 600; color: var(--ink); flex: none; }
.mcp-row .mcp-url { color: var(--ink-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.mcp-row .mcp-x { border: none; background: transparent; color: var(--ink-4); cursor: pointer; font-size: 13px; flex: none; }
.mcp-row .mcp-x:hover { color: var(--maroon); }
.skill-add { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.skill-add textarea {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 90px; line-height: 1.5;
  font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: var(--rad);
  padding: 9px 11px; background: var(--surface-2); color: var(--ink); outline: none;
}
.skill-add textarea:focus { border-color: var(--terra-line); background: var(--surface); }
.mcp-add { display: flex; gap: 6px; }
.mcp-add input { flex: 1; font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: var(--rad); padding: 8px 10px; background: var(--surface-2); outline: none; }
.mcp-add input:first-child { flex: 0 0 34%; }
.mcp-add input:focus { border-color: var(--terra-line); background: var(--surface); }
.mcp-add .btn { flex: none; }
.mcp-row.off { opacity: 0.55; }

/* pill on/off switch (shared by Settings rows + the Tools dropdown) */
.mcp-switch {
  flex: none; width: 30px; height: 17px; border-radius: 100px; padding: 0;
  border: 1px solid var(--line-2); background: var(--surface-3); cursor: pointer; position: relative;
}
.mcp-switch span { position: absolute; top: 1px; left: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--ink-4); transition: transform .15s ease, background .15s ease; }
.mcp-switch.on { background: var(--terra-wash); border-color: var(--terra); }
.mcp-switch.on span { transform: translateX(13px); background: var(--terra); }
.mcp-switch:disabled { cursor: default; opacity: 0.6; }
.mcp-scope { font-family: var(--mono); font-size: 8.5px; letter-spacing: 0.08em; color: var(--ink-3); background: var(--surface-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; margin-left: 7px; vertical-align: middle; }
.mcp-global-opt { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12.5px; color: var(--ink-3); cursor: pointer; }
.mcp-global-opt input { width: 15px; height: 15px; accent-color: var(--terra); }

/* Tools toggle + caret + dropdown (in the composer foot) */
.tool-toggle-wrap { position: relative; display: flex; align-items: center; }
.tool-toggle-wrap .tool-toggle { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.tt-caret-btn {
  flex: none; align-self: stretch;
  border: 1px solid var(--line); border-left: none;
  border-radius: 0 100px 100px 0;
  background: var(--surface); color: var(--ink-4);
  padding: 0 9px; font-size: 9px; cursor: pointer;
}
.tt-caret-btn:hover { color: var(--ink-2); border-color: var(--line-2); }
.tt-caret-btn.on { border-color: var(--terra); background: var(--terra-wash); color: var(--terra-ink); }
.mcp-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 40;
  min-width: 200px; max-width: 280px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--rad-lg);
  box-shadow: 0 8px 28px -8px rgba(0,0,0,.28); padding: 6px;
}
.mcp-menu-head {
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-4); padding: 5px 8px 6px;
}
.mcp-menu-row { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: var(--rad); cursor: pointer; }
.mcp-menu-row:hover { background: var(--surface-2); }
.mcp-menu-name { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ====================== admin console ====================== */
.admin { min-height: 100%; display: flex; flex-direction: column; }
.admin-top {
  height: 60px; flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.admin-top .logo { width: 28px; height: 28px; }
.admin-brand { display: flex; align-items: baseline; gap: 10px; }
.admin-brand .nm { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; margin-right: 2px; }
.admin-brand .nm b { color: var(--terra); }
.admin-brand .tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-4); }
.admin-top .back {
  margin-left: auto;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-2); text-decoration: none;
  border: 1px solid var(--line); border-radius: var(--rad); padding: 8px 13px;
}
.admin-top .back:hover { border-color: var(--line-2); color: var(--ink); }

.admin-wrap { flex: 1; overflow-y: auto; }
.admin-inner { max-width: 920px; margin: 0 auto; padding: 34px 28px 60px; }

.admin-eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-4); }
.admin-h1 { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; margin: 6px 0 22px; }

/* ---- New (chat / agent) split button ---- */
.new-split { position: relative; display: flex; gap: 0; margin: 0 12px 6px; }
.new-split .new-chat { flex: 1; margin: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.new-caret {
  flex: none; width: 34px; border: 1px solid var(--terra); border-left-color: rgba(255,255,255,0.25);
  background: var(--terra); color: #fff; border-top-right-radius: var(--rad); border-bottom-right-radius: var(--rad);
  font-size: 11px; cursor: pointer;
}
.new-caret:hover { filter: brightness(1.06); }
.new-scrim { position: fixed; inset: 0; z-index: 40; }
.new-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 41;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--rad-lg);
  box-shadow: 0 14px 34px -12px rgba(0,0,0,.4); padding: 5px; display: flex; flex-direction: column; gap: 2px;
}
.new-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: transparent; border: none; border-radius: var(--rad); padding: 9px 10px;
  font-size: 13px; color: var(--ink); cursor: pointer;
}
.new-menu button:hover { background: var(--surface-3); }
.new-menu svg { width: 15px; height: 15px; color: var(--ink-3); flex: none; }
.beta { font-family: var(--mono); font-size: 8.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--terra-ink); background: var(--terra-wash); border: 1px solid var(--terra-line); border-radius: 4px; padding: 1px 4px; margin-left: auto; }

/* ---- agent entry badge in the sidebar list ---- */
.entry-badge {
  display: inline-flex; align-items: center; gap: 3px; vertical-align: 1px;
  font-family: var(--mono); font-size: 8.5px; letter-spacing: 0.08em;
  color: var(--terra-ink); background: var(--terra-wash); border: 1px solid var(--terra-line);
  border-radius: 4px; padding: 0 4px; margin-right: 6px;
}
.entry-badge svg { width: 10px; height: 10px; }

/* ---- agent view ---- */
.agent-tag { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; color: var(--terra-ink); background: var(--terra-wash); border: 1px solid var(--terra-line); border-radius: 5px; padding: 3px 7px; }
.agent-name-edit { font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--terra-line); border-radius: var(--rad); padding: 2px 7px; outline: none; min-width: 180px; }
.agent-empty { max-width: 460px; margin: 8vh auto 0; text-align: center; padding: 0 24px; }
.agent-empty-ic { width: 56px; height: 56px; margin: 0 auto 16px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); color: var(--terra-ink); }
.agent-empty-ic svg { width: 28px; height: 28px; }
.agent-empty h2 { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
.agent-empty p { color: var(--ink-3); line-height: 1.55; margin: 0 0 8px; }
.agent-empty-model { font-family: var(--mono); font-size: 11px; color: var(--ink-4); }
.agent-coming {
  max-width: var(--col); margin: 0 auto; padding: 12px 14px;
  border: 1px dashed var(--line-2); border-radius: var(--rad-lg); background: var(--surface-2);
  font-size: 12.5px; line-height: 1.5; color: var(--ink-3);
}

/* ---- Agent workspace files panel ---- */
.icon-btn.on { background: var(--terra-wash); color: var(--terra-ink); border-color: var(--terra-line); }
.agent-files {
  max-width: var(--col); width: 100%; margin: 0 auto 8px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--rad-lg); background: var(--surface);
}
.agent-files-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.agent-files-head span { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; color: var(--ink-3); text-transform: uppercase; }
.agent-files-refresh { font-family: var(--mono); font-size: 11px; color: var(--terra-ink); background: none; border: none; cursor: pointer; padding: 2px 4px; }
.agent-files-refresh:disabled { color: var(--ink-4); cursor: default; }
.agent-files-empty { font-size: 12.5px; color: var(--ink-4); padding: 4px 2px; }
.agent-files-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: auto; }
.agent-file { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.agent-file:hover { background: var(--surface-2); }
.agent-file-name { flex: 1 1 auto; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-file-size { font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); flex: 0 0 auto; }
.agent-file-dl {
  flex: 0 0 auto; display: grid; place-items: center; width: 28px; height: 28px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.agent-file-dl:hover { color: var(--terra-ink); border-color: var(--terra-line); }
.agent-file-dl:disabled { color: var(--ink-4); cursor: default; }
.agent-file-dl svg { width: 15px; height: 15px; }

/* ---- Sidebar tabs: FOREGROUND (interactive) vs BACKGROUND (unattended) ---- */
.side-tabs {
  display: flex; gap: 0; margin-top: 2px; border-top: 1px solid var(--line);
  padding: 6px 12px 2px;
}
.side-tab {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: none; cursor: pointer; padding: 6px 4px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-4); border-bottom: 2px solid transparent;
}
.side-tab.on { color: var(--ink); border-bottom-color: var(--terra); }
.side-tab-badge {
  font-size: 9px; border-radius: 8px; padding: 1px 6px; font-weight: 700;
}
.side-tab-badge.live   { background: var(--green-wash); color: var(--green); border: 1px solid var(--green-line); }
.side-tab-badge.orphan { background: var(--terra-wash); color: var(--maroon); border: 1px solid var(--terra-line); }
.bg-row { padding-top: 8px; padding-bottom: 8px; }
.bg-status {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.03em; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bg-status.live   { color: var(--green); }
.bg-status.queued { color: var(--ink-3); }
.bg-status.orphan { color: var(--maroon); }
.bg-status.idle   { color: var(--ink-4); }
/* Loop indicator chip + loop control panel */
.loop-chip {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--green); background: var(--green-wash); border: 1px solid var(--green-line);
  border-radius: 10px; padding: 2px 8px;
}
/* read-only variant (wiki consumers) — quieter than the writer/loop chips */
.loop-chip.ro { color: var(--ink-3); background: var(--surface-2); border-color: var(--line); }
/* Interrupted-run banner (server restart) */
.orphan-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--terra-wash); border: 1px solid var(--terra-line); border-left: 3px solid var(--maroon);
  border-radius: var(--rad); padding: 9px 12px; font-size: 12.5px; color: var(--ink-2);
}
.orphan-banner .act-btn { margin-left: auto; flex: none; color: var(--maroon); border-color: var(--terra-line); }
.orphan-banner .x { flex: none; border: 0; background: none; color: var(--ink-3); cursor: pointer; }

/* ---- Apps: modular workspace tabs (central pane + agent chat right) ---- */
.apps-head { display: flex; align-items: center; justify-content: space-between; }
.apps-add {
  width: 20px; height: 20px; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--rad); color: var(--ink-3); font-size: 13px; line-height: 1; cursor: pointer;
}
.apps-add:hover { border-color: var(--terra); color: var(--terra); }
/* height is the user's if they've dragged the divider, else content-sized */
.apps-list { flex: none; height: var(--apps-h, auto); max-height: var(--apps-h, 32vh); overflow-y: auto; }
.app-tab .app-ic { margin-right: 7px; font-size: 13px; }
.app-scope {
  margin-left: 7px; font-family: var(--mono); font-size: 8.5px; letter-spacing: 0.1em;
  color: var(--green); border: 1px solid var(--green-line); background: var(--green-wash);
  border-radius: 3px; padding: 1px 4px; vertical-align: 1px;
}
/* Agent engine picker (Settings, admin) */
.agent-be-opt {
  display: flex; gap: 10px; align-items: center; cursor: pointer;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface); font-size: 13px; margin-bottom: 8px;
}
.agent-be-opt input { accent-color: var(--terra); }
.agent-be-opt b { font-weight: 700; }
.agent-be-model { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); margin-left: 8px; }

/* WebMCP tool count on the open app */
.app-tools-chip {
  margin-left: 10px; flex: none; font-family: var(--mono); font-size: 10px; letter-spacing: 0.05em;
  color: var(--green); border: 1px solid var(--green-line); background: var(--green-wash);
  border-radius: 10px; padding: 2px 8px;
}
/* Code-lock toggle (user-only): unlocked = agent may rebuild; locked = read-only to the agent */
.app-lock {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-3);
  border-radius: var(--rad); padding: 5px 10px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
}
.app-lock svg { width: 14px; height: 14px; }
.app-lock:hover { border-color: var(--ink-3); }
.app-lock.on { background: var(--terra-wash); color: var(--terra-ink); border-color: var(--terra-line); font-weight: 700; }
.app-global-opt {
  display: flex; gap: 9px; align-items: flex-start; cursor: pointer;
  font-size: 12px; color: var(--ink-3); line-height: 1.45;
  padding: 10px 12px; border: 1px dashed var(--line); border-radius: var(--rad);
}
.app-global-opt input { margin-top: 2px; accent-color: var(--terra); }
.appws { flex: 1; min-height: 0; display: flex; }
.appws-stage { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.appws-frame { flex: 1; width: 100%; border: 0; background: var(--canvas); }
.appws-note { padding: 26px; font-size: 13px; color: var(--ink-3); }
.appws-note.mono { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-4); }
.appws-chat {
  flex: 0 0 var(--chat-w, 30%); min-width: 280px; min-height: 0;
  display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--surface);
}
/* The docked pane is narrow by design: drop the chrome that only repeats what
   the pane already is, so the agent's NAME gets the width instead. */
.appws-chat .topbar { padding: 0 14px; gap: 8px; }
.appws-chat .topbar-title .tt-kind { display: none; }
.appws-chat .agent-tag { display: none; }
.appws-chat .tools { gap: 6px; }
.appws-chat .agent-shell, .appws-chat .agent-pane { min-width: 0; }
.appws-chat .thread { padding-left: 16px; padding-right: 16px; }
.appws-chat .composer-wrap { padding-left: 12px; padding-right: 12px; }
/* The agent's own canvas split can't fit a 30% column — hide it there. */
.appws-chat .agent-canvas { display: none; }
.appws-chat .agent-empty p { max-width: 260px; }
@media (max-width: 900px) {
  .appws { flex-direction: column; }
  .appws-stage { flex: 1 1 55%; }
  /* stacked, so the stored width is meaningless here */
  .appws-chat { flex: 1 1 45%; max-width: none; min-width: 0; border-left: 0; border-top: 1px solid var(--line); }
  .appws > .splitter { display: none; }
}

/* ---------- draggable pane dividers ----------
   A splitter is a thin hit-target sitting ON the existing 1px border, so the
   layout does not shift when one is added. It only paints on hover/drag. */
.splitter {
  flex: none; position: relative; z-index: 15;
  background: transparent; border: 0; padding: 0;
  touch-action: none;                 /* we handle the drag ourselves */
}
.splitter.v { width: 7px; margin: 0 -3px; cursor: col-resize; align-self: stretch; }
.splitter.h { height: 7px; margin: -3px 0; cursor: row-resize; }
.splitter::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  background: var(--terra); opacity: 0; transition: opacity .12s;
}
.splitter.v::after { width: 2px; }
.splitter.h::after { height: 2px; }
.splitter:hover::after, .splitter.on::after, .splitter:focus-visible::after { opacity: .55; }
.splitter:focus-visible { outline: none; }
/* the sidebar edge is a grid boundary, so its splitter rides the border */
.splitter.side-edge {
  position: absolute; top: 0; bottom: 0; right: -3px; width: 7px;
  cursor: col-resize; margin: 0;
}
/* while dragging, keep the cursor consistent and stop text/iframe selection */
body.resizing { cursor: col-resize; user-select: none; }
body.resizing.row { cursor: row-resize; }
body.resizing iframe { pointer-events: none; }
@media (max-width: 800px) { .splitter.side-edge { display: none; } }
/* right-pane agent picker (app has no linked agent yet) */
.app-agent-pick { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; overflow-y: auto; }
.app-agent-pick .agent-empty-ic { margin-bottom: 2px; }
.app-agent-pick h3 { font-size: 15px; font-weight: 800; margin: 4px 0 0; }
.app-agent-pick p { font-size: 12.5px; color: var(--ink-3); max-width: 250px; margin: 0 0 10px; }
.app-pick-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; max-width: 260px;
  padding: 9px 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--rad); font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.app-pick-btn svg { width: 15px; height: 15px; color: var(--ink-3); flex: none; }
.app-pick-btn:hover { border-color: var(--terra); }
.app-pick-btn.new { color: var(--terra); border-style: dashed; }
/* template picker modal */
.app-picker { width: min(480px, 92vw); }
.app-tpl {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--rad); cursor: pointer; font: inherit;
}
.app-tpl:hover { border-color: var(--terra); }
.app-tpl:disabled { opacity: 0.6; cursor: default; }
.app-tpl-ic { font-size: 20px; flex: none; }
.app-tpl-tx { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.app-tpl-tx b { font-size: 13.5px; }
.app-tpl-tx span { font-size: 12px; color: var(--ink-3); line-height: 1.4; }
.app-tpl-busy { margin-left: auto; font-family: var(--mono); font-size: 10px; color: var(--terra); flex: none; }

/* ---- Agent visual canvas (right split panel) ---- */
.agent-shell { flex: 1; min-height: 0; display: flex; flex-direction: row; position: relative; }
.agent-pane { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.agent-canvas {
  flex: 0 0 46%; min-width: 380px; min-height: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--line); background: var(--surface);
}
.agent-canvas-head {
  flex: none; height: 48px; display: flex; align-items: center; gap: 9px;
  padding: 0 10px 0 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.acv-kind { font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--terra-ink); background: var(--terra-wash); border: 1px solid var(--terra-line); border-radius: 4px; padding: 2px 6px; flex: none; }
.acv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 13px; }
.acv-open { flex: none; font-family: var(--mono); font-size: 10.5px; color: var(--terra-ink); text-decoration: none; background: none; border: 1px solid var(--terra-line); border-radius: 5px; padding: 3px 7px; cursor: pointer; }
.acv-open:hover { background: var(--terra-wash); }
.acv-close { flex: none; border: none; background: transparent; color: var(--ink-4); font-size: 14px; cursor: pointer; padding: 4px 6px; }
.acv-close:hover { color: var(--maroon); }
.acv-tabs { flex: none; display: flex; gap: 4px; overflow-x: auto; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.acv-tab { flex: none; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: var(--ink-3); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; cursor: pointer; }
.acv-tab:hover { color: var(--ink); }
.acv-tab.on { color: var(--terra-ink); background: var(--terra-wash); border-color: var(--terra-line); font-weight: 600; }
.agent-canvas-body { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.canvas-frame { flex: 1; width: 100%; border: none; background: #fff; }
.canvas-md { flex: 1; overflow: auto; padding: 18px 22px; }
.canvas-status { flex: 1; padding: 22px; color: var(--ink-3); font-size: 13px; }
.canvas-status.err { color: var(--maroon); }
.mermaid-fig { margin: 14px 0; text-align: center; }
.mermaid-fig svg { max-width: 100%; height: auto; }
.canvas-table table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.canvas-table th, .canvas-table td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.canvas-table th { background: var(--surface-2); }

/* Narrow screens: the canvas overlays the conversation instead of splitting. */
@media (max-width: 900px) {
  .agent-canvas { position: absolute; inset: 0; flex: none; z-index: 30; min-width: 0; }
}

/* ---- Settings page ---- */
.set-inner { max-width: 720px; }
.set-card {
  border: 1px solid var(--line); border-radius: var(--rad-lg);
  background: var(--surface); padding: 20px 22px; margin-bottom: 16px;
}
.set-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.set-desc { font-size: 13px; line-height: 1.5; color: var(--ink-3); margin: 0 0 14px; }
.set-card .field { margin-bottom: 12px; }
.set-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.brand-accent-row { display: flex; align-items: center; gap: 10px; }
.brand-accent-row > input:last-child { flex: 1; }
.brand-swatch { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: var(--rad); background: var(--surface); cursor: pointer; flex: none; }
.set-row .test-status { flex: 1 1 auto; font-family: var(--mono); font-size: 11px; }
.set-actions { position: sticky; bottom: 0; padding: 14px 0 4px; background: linear-gradient(transparent, var(--canvas) 30%); }
.set-actions .btn.primary { min-width: 150px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.tab {
  position: relative;
  background: transparent; border: none;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); padding: 11px 14px;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); font-weight: 600; }
.tab.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--terra); }
.tab .n { color: var(--ink-4); margin-left: 6px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.section-head .sub { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-4); margin-top: 3px; }

.table { border: 1px solid var(--line); border-radius: var(--rad-lg); overflow: hidden; background: var(--surface); }
.trow {
  display: grid; align-items: center;
  padding: 13px 16px;
  border-top: 1px solid var(--line);
}
.trow:first-child { border-top: none; }
.trow.head {
  background: var(--surface-2);
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3);
}
.trow .cell-main { font-weight: 600; font-size: 14px; }
.trow .cell-sub { font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-top: 2px; word-break: break-all; }
.trow .mono-cell { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); }

.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--rad); border: 1px solid var(--line);
}
.tag-chip .sq { width: 7px; height: 7px; }
.tag-chip.green { color: var(--green); border-color: var(--green-line); background: var(--green-wash); }
.tag-chip.green .sq { background: var(--green); }
.tag-chip.gray { color: var(--ink-3); }
.tag-chip.gray .sq { background: var(--ink-4); }
.tag-chip.terra { color: var(--terra-ink); border-color: var(--terra-line); background: var(--terra-wash); }
.tag-chip.terra .sq { background: var(--terra); }

.row-acts { display: flex; gap: 6px; justify-content: flex-end; }
.mini {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: var(--rad); padding: 5px 9px;
}
.mini:hover { border-color: var(--line-2); color: var(--ink); }
.mini.danger:hover { border-color: var(--terra-line); color: var(--maroon); background: var(--terra-wash); }
.mini.approve { color: var(--green); border-color: var(--green-line); }
.mini.approve:hover { color: var(--green); border-color: var(--green); background: var(--green-wash); }

/* toggle switch */
.switch {
  width: 38px; height: 22px; border-radius: 100px;
  border: 1px solid var(--line-2); background: var(--surface-2);
  position: relative; flex: none; transition: background .14s, border-color .14s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .16s;
}
.switch.on { background: var(--terra); border-color: var(--terra); }
.switch.on::after { transform: translateX(16px); }

.tool-card {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 16px;
  border: 1px solid var(--line); border-radius: var(--rad-lg);
  background: var(--surface); margin-bottom: 10px;
}
.tool-card .tc-body { flex: 1; }
.tool-card .tc-name { font-weight: 700; font-size: 14.5px; }
.tool-card .tc-desc { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; line-height: 1.45; }
.tool-card .tc-key { margin-top: 12px; }
.tool-card .tc-key input {
  width: 100%; font-family: var(--mono); font-size: 11.5px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--rad);
  background: var(--surface-2); color: var(--ink); outline: none;
}
.tool-card .tc-key input:focus { border-color: var(--terra-line); background: var(--surface); }
.tool-card .tc-key label { display: block; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 5px; }

.empty-cell { padding: 22px 16px; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--ink-4); }

/* ====================== auth screen ====================== */
.auth-screen {
  height: 100%;
  display: grid;
  place-items: center;
  background: var(--canvas);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--rad-lg);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.28);
  padding: 30px 30px 24px;
}
.auth-brand {
  display: flex;
  align-items: center;
  margin-bottom: 26px;
}
.auth-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--rad);
  overflow: hidden;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  cursor: pointer;
}
.auth-tab.on { background: var(--terra); color: #fff; }
.auth-tab:hover:not(.on) { background: var(--surface-2); }
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-error {
  background: var(--terra-wash);
  border: 1px solid var(--terra-line);
  border-radius: var(--rad);
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--maroon);
  line-height: 1.4;
}
.auth-notice {
  background: var(--green-wash, #e6efe8);
  border: 1px solid var(--green-line);
  border-radius: var(--rad);
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--green);
  line-height: 1.4;
}
.auth-note-sm {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--ink-4);
  line-height: 1.5;
}
.auth-submit {
  width: 100%;
  padding: 11px;
  font-size: 12px;
  margin-top: 4px;
}
.auth-hint {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-3);
}

/* ====================== user foot in sidebar ====================== */
.user-foot {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
}
.user-avatar {
  width: 28px; height: 28px;
  background: var(--terra);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  flex: none;
}
.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--ink-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 4px 8px;
  font-size: 13px;
  color: var(--ink-3);
  flex: none;
  cursor: pointer;
  line-height: 1;
}
.logout-btn:hover { color: var(--maroon); border-color: var(--terra-line); background: var(--terra-wash); }
