:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8a8f9c;
  --accent: #5b8cff;
  --accent-text: #0b0d12;
  --danger: #ff5b6e;
  --success: #3ddc84;
  --radius: 10px;
}

/* Quicksand, self-hosted (SIL Open Font License) - latin for everything, latin-ext for the rupee sign and similar. */
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-ext-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-ext-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-ext-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-ext-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Quicksand";
  src: url("vendor/fonts/quicksand-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

* { box-sizing: border-box; }

/* Buttons and form fields don't inherit the page font on their own - without this they fall
   back to the browser's system font (model list, sidebar menu, Settings, etc.). */
button, input, textarea, select { font-family: inherit; }

body {
  margin: 0;
  font-family: "Quicksand", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  /* 100vh on a real mobile browser measures the viewport as if the address bar were
     hidden, not the actual visible area - content sized to it runs off the bottom of the
     screen whenever that bar is showing. 100dvh tracks the real visible viewport instead;
     the 100vh line stays first as a fallback for a browser old enough not to know dvh
     (which just ignores that second declaration and keeps this one). */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

/* Login */
.screen { height: 100vh; height: 100dvh; }
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  text-align: center;
}
.login-box h1 { margin: 0 0 4px; font-size: 1.3rem; }
.login-box input {
  width: 100%;
  margin: 16px 0 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
}
button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button:hover { filter: brightness(1.08); }

/* App layout */
#app-screen {
  display: flex;
}
.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 12px;
  font-size: 0.95rem;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}
.dot.connected { background: var(--success); }

.side-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
}
.side-btn:hover { background: var(--surface-2); }
.side-btn.logout { margin-top: auto; background: transparent; border: none; color: var(--muted); }
.side-btn.pairing { font-size: 0.85rem; flex-shrink: 0; }

.sidebar-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bot-search {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}
.bot-search svg {
  position: absolute;
  left: 9px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}
.bot-search input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px 7px 30px;
  font-family: inherit;
  font-size: 0.85rem;
}
.icon-btn.round {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
}
.icon-btn.round svg { width: 16px; height: 16px; }
.icon-btn.round:hover { filter: brightness(1.1); }

.bot-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bot-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.bot-item:hover { background: var(--surface-2); }
.bot-item.active { background: var(--surface-2); }
.bot-item-avatar { flex-shrink: 0; }
.bot-item-text { min-width: 0; flex: 1; }
.bot-item-snippet {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.scroll-to-bottom-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--below-messages, 100px) + 12px);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  z-index: 5;
}
.scroll-to-bottom-btn:hover { filter: brightness(1.15); }
.scroll-to-bottom-btn svg { width: 18px; height: 18px; }
.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header h2 { margin: 0; font-size: 1.05rem; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}
.msg-row.row-right { align-self: flex-end; align-items: flex-end; }
.msg-row.row-left { align-self: flex-start; align-items: flex-start; }

.msg {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  font-size: 0.92rem;
}
.msg.user {
  /* background/color set inline per-message from the bot's avatar color */
  background: var(--accent);
  color: var(--accent-text);
}
.msg.assistant {
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.msg.error {
  background: #2b1518;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.msg.pending { opacity: 0.6; }

.msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.msg-row:hover .msg-actions { opacity: 1; pointer-events: auto; }
.msg-action-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
}
.msg-action-btn:hover { color: var(--text); border-color: var(--accent); }
.msg-action-btn.danger { color: var(--danger); border-color: var(--danger); }
.msg-action-btn.danger:hover { background: var(--danger); color: #fff; }

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-style: italic;
}
.thinking-dots { display: inline-flex; gap: 3px; }
.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.tool-call-status {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9em;
}

.streaming-pending {
  /* The current in-progress line, shown as raw text until its newline arrives and it gets
     parsed as markdown like the rest of the reply. */
  opacity: 0.85;
}

.composer {
  display: flex;
  align-items: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}
/* One pill holding the + button, the text, AND the send button - this is what gives the
   composer its taller, more spacious look, rather than a plain bordered textarea with a
   separate button floating beside it. */
.composer-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 8px 8px 8px 10px;
  min-height: 56px;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  padding: 11px 4px;
  font-family: inherit;
  font-size: 0.92rem;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 360px;
  max-height: 80vh;
  max-height: 80dvh; /* see body's height rule above for why dvh follows vh here */
  overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.modal-box label { display: block; font-size: 0.8rem; color: var(--muted); margin: 12px 0 4px; }
.modal-box input, .modal-box textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.qr-container { display: flex; justify-content: center; margin: 12px 0; }
.qr-container img { border-radius: 8px; background: #fff; padding: 8px; }

.device-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
}
.device-row button {
  padding: 4px 10px;
  font-size: 0.75rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* --- Market levels panel --- */
.modal-box.levels-box { width: 480px; max-width: calc(100vw - 24px); max-height: 88vh; max-height: 88dvh; }
.levels-titlebar { display: flex; align-items: center; justify-content: space-between; }
.levels-titlebar h3 { margin: 0; }
.levels-tabs { display: flex; gap: 6px; margin: 12px 0 10px; flex-wrap: wrap; }
.levels-tab {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.levels-tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.levels-summary { font-size: 0.8rem; color: var(--muted); line-height: 1.5; }
.levels-summary strong { color: var(--text); font-weight: 600; }
.levels-notice {
  margin: 10px 0 0;
  padding: 8px 10px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.levels-structure { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.levels-structure:empty { display: none; }
.struct-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  align-items: start;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
}
.struct-tf { font-weight: 600; color: var(--muted); }
.struct-main { min-width: 0; }
.struct-main .struct-sub { display: block; font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.struct-trend { font-weight: 600; }
.struct-trend.up { color: var(--success); }
.struct-trend.down { color: var(--danger, #e5534b); }
.struct-trend.range { color: var(--muted); }
.struct-ob { display: flex; justify-content: space-between; gap: 10px; padding: 3px 10px; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.levels-list { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.levels-group-title { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 8px 0 2px; }
.level-row {
  display: grid;
  grid-template-columns: minmax(96px, auto) 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
}
.level-price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.level-label { min-width: 0; }
.level-label .level-sub { display: block; font-size: 0.72rem; color: var(--muted); }
.level-distance { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); font-size: 0.78rem; }
.level-row.is-done { opacity: 0.55; }
.level-row.price-row {
  background: transparent;
  border: 1px dashed var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.level-status { font-weight: 600; }
.level-status.untouched { color: var(--success); }
.level-status.tested { color: var(--accent); }
.level-status.broken { color: var(--muted); }
.levels-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.modal-box label.levels-check { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 0.8rem; color: var(--muted); }
.modal-box label.levels-check input { width: auto; margin: 0; }
.levels-controls button { padding: 6px 12px; font-size: 0.8rem; }
.levels-footnote { margin: 12px 0 0; font-size: 0.75rem; }
.device-row button.levels-toggle { color: var(--text); border-color: var(--border); }
.device-row button.levels-toggle.on { color: var(--success); border-color: var(--success); }

/* --- Avatars --- */
.bot-avatar {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.bot-avatar svg { display: block; }

.bot-item-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header {
  cursor: pointer;
  gap: 12px;
}
.chat-header:hover { background: var(--surface-2); }
.chat-header-avatar { flex-shrink: 0; }
.chat-header-text { display: flex; flex-direction: column; }
.chat-header-text h2 { margin: 0; }

/* --- Side panel (edit bot) --- */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 19;
}
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 90vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 20;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,0.3);
}
.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.side-panel-header h3 { margin: 0; font-size: 1rem; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 2px 6px;
}
.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.side-panel-body label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 14px 0 6px;
}
.side-panel-body label:first-child { margin-top: 0; }
.side-panel-body input, .side-panel-body textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 0.9rem;
}
.side-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.side-panel-footer-right { display: flex; gap: 8px; }
button.danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 12px;
  font-size: 0.85rem;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.avatar-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--surface-2);
}
.avatar-choice:hover { border-color: var(--border); }
.avatar-choice.selected { border-color: var(--accent); }

/* --- Model picker (searchable dropdown) --- */
.model-picker { position: relative; }
.model-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.model-option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.model-option:hover, .model-option.highlighted {
  background: var(--surface);
}
.model-option .model-option-id { color: var(--text); }
.model-option .model-option-name { color: var(--muted); font-size: 0.75rem; }
.model-dropdown .model-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- Reply preview bar --- */
.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 24px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.reply-preview-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.reply-preview-label {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
}
#reply-preview-snippet {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Icon-only hover action buttons */
.msg-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
}
.msg-action-btn svg { width: 14px; height: 14px; }

/* Auto-growing composer textarea */
.composer textarea {
  max-height: 160px;
  overflow-y: auto;
  resize: none;
}
.composer textarea:focus { outline: none; }

/* Attach-file "+" button, inside the pill to the left of the text. A visible background
   (not just a muted icon on a barely-different dark background) is what actually makes this
   readable - color alone was too low-contrast against --surface-2. */
.composer-plus-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  flex-shrink: 0;
  border: none;
  background: var(--surface);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
}
.composer-plus-btn svg { width: 20px; height: 20px; }
.composer-plus-btn:hover { background: var(--border); }

/* Send button - a circular accent-colored button with an up arrow, nested inside the same
   pill on the right (not a separate floating button outside it). */
.composer-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  padding: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
}
.composer-send-btn svg { width: 20px; height: 20px; }
.composer-send-btn:hover { filter: brightness(1.08); }

