#selfIterButtons { display: flex; flex-direction: column; gap: 8px; padding: 8px 12px 12px 8px; }
#selfIterButtons .suggestion-btn, #selfIterButtons button { width: 100%; justify-content: flex-start; }
#selfIterPanel .self-iter-actions { padding-top: 0; }
#selfIterPanel { padding-right: 12px; }

/* Subtle glow similar to refresh, at ~50% strength */
.glow-lite { position: relative; }
.glow-lite::after { content: ""; position: absolute; inset: -4px; border-radius: 10px; background: radial-gradient(closest-side, rgba(20,209,197,.35), rgba(20,209,197,0)); filter: blur(8px); opacity: .5; pointer-events: none; }
.app-header { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: rgba(15,17,21,0.6); }
.app-header .brand { display: flex; align-items: center; gap: 8px; }
.app-header .header-extras { margin-left: auto; }
.app-header .toggle-caret.rightmost { margin-left: 8px; }
.app-header.collapsed .header-extras { display: none; }
.app-header.collapsed .more-hint { display: inline-block !important; opacity: .7; }
.app-header { display: flex; align-items: center; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: rgba(15,17,21,0.7); position: sticky; top: 0; z-index: 100; overflow-x: hidden; }
.app-header { scrollbar-width: none; }
.app-header::-webkit-scrollbar { width: 0; height: 0; }
.app-header .brand { display: flex; align-items: center; gap: 8px; }
.app-header .controls { display: flex; align-items: center; gap: 10px; overflow-x: hidden; overflow-y: visible; flex-wrap: nowrap; flex: 1 1 auto; max-width: 100%; }
.app-header .controls { scrollbar-width: none; }
.app-header .controls::-webkit-scrollbar { width: 0; height: 0; }
.v-sep { width: 1px; height: 28px; background: #23283a; margin: 0 8px; align-self: center; }
.app-header .controls > * { flex: 0 0 auto; }
.control-group { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }

/* Header button unification */
.app-header .extras-body { display: flex; align-items: center; gap: 6px; }
.app-header .btn,
.app-header .btn.btn-secondary,
.app-header .btn.btn-primary { 
  padding: 6px 12px; 
  border-radius: 10px; 
  border: 1px solid rgba(255,255,255,.08); 
  background: linear-gradient(180deg, rgba(32,38,54,.9), rgba(23,28,41,.9));
  color: #e7ecf3; 
  font-weight: 600;
}
.app-header .btn.btn-primary { 
  background: linear-gradient(180deg, rgba(27,200,189,.20), rgba(18,120,150,.18));
  border-color: rgba(20,209,197,.35);
}
.app-header .btn:hover { filter: brightness(1.08); }
.app-header .btn:active { transform: translateY(1px); }

/* Apply subtle glow to these primary controls */
#openModelsPanel.glow-lite,
#toggleScaffold.glow-lite,
#openFormsBtn.glow-lite { position: relative; }

/* Suggestions-style pill (blue lining, lettering, reduced glow) */
/* Unified pill buttons matching Suggestions refresh */
.btn-pill { position: relative; display: inline-flex; align-items: center; justify-content: center; height: 32px; line-height: 30px; padding: 0 12px; border-radius: 14px; font-weight: 700; letter-spacing: .2px; background: transparent !important; }
.btn-pill--blue { background: transparent !important; color: #00d3ff; border: 2px solid #00d3ff; box-shadow: none; }
.btn-pill--blue:hover { filter: brightness(1.08); border-color: #37e6ff; }
.btn-pill--blue::after { content: none; }

/* Disabled button styling for Loop button when DevLoops are disabled */
.btn-pill:disabled, .btn-pill.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-pill--red { background: transparent !important; color: #ff5252; border: 2px solid #ff5252; box-shadow: none; }
.btn-pill--red:hover { filter: brightness(1.06); border-color: #ff6b6b; background: rgba(255, 82, 82, 0.12); }
.btn-pill--red:active { background: rgba(255, 82, 82, 0.18); }
/* Hard enforce persistent red outline for the header Stop button */
.app-header #killSwitchBtn { border: 2px solid #ff5252 !important; color: #ff5252 !important; background: transparent !important; }
.app-header #killSwitchBtn:hover { background: rgba(255, 82, 82, 0.12) !important; }
.app-header #killSwitchBtn:active { background: rgba(255, 82, 82, 0.18) !important; }
.btn-pill--red::after { content: none; }
.control-group select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.control-group.toggle { min-width: 0; display: inline-flex; align-items: center; gap: 6px; }
.control-group.toggle span { white-space: nowrap; }
/* Smaller scaffold toggle and blue accent */
#scaffoldToggle { transform: scale(0.85); transform-origin: left center; accent-color: var(--brand); }
#scaffoldToggle + label, label[for="scaffoldToggle"] { font-size: 12px; }
.control-group.toggle input[type="checkbox"] { accent-color: var(--brand); }
/* Basic modern, lovable UI */
:root {
  --bg: #0f1115;
  --panel: #151823;
  --muted: #aab2c0;
  --text: #e7ecf3;
  --brand: #00d3ff; /* unified cyan */
  --brand-2: #4de1ff; /* lighter cyan */
  --accent: #00d3ff;
  --border: #23283a;
  /* Workspace default widths */
  --w-left: 260px;
  --w-editor: 420px;
  --w-chat: 420px;
  --w-preview: 50vw;
  --header-h: 56px;
}

* { box-sizing: border-box; }
/* overflow:clip (not hidden) so the root can NEVER be programmatically
   scrolled. With overflow:hidden the browser could still set scrollTop when
   an element inside the preview iframe receives focus, pushing the sticky
   header out of view. clip removes the scroll container entirely. */
html, body { height: 100%; overflow: clip; }
/* Body is a flex column: header (auto height) + workspace (fills the rest).
   This makes the layout self-correcting — if the header is ever hidden or its
   measured height drifts, the workspace still fills the viewport with no
   leftover blank gap at the bottom. */
body { display: flex; flex-direction: column; }

/* Global zoom-out (20%) for the entire app UI */
html {
  transform: scale(0.8);
  transform-origin: top left;
  width: 125%;
  height: 125%;
}

/* Mobile Mode: undo global zoom-out for readability on small screens */
html.mobile-mode {
  transform: none;
  transform-origin: top left;
  width: 100%;
  height: 100%;
}
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 80% -20%, #1a1f35, transparent),
              radial-gradient(800px 500px at -20% 120%, #192f34, transparent),
              var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica Neue, Arial;
}

.app-header {
  position: sticky; top: 0; z-index: 200;
  display: flex; align-items: center; justify-content: flex-start;
  padding: 12px 16px;
  background: rgba(15, 17, 21, 0.7);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-link { text-decoration: none; color: inherit; cursor: pointer; }
.brand-link:hover { filter: brightness(1.06); }
.brand .logo { font-size: 22px; }
.logo-img { height: 20px; width: auto; object-fit: contain; aspect-ratio: auto; filter: none; image-rendering: auto; }
/* Increase brand title size by ~20% */
.brand h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: 0.3px; white-space: nowrap; }
/* Blue glow for brand title */
.glow-text { color: var(--text); text-shadow: 0 0 10px rgba(0,211,255,.45), 0 0 20px rgba(0,211,255,.25); }

.controls { position: relative; display: flex; align-items: center; gap: 10px; overflow-x: hidden; overflow-y: visible; min-width: 0; flex-wrap: nowrap; white-space: nowrap; }
.controls { scrollbar-width: none; }
.controls::-webkit-scrollbar { width: 0; height: 0; }
.control-group { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.control-group select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

/* Fancy toggle */
.toggle { position: relative; }
.toggle input[type="checkbox"] { appearance: none; width: 44px; height: 24px; border-radius: 999px; position: relative; outline: none; cursor: pointer; transition: background .2s; }
.toggle input[type="checkbox"] { background: #2a3147; }
.toggle input[type="checkbox"]:checked { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
/* Clean switch, no overlaying slider */
.toggle .toggle-slider { display: none; }
.toggle input[type="checkbox"] { appearance: none; -webkit-appearance: none; width: 48px; height: 26px; border-radius: 999px; border: 1px solid var(--border); background: #2a3147; position: relative; cursor: pointer; outline: none; }
.toggle input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform .18s ease; }
.toggle input[type="checkbox"]:checked { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.toggle input[type="checkbox"]:checked::after { transform: translateX(22px); }
/* Force scaffolding toggle to blue even if other rules linger */
#scaffoldToggle:checked { background: linear-gradient(135deg, var(--brand), var(--brand-2)) !important; }
#scaffoldToggle:checked::after { transform: translateX(22px); }

.btn { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: white; border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn-primary { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; border: none; }
.btn-danger { background: #b30000; color: #fff; border: 1px solid #8a0000; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.icon-btn { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; line-height: 1; }
.icon-btn svg { display: block; }
.icon-btn:hover { background: rgba(255,255,255,0.06); }
.icon-btn.is-busy { opacity: .6; cursor: progress; pointer-events: none; }
/* ---- Presets modal ---- */
.preset-section { margin: 14px 0; }
.preset-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.preset-card { position: relative; border: 1px solid var(--border); border-radius: 10px; padding: 8px; cursor: pointer; background: rgba(255,255,255,0.02); transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease; text-align: left; }
.preset-card:hover { border-color: rgba(0,211,255,0.45); transform: translateY(-1px); }
.preset-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(20,209,197,0.35), 0 4px 16px rgba(0,211,255,0.12); }
.preset-card.selected::after { content: "\2713"; position: absolute; top: 6px; right: 8px; color: var(--accent); font-weight: 800; font-size: 13px; }
.preset-swatch { height: 38px; border-radius: 7px; margin-bottom: 7px; border: 1px solid rgba(255,255,255,0.08); overflow: hidden; display: flex; }
.preset-swatch span { flex: 1; height: 100%; }
.preset-card .preset-name { font-size: 12px; font-weight: 600; color: var(--text); }
.preset-card .preset-sub { font-size: 10px; color: var(--muted); }
.preset-layout-glyph { height: 38px; border-radius: 7px; margin-bottom: 7px; border: 1px solid rgba(255,255,255,0.08); display: flex; gap: 3px; padding: 5px; background: rgba(255,255,255,0.03); }
.preset-layout-glyph i { display: block; background: rgba(160,185,255,0.35); border-radius: 2px; }
/* Tooltips managed by JS (#tooltip) so they don't get cut off and appear below */
.has-tip { position: relative; }
/* spacer to right-align end controls */
.flex-spacer { flex: 1 1 auto; }

/* Explorer title inline rename */
.pane .pane-header .title-edit { opacity: 0; transition: opacity .15s ease; }
.pane .pane-header:hover .title-edit { opacity: 1; }
.mini-input { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.pane-header .mini-input { flex: 1 1 auto; min-width: 0; display: inline-block; width: 100%; height: 28px; text-align: center; padding-right: 34px; }
#projectTitleInline { display: inline-block; width: 100%; height: 28px; line-height: 26px; }

/* Place the edit/confirm buttons inside the input on the far right */
#projectTitleEdit, #projectTitleConfirm {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  margin-left: 0 !important; /* override inline */
}
/* Pencil icon: icon-only, no background, no border; reveal on hover */
#projectTitleEdit { background: transparent !important; border: none !important; box-shadow: none !important; opacity: 0; }
.pane .pane-header:hover #projectTitleEdit { opacity: 1; }
/* When confirming, hide edit; when not editing, hide confirm (handled by classes too) */
.title-confirm.hidden { display: none !important; }
.title-edit.hidden { display: none !important; }
.pane-header .mini-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(20,209,197,.2); }

/* Force visibility when entering editing mode */
.pane .pane-header.editing #projectTitleInline { display: inline-block !important; }
.pane .pane-header.editing #projectName { display: none !important; }
.hidden { display: none !important; }

/* Automata badge on user bubbles */
.auto-badge { color: var(--brand); margin-left: 8px; float: right; }
/* App Preview: no white background, match dark theme */
#previewFrame { background: transparent !important; }
.next-step-item { background: rgba(20,209,197,.12); border-radius: 6px; padding: 4px 6px; cursor: pointer; }
.next-step-item:hover { background: rgba(20,209,197,.2); }
.models-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.model-row { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.model-row > .control-group { display: flex; align-items: center; gap: 6px; }
.model-row .row-title { min-width: 150px; font-weight: 700; color: var(--text); margin-right: 6px; display: flex; align-items: center; gap: 8px; }
.model-row .control-group span { font-weight: 600; color: var(--muted, #9aa4af); }
/* Master row drives every text subsystem from one selection. */
.model-row--master { border: 1px solid rgba(20,209,197,.35); border-radius: 8px; padding: 8px 10px; background: rgba(20,209,197,.06); }
.model-row--master .row-title { color: var(--brand); gap: 6px; }
.model-row--master .master-check { width: 15px; height: 15px; margin: 0; accent-color: var(--brand); cursor: pointer; flex: 0 0 auto; }
.model-row--inactive { opacity: .55; }
.model-row--inactive .row-title { color: var(--muted, #9aa4af); }
.model-row--master.model-row--inactive { background: transparent; border-color: rgba(154,164,175,.25); }
/* Rows locked by Master stay readable but not editable. */
.model-row select:disabled { opacity: .7; cursor: not-allowed; }
#modelsModal .modal-content { width: 960px; max-width: 92vw; }
#modelsModal .modal-header { padding: 10px 14px; }
#modelsModal .modal-body { padding: 12px 14px; }
#modelsModal .modal-footer { padding: 10px 14px; }
/* DevLoop modal subheader & compact actions */
#formModal .modal-actions.compact { gap: 6px; }
#formModal .modal-subheader { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--border); }
#formModal .modal-subheader .sub-left { display: flex; gap: 6px; align-items: center; }
#formModal .modal-subheader .sub-right { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.tooltip { position: fixed; background: rgba(0,0,0,.92); color: #fff; font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; z-index: 9999; transform: translate(-50%, 6px); box-shadow: 0 4px 18px rgba(0,0,0,.4); }
.tooltip.hidden { display: none; }

/* Self Iteration panel layout tweaks */
#selfIterPanel { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 56px; column-gap: 12px; row-gap: 8px; align-items: start; }
#selfIterPanel .self-iter-resize { grid-column: 1 / -1; }
#selfIterPanel #selfIterButtons { grid-column: 1 / 2; grid-row: 2; padding-right: 4px; min-width: 0; }
#selfIterPanel .refresh-fab { grid-column: 2 / 3; grid-row: 2; justify-self: end; align-self: center; position: static !important; right: auto !important; top: auto !important; transform: none !important; margin: 0; }
#selfIterPanel .self-iter-actions { grid-column: 1 / -1; grid-row: 3; display: flex; justify-content: center; align-items: center; padding: 6px 0 4px; }

/* Ensure the refresh button is always clickable (not covered by resize handle or other layers) */
#selfIterPanel { z-index: 1; }
#selfIterPanel .self-iter-resize { z-index: 1; position: relative; }
#selfIterPanel #selfIterButtons { z-index: 2; position: relative; }
#selfIterPanel .refresh-fab { z-index: 5; position: relative; pointer-events: auto; touch-action: manipulation; }

.workspace { flex: 1 1 auto; min-height: 0; height: auto; display: grid; grid-template-columns: var(--w-left, 260px) 6px 1fr 6px var(--w-chat, 420px); grid-template-rows: 1fr; }
.pane { display: flex; flex-direction: column; min-width: 0; overflow: hidden; border-right: 1px solid var(--border); background: rgba(21,24,35,0.65); backdrop-filter: blur(6px); }
.pane.collapsed { visibility: hidden; pointer-events: none; border-right: 0 !important; background: transparent; backdrop-filter: none; }
#explorerPane.collapsed { border-right: 0 !important; }
#chatPane.collapsed { border-right: 0 !important; }
.pane-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: rgba(15,17,21,0.6); flex-shrink: 0; }
/* Explorer header (project + version) equal spacing: 6px gap and 6px padding-bottom for the separator */
.pane-header.column { flex-direction: column; align-items: stretch; gap: 6px; padding: 15px 10px 6px; }
/* Project title row: no extra padding/border; no margin so gap controls spacing */
.pane-header.column > .pane-header { border-bottom: none; padding: 0; margin: 0; position: relative; }
.explorer-head-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.explorer-title-input { flex: 1; min-width: 0; background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-weight: 600; }
.explorer-title-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(20,209,197,.2); }
.small-id { font-size: 12px; opacity: .7; }
.explorer-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; align-items: center; width: 100%; padding-top: 15px; padding-bottom: 15px; margin-top: 0; }
.pane-actions { display: flex; align-items: center; gap: 6px; }
label.icon-btn { cursor: pointer; }
.explorer { overflow-y: auto; }
.explorer-tree { padding: 15px 8px; font-size: 13px; }
.explorer-tree .entry { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 6px; cursor: pointer; }
.explorer-tree .entry .actions { margin-left: auto; display: none; align-items: center; gap: 4px; }
.explorer-tree .entry:hover .actions { display: inline-flex; }
.explorer-tree .entry .icon-xxs { width: 18px; height: 18px; display: inline-grid; place-items: center; font-size: 10px; line-height: 1; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.explorer-tree .entry .icon-xxs:hover { color: var(--text); border-color: var(--accent); }
.explorer-tree .entry:hover { background: rgba(255,255,255,0.04); }
.explorer-tree .children { margin-left: 16px; }
.explorer-tree .entry.selected { background: rgba(20,209,197,0.15); border: 1px solid rgba(20,209,197,0.25); }
.explorer-tree .drop-target { outline: 2px dashed rgba(20,209,197,0.45); outline-offset: 2px; }
.explorer-tree .inline-editor { display: inline-block; background: transparent; color: var(--text); border: 1px dashed var(--accent); border-radius: 6px; padding: 2px 6px; }
.version-row { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 0; }
/* Subtle left/right version arrows */
#prevVersion.icon-btn.mini, #nextVersion.icon-btn.mini {
  border: none;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
#prevVersion.icon-btn.mini:hover, #nextVersion.icon-btn.mini:hover {
  color: var(--text);
  background: transparent;
}

/* Explorer tabs */
.tabs-explorer { display: flex; gap: 6px; justify-content: center; margin-top: 15px; padding-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 6px; flex-shrink: 0; }
.tabs-explorer .tab { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 3px 8px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tabs-explorer .tab.active { border-color: var(--accent); color: var(--text); background: transparent; }

/* Center title undo/redo minimal buttons */
.tab-center .icon-btn { border: none; background: transparent; box-shadow: none; color: var(--muted); }
.tab-center .icon-btn:hover { color: var(--text); background: transparent; }
.tab-center { gap: 8px; }
.tool-results { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 6px; font-size: 12px; }
.tool-results .tool-result { margin: 2px 0; }
.tool-results .tool-result.ok { color: #19c37d; }
.tool-results .tool-result.err { color: #ff6b6b; }
.tool-results .tool-controls { margin-top: 6px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
/* Collapsible tool-call list: summary always visible, list hidden by default */
.tool-results .tool-summary { color: var(--muted); padding: 2px 0; }
.tool-results .tool-summary .tc-count { font-weight: 600; }
.tool-results .tool-summary .meta { margin-left: 8px; font-weight: 400; opacity: .8; }
.tool-results .tool-list.collapsed { display: none; }
.tool-results .tool-toggle { margin-left: auto; }
/* Collapsible long system error lines */
.sysline .sys-toggle { margin-left: 6px; vertical-align: baseline; }
.sysline .sys-full { display: block; white-space: pre-wrap; margin-top: 4px; font-size: 11px; opacity: .85; max-height: 240px; overflow: auto; padding: 6px 8px; border-left: 2px solid var(--border); }
/* The [hidden] attribute must win over the display:block above so messages
   start COLLAPSED and the Expand/Collapse toggle actually shows/hides them. */
.sysline .sys-full[hidden] { display: none; }

/* Tool result file path links (explicit user action to open editor) */
.tool-path-link { color: var(--brand); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.tool-path-link:hover { color: var(--brand-2); }
.tool-path-link:focus { outline: 2px solid rgba(0,211,255,.35); outline-offset: 2px; border-radius: 4px; }

/* Chat run indicator (left side above prompt) */
.chat-run-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; padding: 0 2px; }
.chat-run-row.hidden { display: none; }
.chat-run-avatar {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: rgba(0,211,255,1);
  background: rgba(0,211,255,.10);
  border: 1px solid rgba(0,211,255,.20);
}
.chat-run-avatar.tooling {
  box-shadow:
    0 0 0 1px rgba(0,211,255,.22),
    0 0 10px rgba(0,211,255,.18);
}
.chat-run-avatar.tooling .chat-run-indicator {
  filter: drop-shadow(0 0 6px rgba(0,211,255,.35));
}

.chat-run-indicator {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  flex-shrink: 0;
  position: relative;
  display: inline-block;
}

/* Unique, clean white spinner: conic-gradient ring + subtle pulse */
.chat-run-indicator.running::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: conic-gradient(from 0deg,
    rgba(255,255,255,1),
    rgba(255,255,255,.35),
    rgba(255,255,255,.12),
    rgba(255,255,255,1)
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 1px));
  animation: chatSpin 0.9s linear infinite;
}
.chat-run-indicator.running::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.22), rgba(0,0,0,0) 62%);
  animation: chatPulse 1.2s ease-in-out infinite;
}

/* Done: crisp white check */
.chat-run-indicator.done::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  border: 1.5px solid rgba(255,255,255,.45);
}
.chat-run-indicator.done::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255,255,255,1);
  font-weight: 900;
  font-size: 12px;
  line-height: 1;
  text-shadow: 0 0 1px rgba(255,255,255,0.8);
}

@keyframes chatSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes chatPulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.mini-btn { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 11px; }
.mini-btn:hover { color: var(--text); border-color: var(--accent); }
.editor { min-width: 0; }
.code-area { flex: 1; width: 100%; background: #0f1320; color: #e7ecf3; border: none; outline: none; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 13px; padding: 12px; }
.chat-pane { display: flex; flex-direction: column; min-height: 0; }
/* Make the + button in chat header green-outlined */
#newChatBtn.icon-btn { color: #19c37d; border-color: #19c37d; }
#newChatBtn.icon-btn:hover { background: rgba(25,195,125,0.12); }
.thinking { padding: 6px 8px; border-bottom: 1px solid var(--border); background: #0f1320; font-size: 10px; color: var(--muted); }
.thinking svg { width: 12px; height: 12px; }
.thinking.hidden { display: none; }
.chat { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.self-iter { position: relative; border-top: 1px dashed var(--border); background: rgba(15,17,21,0.5); padding: 10px 12px; }
.self-iter.hidden { display: none; }
.self-iter-resize { height: 6px; cursor: row-resize; margin: -4px 0 6px 0; background: transparent; }
.self-iter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.self-iter-row .suggestion { background: #0f1320; color: var(--text); border: 1px solid #1f2740; border-radius: 12px; padding: 10px 14px; font-size: 13px; cursor: pointer; box-shadow: 0 0 14px rgba(0,197,255,.25); display: block; width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.self-iter-row .suggestion:hover { border-color: var(--accent); box-shadow: 0 0 18px rgba(0,197,255,.4); }
.self-iter-actions { margin-top: 8px; display: flex; gap: 8px; }
/* Floating refresh FAB */
.refresh-fab { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; border: 3px solid var(--brand); border-radius: 999px; display: inline-grid; place-items: center; background: transparent; color: var(--brand); box-shadow: none; cursor: pointer; }
.refresh-fab:hover { box-shadow: none; filter: brightness(1.1); }
.message { display: flex; align-items: flex-end; gap: 10px; width: 100%; }
.message.user { justify-content: flex-end; padding-left: 18px; padding-right: 36px; position: relative; }
.message.assistant { justify-content: flex-start; padding-right: 56px; }
.message.system { align-items: center; }

/* Undo button on user prompt bubbles (revert to before this prompt) */
.message.user .prompt-undo-btn {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; padding: 0; border-radius: 999px;
  display: grid; place-items: center; cursor: pointer; z-index: 4;
  background: rgba(21,24,35,0.92); border: 1px solid rgba(255,255,255,0.16);
  color: var(--muted); opacity: 0; pointer-events: none; transition: opacity .15s ease, color .15s ease, border-color .15s ease;
}
.message.user:hover .prompt-undo-btn,
.message.user.show-actions .prompt-undo-btn { opacity: 1; pointer-events: auto; }
.message.user .prompt-undo-btn:hover { color: var(--text); border-color: var(--brand); }

/* Inline editable prompt (after a revert) with its own send button */
.message.user.prompt-edit-msg { padding-right: 18px; }
.prompt-edit-wrap { position: relative; width: 94%; margin-left: auto; }
.prompt-edit {
  width: 100%; box-sizing: border-box; min-height: 64px; resize: none;
  background: rgba(21,24,35,0.92); color: var(--text);
  border: 1px solid var(--brand); border-radius: 16px;
  padding: 10px 46px 10px 14px; font: inherit; line-height: 1.5; outline: none;
}
.prompt-edit-send {
  position: absolute; right: 8px; bottom: 8px; width: 32px; height: 32px;
  border-radius: 999px; border: none; cursor: pointer; padding: 0;
  display: grid; place-items: center; background: var(--brand); color: #04222b;
}
.prompt-edit-send:hover { filter: brightness(1.08); }

/* Confirm-revert modal */
.revert-modal-overlay {
  position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); padding: 20px;
}
.revert-modal {
  width: min(560px, 100%); max-height: 80vh; display: flex; flex-direction: column;
  background: var(--panel, #14171f); border: 1px solid var(--border, rgba(255,255,255,0.12));
  border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,0.5); overflow: hidden;
}
.revert-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border, rgba(255,255,255,0.1)); }
.revert-modal-title { font-weight: 700; font-size: 15px; color: var(--text); }
.revert-modal-x { background: transparent; border: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.revert-modal-x:hover { color: var(--text); }
.revert-modal-body { padding: 14px 16px; overflow: auto; }
.revert-modal-sub { margin: 0 0 10px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.revert-diff-list { max-height: 42vh; overflow: auto; border: 1px solid var(--border, rgba(255,255,255,0.1)); border-radius: 10px; }
.revert-diff-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }
.revert-diff-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; font-size: 12px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.revert-diff-row:last-child { border-bottom: none; }
.revert-diff-status { flex: 0 0 auto; text-transform: uppercase; font-size: 10px; font-weight: 700; letter-spacing: .03em; padding: 2px 6px; border-radius: 6px; }
.revert-diff-status.modified { color: #e3b341; background: rgba(227,179,65,0.12); }
.revert-diff-status.restored { color: #19c37d; background: rgba(25,195,125,0.12); }
.revert-diff-status.deleted { color: #ff6b6b; background: rgba(255,107,107,0.12); }
.revert-diff-path { flex: 1 1 auto; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.revert-diff-counts { flex: 0 0 auto; display: flex; gap: 8px; font-family: ui-monospace, monospace; }
.revert-diff-counts .add { color: #19c37d; }
.revert-diff-counts .del { color: #ff6b6b; }
.revert-modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border, rgba(255,255,255,0.1)); }
.revert-modal-foot .revert-confirm { background: #ff6b6b; border-color: #ff6b6b; color: #2a0a0a; font-weight: 700; }
.revert-modal-foot .revert-confirm:hover { filter: brightness(1.08); }

.message .avatar { display: none; }

.avatar { width: 34px; height: 34px; border-radius: 999px; display: grid; place-items: center; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.10); flex: 0 0 auto; }
.user .avatar { background: rgba(42,49,71,0.85); border-color: rgba(150,170,210,0.22); }
.assistant .avatar { background: rgba(31,42,41,0.85); border-color: rgba(120,190,160,0.22); }
.avatar.sys { width: 24px; height: 24px; background: transparent; border: none; }

.bubble {
  max-width: min(76ch, 88%);
  background: rgba(21,24,35,0.78);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 10px 14px;
  line-height: 1.5;
  box-shadow: 0 10px 26px rgba(0,0,0,0.28);
  backdrop-filter: blur(10px);
}
.user .bubble {
  background: linear-gradient(135deg, rgba(0,211,255,0.30), rgba(77,225,255,0.10));
  border-color: rgba(0,211,255,0.22);
  border-bottom-right-radius: 8px;
  max-width: 94%;
}
.assistant .bubble {
  background: rgba(21,24,35,0.76);
  border-color: rgba(255,255,255,0.10);
  border-bottom-left-radius: 8px;
}

@media (max-width: 640px) {
  .message.user { padding-left: 8px; }
  .message.assistant { padding-right: 12px; }
  .user .bubble { max-width: 96%; }
}

.meta { margin-top: 6px; color: var(--muted); font-size: 11px; }
.bubble .md { font-size: 14px; overflow-wrap: anywhere; word-break: break-word; }
.bubble .md pre, .bubble .md code { background: #0b0e18; border: 1px solid #23283a; border-radius: 8px; padding: 2px 6px; }
.bubble .md pre { padding: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
/* Hide empty paragraphs that create rectangular artifacts in markdown output */
.bubble .md p:empty { display: none; }
.bubble .md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
/* Next Steps styling */
.next-steps-title { background: rgba(0,197,255,.08); border-left: 3px solid rgba(0,197,255,.35); padding: 4px 8px; border-radius: 6px; }
.next-step-item { cursor: pointer; border-radius: 8px; padding: 4px 6px; }
.next-step-item:hover, .next-step-item:focus { background: rgba(0,197,255,.15); outline: none; }
.bubble .md code { white-space: pre-wrap; word-break: break-word; }
.bubble .md h1, .bubble .md h2, .bubble .md h3 { margin: 10px 0 6px; }
.bubble .md ul, .bubble .md ol { margin: 8px 0 8px 22px; }
.user .bubble { background: linear-gradient(135deg, rgba(0,211,255,0.30), rgba(77,225,255,0.10)); }
.system .bubble { background: #1a1d2b; color: var(--muted); font-style: italic; }
.message.system .bubble { background: transparent; border: none; padding: 0; }
.sysline { font-size: 12px; color: var(--muted); padding: 6px 0; }
.muted { color: var(--muted); font-size: 12px; }
.chat-input { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--border); background: rgba(15, 17, 21, 0.6); backdrop-filter: blur(10px); margin-top: auto; align-items: center; }
.chat-input .glow-outline { width: 100%; padding: 2px; border-radius: 12px; background: linear-gradient(135deg, var(--brand), var(--brand-2), var(--brand)); background-size: 200% 200%; animation: gradientMove 6s linear infinite; }
.chat-input .glow-outline > * { width: 100%; display: block; border-radius: 10px; }
.chat-input .glow-outline.send-muted { background: rgba(255,255,255,0.10) !important; animation: none !important; }
.chat-input textarea { resize: none; background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; min-height: 40px; max-height: 160px; line-height: 1.3; overflow: auto; }
button[aria-label="Send"].icon-btn { height: 40px; width: 44px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #0b0e18; box-shadow: 0 0 14px rgba(0,197,255,.45); }

/* Send button now contains the run indicator; default is disabled/gray until ready */
#sendBtn {
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,0.07) !important;
  color: rgba(210, 220, 235, 0.65) !important;
  box-shadow: none !important;
}
#sendBtn.send-active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)) !important;
  color: #0b0e18 !important;
  box-shadow: 0 0 14px rgba(0,197,255,.45) !important;
}
#sendBtn:disabled {
  opacity: 1;
  cursor: not-allowed;
}

/* Hide the send icon whenever the embedded indicator is showing */
#sendBtn.show-indicator .send-icon { opacity: 0; }

/* Position the indicator inside the button */
#sendBtn .chat-run-indicator {
  position: absolute;
  inset: 0;
  margin: auto;
  display: none;
}
#sendBtn.show-indicator .chat-run-indicator { display: block; }

/* Send button spinner: bolder, no glow */
#sendBtn .chat-run-indicator.running::before {
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 1px));
}
#sendBtn.tooling .chat-run-indicator.running::before {
  filter: none;
}

/* Header run indicator: Cogsynth blue glow with 1.5x intensity and radius */
#headerRunIndicator.running::before {
  filter: drop-shadow(0 0 15px rgba(0,211,255,.82));
}
#headerRunIndicator.tooling.running::before {
  filter: drop-shadow(0 0 15px rgba(0,211,255,.82));
}
#headerRunIndicator.done::after {
  filter: drop-shadow(0 0 15px rgba(0,211,255,.82));
}

/* Native agent status row and diagnostics drawer */
#chatRunRow { display: none; }
#chatRunRow:not(.hidden) { display: flex !important; }
.agent-status { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 12px; color: var(--muted); font-size: 12px; }
/* No spinner or checkmark here: the status text carries the state itself via a
   travelling shine. Kept in the DOM for screen readers and layout stability. */
.agent-status-mark { display: none; }
/* Same treatment as the preview loader's "Building your app..." label: the text
   keeps its own colour at all times and the animation only drives opacity and
   text-shadow. Background-clip gradients were replaced because a mid-sweep
   gradient could leave the glyphs with no background at all. */
.agent-status-text {
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  color: var(--muted);
  animation: agentStatusGlow 1.9s ease-in-out infinite;
}
@keyframes agentStatusGlow {
  0%, 100% {
    opacity: .62;
    color: var(--muted);
    text-shadow: 0 0 6px rgba(0, 211, 255, .12);
  }
  50% {
    opacity: 1;
    color: #ffffff;
    text-shadow:
      0 0 10px rgba(0, 211, 255, .55),
      0 0 22px rgba(140, 120, 255, .38);
  }
}
/* Never animate for a user who asked for reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .agent-status-text { animation: none; opacity: 1; }
}
.agent-status.done .agent-status-text {
  animation: none;
  background-image: none;
  -webkit-text-fill-color: currentColor;
  color: #19c37d;
}
.agent-status.error .agent-status-text {
  animation: none;
  background-image: none;
  -webkit-text-fill-color: currentColor;
  color: #ff6b6b;
}
.agent-diagnostics { margin: 0 12px 4px; border: 1px solid rgba(255,107,107,.25); border-radius: 8px; background: rgba(255,107,107,.05); color: var(--muted); font-size: 11px; }
.agent-diagnostics summary { cursor: pointer; padding: 6px 8px; color: #ffb0b0; }
.agent-diagnostics-body { max-height: 180px; overflow: auto; padding: 0 8px 6px; }
.agent-diagnostic { padding: 4px 0; border-top: 1px solid rgba(255,255,255,.06); overflow-wrap: anywhere; }
.agent-diagnostic.warning { color: #e4c77c; }
.agent-diagnostic.error { color: #ff9b9b; }
.agent-message .agent-summary { min-height: 1.4em; }
/* Canvas context note: visible that research ran, collapsed by default. */
.canvas-brief-row { margin-bottom: 8px; font-size: 11px; color: var(--muted); }
.canvas-brief-row summary { cursor: pointer; user-select: none; color: var(--brand); opacity: .85; }
.canvas-brief-row summary:hover { opacity: 1; }
.canvas-brief-row pre { margin: 6px 0 0; padding: 8px 10px; max-height: 200px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: rgba(0,0,0,0.22); border: 1px solid rgba(255,255,255,0.07); border-radius: 8px; font-size: 10.5px; line-height: 1.5; color: var(--muted); }
.agent-tools { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 6px; color: var(--muted); font-size: 11px; }
.agent-tools summary { cursor: pointer; user-select: none; }
.agent-tool-list { margin: 5px 0 0 18px; padding: 0; }
.agent-tool { padding: 2px 0; overflow-wrap: anywhere; }
.agent-tool.running { color: var(--muted); }
.agent-tool.ok { color: #19c37d; }
.agent-tool.error { color: #ff6b6b; }


/* Animated blue/green glow for chat input and send button */
@keyframes glowshift {
  0% { filter: drop-shadow(0 0 0px rgba(20,209,197,.35)); }
  50% { filter: drop-shadow(0 0 8px rgba(24,183,106,.55)); }
  100% { filter: drop-shadow(0 0 0px rgba(20,209,197,.35)); }
}
/* generic glow-outline (used by chat) */
.glow-outline { position: relative; }

@keyframes gradientMove { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

/* subtle breathing */
.chat-input textarea { box-shadow: 0 0 0 2px transparent; }

/* Scrollbar styling (subtle dark) */
.chat, .chat-input textarea, .explorer, .code-area, body {
  scrollbar-width: thin;
  scrollbar-color: #2a3147 transparent;
}
.chat::-webkit-scrollbar, .chat-input textarea::-webkit-scrollbar, .explorer::-webkit-scrollbar, .code-area::-webkit-scrollbar {
  width: 8px; height: 8px;
}
.chat::-webkit-scrollbar-thumb, .chat-input textarea::-webkit-scrollbar-thumb, .explorer::-webkit-scrollbar-thumb, .code-area::-webkit-scrollbar-thumb {
  background: #2a3147; border-radius: 8px;
}
.chat::-webkit-scrollbar-track, .chat-input textarea::-webkit-scrollbar-track, .explorer::-webkit-scrollbar-track, .code-area::-webkit-scrollbar-track {
  background: transparent;
}

/* Header glow text */
.glow-text { position: relative; }
.glow-text::after { content: ""; position: absolute; inset: 0; z-index: -1; filter: blur(18px); background: radial-gradient(120px 40px at 0% 50%, rgba(20,209,197,.28), transparent 60%), radial-gradient(140px 40px at 100% 50%, rgba(24,183,106,.28), transparent 60%); }
button[aria-label="Send"].icon-btn { height: 38px; display: inline-flex; align-items: center; justify-content: center; }

 /* Preview */
 .preview { min-width: 0; display: flex; flex-direction: column; min-height: 0; }
 #previewContainer { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #0b0e18; }
 .preview-frame { flex: 1; width: 100%; height: 100%; display: block; border: none; background: #0b0e18; overflow: auto; }
 /* Make preview scrollbar track transparent so it floats over content */
 .preview-frame { scrollbar-color: rgba(180,180,180,0.5) transparent; }
 .preview-frame::-webkit-scrollbar { width: 10px; height: 10px; }
 .preview-frame::-webkit-scrollbar-track { background: transparent; }
 .preview-frame::-webkit-scrollbar-thumb { background: rgba(160,160,160,0.5); border-radius: 8px; }
 .preview-frame::-webkit-scrollbar-thumb:hover { background: rgba(200,200,200,0.6); }

 /* Preview runtime error overlay */
 .preview-error-overlay {
   position: absolute;
   inset: 0;
   display: flex;
   align-items: center;
   justify-content: center;
   padding: 18px;
   background: rgba(0, 0, 0, 0.42);
   z-index: 50;
 }
 .preview-error-card {
   width: min(860px, 92vw);
   max-height: 78vh;
   overflow: hidden;
   border: 1px solid var(--border);
   border-radius: 14px;
   background: rgba(15, 19, 32, 0.96);
   box-shadow: 0 18px 60px rgba(0,0,0,0.45);
   display: flex;
   flex-direction: column;
 }
 .preview-error-head {
   display: flex;
   align-items: center;
   gap: 10px;
   padding: 10px 12px;
   border-bottom: 1px solid var(--border);
 }
 .preview-error-status {
   padding: 8px 12px 0;
   font-size: 12px;
   color: var(--muted);
 }
 .preview-error-text {
   margin: 0;
   padding: 12px;
   overflow: auto;
   font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
   font-size: 12px;
   color: #ffd7d7;
   background: rgba(0,0,0,0.25);
 }
 .preview-error-actions {
   display: flex;
   gap: 8px;
   justify-content: flex-end;
   padding: 10px 12px;
   border-top: 1px solid var(--border);
 }

 /* Graph */
 .graph-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
 .graph-subheader { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: rgba(15,17,21,0.5); }
 .graph-subheader .control-group.toggle { gap: 8px; }
 .graph-subheader-mode .mini-btn.active { color: var(--text); border-color: var(--accent); }
 .graph-main { flex: 1; min-height: 0; display: flex; }
 .graph-canvas { flex: 1; min-height: 0; background: #0f1320; position: relative; overflow: hidden; }
 .graph-canvas canvas { display: block; width: 100%; height: 100%; }
 .graph-tree-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: #0f1320; }
 .tree-subheader { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.08); background: rgba(15,17,21,0.45); flex: 0 0 auto; }
 .graph-panel-section-title { padding: 8px 10px; font-size: 12px; font-weight: 700; color: var(--muted); border-bottom: 1px solid rgba(255,255,255,0.06); background: rgba(0,0,0,0.10); flex: 0 0 auto; }
 .graph-side { width: 300px; min-width: 260px; border-left: 1px solid var(--border); background: rgba(15,17,21,0.55); padding: 10px 10px 14px; overflow: auto; }
 .graph-side-group { border-bottom: 1px solid rgba(255,255,255,0.06); padding: 6px 0; }
 .graph-side-group:last-child { border-bottom: none; }
 .graph-side-group > summary { cursor: pointer; list-style: none; font-weight: 700; color: var(--text); padding: 8px 6px 18px; border-radius: 10px; position: relative; }
 .graph-side-group > summary::-webkit-details-marker { display: none; }
 .graph-side-group > summary:hover { background: rgba(255,255,255,0.04); }
 .graph-side-group > summary::after { content: "▾"; position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); font-size: 12px; color: var(--muted); opacity: 0.85; }
 .graph-side-group[open] > summary::after { content: "▴"; }
 .graph-side-body { padding: 10px 8px 6px; display: grid; gap: 10px; }
 .graph-side-row { display: flex; align-items: center; gap: 10px; }
 .graph-side-row .mini-input { flex: 1 1 auto; min-width: 0; }
 .graph-side-toggle { justify-content: space-between; color: var(--muted); font-size: 13px; }
 .graph-side-range { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
 .graph-side-range span { color: var(--muted); }
 .graph-side-range input[type="range"] { width: 100%; }
 .graph-side input[type="checkbox"] { appearance: none; -webkit-appearance: none; width: 44px; height: 24px; border-radius: 999px; border: 1px solid var(--border); background: #2a3147; position: relative; cursor: pointer; outline: none; }
 .graph-side input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .18s ease; }
 .graph-side input[type="checkbox"]:checked { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
 .graph-side input[type="checkbox"]:checked::after { transform: translateX(20px); }

 .graph-tree-list { display: grid; gap: 4px; padding: 10px 8px 14px; overflow: auto; min-height: 0; flex: 1 1 auto; }
 .graph-tree-row { display: grid; grid-template-columns: 20px 10px 1fr auto; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05); background: rgba(0,0,0,0.12); cursor: pointer; }
 .graph-tree-row:hover { background: rgba(255,255,255,0.04); }
 .graph-tree-row.selected { outline: 2px solid rgba(20,209,197,0.25); }
 .graph-tree-caret { width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid rgba(255,255,255,0.10); background: rgba(255,255,255,0.03); color: var(--muted); cursor: pointer; }
 .graph-tree-caret:disabled { opacity: 0.5; cursor: default; }
 .graph-tree-dot { width: 10px; height: 10px; border-radius: 999px; background: rgba(255,255,255,0.18); box-shadow: 0 0 0 3px rgba(255,255,255,0.04); }
 .graph-tree-dot.status-pending { background: rgba(255,255,255,0.18); box-shadow: 0 0 0 3px rgba(255,255,255,0.04); }
 .graph-tree-dot.status-running { background: #60a5fa; box-shadow: 0 0 0 3px rgba(96,165,250,0.18); }
 .graph-tree-dot.status-passed { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,0.18); }
 .graph-tree-dot.status-failed { background: #fb7185; box-shadow: 0 0 0 3px rgba(251,113,133,0.18); }
 .graph-tree-title { color: var(--text); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
 .graph-tree-meta { color: var(--muted); font-size: 12px; }

 .graph-traversal-log { display: grid; gap: 6px; padding-top: 6px; max-height: 260px; overflow: auto; }
 .graph-traversal-row { display: grid; grid-template-columns: 10px 1fr; gap: 8px; align-items: start; padding: 6px 8px; border: 1px solid rgba(255,255,255,0.06); border-radius: 10px; background: rgba(0,0,0,0.12); }
 .graph-traversal-dot { width: 10px; height: 10px; border-radius: 999px; margin-top: 4px; background: rgba(255,255,255,0.18); box-shadow: 0 0 0 3px rgba(255,255,255,0.04); }
 .graph-traversal-dot.status-running { background: #60a5fa; box-shadow: 0 0 0 3px rgba(96,165,250,0.18); }
 .graph-traversal-dot.status-passed { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,0.18); }
 .graph-traversal-dot.status-failed { background: #fb7185; box-shadow: 0 0 0 3px rgba(251,113,133,0.18); }
 .graph-traversal-text { color: var(--text); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

 .graph-traversal-log-full { max-height: none; flex: 1; min-height: 0; padding: 10px 10px 14px; overflow: auto; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }

 .devloop-traversal { margin-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); padding-top: 10px; }
 .devloop-traversal-log { display: grid; gap: 6px; max-height: 200px; overflow: auto; margin-top: 6px; }
 .devloop-traversal-log .graph-traversal-row { background: rgba(0,0,0,0.16); }

 @media (max-width: 980px) {
  .graph-side { width: 260px; min-width: 220px; }
 }

 /* Tabs */
 .tabs { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: rgba(15,17,21,0.5); flex-shrink: 0; }
 .tab-left { display: flex; align-items: center; gap: 8px; }
 .tab-center { flex: 1; display: flex; align-items: center; justify-content: center; pointer-events: none; }
 .pane-title { font-weight: 600; color: var(--muted); margin-right: 6px; }
 .tab-btn { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
 .tab-btn.active { color: var(--text); border-color: var(--accent); }
 .tab-actions { display: flex; align-items: center; gap: 8px; }
.mini-select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; font-size: 12px; }
.hidden { display: none; }
.tab-panel { flex: 1; display: flex; min-height: 0; }

/* Editor bar and line numbers */
.editor-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: #0f1320; color: var(--muted); font-size: 12px; }
.editor-wrap { flex: 1; display: grid; grid-template-columns: 44px 1fr; min-height: 0; }
.gutter { margin: 0; padding: 12px 8px; background: #0b0e18; color: #6b7280; border-right: 1px solid #23283a; width: 44px; min-width: 44px; text-align: right; overflow-y: auto; overflow-x: hidden; white-space: pre; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 13px; scrollbar-width: none; }
.gutter::-webkit-scrollbar { width: 0; height: 0; }
.editor-wrap .code-area { padding-left: 12px; resize: none; overflow-y: auto; }
.editor-wrap .code-area, .editor-wrap .gutter { line-height: 1.4; }
.editor-wrap .code-area { overflow: auto; }

/* Remove redundant file path shown above editor (we show filename in header center) */
#editorPathBar { display: none; }

/* Success button */
.btn-success { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; border: none; box-shadow: 0 0 14px rgba(0,197,255,.35); }

/* Resizers */
.resizer { cursor: col-resize; background: #0d1220; border-left: 1px solid var(--border); border-right: 1px solid var(--border); z-index: 50; }
.resizer:hover { background: #151a2a; }
.resizer { position: relative; }
.edge-toggle { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(15,17,21,0.8); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; cursor: pointer; pointer-events: auto; }
.resizer[data-resize="left"] .edge-toggle { left: 2px; }
.resizer[data-resize="right"] .edge-toggle { right: 2px; }

/* Collapsible header extras */
.header-extras { position: relative; margin-left: 12px; display: inline-flex; align-items: center; gap: 8px; width: auto; flex: 0 1 auto; justify-content: flex-start; overflow: hidden; white-space: nowrap; }
.header-extras .control-group.toggle { gap: 6px; }
.toggle-caret { background: transparent; border: 1px solid var(--border); height: 28px; width: 22px; border-radius: 6px; color: var(--muted); cursor: pointer; display: inline-grid; place-items: center; padding: 0 4px; margin-left: 8px; }
/* Show 'More…' to the LEFT of the collapse caret */
.more-hint { position: static; margin: 0 8px; color: var(--muted); font-size: 12px; pointer-events: none; align-self: center; }
.header-extras.collapsed .extras-body { display: none; }

/* Prevent flex shrinking/distortion in header */
.app-header .btn, .app-header select, .app-header .toggle-caret, .app-header .control-group { flex: 0 0 auto; }

/* Fixed left group to avoid shifting */
#headerLeft { display: inline-flex; align-items: center; gap: 10px; flex: 0 0 auto; }
/* Force horizontal label+input in header */
.app-header .control-group { display: inline-flex; align-items: center; gap: 8px; }
.app-header .control-group span { display: inline; white-space: nowrap; }

/* Scaffold overlay */
.scaffold { position: fixed; inset: var(--header-h) 0 0 0; background: rgba(5,7,12,0.92); z-index: 190; display: grid; place-items: start center; overflow: auto; }
.scaffold-content { width: min(1100px, 92vw); background: #0f1320; border: 1px solid var(--border); border-radius: 14px; margin: 16px; overflow: hidden; }
.scaffold-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); background: rgba(15,17,21,0.6); gap: 10px; }
.scaffold-header strong { font-size: 16px; }
.scaffold-head-actions { display: inline-flex; align-items: center; gap: 10px; }
.scaffold-head-actions .icon-btn, .scaffold-grid .icon-btn.mini { color: var(--muted); border: none; }
.scaffold-grid .icon-btn.mini { width: 22px; height: 22px; border-radius: 6px; }
.scaffold-head-actions .icon-btn:hover, .scaffold-grid .icon-btn.mini:hover { color: var(--text); }
/* Remove focus outline for these mini buttons to reduce clutter, but keep keyboard focus visible via subtle shadow */
.scaffold-head-actions .icon-btn:focus-visible, .scaffold-grid .icon-btn.mini:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(20,209,197,0.2); border: none; }
.scaffold-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; }
.scaffold-grid label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); min-height: 110px; }
.scaffold-grid textarea { width: 100%; min-height: 60px; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; overflow-y: auto; }
.scaffold-grid .chip-box, .scaffold-grid .attach-box { width: 100%; min-height: 60px; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px; display: grid; grid-template-rows: 1fr auto; gap: 6px; max-height: 180px; overflow-y: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.chips.vertical { display: grid; grid-auto-rows: min-content; gap: 6px; justify-items: start; align-items: start; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #1b2236; color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 4px 8px; font-size: 12px; width: fit-content; max-width: 100%; }
.chips.vertical .chip { width: fit-content; }
.chip button { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 12px; }
.chip-input { background: transparent; color: var(--text); border: none; outline: none; padding: 4px; min-width: 120px; }
.chip-backstore { display: none; }
.attach-list { display: grid; gap: 6px; justify-items: start; }
.attach-item { display: inline-flex; align-items: center; gap: 8px; background: #1b2236; border: 1px solid var(--border); border-radius: 999px; padding: 4px 8px; font-size: 12px; width: fit-content; }
.attach-item button { background: transparent; border: none; color: var(--muted); cursor: pointer; }

/* Modal */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.4); z-index: 300; }
.hidden { display: none; }
.modal-content { width: min(720px, 92vw); max-height: 90vh; background: #0f1320; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,0.4); display: flex; flex-direction: column; }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.modal-footer { border-top: 1px solid var(--border); border-bottom: none; position: sticky; bottom: 0; background: #0f1320; }
.modal-body { padding: 14px; overflow: auto; flex: 1 1 auto; }
.clarify-form { display: grid; gap: 12px; }
.clarify-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.clarify-form input, .clarify-form select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }

/* Loop modal — the real agent budget knobs */
.loop-intro { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.loop-presets { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.loop-preset {
  flex: 1 1 auto;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.loop-preset:hover { background: rgba(0,211,255,0.08); border-color: rgba(0,211,255,0.35); color: var(--text); }
.loop-preset.active { background: linear-gradient(135deg, rgba(20,209,197,0.22), rgba(0,211,255,0.12)); border-color: rgba(20,209,197,0.5); color: #eaf7f5; }
.loop-config { display: grid; gap: 4px; margin-bottom: 12px; }
.loop-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(200px, 1.1fr);
  align-items: center;
  gap: 14px;
  padding: 10px 2px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.loop-row:last-child { border-bottom: none; }
.loop-label { display: grid; gap: 2px; font-size: 13px; color: var(--text); font-weight: 600; }
.loop-label em { font-style: normal; font-size: 11px; font-weight: 400; color: var(--muted); }
.loop-field { display: flex; align-items: center; gap: 10px; }
.loop-field input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: var(--brand); background: transparent; padding: 0; height: 20px; }
.loop-field select { flex: 1 1 auto; min-width: 0; }
.loop-value {
  flex: 0 0 auto;
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--brand);
}
.loop-footnote { font-size: 11px; color: var(--muted); line-height: 1.55; padding: 8px 10px; border-radius: 8px; background: rgba(0,211,255,0.05); border: 1px solid rgba(0,211,255,0.14); }
.modal-footer #loopReset { margin-left: auto; }

/* Canvas research panel */
.canvas-sources { margin-top: 12px; display: grid; gap: 6px; max-height: 260px; overflow: auto; }
.canvas-source { display: grid; gap: 2px; padding: 7px 9px; border: 1px solid rgba(255,255,255,0.07); border-radius: 8px; background: rgba(0,0,0,0.14); }
.canvas-source code { font-size: 11px; color: var(--brand); overflow-wrap: anywhere; }
.canvas-source span { font-size: 11px; color: var(--muted); line-height: 1.5; }
/* Canvas toggle active state, matching the pill buttons in the header */
.btn-pill.active { background: linear-gradient(135deg, rgba(20,209,197,0.32), rgba(0,211,255,0.18)); border-color: rgba(20,209,197,0.55); color: #eaf7f5; }
.btn-pill.active::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: #19c37d; box-shadow: 0 0 8px rgba(25,195,125,0.8); vertical-align: middle; }

@media (max-width: 720px) {
  .loop-row { grid-template-columns: 1fr; gap: 8px; }
}

/* Templates Gallery */
#templatesModal .templates-grid { align-items: stretch; }
#templatesModal .modal-body { max-height: calc(90vh - 120px); overflow: auto; }
.modal-header .modal-actions { display: flex; align-items: center; gap: 8px; }
#templatesModal .modal-header .modal-actions .muted { line-height: 32px; display: inline-block; }
.tpl-card { display: grid; grid-template-rows: auto 1fr auto auto; gap: 6px; background: #0f1320; border: 1px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer; }
.tpl-card .tpl-head { font-weight: 800; }
.tpl-card .tpl-body { color: var(--muted); font-size: 12px; }
.tpl-card .tpl-tags { color: var(--muted); font-size: 11px; display: flex; gap: 6px; flex-wrap: wrap; }
.tpl-card .tag { background: #12162a; border: 1px solid #1f2740; border-radius: 999px; padding: 2px 6px; }
.tpl-card .tpl-foot { display: flex; justify-content: flex-start; }
.tpl-card:hover { border-color: var(--accent); }
.tpl-card.selected { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,211,255,.15) inset; }
.tpl-card .mini-btn { padding: 4px 8px; }

/* Responsive tweaks */
@media (max-width: 720px) {
  .controls { gap: 8px; }
  .control-group span { display: none; }
}

/* ---- Mobile Mode (portrait: single panel) ---- */
body.mobile-mode .app-header { padding: 6px 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
body.mobile-mode .brand h1 { font-size: 16px; }
body.mobile-mode .logo-img { height: 16px; }

/* One panel at a time; hide all panes by default, show only .mobile-active */
body.mobile-mode .workspace { grid-template-columns: 1fr !important; }
body.mobile-mode .pane { display: none !important; border-right: none !important; }
body.mobile-mode .pane.mobile-active { display: flex !important; }

/* Keep resizer toggle arrows accessible on the page edges */
/* Make edge zones wide enough so the arrow is always clickable */
body.mobile-mode .resizer { position: fixed; top: var(--header-h); bottom: 0; width: 44px; border: none; background: transparent; cursor: default; z-index: 205; pointer-events: none; }
body.mobile-mode .resizer[data-resize="left"] { left: 0; }
body.mobile-mode .resizer[data-resize="right"] { right: 0; }
/* Move arrows slightly higher than center: ~40% from top */
body.mobile-mode .resizer .edge-toggle { position: absolute; top: 40%; transform: translateY(-50%); pointer-events: auto; }
/* Slightly larger touch target on mobile */
body.mobile-mode .edge-toggle { width: 36px; height: 36px; border-radius: 10px; }

/* Pulse highlight to indicate preview was updated and can be shown via that arrow */
@keyframes edgePulse {
  0% { box-shadow: 0 0 0 0 rgba(0,211,255,0.65); }
  70% { box-shadow: 0 0 0 10px rgba(0,211,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,211,255,0); }
}
.edge-toggle.pulse { animation: edgePulse 1.05s ease-out 0s 18; border-color: var(--accent); color: var(--accent); }

/* Mobile-only: allow horizontal scroll for header controls; brand stays fixed at left */
body.mobile-mode .app-header { overflow: hidden; }
/* Hide usage badge text on very small screens, show only icon */
@media (max-width: 400px) {
  body.mobile-mode .usage-badge { font-size: 10px; padding: 2px 6px; margin-left: 4px; }
}
body.mobile-mode .app-header .brand { flex: 0 0 auto; position: relative; z-index: 2; }
/* Header extras: make inner extras-body horizontally scrollable while brand stays fixed */
body.mobile-mode .header-extras { flex: 1 1 auto; min-width: 0; overflow: hidden; }
body.mobile-mode .header-extras .extras-body { display: flex; gap: 8px; overflow-x: auto !important; overflow-y: visible; -webkit-overflow-scrolling: touch; white-space: nowrap; scrollbar-width: none; -ms-overflow-style: none; touch-action: pan-x; overscroll-behavior-x: contain; user-select: none; -webkit-user-select: none; }
body.mobile-mode .header-extras .extras-body::-webkit-scrollbar { height: 0; width: 0; display: none; }
body.mobile-mode .header-extras .extras-body > * { flex: 0 0 auto; }

body.mobile-mode #previewPane .tabs { overflow: hidden; display: flex !important; flex-direction: column; align-items: stretch; gap: 6px; }
body.mobile-mode #previewPane .tabs .tab-left { display: flex; gap: 8px; overflow: hidden; white-space: nowrap; }
body.mobile-mode #previewPane .tabs .tab-left > * { flex: 1 1 0; min-width: 0; }
body.mobile-mode #previewPane .tabs .tab-btn { padding: 8px 10px; font-size: 12px; text-align: center; }
body.mobile-mode #previewPane .tabs .tab-center { display: none; }
body.mobile-mode #previewPane .tabs .tab-actions { order: 3; flex-wrap: nowrap; justify-content: flex-start; gap: 8px; align-items: center; overflow: hidden; }
body.mobile-mode #previewPane .tabs .tab-actions #headerCenterLabel { flex: 1 1 120px; min-width: 120px; max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
body.mobile-mode #previewPane .tabs .tab-actions #stopPreview + #headerCenterLabel { margin: 0 4px; }
body.mobile-mode #headerRunIndicator { display: block !important; flex: 0 0 auto; width: 16px; height: 16px; min-width: 16px; min-height: 16px; margin-left: 8px; }

body.mobile-mode #stopPreview { display: none !important; }

body.mobile-mode #previewPane .tabs .tab-actions #entryPicker,
body.mobile-mode #previewPane .tabs .tab-actions #versionLabel { flex: 0 0 auto; }
body.mobile-mode #previewPane .tabs .tab-actions #entryPicker { max-width: 28vw; }
body.mobile-mode #previewPane .tabs .tab-actions #versionLabel { margin-left: 0; }

body.mobile-mode .scaffold { place-items: start center; padding: 10px 10px 18px; }
body.mobile-mode .scaffold-content { width: min(980px, calc(100vw - 20px)); margin: 10px auto; }
body.mobile-mode .scaffold-header { flex-wrap: nowrap; }
body.mobile-mode .scaffold-head-actions { gap: 8px; flex-wrap: nowrap; }
body.mobile-mode .scaffold-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
body.mobile-mode .scaffold-grid label { min-width: 0; }
body.mobile-mode .scaffold-grid textarea,
body.mobile-mode .scaffold-grid .chip-box,
body.mobile-mode .scaffold-grid .attach-box { min-width: 0; }

body.mobile-mode .graph-subheader { flex-wrap: wrap; gap: 6px; }
body.mobile-mode .graph-subheader .control-group.toggle span { display: none; }
body.mobile-mode .graph-subheader .control-group.toggle { gap: 6px; }
body.mobile-mode .graph-subheader #graphStatus { display: none; }

body.mobile-mode .graph-subheader .control-group.toggle input[type="checkbox"] { width: 38px; height: 22px; }
body.mobile-mode .graph-subheader .control-group.toggle input[type="checkbox"]::after { width: 16px; height: 16px; top: 2px; left: 2px; }
body.mobile-mode .graph-subheader .control-group.toggle input[type="checkbox"]:checked::after { transform: translateX(16px); }

.graph-main { position: relative; }
.graph-side-toggle-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15,17,21,0.75);
  color: var(--text);
  display: inline-grid;
  place-items: center;
}
body.mobile-mode .graph-side-toggle-btn { display: inline-grid; place-items: center; }

body.mobile-mode .graph-side { width: 150px; min-width: 140px; padding: 8px 8px 10px; }
body.mobile-mode .graph-side-body { padding: 8px 6px 6px; }
body.mobile-mode .graph-side-range input[type="range"] { width: 100%; }

/* Mobile: avoid refresh button overlapping suggestion buttons; keep it tappable */
body.mobile-mode #selfIterPanel { grid-template-columns: minmax(0, 1fr) 44px; column-gap: 10px; padding-right: 8px; }
body.mobile-mode #selfIterPanel .refresh-fab { width: 34px; height: 34px; z-index: 10; }
body.mobile-mode .self-iter-row .suggestion { padding: 9px 10px; font-size: 12px; }

/* ── Mobile Touch Target & UX Fixes ─────────────────────────────────────── */

/* 1. Minimum 44×44px tap targets on all interactive elements in mobile mode */
body.mobile-mode .btn-pill {
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
}
body.mobile-mode .icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
}
body.mobile-mode .tab-btn {
  min-height: 44px;
  padding: 10px 12px;
}
body.mobile-mode .mini-btn {
  min-height: 36px;
  padding: 6px 10px;
}
body.mobile-mode .toggle-caret {
  width: 36px;
  height: 36px;
}

/* 2. Prevent iOS font-size zoom on input focus (font-size must be ≥16px) */
body.mobile-mode .chat-input textarea,
body.mobile-mode input[type="text"],
body.mobile-mode input[type="email"],
body.mobile-mode input[type="password"],
body.mobile-mode input[type="search"],
body.mobile-mode select,
body.mobile-mode textarea {
  font-size: 16px !important;
}

/* 3. Chat input — larger send button area and textarea on mobile */
body.mobile-mode .chat-input {
  padding: 10px;
  gap: 8px;
}
body.mobile-mode .chat-input textarea {
  min-height: 48px;
  padding: 12px;
}
body.mobile-mode #sendBtn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 12px;
}

/* 4. Scaffold: single column on narrow phones */
@media (max-width: 540px) {
  body.mobile-mode .scaffold-grid {
    grid-template-columns: 1fr;
  }
}

/* 5. Modal: safer max-height accounting for virtual keyboard */
body.mobile-mode .modal-content {
  max-height: min(90vh, calc(100dvh - 20px));
  width: min(96vw, 600px);
}
body.mobile-mode .modal-body {
  max-height: calc(100dvh - 180px);
}

/* 6. Safe-area insets for notched phones (bottom toolbar area) */
body.mobile-mode .chat-input {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
body.mobile-mode .workspace {
  padding-bottom: env(safe-area-inset-bottom);
}

/* 7. Explorer tree items — easier tap targets */
body.mobile-mode .tree-item {
  min-height: 40px;
  padding: 8px 10px;
}
body.mobile-mode .tree-row {
  min-height: 40px;
}

/* 8. Version control arrows — larger tap zone */
body.mobile-mode #prevVersion,
body.mobile-mode #nextVersion {
  width: 40px;
  height: 40px;
}

/* 9. Templates grid — single column on small screens */
@media (max-width: 480px) {
  .templates-grid {
    grid-template-columns: 1fr !important;
  }
}

/* 10. Tab buttons in preview pane — ensure full-width, easy tap */
body.mobile-mode #previewPane .tab-btn {
  flex: 1 1 0;
  text-align: center;
  min-height: 44px;
  padding: 10px 4px;
  font-size: 12px;
}

/* ── Usage badge (plan quota indicator in header) ── */
.usage-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: #94a3b8;
  white-space: nowrap;
  margin-left: 6px;
  cursor: default;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.usage-badge.warn {
  background: rgba(251,191,36,0.12);
  border-color: rgba(251,191,36,0.35);
  color: #fbbf24;
}
.usage-badge.danger {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.35);
  color: #f87171;
}
.usage-badge.unlimited {
  background: rgba(167,139,250,0.1);
  border-color: rgba(167,139,250,0.25);
  color: #a78bfa;
}

/* ═══════════════════════════════════════════════════════════════
   PREMIUM GLASSMORPHISM SKIN — purely cosmetic overrides.
   No layout, spacing, or sizing changes. Appended last so the
   cascade wins over earlier component rules.
   ═══════════════════════════════════════════════════════════════ */

/* Richer ambient backdrop so the glass has something to refract */
body {
  background:
    radial-gradient(1100px 700px at 85% -10%, rgba(56,68,135,0.38), transparent 60%),
    radial-gradient(900px 600px at -15% 110%, rgba(18,84,96,0.32), transparent 60%),
    radial-gradient(700px 500px at 50% 120%, rgba(60,35,110,0.16), transparent 65%),
    var(--bg);
}

/* App header — frosted glass bar with a luminous bottom hairline */
.app-header {
  background: linear-gradient(180deg, rgba(23,27,42,0.72), rgba(15,17,27,0.60));
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid rgba(120,150,255,0.10);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.05),
    0 1px 18px rgba(0,0,0,0.35);
}

/* Workspace panes — translucent glass slabs, tuned to match the header tone */
.pane {
  background: linear-gradient(180deg, rgba(23,27,42,0.66), rgba(15,17,27,0.58)) !important;
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border-right: 1px solid rgba(120,150,255,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
/* Inner scroll regions must stay transparent so the pane glass shows through */
.explorer, .chat, .chat-pane, .editor { background: transparent !important; }
.pane.collapsed { background: transparent; box-shadow: none; }

/* Pane headers — slightly brighter glass with top highlight */
.pane-header {
  background: linear-gradient(180deg, rgba(30,35,56,0.55), rgba(20,23,38,0.45));
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid rgba(120,150,255,0.09);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Header buttons — frosted pills with soft inner highlight */
.app-header .btn,
.app-header .btn.btn-secondary {
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.025));
  border: 1px solid rgba(160,185,255,0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.07),
    0 2px 8px rgba(0,0,0,0.25);
  transition: border-color .2s ease, box-shadow .2s ease, filter .2s ease;
}
.app-header .btn:hover {
  border-color: rgba(0,211,255,0.35);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.09),
    0 2px 12px rgba(0,211,255,0.10);
}
.app-header .btn.btn-primary {
  background: linear-gradient(180deg, rgba(27,200,189,0.24), rgba(18,120,150,0.20));
  border-color: rgba(20,209,197,0.40);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.10),
    0 2px 14px rgba(20,209,197,0.14);
}

/* Icon buttons + explorer tabs — glassy chips */
.icon-btn,
.tabs-explorer .tab {
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.015));
  border-color: rgba(160,185,255,0.13);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  transition: border-color .18s ease, box-shadow .18s ease, color .18s ease;
}
.icon-btn:hover,
.tabs-explorer .tab:hover {
  border-color: rgba(0,211,255,0.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.07), 0 2px 10px rgba(0,211,255,0.08);
}
.tabs-explorer .tab.active {
  background: linear-gradient(180deg, rgba(0,211,255,0.10), rgba(0,211,255,0.03));
  border-color: rgba(0,211,255,0.45);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 0 12px rgba(0,211,255,0.10);
}

/* Selects — frosted dropdowns */
.control-group select {
  background: linear-gradient(180deg, rgba(30,35,56,0.75), rgba(20,23,38,0.70));
  border: 1px solid rgba(160,185,255,0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.control-group select:focus {
  outline: none;
  border-color: rgba(0,211,255,0.45);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 0 0 2px rgba(0,211,255,0.15);
}

/* Vertical separators — luminous hairlines */
.v-sep {
  background: linear-gradient(180deg, transparent, rgba(140,170,255,0.25), transparent);
}

/* Explorer selected entry — glassy cyan highlight */
.explorer-tree .entry.selected {
  background: linear-gradient(180deg, rgba(20,209,197,0.14), rgba(20,209,197,0.07));
  border-color: rgba(20,209,197,0.30);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Preview error card — frosted glass dialog */
.preview-error-card {
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  background: linear-gradient(180deg, rgba(28,24,38,0.85), rgba(18,16,28,0.82));
  border: 1px solid rgba(255,120,120,0.22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 12px 48px rgba(0,0,0,0.55);
}

/* ═══════════════════════════════════════════════════════════════
   PREVIEW "BUILDING" OVERLAY — clean cascading-glyph loader.
   Shown while a prompt is applying; hidden when the preview loads.
   ═══════════════════════════════════════════════════════════════ */
.preview-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 40; /* below the error overlay (50) */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(120% 120% at 50% 0%, rgba(13,16,28,0.92), rgba(9,11,20,0.96));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity .35s ease;
}
/* Clean dynamic aurora backdrop behind the loader glyphs. */
.preview-loading-overlay::before {
  content: "";
  position: absolute;
  inset: -25%;
  background:
    radial-gradient(38% 38% at 30% 32%, rgba(0,211,255,0.28), transparent 70%),
    radial-gradient(42% 42% at 72% 68%, rgba(0,211,255,0.24), transparent 70%),
    radial-gradient(30% 30% at 60% 20%, rgba(20,209,197,0.22), transparent 70%);
  filter: blur(16px);
  animation: previewAuroraDrift 12s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes previewAuroraDrift {
  0%   { transform: translate3d(-3%, -2%, 0) scale(1); opacity: .85; }
  50%  { transform: translate3d(3%, 2%, 0) scale(1.08); opacity: 1; }
  100% { transform: translate3d(-2%, 3%, 0) scale(1.03); opacity: .9; }
}
@media (prefers-reduced-motion: reduce) {
  .preview-loading-overlay::before { animation: none; }
}
.preview-loading-overlay.hidden { display: none; }
.preview-loading-inner { position: relative; z-index: 1; }
.preview-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  user-select: none;
}
.preview-loading-glyphs {
  display: flex;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 4px;
  color: var(--brand);
}
.preview-loading-glyphs span {
  animation: previewGlyphWave 1.6s ease-in-out infinite;
  text-shadow: 0 0 12px rgba(0,211,255,0.35);
}
.preview-loading-glyphs span:nth-child(1),
.preview-loading-glyphs span:nth-child(2),
.preview-loading-glyphs span:nth-child(3),
.preview-loading-glyphs span:nth-child(4),
.preview-loading-glyphs span:nth-child(5),
.preview-loading-glyphs span:nth-child(6),
.preview-loading-glyphs span:nth-child(7),
.preview-loading-glyphs span:nth-child(8) {
  filter: drop-shadow(0 0 6px rgba(0,211,255,0.5)) drop-shadow(0 0 14px rgba(140,120,255,0.35));
}
.preview-loading-glyphs span:nth-child(1) { animation-delay: 0s; }
.preview-loading-glyphs span:nth-child(2) { animation-delay: .12s; }
.preview-loading-glyphs span:nth-child(3) { animation-delay: .24s; }
.preview-loading-glyphs span:nth-child(4) { animation-delay: .36s; }
.preview-loading-glyphs span:nth-child(5) { animation-delay: .48s; }
.preview-loading-glyphs span:nth-child(6) { animation-delay: .60s; }
.preview-loading-glyphs span:nth-child(7) { animation-delay: .72s; }
.preview-loading-glyphs span:nth-child(8) { animation-delay: .84s; }
@keyframes previewGlyphWave {
  0%, 100% { opacity: .25; text-shadow: 0 0 8px rgba(0,211,255,0.2); filter: drop-shadow(0 0 3px rgba(0,211,255,0.3)); }
  35% { opacity: 1; text-shadow: 0 0 16px rgba(0,211,255,0.6), 0 0 28px rgba(140,120,255,0.45); filter: drop-shadow(0 0 8px rgba(0,211,255,0.7)) drop-shadow(0 0 18px rgba(140,120,255,0.5)); }
  70% { opacity: .25; text-shadow: 0 0 8px rgba(0,211,255,0.2); filter: drop-shadow(0 0 3px rgba(0,211,255,0.3)); }
}
.preview-loading-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .4px;
}
.preview-loading-dots i {
  font-style: normal;
  animation: previewGlyphWave 1.4s ease-in-out infinite;
}
.preview-loading-dots i:nth-child(2) { animation-delay: .2s; }
.preview-loading-dots i:nth-child(3) { animation-delay: .4s; }
@media (prefers-reduced-motion: reduce) {
  .preview-loading-glyphs span, .preview-loading-dots i { animation: none; opacity: .8; }
}

/* Subtle top sheen across the whole frame (decorative only) */
.workspace { position: relative; }
.workspace::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(140,170,255,0.18), rgba(0,211,255,0.22), rgba(140,170,255,0.18), transparent);
  pointer-events: none;
  z-index: 5;
}

/* ── Onboarding spotlight tour ─────────────────────────────────────────────
   Anchored coachmarks that cut a transparent hole around a real control and
   float a popover beside it. The dim is intentionally light so the underlying
   UI stays vaguely visible. Children are position:fixed inside the globally
   scaled <html>; JS converts viewport rects into this scaled space. */
#csTour { position: fixed; inset: 0; z-index: 100000; pointer-events: none; }
#csTour .cs-tour-mask {
  position: fixed; background: rgba(5, 7, 12, 0.42);
  pointer-events: auto;
}
#csTour .cs-tour-dim {
  position: fixed; left: 0; top: 0;
  background: rgba(5, 7, 12, 0.42);
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#csTour .cs-tour-ring {
  position: fixed; border: 2px solid #7c6af7; border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(124, 106, 247, 0.35), 0 0 22px rgba(124, 106, 247, 0.55);
  pointer-events: none;
}
#csTour .cs-tour-hole {
  position: fixed; border-radius: 12px; cursor: pointer; pointer-events: auto;
}
#csTour .cs-tour-pop {
  position: fixed; width: 300px; max-width: calc(100vw - 24px);
  background: #16213e; border: 1px solid #2d2d3e; border-radius: 14px;
  padding: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}
#csTour .cs-tour-pop--center { position: static; }
#csTour .cs-tour-dots { display: flex; gap: 6px; margin-bottom: 10px; }
#csTour .cs-tour-dot { width: 18px; height: 4px; border-radius: 2px; background: #2d2d3e; transition: background .2s, width .2s; }
#csTour .cs-tour-dot--active { background: #7c6af7; width: 30px; }
#csTour .cs-tour-title { margin: 0 0 6px; font-size: 1.05rem; font-weight: 700; color: #fff; }
#csTour .cs-tour-body { margin: 0 0 14px; font-size: 0.9rem; line-height: 1.55; color: #94a3b8; }
#csTour .cs-tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#csTour .cs-tour-actions-right { display: flex; gap: 8px; }
#csTour .cs-tour-btn { font: inherit; cursor: pointer; border-radius: 8px; padding: 6px 12px; font-size: 0.85rem; border: 1px solid transparent; }
#csTour .cs-tour-skip { background: transparent; color: #64748b; }
#csTour .cs-tour-back { background: #1e1e2e; color: #94a3b8; border-color: #2d2d3e; }
#csTour .cs-tour-next { background: linear-gradient(180deg, #7c6af7, #6354d6); color: #fff; font-weight: 600; }
#csTour .cs-tour-btn:hover { filter: brightness(1.08); }
