/* Agent Harness Web — dark workspace look, vanilla CSS. */

:root {
  --bg: #0f1115;
  --bg-panel: #161a21;
  --bg-raised: #1d222b;
  --bg-hover: #242a35;
  --border: #2a3140;
  --text: #d7dce4;
  --text-dim: #8b94a3;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --ok: #3fb27f;
  --err: #e5695e;
  --warn: #d9a441;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
  --bar-h: 36px;
  --chat-width: 820px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
.sprite { position: absolute; width: 0; height: 0; }
.icon { width: 15px; height: 15px; vertical-align: -2px; }
.mono { font-family: var(--mono); }

button {
  font: inherit;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
}
button:hover { background: var(--bg-hover); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.1); background: var(--accent); }
button.ghost { background: transparent; color: var(--text-dim); }
button.ghost:hover { color: var(--text); background: var(--bg-hover); }
button.block { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 7px;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn.sm { padding: 3px 5px; }
.icon-btn.sm .icon { width: 13px; height: 13px; }
.icon-btn.danger:hover { color: var(--err); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 9px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.hint { font-weight: 400; font-size: 12px; color: var(--text-dim); }
.badge {
  font-size: 11px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.badge.err { color: var(--err); border-color: var(--err); }

/* ---- views ---- */
/* dvh is what a phone shows between its browser bars; 100vh is the fallback. */
.view { height: 100vh; height: 100dvh; }
/* When the row runs out the file panel gives way: the sidebar leaves room only for its floor. */
.app-view {
  display: flex;
  --sidebar-w: 264px;
  --side: var(--sidebar-w);
  --file-w: clamp(360px, 42vw, 640px);
  --file-room: 0px;
  --chat-min: 320px;
}
.app-view.file-open { --file-room: 275px; --chat-min: 420px; }
.app-view.sidebar-hidden { --side: 0px; }
.app-view.sidebar-hidden .sidebar, .app-view.sidebar-hidden #sidebar-splitter { display: none; }

/* ---- auth ---- */
.auth-view { display: flex; align-items: center; justify-content: center; }
.auth-card {
  width: min(380px, 90vw);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 30px 26px;
}
.auth-brand { font-size: 19px; font-weight: 650; text-align: center; }
.auth-subtitle { text-align: center; color: var(--text-dim); margin: 8px 0 20px; }
.auth-card form, #auth-confirm-wrap { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 12.5px; color: var(--text-dim); }
.form-message { font-size: 12.5px; color: var(--err); margin: 2px 0; }
.auth-card button.primary { margin-top: 10px; padding: 9px; }

/* ---- sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  min-width: 180px;
  max-width: calc(100vw - var(--file-room) - var(--chat-min) - 1px);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  flex: none;
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--bar-h);
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; }
.new-chat { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; font-size: 12.5px; }
.sidebar-foot { display: flex; gap: 2px; padding: 4px 6px; border-top: 1px solid var(--border); flex: none; }
.sidebar-foot button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 6px; border: none; font-size: 12.5px; }

.side-section { display: flex; flex-direction: column; min-height: 60px; }
/* Shrinkable: a dragged or saved height never pushes Files out of the window. */
#sessions-section { flex: 0 1 auto; height: 38%; }
#files-section { flex: 1; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px;
  flex: none;
}
.side-title { font-size: 12px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.4px; }
.side-actions { display: flex; gap: 1px; }
.side-body { flex: 1; overflow-y: auto; margin: 0; padding: 2px 6px 8px; min-height: 0; }

#session-list, #search-results { list-style: none; }
:is(#session-list, #search-results) li {
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
#session-list .archived-head { font-size: 12px; }
.session-search { padding: 0 8px 4px; flex: none; }
.session-search input { width: 100%; padding: 4px 8px; font-size: 12.5px; }
#search-results li { flex-direction: column; align-items: stretch; gap: 2px; }
#search-results li.empty-note:hover { background: none; color: var(--text-dim); }
.search-snippet { font-size: 11.5px; line-height: 1.4; color: var(--text-dim); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; word-break: break-word; }
.search-snippet mark { background: var(--accent-soft); color: var(--text); border-radius: 2px; padding: 0 1px; }
.pinned-mark { width: 12px; height: 12px; flex: none; color: var(--accent); }
:is(#session-list, #search-results) li:hover { background: var(--bg-hover); color: var(--text); }
#session-list li.active { background: var(--accent-soft); color: var(--text); }
:is(#session-list, #search-results) .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#session-list .row-actions { display: none; gap: 0; }
.row-label { display: none; }
@media (hover: hover) {
  .row-more { display: none; }
  #session-list li:hover .row-actions, #session-list li:focus-within .row-actions { display: flex; }
}
@media (hover: none) {
  #session-list li.menu-open .row-actions {
    display: flex; flex-direction: column; position: fixed; left: 8px; bottom: 8px; z-index: 30;
    width: min(284px, calc(100vw - 16px)); padding: 6px;
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
  #session-list .row-actions .icon-btn { display: flex; align-items: center; width: 100%; gap: 12px; padding: 10px; }
  .row-label { display: inline; font-size: 14px; }
}

/* ---- file tree ---- */
.file-tree { font-size: 13px; }
.file-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-dim);
  user-select: none;
  white-space: nowrap;
}
.file-row:hover { background: var(--bg-hover); color: var(--text); }
.file-row.is-selected { background: var(--accent-soft); color: var(--text); }
.file-caret, .tool-caret { width: 11px; height: 11px; flex: none; transition: transform 0.12s; }
.file-row.is-open .file-caret { transform: rotate(90deg); }
.file-caret.is-leaf { visibility: hidden; }
.file-glyph { width: 13px; height: 13px; flex: none; }
.file-row.is-dir .file-glyph { color: var(--warn); }
.file-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.file-size { font-size: 11px; font-family: var(--mono); color: var(--text-dim); }
.empty-note { color: var(--text-dim); font-size: 12px; text-align: center; padding: 12px 0; }

/* ---- splitters ---- */
/* A 1px line with a wider grip laid over its neighbours. */
.splitter-v, .splitter-h { background: var(--border); flex: none; position: relative; touch-action: none; transition: background 0.15s; }
.splitter-v { width: 1px; cursor: col-resize; }
.splitter-h { height: 1px; cursor: row-resize; }
.splitter-v::before, .splitter-h::before { content: ""; position: absolute; z-index: 6; }
.splitter-v::before { top: 0; bottom: 0; left: -3px; right: -3px; }
.splitter-h::before { left: 0; right: 0; top: -3px; bottom: -3px; }
.splitter-v:hover, .splitter-h:hover, .splitter-v.dragging, .splitter-h.dragging { background: var(--accent); }

/* A frame under the pointer would take its release. */
body.dragging iframe { pointer-events: none; }

/* ---- main panes ---- */
.main { flex: 1; min-width: 320px; display: flex; min-height: 0; position: relative; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#file-pane { flex: none; width: var(--file-w); min-width: 274px; max-width: calc(100vw - var(--side) - var(--chat-min) - 2px); background: var(--bg); }
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--bar-h);
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex: none;
}
/* The title yields to the controls but never vanishes: a floor keeps an ellipsis. */
.topbar-title { flex: 1; min-width: 5ch; margin: 0; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#file-title { direction: rtl; text-align: left; } /* the ellipsis goes in front; see setFileTitle */
/* Controls that no longer fit beside the title's floor wrap instead of widening the page. */
.top-controls { display: flex; align-items: center; gap: 4px 6px; flex: 0 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; padding: 3px 0; }
.top-controls button:not(.icon-btn) { padding: 2px 10px; font-size: 12.5px; }
.pane-body { flex: 1; overflow-y: auto; padding: 6px 22px 24px; width: 100%; }
.context-meter { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.cm-bar { position: relative; width: 64px; height: 4px; border-radius: 2px; background: var(--bg-raised); }
.cm-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; background: var(--text-dim); }
.cm-line { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--accent); }
.context-meter.near { color: var(--warn); }
.context-meter.near .cm-fill { background: var(--warn); }

/* ---- chat ---- */
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--text-dim); padding: 0 30px; }
.chat-empty h2 { color: var(--text); margin: 0 0 8px; }