/* Chips for files picked but not sent yet, shown above the composer */
.pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 24px 0;
}
.pending-attachments.hidden { display: none; }
.pending-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 6px 4px 10px;
  font-size: 0.78rem;
  color: var(--text);
  max-width: 220px;
}
.pending-attachment-chip .chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pending-attachment-chip button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.pending-attachment-chip button:hover { color: var(--text); }

/* Chips shown inside a sent message bubble, one per attached file */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.msg-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(0,0,0,0.12);
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 0.76rem;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Light theme ------------------------------------------------------ */
/* Dark (the :root block above) is the default; this overrides it when active. */
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d9dce2;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #3b6fff;
  --accent-text: #ffffff;
  --danger: #d6304a;
  --success: #17a361;
}

/* --- Sidebar footer (gear + sign out) --------------------------------- */
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}
.sidebar-footer .side-btn.logout {
  margin-top: 0;
  flex: 1;
}
.sidebar-footer .icon-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.sidebar-footer .icon-btn:hover { color: var(--text); background: var(--surface-2); }
.sidebar-footer .icon-btn svg { width: 18px; height: 18px; }

/* --- Settings screen (two-pane: nav + content, like a proper settings app) --- */
.settings-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(1200px, 92vw);
  height: min(820px, 88vh);
  height: min(820px, 88dvh); /* see body's height rule above for why dvh follows vh here */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.settings-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-titlebar h3 { margin: 0; font-size: 1.05rem; }

.settings-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.settings-nav {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
}
.settings-nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.settings-nav-item:hover { background: var(--surface-2); color: var(--text); }
.settings-nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.settings-content {
  flex: 1;
  min-width: 0;
  padding: 28px 36px;
  overflow-y: auto;
}
.settings-panel h4 { margin: 0 0 4px; font-size: 1rem; }
.settings-panel > p.muted { margin: 0 0 16px; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.settings-row:first-of-type { border-top: none; padding-top: 4px; }
.settings-row-text strong { display: block; font-size: 0.88rem; margin-bottom: 2px; }
.settings-row-text p.muted { margin: 0; }

.theme-toggle { display: flex; gap: 8px; }
.theme-btn {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.theme-btn.active { border-color: var(--accent); color: var(--accent); background: var(--surface); }

.provider-key-list { display: flex; flex-direction: column; gap: 10px; }
.provider-key-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.provider-key-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.provider-key-name { font-size: 0.9rem; }
.provider-key-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}
.provider-key-status.configured { color: var(--success); }
.provider-key-status svg { width: 14px; height: 14px; }
.provider-key-row-input { display: flex; gap: 6px; }
.provider-key-row-input input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 9px;
  font-family: inherit;
  font-size: 0.85rem;
}
.provider-key-row-input button {
  padding: 7px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}
.provider-key-row-input .provider-key-clear {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.provider-key-row-input .provider-key-clear:hover { color: var(--danger); border-color: var(--danger); }

/* --- Rendered markdown inside assistant message bubbles --------------- */
.msg.assistant.markdown { white-space: normal; }
.msg.markdown > *:first-child { margin-top: 0; }
.msg.markdown > *:last-child { margin-bottom: 0; }
.msg.markdown p { margin: 0 0 0.6em; }
.msg.markdown h1, .msg.markdown h2, .msg.markdown h3, .msg.markdown h4 {
  margin: 0.8em 0 0.4em;
  line-height: 1.25;
}
.msg.markdown h1 { font-size: 1.25rem; }
.msg.markdown h2 { font-size: 1.15rem; }
.msg.markdown h3 { font-size: 1.05rem; }
.msg.markdown h4 { font-size: 1rem; }
.msg.markdown ul, .msg.markdown ol {
  margin: 0 0 0.6em;
  padding-left: 1.4em;
}
.msg.markdown li { margin: 0.2em 0; }
.msg.markdown li > p { margin: 0; }
.msg.markdown strong { font-weight: 700; }
.msg.markdown em { font-style: italic; }
.msg.markdown u { text-decoration: underline; }
.msg.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}
.msg.markdown blockquote {
  margin: 0 0 0.6em;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}
