/* Open in editor: a reply, or a code block from it, as a document beside the chat.
 *
 * It slides open by width beside the conversation, like the workbench, and
 * reads as part of the page rather than a window over it: the page's own
 * background, a hairline between, the chat's type for a draft and the code
 * pane's dark glass for code. The ask box at its foot is a small composer.
 */

#editor {
  position: relative;
  width: 0;
  flex: none;
  overflow: hidden;
  background: var(--bg);
  /* No border while closed: a closed panel takes no room at all. */
  border-left: 0 solid transparent;
  transition: width var(--dur-slow) var(--ease-out), border-color var(--dur-slow) var(--ease);
  --editor-w: clamp(360px, 44vw, 760px);
}
#app.editor-open[data-view="chat"] #editor { width: var(--editor-w); border-left-color: var(--border); border-left-width: 1px; }

#editor .ed-inner {
  display: flex;
  flex-direction: column;
  width: var(--editor-w);
  height: 100%;
}
/* Shut and slid away (editor.js sleep), or left open behind another view:
   nothing in it is styled or laid out. */
:is(#editor.asleep, #app:not([data-view="chat"]) #editor) .ed-inner { content-visibility: hidden; }

/* ---- head ------------------------------------------------------------------ */
#editor .ed-head {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
  padding: 0 8px 0 14px;
  flex: none;
}
#editor .ed-kind { display: inline-grid; place-items: center; color: var(--accent); margin-right: 4px; }
#editor .ed-kind .icon { width: 16px; height: 16px; }
#editor .ed-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--ui-size);
  font-weight: 600;
}
#editor .ed-spacer { flex: 1; }
#editor .ed-versions { display: inline-flex; align-items: center; gap: 0; margin-right: 6px; }
#editor .ed-versions[hidden] { display: none; }
#editor .ed-count {
  min-width: 44px;
  height: 26px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text2);
  font: inherit;
  font-size: var(--ui-meta);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
#editor .ed-count:hover { background: var(--surface-hover); color: var(--text); }
#editor .ed-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
#editor .ed-btn:hover:not(:disabled) { background: var(--soft); color: var(--text); }
#editor .ed-btn:disabled { opacity: 0.35; cursor: default; }
#editor .ed-btn[hidden] { display: none; }
#editor .ed-btn .icon { width: 15px; height: 15px; }
#editor .ed-versions .ed-btn { width: 24px; height: 26px; }

#editor .ed-note {
  display: flex;
  gap: 12px;
  flex: none;
  padding: 0 16px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text3);
  font-size: var(--ui-meta);
  white-space: nowrap;
}
#editor .ed-note-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#editor .ed-note.model .ed-note-text { color: var(--accent-ink); }
#editor .ed-stats { flex: none; font-variant-numeric: tabular-nums; }

/* Read, Edit, Changes: three words in a quiet segmented row. */
#editor .ed-views {
  display: inline-flex;
  gap: 2px;
  margin-right: 6px;
  padding: 2px;
  border-radius: 9px;
  background: var(--surface);
}
#editor .ed-view {
  height: 24px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text3);
  font: 500 var(--ui-meta) var(--ui);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
#editor .ed-view:hover:not(:disabled) { color: var(--text); }
#editor .ed-view.on { background: var(--surface-pressed); color: var(--text); }
#editor .ed-view:disabled:not(.on) { opacity: 0.4; cursor: default; }

/* ---- the document ------------------------------------------------------------ */
#editor .ed-body { position: relative; flex: 1; min-height: 0; display: flex; overflow: hidden; }
#editor .ed-body > [hidden] { display: none; }
#editor .ed-read, #editor .ed-changes {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 18px 22px 24px;
  outline: none;
  color: var(--text);
  font-family: var(--font-sans, var(--ui));
  font-size: 15px;
  line-height: 1.65;
  --block-gap: 0.8em;
}
#editor.code .ed-read { padding: 12px; }
#editor .ed-read ::selection, #editor .ed-changes ::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
#editor .ed-changes { white-space: pre-wrap; overflow-wrap: break-word; }
#editor.code .ed-changes { font-family: var(--font-mono); font-size: 13px; line-height: 1.55; }
#editor .ed-changes ins {
  border-radius: 3px;
  background: color-mix(in srgb, var(--added) 22%, transparent);
  text-decoration: none;
}
#editor .ed-changes del {
  border-radius: 3px;
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--text3);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent);
}
#editor .ed-text {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  padding: 18px 22px 24px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans, var(--ui));
  font-size: 15px;
  line-height: 1.65;
  tab-size: 4;
}
#editor .ed-text::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
#editor.code .ed-text {
  margin: 12px;
  padding: 14px 16px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
}
#editor.busy .ed-text { cursor: progress; }
/* The same working bar as a design's (css/design.css): a band moved by
   transform from off the left edge to off the right. */
#editor.busy .ed-body::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 40%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  transform: translateX(-100%);
  animation: ed-working 1.2s linear infinite;
}
@keyframes ed-working { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
html.reduced-motion #editor.busy .ed-body::after { animation: none; width: 100%; transform: none; opacity: 0.5; }

/* ---- asking for a change -------------------------------------------------------- */
#editor .ed-foot { flex: none; padding: 8px 12px 12px; }
#editor .ed-error { color: var(--danger); font-size: var(--ui-meta); padding: 0 4px 6px; }
#editor .ed-error:empty { display: none; }
#editor .ed-scope {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 2px 6px;
  padding: 3px 3px 3px 9px;
  border-radius: 9px;
  background: var(--accent-wash);
  color: var(--accent-ink);
  font-size: 12.5px;
}
#editor .ed-scope[hidden] { display: none; }
#editor .ed-scope > .icon { width: 14px; height: 14px; flex: none; }
#editor .ed-scope-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#editor .ed-scope .ed-btn { width: 22px; height: 22px; color: inherit; }
#editor .ed-scope .ed-btn .icon { width: 12px; height: 12px; }
#editor .ed-ask {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease);
}
html.light #editor .ed-ask { border-color: var(--border); }
#editor .ed-ask:focus-within { border-color: color-mix(in srgb, var(--border-strong) 55%, var(--text3)); }
#editor .ed-ask-input {
  flex: 1;
  min-width: 0;
  min-height: 24px;
  max-height: 140px;
  resize: none;
  border: 0;
  outline: none;
  padding: 3px 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--ui-size);
  line-height: 1.4;
}
#editor .ed-ask-input::placeholder { color: var(--text3); }
#editor .ed-ask .ed-send, #editor .ed-ask .ed-stop {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
}
#editor .ed-ask .ed-send:hover { background: var(--accent-hover); color: var(--accent-text); }
#editor .ed-ask .ed-stop { background: var(--surface-pressed); color: var(--text); }
#editor .ed-ask .ed-stop .icon { width: 12px; height: 12px; }