.transcript-row { flex: 1; display: flex; min-height: 0; }
#transcript { flex: 1; min-width: 0; overflow-y: auto; padding: 18px 22px; }
.compact-note { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 12px; color: var(--text-dim); }
.compact-note::before, .compact-note::after { content: ""; flex: 1; border-top: 1px dashed var(--border); }
.msg.flash { animation: msg-flash 1.6s ease-out; border-radius: var(--radius); }
@keyframes msg-flash { from { background: var(--accent-soft); } to { background: transparent; } }
.older-mark { text-align: center; font-size: 12px; color: var(--text-dim); padding-bottom: 14px; }
.msg { max-width: var(--chat-width); margin: 0 auto 20px; }
.msg .who { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.msg.user { margin-bottom: 30px; }
.msg.user:not(.scheduled) .who { display: none; }
.msg.user.scheduled .who { text-align: right; }
/* Sized to its text, on the right; its actions hang below it, out of the text's way. */
.msg.user .bubble {
  position: relative;
  width: fit-content;
  max-width: 85%;
  margin-left: auto;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, 0.25);
  border-radius: 12px;
  padding: 8px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .msg-actions { position: absolute; top: 100%; right: 0; opacity: 0; }
@media (hover: none) { .msg.user .msg-actions { opacity: 0.7; } }
.msg.user:has(.goal-chip) .bubble, .msg.user:has(.attach-list) .bubble { min-width: 40%; }
/* Rendered markdown: chat replies and the file pane's preview alike. */
:is(.msg .text, .file-md) { word-break: break-word; }
:is(.msg .text, .file-md) p { margin: 0 0 8px; }
:is(.msg .text, .file-md) p:last-child { margin-bottom: 0; }
:is(.msg .text, .file-md) pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
}
:is(.msg .text, .file-md) code { font-family: var(--mono); font-size: 0.92em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
:is(.msg .text, .file-md) pre code { background: none; padding: 0; }
:is(.msg .text, .file-md) :is(h1, h2, h3, h4, h5, h6) {
  margin: 14px 0 6px; line-height: 1.3; font-weight: 600;
}
:is(.msg .text, .file-md) > :first-child { margin-top: 0; }
:is(.msg .text, .file-md) h1 { font-size: 1.4em; }
:is(.msg .text, .file-md) h2 { font-size: 1.25em; }
:is(.msg .text, .file-md) h3 { font-size: 1.12em; }
:is(.msg .text, .file-md) :is(h4, h5, h6) { font-size: 1em; }
:is(.msg .text, .file-md) :is(ul, ol) { margin: 0 0 8px; padding-left: 22px; }
:is(.msg .text, .file-md) li { margin: 2px 0; }
:is(.msg .text, .file-md) a { color: var(--accent); text-decoration: underline; }
:is(.msg .text, .file-md) blockquote {
  margin: 0 0 8px; padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border); color: var(--text-dim);
}
:is(.msg .text, .file-md) hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
/* Wide tables scroll inside the bubble instead of stretching it. The
   bubble's break-word would let columns shrink by splitting numbers. */