.msg.markdown code {
  background: rgba(127, 127, 127, 0.18);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.85em;
}
.msg.markdown pre {
  background: rgba(127, 127, 127, 0.14);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 0.6em;
}
.msg.markdown pre code {
  background: none;
  padding: 0;
  font-size: 0.82em;
}
.msg.markdown table {
  border-collapse: collapse;
  margin: 0 0 0.6em;
  font-size: 0.88em;
  display: block;
  overflow-x: auto;
}
.msg.markdown th, .msg.markdown td {
  border: 1px solid var(--border);
  padding: 5px 9px;
  text-align: left;
}
.msg.markdown th {
  background: rgba(127, 127, 127, 0.14);
  font-weight: 600;
}
.msg.markdown a {
  color: var(--accent);
  text-decoration: underline;
}
.msg.markdown img {
  max-width: 100%;
  border-radius: 8px;
  margin: 4px 0;
  display: block;
}

/* --- Memory list (Settings) --------------------------------------------- */
.memory-list { display: flex; flex-direction: column; gap: 6px; }
.memory-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
}
.memory-row-text { flex: 1; line-height: 1.35; }
.memory-row-delete {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.memory-row-delete:hover { color: var(--danger); border-color: var(--danger); }
.memory-row-delete svg { width: 12px; height: 12px; }

/* --- Skills list (Settings) ---------------------------------------------- */
.skills-list { display: flex; flex-direction: column; gap: 8px; }
.skill-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.82rem;
}
.skill-row.pending { border-color: var(--accent); }
.skill-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.skill-row-name { font-weight: 600; }
.skill-row-badge {
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  white-space: nowrap;
}
.skill-row-desc { color: var(--muted); margin-top: 3px; line-height: 1.35; }
.skill-row-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 0 0;
}
.skill-row-content {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  font-size: 0.78rem;
  color: var(--text);
  max-height: 160px;
  overflow-y: auto;
}
.skill-row-actions { display: flex; gap: 6px; margin-top: 8px; }
.skill-row-actions button { padding: 4px 10px; font-size: 0.75rem; }
.skill-row-actions .reject-btn, .skill-row-actions .delete-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* --- Scheduled jobs list (bot edit panel) --------------------------------- */
.job-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.82rem;
}
.job-row.paused { opacity: 0.65; }
.job-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.job-row-label { font-weight: 600; }
.job-row-badge {
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3, var(--border));
  color: var(--muted);
  white-space: nowrap;
}
.job-row-badge.active { background: var(--accent); color: var(--accent-text); }
.job-row-schedule { color: var(--muted); margin-top: 3px; line-height: 1.35; }
.job-row-next { color: var(--muted); margin-top: 2px; font-size: 0.76rem; }
.job-row-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.job-row-actions button {
  padding: 4px 10px;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
.job-row-actions button:hover { border-color: var(--accent); color: var(--accent); }
.job-row-actions .delete-btn { border-color: var(--danger); color: var(--danger); }
.job-row-actions .delete-btn:hover { background: var(--danger); color: white; }

/* ---- Mobile layout (phones/narrow windows) ----
   Below this breakpoint there isn't room for the sidebar and chat side by side, so instead
   of squeezing both into the same screen, mobile gets a two-screen list/detail pattern (same
   idea as WhatsApp/Telegram/Slack mobile): the bot list IS the first full screen (its own
   search bar, add-bot button, connection status, sign-out/pair-device - nothing new, just
   the existing sidebar shown at full width/height instead of a narrow column), and tapping a
   bot swaps to the chat as a second full screen, with a back arrow in its header to return.
   #app-screen.mobile-chat-active is the single switch between the two - set by
   showChatMobile()/showListMobile() in app.js. */
.mobile-back-btn {
  display: none;
  flex-shrink: 0;
}

@media (max-width: 820px) {
  .sidebar {
    width: 100%;
  }
  .main {
    width: 100%;
    display: none;
  }
  #app-screen.mobile-chat-active .sidebar {
    display: none;
  }
  #app-screen.mobile-chat-active .main {
    display: flex;
  }
  .mobile-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .msg-row {
    max-width: 88%;
  }
  .chat-header {
    padding: 12px 14px;
    gap: 8px;
  }
  .messages {
    padding: 14px 12px;
  }
}

/* --- Settings screen on phones: full screen, nav becomes a tab strip on top ------------ */
@media (max-width: 700px) {
  #settings-modal { align-items: stretch; justify-content: stretch; }
  .settings-box {
    width: 100%;
    height: 100%;
    max-height: none;
    border: none;
    border-radius: 0;
  }
  .settings-titlebar { padding: 12px 14px; }
  .settings-shell { flex-direction: column; }
  .settings-nav {
    width: auto;
    flex-direction: row;
    gap: 6px;
    padding: 8px 10px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
  }
  .settings-nav-item { flex: 1 0 auto; justify-content: center; white-space: nowrap; padding: 8px 9px; gap: 6px; font-size: 0.82rem; }
  .settings-nav-item svg { width: 15px; height: 15px; }
  .settings-nav { gap: 4px; padding: 8px 8px; }
  .settings-content { padding: 16px 14px 28px; }
  .settings-row { flex-wrap: wrap; gap: 10px; }
  .settings-row-text { min-width: 0; flex: 1 1 100%; }
  .theme-toggle { width: 100%; }
  .provider-key-row { min-width: 0; }
  .provider-key-row-top { gap: 8px; flex-wrap: wrap; }
  .provider-key-row-input { flex-wrap: wrap; }
  .provider-key-row-input input { min-width: 0; width: 100%; flex: 1 1 100%; }
  .provider-key-row-input button { flex: 1 1 auto; }
  .settings-content * { overflow-wrap: anywhere; }
}

/* --- Avatar colour swatches (under the alien picker) --- */
.color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.color-swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px var(--surface);
  cursor: pointer;
}
.color-swatch:hover { border-color: var(--border); }
.color-swatch.selected { border-color: var(--accent); }
.color-swatch.original { position: relative; }
.color-swatch.original::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
  opacity: 0.55;
}

/* --- Chat header: avatar and name on one centred line ------------------------------------ */
.chat-header { align-items: center; }
.chat-header h2 { line-height: 1.2; }
.chat-header-avatar { display: flex; align-items: center; }

/* --- Composer, Claude style: text on top, a toolbar row underneath (+ on the left; model
   chip and send on the right) ---------------------------------------------------------- */
.composer-input-wrap {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  border-radius: 26px;
  padding: 12px 10px 8px 16px;
  min-height: 0;
}
.composer-input-wrap textarea { flex: none; width: 100%; min-height: 28px; padding: 2px 0; }
.composer-toolbar { display: flex; align-items: center; gap: 8px; }
.composer-spacer { flex: 1; }
.composer-input-wrap { position: relative; }
.composer-model { min-width: 0; }
.composer-model-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 190px;
  padding: 6px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
}
.composer-model-btn:hover { background: var(--surface); color: var(--text); }
.composer-model-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-model-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.composer-model-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(420px, 100%);
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  padding: 8px;
  z-index: 40;
}
.composer-model-menu input {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.composer-model-list { max-height: min(300px, 45vh); overflow-y: auto; }
.composer-model-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.composer-model-option:hover { background: var(--surface-2); }
.composer-model-option.current { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.composer-model-option .cmo-name { font-size: 0.88rem; }
.composer-model-option .cmo-id { font-size: 0.74rem; color: var(--muted); overflow-wrap: anywhere; }

/* --- Message actions: small bare icons (copy, reply, delete), shown when a message is tapped */
.msg-actions { gap: 2px; margin-top: 2px; opacity: 0; pointer-events: none; }
.msg-row.show-actions .msg-actions { opacity: 1; pointer-events: auto; }
.msg-action-btn,
.msg-action-btn.danger {
  width: 30px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--muted);
}
.msg-action-btn svg { width: 12px; height: 12px; }
.msg-action-btn:hover { background: transparent; color: var(--text); border: none; }
.msg-action-btn.danger:hover { background: transparent; color: var(--danger); }
/* Touch screens: no space is reserved for the icons until a message is tapped (a tap would
   otherwise leave a sticky :hover on the last message touched). */
@media (hover: none) {
  .msg-actions { display: none; }
  .msg-row.show-actions .msg-actions { display: flex; }
}
/* Mouse: hovering a message still shows them too. */
@media (hover: hover) {
  .msg-row:hover .msg-actions { opacity: 1; pointer-events: auto; }
}

/* --- Chat header as a floating pill (opens the bot's side panel), over a soft fade ----------
   The header no longer takes up a row: it floats over the top of the chat, and the messages
   scroll underneath it, faded out by the gradient behind the pill. */
.chat-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px 0;
  height: 70px;
  background: none;
  border-bottom: none;
  cursor: default;
  pointer-events: none; /* only the pill and the back button take clicks */
}
.chat-header:hover { background: none; }
/* The vignette: page colour at the top fading to nothing, behind the pill. */
.chat-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 116px;
  background: linear-gradient(to bottom, var(--bg) 0%, var(--bg) 38%, transparent 100%);
  z-index: -1;
  pointer-events: none;
}
.chat-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 140px);
  padding: 6px 22px 6px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.chat-pill:hover { border-color: var(--accent); background: var(--surface-2); }
.chat-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-pill h2 {
  margin: 0;
  font-size: 1.225rem;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-pill .chat-header-avatar { width: 40px; height: 40px; flex-shrink: 0; }
/* Back button (phones): a round floating button at the left, same glass look. */
.chat-header .mobile-back-btn {
  position: absolute;
  left: 14px;
  top: 12px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  padding: 0;
}
/* Leave room at the top of the message list for the floating header. */
.messages { padding-top: 92px; }
@media (max-width: 820px) {
  .chat-header { padding: 10px 12px 0; }
  .chat-header .mobile-back-btn { left: 12px; top: 10px; }
  .messages { padding-top: 84px; }
}

/* --- Bot messages: small avatar at the top-left, with the bubble's tail pointing at it ------ */
.msg-row.has-avatar { position: relative; padding-left: 40px; }
.msg-avatar {
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  display: block;
}
.msg-avatar svg { width: 28px; height: 28px; }
.msg-row.has-avatar .msg.assistant {
  position: relative;
  border-top-left-radius: 3px;
}
/* The tail: a small curved wedge in the bubble's colour, tip toward the avatar. */
.msg-row.has-avatar .msg.assistant::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -13px;
  width: 14px;
  height: 18px;
  background: var(--surface-2);
  clip-path: path("M14 0 L0 1 Q9 4 14 18 Z");
  pointer-events: none;
}
@media (max-width: 820px) {
  .msg-row.has-avatar { max-width: 94%; }
}

/* --- Scrollbars: dark and subtle (no white track), thin thumb that brightens on hover -------- */
:root { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-corner { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 75%, transparent); }
*::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