:is(.msg .text, .file-md) .md-table { overflow-x: auto; margin: 0 0 8px; word-break: normal; }
:is(.msg .text, .file-md) table { border-collapse: collapse; font-size: 0.94em; }
:is(.msg .text, .file-md) :is(th, td) {
  border: 1px solid var(--border); padding: 4px 9px; text-align: left;
}
:is(.msg .text, .file-md) th { background: var(--bg); font-weight: 600; white-space: nowrap; }
.msg.error .bubble { border: 1px solid var(--err); border-radius: var(--radius); padding: 10px 14px; color: var(--err); }

.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.attach-list .chip, #attach-chips .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-family: var(--mono);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  overflow-wrap: anywhere;
}
.attach-list img { max-width: 220px; height: 160px; object-fit: scale-down; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; display: block; }

details.tool {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-size: 12.5px;
}
details.tool summary { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 5px 10px; font-family: var(--mono); font-size: 12px; color: var(--text-dim); user-select: none; list-style: none; }
details.tool summary::-webkit-details-marker { display: none; }
details.tool .tool-name { color: var(--ok); font-weight: 600; flex: none; }
details.tool.err .tool-name { color: var(--err); }
details.tool.warn .tool-name, details.tool.warn .tool-state { color: var(--warn); }
details.tool.err { border-color: rgba(229, 105, 94, 0.45); }
.tool-head { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-state { flex: none; }
details.tool[open] .tool-caret { transform: rotate(90deg); }
details.tool .tool-body { padding: 0 10px 8px; }
.tool-args { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 10px; margin: 2px 0 0; font-family: var(--mono); font-size: 12px; }
.tool-args dt { color: var(--text-dim); }
.tool-args dd { margin: 0; word-break: break-word; white-space: pre-wrap; }
.tool-diff span { display: block; min-height: 1.4em; }
.tool-diff .add { color: var(--ok); background: rgba(63, 178, 127, 0.12); }
.tool-diff .del { color: var(--err); background: rgba(229, 105, 94, 0.12); }
details.tool pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  max-height: 260px;
  overflow-y: auto;
}