/* --- Left menu 15% larger, bolder title, bigger bot cards ------------------------------- */
.sidebar { width: 299px; padding: 18px 14px; gap: 9px; }
.sidebar-header { gap: 10px; padding: 4px 4px 14px; }
.sidebar-header strong {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.sidebar-header .dot { width: 11px; height: 11px; }
.bot-search svg { left: 10px; width: 16px; height: 16px; }
.bot-search input { font-size: 0.98rem; padding: 8px 11px 8px 34px; border-radius: 9px; }
.icon-btn.round { width: 37px; height: 37px; }
.icon-btn.round svg { width: 18px; height: 18px; }
.bot-item { padding: 10px 12px; gap: 13px; font-size: 1.04rem; border-radius: 10px; }
.bot-item-name { font-size: 1.08rem; }
.bot-item-snippet { font-size: 0.9rem; margin-top: 2px; }
.side-btn.pairing { font-size: 0.98rem; padding: 11px 18px; }
.sidebar-footer .side-btn.logout { font-size: 1.02rem; }
.sidebar-footer .icon-btn { width: 39px; height: 39px; }
.sidebar-footer .icon-btn svg { width: 21px; height: 21px; }
@media (max-width: 820px) {
  .sidebar { width: 100%; }
}

/* --- Brand icon (animated peeking alien, transparent background) in place of the status dot.
   Full colour and animated while connected; greyed out and paused while offline. ----------- */
.brand-icon { display: inline-flex; flex-shrink: 0; width: 40px; height: 40px; line-height: 0; margin-left: -2px; }
.brand-icon svg { width: 40px; height: 40px; overflow: hidden; }
.brand-icon:not(.connected) { filter: grayscale(1); opacity: 0.45; }
.brand-icon:not(.connected) * { animation-play-state: paused !important; }
.sidebar-header { align-items: center; }
.ai-mv { transform-origin: 100px 200px; animation: ai-peek 6s ease-in-out infinite; }
.ai-lk { animation: ai-look 6s ease-in-out infinite; }
.ai-bl { transform-box: fill-box; transform-origin: center; animation: ai-blink 6s infinite; }
.ai-hl { animation: ai-hl 6s infinite; }
.ai-mo { transform-box: fill-box; transform-origin: center; animation: ai-smile 6s ease-in-out infinite; }
@keyframes ai-peek { 0%,100%{transform:translateY(0) rotate(-3deg)} 15%{transform:translateY(-4px) rotate(2deg)} 30%{transform:translateY(0) rotate(4deg)} 45%{transform:translateY(-3px) rotate(-1deg)} 60%{transform:translateY(0) rotate(-3deg)} 68%{transform:translateY(34px) rotate(0deg)} 74%{transform:translateY(34px) rotate(0deg)} 84%{transform:translateY(-10px) rotate(5deg)} 92%{transform:translateY(2px) rotate(-3deg)} }
@keyframes ai-look { 0%,8%{transform:translateX(0)} 18%,32%{transform:translateX(5px)} 42%,56%{transform:translateX(-5px)} 64%{transform:translateX(0)} 84%,100%{transform:translateX(0)} }
@keyframes ai-blink { 0%,19%,23%,26%,29%,48%,52%,100%{transform:scaleY(1)} 20.5%,27.5%,50%{transform:scaleY(0.08)} }
@keyframes ai-hl { 0%,19%,23%,26%,29%,48%,52%,100%{opacity:1} 20.5%,27.5%,50%{opacity:0} }
@keyframes ai-smile { 0%,34%,46%,100%{transform:scale(1,1)} 40%{transform:scale(1.3,1.6)} }
@media (prefers-reduced-motion: reduce) { .ai-mv, .ai-lk, .ai-bl, .ai-hl, .ai-mo { animation: none; } }
.sidebar-header .brand-icon { margin-right: 8px; }

/* --- Edit panel: no sideways scroll, pill buttons, icon delete, clamped notes + popup ---- */
.side-panel, .side-panel * { box-sizing: border-box; }
.side-panel { width: 360px; }
.side-panel-body { overflow-x: hidden; }
.side-panel-body input, .side-panel-body textarea { max-width: 100%; }
.side-panel-body textarea { resize: vertical; }
.side-panel .memory-row-text { min-width: 0; overflow-wrap: anywhere; }
.side-panel-footer { gap: 10px; }
.side-panel-footer-right button, .note-popup .pill { border-radius: 999px; padding: 9px 20px; }
button.icon-danger { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; border-radius: 999px; flex-shrink: 0; }
button.icon-danger svg { width: 17px; height: 17px; }
.note-row { cursor: pointer; }
.note-row:hover { border-color: var(--muted); }
.note-clamp { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-popup { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,0.55); }
.note-popup.hidden { display: none; }
.note-popup-card { width: min(420px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,0.5); padding: 16px; }
.note-popup-text { overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9rem; line-height: 1.5; padding-right: 4px; }
.note-popup-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

/* Sidebar footer: four icon buttons in one row */
.sidebar-footer { justify-content: space-around; gap: 4px; }
.sidebar-footer .icon-btn { width: 44px; height: 44px; }
.sidebar-footer .icon-btn svg { width: 22px; height: 22px; }
#logout-btn:hover { color: var(--danger); }

/* --- Message action icons: thin outline style; thumbs; rating popup; style suggestions ---- */
.msg-action-btn svg { width: 15px; height: 15px; }
.msg-actions { gap: 6px; }
.msg-rate-btn.rated { color: var(--accent); }
.msg-rate-btn.rated svg { fill: currentColor; fill-opacity: 0.25; }
.rate-title { font-weight: 700; font-size: 1rem; }
.rate-sub { font-size: 0.8rem; margin: 2px 0 12px; }
.rate-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.rate-chip { border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; background: transparent; border: 1px solid var(--border); color: var(--muted); cursor: pointer; }
.rate-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#rate-note { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 9px 11px; font-size: 0.9rem; }
.rate-spacer { flex: 1; }
.note-popup-actions { gap: 8px; }
.suggest-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.suggest-head { font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.suggest-ex { font-size: 0.78rem; margin-bottom: 6px; }
.suggest-card textarea { font-size: 0.85rem; }
.suggest-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.suggest-actions .pill { border-radius: 999px; padding: 7px 16px; font-size: 0.82rem; }
/* Tighter message action icons */
.msg-actions { gap: 0; }
.msg-action-btn, .msg-action-btn.danger { width: 22px; height: 22px; }
.msg-action-btn svg { width: 13px; height: 13px; }
/* Date/time sits above the message (overlaid in the gap, so nothing shifts); shown like the icons */
.msg-row { position: relative; }
.messages { gap: 16px; }
.msg-time-top { position: absolute; top: -15px; font-size: 0.7rem; line-height: 14px; color: var(--muted); white-space: nowrap; opacity: 0; pointer-events: none; }
.msg-row.row-right .msg-time-top { right: 2px; }
.msg-row.row-left .msg-time-top { left: 4px; }
.msg-row.has-avatar .msg-time-top { left: 44px; }
.msg-row.show-actions .msg-time-top { opacity: 0.85; }
@media (hover: hover) { .msg-row:hover .msg-time-top { opacity: 0.85; } }

/* --- Collapsible sidebar (desktop): collapses to a slim rail of avatars + icons ---------- */
.sidebar-toggle { margin-left: auto; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; background: transparent; border: none; border-radius: 10px; color: var(--muted); cursor: pointer; flex-shrink: 0; }
.sidebar-toggle:hover { color: var(--text); background: var(--surface-2); }
.sidebar-toggle svg { width: 20px; height: 20px; }
.sidebar { transition: width 0.2s ease; overflow: hidden; }
@media (min-width: 821px) {
  .sidebar.collapsed { width: 76px; padding: 18px 8px; }
  .sidebar.collapsed .sidebar-header { flex-direction: column; gap: 10px; padding: 4px 0 10px; }
  .sidebar.collapsed .sidebar-header strong { display: none; }
  .sidebar.collapsed .sidebar-header .brand-icon { margin: 0; }
  .sidebar.collapsed .sidebar-toggle { margin: 0; }
  .sidebar.collapsed .bot-search { display: none; }
  .sidebar.collapsed .sidebar-toolbar { justify-content: center; }
  .sidebar.collapsed .bot-item { justify-content: center; padding: 8px 0; }
  .sidebar.collapsed .bot-item-text { display: none; }
  .sidebar.collapsed .sidebar-footer { flex-direction: column; gap: 4px; }
}
@media (max-width: 820px) { .sidebar-toggle { display: none; } }

/* --- Secrets: private key card in chat + Edit panel section --------------------------- */
.secret-requests { padding: 0 16px; }
.secret-requests:empty { display: none; }
.secret-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; margin: 0 auto 10px; max-width: 620px; }
.secret-card-title { font-size: 0.95rem; margin-bottom: 2px; }
.secret-card-purpose, .secret-card-note { font-size: 0.8rem; margin-bottom: 4px; }
.secret-card-input, .secret-add input[type="text"], .secret-add input[type="password"] { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 9px 11px; font-size: 0.9rem; margin: 6px 0; }
.secret-share { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); margin: 4px 0 8px; text-transform: none; letter-spacing: 0; }
.secret-share input { width: auto; margin: 0; }
.secret-card-actions { display: flex; justify-content: flex-end; gap: 8px; }
.secret-card-actions .pill, .secret-add .pill { border-radius: 999px; padding: 8px 18px; }
.secret-card-error:empty { display: none; }
.secret-meta { font-size: 0.75rem; margin-top: 2px; }
.secret-add { margin-top: 8px; }
.memory-row-delete { padding: 0; box-sizing: border-box; }
.memory-row-delete svg { flex-shrink: 0; }

/* --- Sidebar header as a "wall": tinted panel the alien peeks over -------------------------
   The header band runs edge to edge in its own gradient; the icon sits on its bottom edge, so
   the SVG's clipped bottom looks like the alien ducking behind the wall below it. */
.sidebar-header {
  margin: -18px -14px 6px;
  padding: 16px 14px 0;
  align-items: flex-end;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--accent) 30%, var(--surface)) 0%,
    color-mix(in srgb, var(--accent) 12%, var(--surface)) 100%);
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: 0 6px 14px -8px rgba(0, 0, 0, 0.6);
}
.sidebar-header strong { padding-bottom: 11px; }
.sidebar-header .sidebar-toggle { margin-bottom: 6px; }
.sidebar-header .brand-icon { margin-bottom: -1px; }
@media (min-width: 821px) {
  .sidebar.collapsed .sidebar-header { margin: -18px -8px 6px; padding: 12px 0 0; align-items: center; gap: 8px; }
  .sidebar.collapsed .sidebar-toggle { order: -1; margin: 0; }
}

/* Header wall: subtle green, no outline, rounded bottom corners */
.sidebar-header {
  background: linear-gradient(180deg,
    color-mix(in srgb, #A9E34B 20%, var(--surface)) 0%,
    color-mix(in srgb, #A9E34B 7%, var(--surface)) 100%);
  border-bottom: none;
  border-radius: 0 0 22px 22px;
  box-shadow: 0 8px 16px -10px rgba(0, 0, 0, 0.55);
}

/* Taller wall (+25%) with inverted (flared) bottom corners that sweep down the sidebar edges */
.sidebar-header {
  --wall-bottom: color-mix(in srgb, #A9E34B 7%, var(--surface));
  position: relative;
  padding-top: 30px;
  margin-bottom: 20px;
  border-radius: 0;
  box-shadow: none;
}
.sidebar-header::before,
.sidebar-header::after {
  content: "";
  position: absolute;
  top: 100%;
  width: 18px;
  height: 18px;
  pointer-events: none;
}
.sidebar-header::before { left: 0; background: radial-gradient(circle at 100% 100%, transparent 17.5px, var(--wall-bottom) 18px); }
.sidebar-header::after { right: 0; background: radial-gradient(circle at 0% 100%, transparent 17.5px, var(--wall-bottom) 18px); }
@media (min-width: 821px) {
  .sidebar.collapsed .sidebar-header { padding-top: 26px; }
}

/* --- Compact Edit panel + "More settings" popup ---------------------------------------- */
.more-settings-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 16px; border-radius: 999px; padding: 10px 16px; }
.more-settings-btn svg { width: 16px; height: 16px; }
.more-settings-box { width: 520px; max-width: calc(100vw - 24px); max-height: 86vh; max-height: 86dvh; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.more-settings-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
.more-settings-head h3 { margin: 0; }
.more-settings-body { overflow-y: auto; overflow-x: hidden; padding: 4px 20px 20px; }
.more-settings-body > label { display: block; font-size: 0.8rem; color: var(--muted); margin: 16px 0 6px; }
.more-settings-body > label:first-child { margin-top: 4px; }
.more-settings-body input[type="text"], .more-settings-body input[type="password"] { width: 100%; }
#more-settings-modal { z-index: 40; }
.more-settings-box, .more-settings-box * { box-sizing: border-box; }

/* --- Dark theme shade: neutral graphite, no blue tint (earlier shades: original bg #0f1115,
   surface #171a21, surface-2 #1f232c, border #2a2f3a, muted #8a8f9c; midnight bg #0a0d17,
   surface #111626, surface-2 #192036, border #242c47, muted #8d95b3) ------------------------ */
:root {
  --bg: #0d0d0e;
  --surface: #151516;
  --surface-2: #1e1e20;
  --border: #2d2d30;
  --text: #ececec;
  --muted: #929297;
}

/* --- Settings: bigger theme buttons + Models panel ------------------------------------- */
.theme-toggle { gap: 10px; }
.theme-btn { padding: 11px 24px; font-size: 0.95rem; min-width: 92px; border-radius: 12px; }
.models-search { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 9px 12px; font-size: 0.9rem; margin-bottom: 12px; }
.models-list { display: flex; flex-direction: column; gap: 8px; }
.models-group { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.models-group > summary { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; cursor: pointer; font-weight: 600; list-style: none; }
.models-group > summary::-webkit-details-marker { display: none; }
.models-group > summary::after { content: "\203A"; margin-left: 10px; color: var(--muted); transition: transform 0.15s; }
.models-group[open] > summary::after { transform: rotate(90deg); }
.models-group-name { flex: 1; }
.models-group-count { font-size: 0.8rem; font-weight: 400; }
.models-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 0.86rem; }
.models-row-main { min-width: 0; display: flex; flex-direction: column; }
.models-row-name { overflow-wrap: anywhere; }
.models-row-id { font-size: 0.74rem; overflow-wrap: anywhere; }
.models-badge { flex-shrink: 0; font-size: 0.72rem; padding: 3px 9px; border-radius: 999px; background: var(--accent); color: var(--accent-text); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.models-note { font-size: 0.8rem; }
.models-group-count { margin-right: 4px; }

/* --- Provider picker (select next to the model) ---------------------------------------- */
.provider-select { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 9px 11px; font-size: 0.88rem; }
.composer-provider-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px 4px; font-size: 0.82rem; color: var(--muted); }
.composer-provider-row select { flex: 1; min-width: 0; padding: 7px 9px; font-size: 0.82rem; }

/* --- Skills: minimal, box-free actions ---------------------------------------------------- */
.skill-row-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.skill-row-foot .skill-row-toggle { margin: 0; padding: 4px 0; background: none; border: none; color: var(--accent); font-size: 0.82rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.skill-row-foot .skill-row-toggle::after { content: "\203A"; display: inline-block; transition: transform 0.15s; font-size: 1rem; line-height: 1; }
.skill-row-foot .skill-row-toggle.open::after { transform: rotate(90deg); }
.skill-row-foot .skill-row-toggle:hover { text-decoration: underline; }
.skill-row-foot .skill-row-actions { margin: 0; gap: 4px; align-items: center; }
.skill-row-actions button { border: none; background: none; box-shadow: none; }
.skill-row-actions .delete-btn.icon-only { width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); border-radius: 999px; }
.skill-row-actions .delete-btn.icon-only svg { width: 16px; height: 16px; }
.skill-row-actions .delete-btn.icon-only:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.skill-row-actions .reject-btn { color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 0.8rem; }
.skill-row-actions .reject-btn:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.skill-row-actions button:not(.reject-btn):not(.delete-btn) { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 6px 16px; font-size: 0.8rem; font-weight: 600; }
.skill-row .skill-row-actions .delete-btn, .skill-row .skill-row-actions .reject-btn { border: none; background: none; box-shadow: none; }
.skill-row .skill-row-actions .delete-btn:hover, .skill-row .skill-row-actions .reject-btn:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); border: none; }

/* --- Modern pill buttons everywhere + icon-only delete/remove ------------------------------ */
button { border-radius: 999px; }
.settings-nav-item { border-radius: 10px; }
.theme-btn { border-radius: 999px; }
.provider-key-row-input button { border-radius: 999px; padding-left: 18px; padding-right: 18px; }
.job-row-actions button { border-radius: 999px; padding: 6px 14px; }
.skill-row-actions button { border-radius: 999px; }
.modal-actions button, .side-panel-footer-right button { border-radius: 999px; padding-left: 20px; padding-right: 20px; }
.provider-key-row-input .provider-key-clear.icon-only,
.job-row-actions .delete-btn.icon-only {
  width: 34px; height: 34px; padding: 0; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted); border-radius: 999px;
}
.provider-key-clear.icon-only svg, .job-row-actions .delete-btn.icon-only svg { width: 16px; height: 16px; }
.provider-key-row-input .provider-key-clear.icon-only:hover,
.job-row-actions .delete-btn.icon-only:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); border: none; }
.job-row-actions { align-items: center; }