/* The right side also clears the minimap, so the card lines up with the chat column. */
#composer { padding: 6px 58px 12px 22px; flex: none; }
.composer-card {
  max-width: var(--chat-width);
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.composer-card:focus-within { border-color: var(--accent); }
.composer-row { --line-h: 36px; display: flex; gap: 8px; align-items: flex-end; padding: 6px 6px 0; }
/* As tall as one line of #input: centred beside it, and still at the bottom as it grows. */
.composer-row button { height: var(--line-h); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 2px 8px; padding: 2px 6px 4px; }
.composer-tools, .composer-model { display: flex; align-items: center; gap: 4px; min-width: 0; }
.composer-bar select { background: transparent; border-color: transparent; color: var(--text-dim); font-size: 12.5px; padding: 2px 4px; }
.composer-bar select:hover { color: var(--text); background: var(--bg-hover); }
#quick-model { max-width: min(280px, 40vw); }
#quick-thinking { flex: none; }
#input { flex: 1; resize: none; min-height: var(--line-h); max-height: 180px; background: transparent; border-color: transparent; }
#attach-chips { max-width: var(--chat-width); margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.goal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--chat-width);
  margin: 0 auto 6px;
  padding-left: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
}
.goal-row:focus-within { border-color: var(--accent); }
.goal-row label { flex: none; color: var(--accent); }
.goal-row input { flex: 1; min-width: 0; border: none; background: transparent; padding-left: 0; font-size: inherit; }
#btn-goal[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); }
.goal-chip, .goal-note, .end-note { margin-top: 6px; font-size: 12px; color: var(--text-dim); }
#attach-chips .chip button { background: none; border: none; color: var(--text-dim); padding: 0; cursor: pointer; }
.run-status { max-width: var(--chat-width); margin: 6px auto 0; font-size: 12px; color: var(--text-dim); }
.run-status .spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- minimap ---- */
/* Keeps its width while idle: the chat column does not jump when it first overflows. */
.minimap { width: 36px; flex: none; position: relative; cursor: pointer; user-select: none; touch-action: none; border-left: 1px solid var(--border); background: var(--bg-panel); }
.mm-idle { visibility: hidden; }
.mm-line, .mm-earlier { position: absolute; left: 50%; width: 1px; transform: translateX(-50%); }
.mm-line { top: 12px; background: var(--border); }
.mm-earlier { top: 0; height: 12px; background: repeating-linear-gradient(to bottom, var(--text-dim) 0 2px, transparent 2px 4px); }
.mm-node {
  position: absolute; left: 50%; width: 8px; height: 8px; border-radius: 2px;
  transform: translate(-50%, -50%); pointer-events: none;
  background: rgba(139, 148, 163, 0.16); border: 1.5px solid rgba(139, 148, 163, 0.58);
  transition: transform 0.1s, background 0.1s;
}
.mm-node.active { background: rgba(139, 148, 163, 0.42); border-color: rgba(139, 148, 163, 0.95); box-shadow: 0 0 0 2px var(--bg-panel); }
.mm-node.near { transform: translate(-50%, -50%) scale(1.25); }
.mm-lock { position: absolute; left: 3px; bottom: 6px; width: 30px; height: 30px; padding: 0; display: grid; place-items: center; background: transparent; border: none; border-radius: 6px; color: var(--text-dim); }
.mm-lock:hover { color: var(--text); background: var(--bg-hover); }
.mm-lock[aria-pressed="true"] { color: var(--accent); }
.mm-preview {
  position: absolute; top: 0; bottom: 0; right: 100%; z-index: 8; width: 320px;
  overflow: hidden auto; overscroll-behavior: contain; cursor: default; user-select: text;
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: -10px 0 26px rgba(0, 0, 0, 0.35);
}
:where(.mm-preview) button { display: block; width: 100%; padding: 0; background: none; border: none; border-radius: 0; text-align: left; }
:where(.mm-preview) button:hover { background: var(--bg-hover); }
.mm-more { padding: 7px 10px; font-size: 11px; color: var(--text-dim); text-align: center; border-bottom: 1px dashed var(--border); }
.mm-turn { display: grid; grid-template-columns: 34px minmax(0, 1fr); border-bottom: 1px solid var(--border); }
.mm-turn[data-located] { background: var(--bg-hover); box-shadow: inset 2px 0 0 var(--text-dim); }
.mm-num { display: flex; flex-direction: column; align-items: center; gap: 1px; padding-top: 7px; color: var(--text-dim); font-family: var(--mono); font-size: 10px; line-height: 13px; }
.mm-tools { min-width: 15px; padding: 0 3px; border-radius: 999px; background: var(--bg-raised); text-align: center; font-size: 9px; line-height: 12px; }
.mm-body { min-width: 0; }
.mm-user { padding: 7px 10px 7px 0; font-weight: 500; line-height: 18px; overflow-wrap: anywhere; white-space: pre-wrap; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }
.mm-answer { position: relative; border-top: 1px solid var(--border); padding: 3px 0; }
.mm-a { position: absolute; top: 3px; left: -34px; width: 34px; text-align: center; font-size: 11px; color: var(--text-dim); }
.mm-heading, .mm-para { padding: 2px 10px 2px 0; font-size: 12.5px; color: var(--text-dim); overflow: hidden; }
.mm-heading { white-space: nowrap; text-overflow: ellipsis; }
.mm-heading[data-level="2"] { padding-left: 10px; }
.mm-heading[data-level="3"] { padding-left: 20px; }
.mm-para { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

/* ---- file editor ---- */
.file-editor {
  flex: 1;
  margin: 0;
  border: none;
  border-radius: 0;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 16px 20px;
  resize: none;
}
/* Edit / Preview, for Markdown and HTML files. */
.file-views { display: inline-flex; gap: 2px; }
.file-views button[aria-pressed="true"] { background: var(--accent-soft); border-color: rgba(79, 140, 255, 0.25); color: var(--text); }
/* The side padding centres an 860px column and keeps the scrollbar at the pane's edge. */
.file-md { flex: 1; overflow: auto; padding: 16px max(20px, calc((100% - 860px) / 2)); }
/* Rendered HTML and PDFs bring their own look: a page is drawn on white. */
.file-frame { flex: 1; width: 100%; border: 0; background: #fff; }
/* What a file is, for one the editor cannot open (binary, too large). */
.file-info { flex: 1; padding: 22px 26px; overflow: auto; }
.file-info dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 12px 0 18px; }
.file-info dt { color: var(--text-dim); }
.file-info dd { margin: 0; font-family: var(--mono); }
.file-info button { display: inline-flex; align-items: center; gap: 6px; }

/* ---- settings ---- */
.settings-dialog {
  width: min(860px, 94vw);
  height: min(86vh, 900px);
  height: min(86dvh, 900px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.pane-body h3 { margin: 20px 0 8px; font-size: 13.5px; }
.form-grid, .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid label, .p-label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-dim); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid label.check { flex-direction: row; align-items: center; }
.panel-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
#settings-msg, #password-msg { font-size: 12.5px; color: var(--text-dim); }
#settings-msg.ok, #password-msg.ok { color: var(--ok); }
#settings-msg.err, #password-msg.err { color: var(--err); }

/* ---- overlays / toast ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
#preview-overlay img { max-width: 92vw; max-height: 90vh; border-radius: 8px; }
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 16px;
  z-index: 40;
  max-width: 70vw;
}
#toast.err { border-color: var(--err); color: var(--err); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }
::-webkit-scrollbar-track { background: transparent; }

/* ---- provider catalog cards ---- */
.provider-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 10px 12px 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.provider-head { display: flex; align-items: center; justify-content: space-between; }


/* ---- instant CSS tooltips (data-tip) ----
   Native title tooltips are slow and unreliable on disabled buttons;
   these render immediately and work for disabled controls too. A tap
   leaves :hover set, so touch screens get none. */
[data-tip] { position: relative; }
@media (hover: hover) {
  [data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 12px;
    font-family: inherit;
    /* Wraps past a line's worth: anchored right, a long one-liner runs off the pane's left edge. */
    width: max-content;
    max-width: min(60ch, 80vw);
    z-index: 60;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
  [data-tip].tip-left:hover::after { right: auto; left: 0; }
  /* The composer sits at the window's bottom edge: below it is off-screen. */
  #composer [data-tip]:hover::after { top: auto; bottom: calc(100% + 6px); }
}

/* ---- responsive / mobile ---- */
.only-narrow, .only-overlay { display: none; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.55);
  z-index: 19;
}

/* Too narrow to share the row: the file panel covers the chat. Must match splitQuery in app.js. */
@media (max-width: 959px) {
  .only-overlay { display: inline-block; }
  .app-view.file-open { --file-room: 0px; --chat-min: 320px; }
  #file-splitter { display: none; }
  #file-pane { position: absolute; inset: 0; width: auto; max-width: none; z-index: 5; }
}

/* Phones upright, and phones on their side (touch and short). Must match narrowQuery in app.js. */
@media (max-width: 768px), (pointer: coarse) and (max-height: 500px) {
  :root { --bar-h: 44px; }
  .only-narrow { display: inline-block; }
  .app-view.sidebar-hidden .sidebar { display: flex; }
  /* Off-canvas sidebar: overlays the content, opened from the topbar. */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    width: min(300px, 84vw);
    max-width: none;
    transform: translateX(-105%);
    transition: transform 0.18s ease-out;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .splitter-v, .minimap, .cm-bar { display: none; }
  .main { min-width: 0; }
  #quick-model { max-width: 34vw; }
  #transcript { padding: 12px 10px; }
  #composer { padding: 6px 10px 8px; }
  .pane-body { padding: 4px 12px 20px; }
  .form-grid, .two-col { grid-template-columns: 1fr; }
  .attach-list img { max-width: 100%; }
  .settings-dialog { width: 100%; height: 100%; border: none; border-radius: 0; }
  /* Narrow layouts get a fatter grip for the sessions/files split. */
  .splitter-h::before { top: -8px; bottom: -8px; }
}

/* Structured model rows inside a provider card. */
.model-row {
  display: grid;
  grid-template-columns: 1fr 120px 80px auto 32px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.p-add-model { margin-top: 2px; }

/* Five columns do not fit a phone: the name takes the first line, the two
   numbers and the switches share the second. This has to sit after the rule
   above — same specificity, so position decides. */
@media (max-width: 768px) {
  .model-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto 32px; }
  .model-row .m-name { grid-column: 1 / -1; }
  .model-row input { min-width: 0; }
}

/* iOS zooms the page into a text field under 16px on focus and stays zoomed.
   After the rules above: same specificity, so position decides. */
@media (pointer: coarse) {
  input, select, textarea, .goal-row input, .file-editor, .composer-bar select, .session-search input { font-size: 16px; }
  #input { line-height: 22px; } /* one line stays var(--line-h) tall */
  /* Fingertip-sized; the six Files buttons fit the sidebar at 40, not at 44. */
  .icon-btn { min-width: 36px; min-height: 36px; }
}

/* Text the agent never received (a stop or a refusal): kept on screen, dimmed. */
.msg .text.undelivered { opacity: 0.6; }
.undelivered-note { font-size: 12px; color: var(--text-dim); margin: -4px 0 6px; }
#btn-send.danger { background: var(--err); border-color: var(--err); }

/* copy/fork icon actions: at the end of an answer's bubble, below a user's. */
.msg-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  margin-top: 4px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
/* What the turn cost, opposite the buttons. */
.msg-cost {
  margin-right: auto;
  font-size: 0.82em;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Unread marker for sessions updated since they were last looked at. */
.unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.msg.scheduled .who { color: var(--accent); }