/* Smooth slide-in for the right-hand side panel */
.side-panel {
  transform: translateX(0);
  transition: transform .32s cubic-bezier(.22,.9,.3,1), visibility 0s linear 0s, box-shadow .32s;
  will-change: transform;
}
.side-panel.hidden {
  display: flex !important;
  transform: translateX(105%);
  visibility: hidden;
  pointer-events: none;
  box-shadow: none;
  transition: transform .26s cubic-bezier(.4,0,.6,1), visibility 0s linear .26s, box-shadow .26s;
}
@media (prefers-reduced-motion: reduce) {
  .side-panel, .side-panel.hidden { transition: none; }
}

/* Settings > Usage */
.usage-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 8px; }
.usage-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.usage-tile strong { font-size: 1.35rem; }
.usage-label { font-size: .75rem; color: var(--muted); }
.usage-sub { font-size: .72rem; color: var(--muted); }
.usage-meta { margin: 6px 0; font-size: .82rem; }
.usage-body h5 { margin: 18px 0 6px; font-size: .85rem; }
.usage-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: .85rem; }
.usage-row > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .usage-tiles { grid-template-columns: 1fr; } }

/* Wide screens: keep the conversation in a centred column instead of stretching edge to edge. */
:root { --chat-col: 880px; }
.messages { padding-left: max(24px, calc((100% - var(--chat-col)) / 2)); padding-right: max(24px, calc((100% - var(--chat-col)) / 2)); }
.composer, .reply-preview, .pending-attachments, .secret-requests {
  padding-left: max(24px, calc((100% - var(--chat-col)) / 2));
  padding-right: max(24px, calc((100% - var(--chat-col)) / 2));
}

/* Model source tags (which connection serves the model) */
.model-tag { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: .68rem; font-weight: 600; vertical-align: middle; color: var(--tag-c); background: color-mix(in srgb, var(--tag-c) 14%, transparent); }
.tag-openrouter { --tag-c: #a78bfa; }
.tag-gemini { --tag-c: #4ade80; }
.tag-openai { --tag-c: #2dd4bf; }
.tag-anthropic { --tag-c: #fb923c; }
.tag-groq { --tag-c: #f472b6; }
.tag-mistral { --tag-c: #fbbf24; }
.composer-model-btn { max-width: min(320px, 60vw); }

/* ===== Three-panel layout: compact bot list | chat | trade terminal ===== */
.main { position: relative; }
@media (min-width: 821px) {
  .sidebar:not(.collapsed) { width: 248px; padding: 18px 12px; }
}
.bot-item { padding: 8px 10px; gap: 10px; font-size: .98rem; }
.bot-item-name { font-size: .98rem; line-height: 1.25; }
.bot-item-snippet { font-size: .78rem; margin-top: 1px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.terminal {
  width: 400px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--border);
}
.terminal.collapsed { display: none; }
.terminal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.terminal-head strong { font-size: 1.02rem; }
.terminal-head-actions { display: flex; gap: 2px; }
.terminal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
.term-empty { padding: 18px 8px; font-size: .85rem; line-height: 1.5; text-align: center; }
.term-empty.small { padding: 4px 8px; text-align: left; }

.term-open-btn { position: absolute; top: 14px; right: 14px; z-index: 5; display: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; width: 38px; height: 38px; padding: 0; align-items: center; justify-content: center; color: var(--muted); }
.term-open-btn:hover { color: var(--text); }
.term-open-btn svg { width: 20px; height: 20px; }
#app-screen:not(.terminal-open) .term-open-btn { display: inline-flex; }

@media (max-width: 1279px) {
  .terminal { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 30; box-shadow: -12px 0 32px rgba(0,0,0,.45); }
}

.tcard { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 13px 14px; margin-bottom: 12px; }
.tcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.tcard-sym { font-size: .74rem; margin-top: 1px; }
.tcard-price { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tcard-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.tcard-time { font-size: .72rem; }
.tcard-note { font-size: .78rem; margin: 8px 0 0; line-height: 1.45; }
.tcard .levels-structure { margin-top: 10px; }
.tcard .levels-list { margin-top: 4px; }
.terminal .chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .7rem; font-weight: 600; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.terminal .chip.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.terminal .chip.warn { color: #f5a524; border-color: color-mix(in srgb, #f5a524 45%, transparent); }

.side-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-left: 4px; vertical-align: middle; }
.side-chip.long { color: var(--success); background: color-mix(in srgb, var(--success) 15%, transparent); }
.side-chip.short { color: var(--danger, #e5534b); background: color-mix(in srgb, var(--danger, #e5534b) 15%, transparent); }
.side-chip.watch { color: var(--muted); background: var(--surface); }
.pos { color: var(--success); }
.neg { color: var(--danger, #e5534b); }

.term-filter { display: flex; gap: 6px; margin-bottom: 10px; }
.term-chip { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); padding: 5px 13px; font-size: .78rem; }
.term-chip.active { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.idea.dismissed { opacity: .55; }
.idea-levels { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 9px; font-size: .84rem; font-variant-numeric: tabular-nums; }
.idea-why { font-size: .83rem; line-height: 1.5; margin: 9px 0 0; color: var(--text); white-space: pre-wrap; }
.idea-actions { display: flex; align-items: center; gap: 6px; margin-top: 11px; }
.idea-btn { display: inline-flex; align-items: center; gap: 5px; background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 5px 12px; font-size: .78rem; }
.idea-btn svg { width: 14px; height: 14px; }
.idea-btn.accept { color: var(--success); }
.idea-btn.icon-only { margin-left: auto; width: 30px; height: 30px; padding: 0; justify-content: center; border: none; background: none; color: var(--muted); }
.idea-btn.icon-only:hover { color: var(--danger, #e5534b); }
.idea-state { font-size: .78rem; }

.term-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.term-tiles .usage-tile strong { font-size: 1.15rem; }
.trade-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--border); font-size: .85rem; font-variant-numeric: tabular-nums; }
.trade-right { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: .8rem; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; margin-top: 11px; }
.stat-cell { display: flex; flex-direction: column; gap: 1px; }
.stat-cell strong { font-size: .95rem; font-variant-numeric: tabular-nums; }
.setup-row { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; font-size: .8rem; font-variant-numeric: tabular-nums; }

.terminal-head-actions .icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border-radius: 10px; }
.terminal-head-actions .icon-btn svg { width: 20px; height: 20px; }
.terminal-head-actions .icon-btn:hover { color: var(--text); background: var(--surface-2); }
.term-open-btn { z-index: 20; }

/* ---- Per-bot panel: width variable, drag handle, blocks ---- */
.terminal { width: var(--terminal-w, 400px); position: relative; }
@media (max-width: 1279px) { .terminal { width: min(var(--terminal-w, 420px), 100vw); } }
.panel-resizer { position: absolute; left: -6px; top: 0; bottom: 0; width: 12px; cursor: col-resize; z-index: 40; touch-action: none; }
.panel-resizer::after { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 2px; background: transparent; transition: background .15s; }
.panel-resizer:hover::after, .panel-resizer:focus-visible::after, body.panel-dragging .panel-resizer::after { background: var(--accent); }
.panel-resizer::before { content: ""; position: absolute; left: 3px; top: 50%; width: 6px; height: 34px; margin-top: -17px; border-radius: 4px; background: var(--border); opacity: 0; transition: opacity .15s; }
.panel-resizer:hover::before, body.panel-dragging .panel-resizer::before { opacity: 1; }
body.panel-dragging { user-select: none; cursor: col-resize; }
body.panel-dragging iframe { pointer-events: none; }
@media (max-width: 560px) { .panel-resizer { display: none; } }

.term-open-btn.has-update::after { content: ""; position: absolute; top: 2px; right: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface-2); }
.pblock { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.pblock-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.pblock-title { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pblock-x { background: transparent; border: none; color: var(--muted); padding: 2px; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; opacity: .55; border-radius: 6px; }
.pblock-x svg { width: 14px; height: 14px; }
.pblock:hover .pblock-x, .pblock-x:focus-visible { opacity: 1; }
.pblock-x:hover { color: var(--danger, #ff6b6b); filter: none; }
.pblock-text { font-size: .9rem; line-height: 1.5; overflow-wrap: anywhere; }
.pblock-text > :first-child { margin-top: 0; }
.pblock-text > :last-child { margin-bottom: 0; }
.pblock .tcard { background: transparent; border: none; padding: 0; margin: 0 0 10px; }
.pblock .tcard:last-child { margin-bottom: 0; }
.pblock .tcard.idea { border-top: 1px solid var(--border); padding-top: 10px; }
.pblock .term-empty.small { padding: 2px 0; }
.pblock .term-tiles { margin: 0; }
.pblock .trade-row.total { border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.tone-good { color: var(--success, #3ddc84); }
.tone-bad { color: var(--danger, #ff6b6b); }
.tone-warn { color: #f5a524; }
.tone-info { color: #6ea8ff; }
.pl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.pl-list li { display: flex; gap: 9px; align-items: flex-start; font-size: .88rem; line-height: 1.4; }
.pl-list li > span:last-child { color: var(--text); overflow-wrap: anywhere; }
.pl-dot { flex: 0 0 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--muted); }
.pl-list li.tone-good .pl-dot { background: var(--success, #3ddc84); }
.pl-list li.tone-bad .pl-dot { background: var(--danger, #ff6b6b); }
.pl-list li.tone-warn .pl-dot { background: #f5a524; }
.pl-list li.tone-info .pl-dot { background: #6ea8ff; }
.ptable-wrap { overflow-x: auto; }
.ptable { border-collapse: collapse; width: 100%; font-size: .82rem; font-variant-numeric: tabular-nums; }
.ptable th { text-align: left; color: var(--muted); font-weight: 600; font-size: .72rem; padding: 4px 8px 6px 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ptable td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); }
.ptable tr:last-child td { border-bottom: none; }
.term-empty-hero { padding: 26px 8px; text-align: center; }
.term-empty-hero ul { text-align: left; display: inline-block; margin: 6px 0 0; padding-left: 18px; font-size: .85rem; line-height: 1.7; }
.terminal-body { overscroll-behavior: contain; }

/* ---- Charts in the panel ---- */
.chart-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: .8rem; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.chart-box { width: 100%; position: relative; }
.chart-note { font-size: .75rem; margin-bottom: 4px; }
.pblock.kind-chart { padding-bottom: 8px; }
.chart-credit { font-size: .7rem; text-align: center; margin: 4px 0 8px; } .chart-credit a { color: inherit; text-decoration: underline; }

/* ---- Collapsible, draggable panel blocks ---- */
.pblock { position: relative; }
.pblock-head { cursor: grab; user-select: none; touch-action: pan-y; margin: -4px -6px 4px; padding: 4px 6px; border-radius: 10px; }
.pblock-head:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.pblock-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pblock-grip { display: inline-flex; width: 14px; height: 14px; color: var(--muted); opacity: .45; flex: none; touch-action: none; margin-right: 2px; }
.pblock-grip svg { width: 14px; height: 14px; }
.pblock-head:hover .pblock-grip { opacity: .9; }
.pblock-chev { display: inline-flex; width: 16px; height: 16px; color: var(--muted); flex: none; transition: transform .18s; }
.pblock-chev svg { width: 16px; height: 16px; }
.pblock.collapsed .pblock-chev { transform: rotate(-90deg); }
.pblock.collapsed .pblock-body, .pblock.collapsed .chart-note { display: none; }
.pblock.collapsed .pblock-head { margin-bottom: -4px; }
.pblock-head { justify-content: flex-start; }
.pblock-head .pblock-x { margin-left: auto; }
.pblock.dragging { z-index: 10; cursor: grabbing; box-shadow: 0 10px 30px rgba(0,0,0,.5); border-color: var(--accent); opacity: .96; }
.pblock.dragging .pblock-head { cursor: grabbing; }
body.panel-reordering { user-select: none; cursor: grabbing; }

/* ---- Notification settings ---- */
.push-opt { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); cursor: pointer; }
.push-opt input { margin-top: 4px; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.push-opt span { display: flex; flex-direction: column; gap: 2px; }
.push-opt small { font-size: .78rem; }
#push-options { margin-top: 4px; }
#push-options #push-test { margin-top: 10px; }

/* Long unbroken text (tokens, URLs, keys) wraps onto several lines instead of scrolling sideways. */
.msg-row { min-width: 0; }
.msg { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.msg.markdown pre, .msg.markdown table { overflow-wrap: normal; word-break: normal; }
