/* ---------- Tokens ---------- */

:root {
  --bg: #ffffff;
  --fg: #1c1c1f;            /* body text */
  --fg-strong: #0d0d0f;     /* headings, bold */
  --mark: #b4b4bb;          /* faded syntax in the source view */
  --list-mark: #8e8e96;     /* list bullets are syntax too, but you navigate by them */
  --soft: #6b6b73;          /* quotes, link text, URLs */
  --chrome: #a1a1a9;        /* resting colour of controls */
  --chrome-hover: #3f3f46;
  --rule: #e6e6ea;
  --code-bg: #f4f4f6;
  --caret: #3b7cf0;
  --link: #2563c9;          /* rendered links */
  --selection: rgba(59, 124, 240, 0.17);
  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-border: #e6e6ea;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);

  --font-text: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --text-size: 18px;
  --text-lh: 1.7;
  --column: 40rem;          /* ~68 characters of Inter at 18px */
  --gutter: max(20px, calc((100vw - var(--column)) / 2));

  --ease: cubic-bezier(0.65, 0, 0.35, 1);
  --hide-ms: 700ms;         /* controls drift away slowly while you write... */
  --show-ms: 200ms;         /* ...and come back promptly when you reach for them */
}

:root[data-theme="dark"] {
  --bg: #18181b;
  --fg: #cacad2;
  --fg-strong: #ececf1;
  --mark: #55555e;
  --list-mark: #6c6c75;
  --soft: #8f8f99;
  --chrome: #5f5f68;
  --chrome-hover: #d4d4da;
  --rule: #2c2c31;
  --code-bg: #232327;
  --caret: #6aa1ff;
  --link: #7aa9ff;
  --selection: rgba(106, 161, 255, 0.24);
  --panel-bg: rgba(32, 32, 36, 0.94);
  --panel-border: #2f2f35;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18181b;
    --fg: #cacad2;
    --fg-strong: #ececf1;
    --mark: #55555e;
    --list-mark: #6c6c75;
    --soft: #8f8f99;
    --chrome: #5f5f68;
    --chrome-hover: #d4d4da;
    --rule: #2c2c31;
    --code-bg: #232327;
    --caret: #6aa1ff;
  --link: #7aa9ff;
    --selection: rgba(106, 161, 255, 0.24);
    --panel-bg: rgba(32, 32, 36, 0.94);
    --panel-border: #2f2f35;
    --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  }
}

@media (max-width: 640px) {
  :root { --text-size: 16.5px; --text-lh: 1.65; }
}

/* ---------- Page ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--chrome) 35%, transparent) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-text);
  font-size: var(--text-size);
  line-height: var(--text-lh);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11";          /* single-storey a is calmer at length */
  transition: background-color 250ms ease, color 250ms ease;
}

::selection { background: var(--selection); }

main { min-height: 100vh; }

button { font: inherit; color: inherit; }

/* ---------- Chrome ---------- */

.chrome {
  position: fixed;
  z-index: 10;
  display: flex;
  align-items: center;
  font-size: 13px;
  line-height: 1;
  font-feature-settings: "tnum";
  color: var(--chrome);
  opacity: 1;
  transition: opacity var(--show-ms) var(--ease);
}
/* Its pictures and links are buttons: a press clicks them, the browser doesn't drag them away. */
.chrome :is(img, a, svg) { -webkit-user-drag: none; }
.chrome-top { top: max(12px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); gap: 2px; }
.chrome-bottom {
  left: 0; right: 0; bottom: max(12px, env(safe-area-inset-bottom));
  justify-content: space-between;
  padding: 0 22px;
  pointer-events: none;
}
.chrome-bottom > * { pointer-events: auto; }

/* While you type the controls fade to a quiet 55%, and stay where a click reaches them; any deliberate mouse movement or
   keyboard focus brings them back. The status line at the bottom goes out of sight (on touch, it stays at 55% too). */
body.chrome-hidden .chrome { opacity: 0.55; transition-duration: var(--hide-ms); }
body.chrome-hidden .chrome-bottom { opacity: 0; }
body.chrome-hidden .chrome-bottom > * { pointer-events: none; }
body.chrome-hidden .chrome:focus-within { opacity: 1; }
/* A save failure is never hidden. */
body.chrome-hidden .chrome-bottom:has(.status.error) { opacity: 1; }

.icon-btn {
  position: relative;
  -webkit-user-select: none; user-select: none;
  display: grid; place-items: center;
  width: 34px; height: 34px;
  padding: 0;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--chrome);
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
}
.icon-btn[hidden] { display: none; }
.icon-btn:hover { color: var(--chrome-hover); background: color-mix(in srgb, var(--chrome) 12%, transparent); }
.icon-btn:focus-visible, .stat:focus-visible { outline: 2px solid var(--caret); outline-offset: 1px; }
/* Each page action's icon is drawn 15 units tall of its 24, centred: a group in it scales it there, and sets the stroke's
   width back by the same amount. So every icon in a header has the same height. */
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Tooltips, the same on every control: plain text, the moment the pointer is on it,
   just below the pointer with its right edge there, following it (server/pages/account-menu.ts sets
   --tip-x and --tip-y as it moves; without them, right-aligned under the control).
   (Avatars use ::before: their ::after widens them for a finger.) */
.icon-btn[data-tip]::after, :is(.avatar, .agent-badge)[data-tip]::before {
  content: attr(data-tip);
  position: absolute; left: var(--tip-x, 100%); top: var(--tip-y, calc(100% + 6px)); transform: translateX(-100%); z-index: 40;
  white-space: pre;
  font: 400 12px/1.3 var(--font-text); letter-spacing: 0.01em;
  color: var(--soft);
  opacity: 0; pointer-events: none;
}
@media (hover: hover) {
  .icon-btn[data-tip]:hover::after, :is(.avatar, .agent-badge)[data-tip]:hover::before { opacity: 1; }
}
/* Its card or menu is open, where the tooltip would be. */
.icon-btn[aria-expanded="true"][data-tip]::after, .avatar[aria-expanded="true"][data-tip]::before { display: none; }
/* A control that's on (paused, editing, its card open) is blue, and keeps the same hover as the others: in the editor and on the admin pages. */
.chrome-top :is(.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"]) { color: var(--caret); }

.stat {
  border: 0; background: none; padding: 6px 0; margin: 0;
  color: var(--chrome); cursor: pointer; font-size: 13px;
  font-feature-settings: "tnum";
  transition: color 150ms ease;
}
.stat:hover { color: var(--chrome-hover); }

.status { opacity: 0; transition: opacity 400ms ease; }
.status.show { opacity: 1; }
.status.error { opacity: 1; color: #d9534f; }

/* ---------- Help panel & toast ---------- */

.help, .toast {
  position: fixed;
  z-index: 20;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 13.5px;
  line-height: 1.5;
}
.help {
  top: 58px; right: 16px;
  width: min(320px, calc(100vw - 32px));
  padding: 16px 18px 14px;
  border-radius: 12px;
  color: var(--fg);
  animation: pop 160ms var(--ease);
}
/* The shortcut card is long: it scrolls in a low window. */
#help { max-height: calc(100vh - 74px); overflow-y: auto; overscroll-behavior: contain; }
#help dl { gap: 5px 12px; }
.help dl { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; margin: 0; }
.help dt { color: var(--soft); }
.help dd { margin: 0; display: flex; gap: 3px; align-items: center; color: var(--soft); }
.help p { margin: 14px 0 0; color: var(--soft); font-size: 12.5px; }
/* The editor's Share with people card. */
.help.share { width: min(400px, calc(100vw - 32px)); }
.help.share h2 { margin: 0 0 6px; font: 600 14px/1.3 var(--font-text); color: var(--fg-strong, var(--fg)); }
.help.share p { margin: 0 0 10px; }
.share-actions { display: flex; gap: 8px; align-items: center; margin: 10px 0 0; }
.share-actions button {
  font: 600 12.5px var(--font-text); border-radius: 7px; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--panel-border); background: transparent; color: var(--fg);
}
.share-actions .share-primary { background: var(--caret); border-color: var(--caret); color: #fff; }
.share-actions button[aria-disabled="true"] { opacity: 0.5; cursor: default; }
.share-status { font-size: 12px; color: var(--soft); }
/* A copy that worked: the button says so (share-agent.ts, showCopied), green, with a short pop. An icon button says it in
   its tooltip, shown for the moment. */
.share-actions .share-primary.copied { background: #16a34a; border-color: #16a34a; }
.text-btn.copied { color: #16a34a; }
.icon-btn.copied[data-tip]::after { opacity: 1; color: #16a34a; }
button.copied { animation: copied-pop 260ms ease-out; }
@keyframes copied-pop { 0% { transform: scale(0.94); } 55% { transform: scale(1.05); } 100% { transform: scale(1); } }
.help.share .share-note { margin: 10px 0 0; font-size: 12px; }
.help.share .share-note a { color: inherit; }
/* Share (#sharing): Share with people. Every row (the box to add someone, each person, the link) is one line on one grid:
   face, who, the role menu, and a last column (Add, ×, Copy link), so the menus line up and the row ends share one right edge. */
.help.sharing { width: min(380px, calc(100vw - 32px)); padding: 0; }
.sharing section { padding: 12px 14px; }
.sharing section + section { border-top: 1px solid var(--rule); }
.sharing section[hidden] { display: none; }
.help.sharing h2 { margin: 0 0 8px; }
.share-grid { display: grid; grid-template-columns: 24px minmax(0, 1fr) 96px 60px; align-items: center; column-gap: 8px; }
.sharing-add { margin: 0 0 4px; }
.sharing-add .naming-input { grid-column: 1 / span 2; min-width: 0; height: 28px; margin: 0; padding: 0 9px; }
.sharing-add button { height: 28px; padding: 0; font: 600 12.5px var(--font-text); border-radius: 7px; border: 1px solid var(--panel-border); background: var(--bg); color: var(--fg); cursor: pointer; }
.sharing-add button:hover { border-color: color-mix(in srgb, var(--chrome) 45%, var(--panel-border)); }
.sharing-list { list-style: none; margin: 0; padding: 0; }
.sharing-list li, .sharing-anyone { min-height: 32px; }
.sharing :is(.sharing-list, .sharing-anyone) .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-strong, var(--fg)); }
.sharing .who small { margin-left: 6px; font-size: 11.5px; color: var(--soft); }
.sharing-list .who .pending { color: #c2410c; }
.sharing-list .fixed { grid-column: 3 / span 2; justify-self: end; font-size: 12.5px; color: var(--soft); }
.sharing-list .remove { justify-self: end; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--chrome); cursor: pointer; font-size: 16px; line-height: 1; }
.sharing-list .remove:hover { color: var(--chrome-hover); background: color-mix(in srgb, var(--chrome) 12%, transparent); }
.sharing .face { position: relative; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; overflow: hidden; font: 600 11px/1 var(--font-text); color: #fff; background: var(--c, var(--chrome)); }
.sharing .face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sharing .face.anyone { color: var(--soft); background: color-mix(in srgb, var(--chrome) 16%, transparent); }
.sharing .face.anyone svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }
/* The link's row: who it lets in, its menu (while it's offered: the who takes its place otherwise), then Copy link. The
   who wraps where it doesn't fit, a phone's width, rather than being cut off. */
.sharing .sharing-anyone .who { white-space: normal; line-height: 1.3; }
.sharing-anyone label { cursor: pointer; }
.sharing-anyone .text-btn { grid-column: 4; justify-self: end; white-space: nowrap; }
.text-btn { padding: 0; border: 0; background: none; color: var(--caret); font: 500 12.5px/1.6 var(--font-text); cursor: pointer; }
.text-btn:hover { text-decoration: underline; text-underline-offset: 2px; }
.sharing select.role { width: 96px; height: 28px; padding: 0 22px 0 8px; border: 1px solid var(--rule); border-radius: 7px; color: var(--fg); font: 12.5px var(--font-text); cursor: pointer;
  appearance: none; -webkit-appearance: none; background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1a9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 6px center / 13px; }
.sharing select.role:hover { border-color: color-mix(in srgb, var(--chrome) 55%, var(--rule)); }
.sharing :is(select.role, .text-btn, .sharing-add button):focus-visible { outline: 2px solid var(--caret); outline-offset: 1px; }
.sharing-status { margin: 6px 0 0 !important; }
.sharing-status:empty { display: none; }
.sharing-status.error { color: #c2410c; }

kbd {
  font-family: var(--font-text);
  font-size: 11.5px;
  min-width: 20px; height: 20px;
  display: inline-grid; place-items: center;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid var(--panel-border);
  background: color-mix(in srgb, var(--chrome) 10%, transparent);
  color: var(--fg);
}

/* The notes: at the bottom, in the middle of the page's part of the window (beside the agent's panel, not under it). A
   confirmation (the toast) sits over the alerts, so neither covers the other. */
.notes {
  position: fixed; z-index: 21;
  left: calc((var(--frame-l, 0px) + 100vw - var(--frame-r, 0px)) / 2);
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 32px);
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
/* A presentation has its steps bar at the bottom centre (36 px high, 14 px up): the notes sit 8 px over it. */
body.has-steps .notes { bottom: 58px; }
.toast {
  position: relative;
  max-width: calc(100vw - 32px); box-sizing: border-box;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--soft);
  opacity: 0; transform: translateY(6px);
  transition: opacity 200ms ease, transform 200ms var(--ease);
}
.toast.show { opacity: 1; transform: none; }

/* ---------- Alerts (client/shell/alerts.ts) ---------- */

.alerts { --bad: #c2410c; --ok: #1f7a4d; pointer-events: auto; font: 13.5px/1.5 var(--font-text); color: var(--fg); text-align: left; }
.alerts:empty { display: none; }
:root[data-theme="dark"] .alerts { --bad: #ff8a65; --ok: #4cc38a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .alerts { --bad: #ff8a65; --ok: #4cc38a; } }
.alerts-pill, .alerts-card {
  background: var(--panel-bg); border: 1px solid var(--panel-border); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
/* Progress alone: one line. A click opens the card. */
.alerts-pill { display: flex; align-items: center; margin: 0; padding: 7px 14px; border-radius: 999px; color: var(--soft); font: inherit; white-space: nowrap; }
button.alerts-pill { cursor: pointer; }
.alerts-seg { display: inline-flex; align-items: center; gap: 7px; }
.alert-mark { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--bad); }
.alert-mark.progress {
  width: 13px; height: 13px;
  background: conic-gradient(var(--caret) calc(var(--p) * 360deg), color-mix(in srgb, var(--chrome) 34%, transparent) 0);
  -webkit-mask: radial-gradient(circle, transparent 3.6px, #000 4.2px); mask: radial-gradient(circle, transparent 3.6px, #000 4.2px);
}
/* (It can't tell how far it is: a quarter of the ring, turning.) */
.alert-mark.progress.unknown { --p: 0.25; animation: alert-turn 900ms linear infinite; }
@keyframes alert-turn { to { transform: rotate(360deg); } }
.alert-mark.done { width: 13px; height: 13px; background: none; color: var(--ok); }
.alert-mark.done svg { display: block; width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.alerts-pill .chev { width: 12px; height: 12px; margin-left: 8px; fill: none; stroke: var(--chrome); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* The card: every alert, one block each. */
.alerts-card { display: flex; flex-direction: column; width: min(440px, calc(100vw - 32px)); max-height: min(60vh, 480px); border-radius: 16px; overflow: hidden; }
.alerts-head { display: flex; align-items: center; gap: 8px; box-sizing: border-box; min-height: 40px; padding: 6px 6px 6px 16px; }
.alerts-head h2 { flex: 1; margin: 0; font: 600 13px/1.5 var(--font-text); color: var(--fg-strong); }
.alerts-all { flex: none; margin-right: 2px; padding: 0 6px; border: 0; background: none; color: var(--caret); font: 500 12.5px/1.6 var(--font-text); cursor: pointer; }
.alerts-close { flex: none; width: 28px; height: 28px; border: 0; border-radius: 8px; background: none; color: var(--soft); font: 400 20px/1 var(--font-text); cursor: pointer; }
.alerts-close:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); color: var(--fg); }
.alerts-list { margin: 0; padding: 0; list-style: none; overflow-y: auto; overscroll-behavior: contain; }
.alert { display: grid; grid-template-columns: 13px minmax(0, 1fr) auto; align-items: center; column-gap: 10px; padding: 10px 10px 10px 16px; border-top: 1px solid var(--rule); }
.alert > .alert-mark { align-self: start; justify-self: center; margin-top: 7px; }
.alert > .alert-mark.progress, .alert > .alert-mark.done { margin-top: 4px; }
.alert-text { min-width: 0; }
.alert-title { margin: 0; font-weight: 500; color: var(--fg-strong); overflow-wrap: anywhere; }
.alert-count { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--chrome) 18%, transparent); color: var(--soft); font: 600 11.5px/1.55 var(--font-text); vertical-align: 1px; font-variant-numeric: tabular-nums; }
.alert-detail { margin: 0; font-size: 12.5px; color: var(--soft); overflow-wrap: anywhere; }
.alert-actions { display: flex; gap: 6px; }
/* Two actions or more: on a line of their own, under the text. */
.alert-actions.under { grid-column: 2 / -1; margin-top: 8px; }
.alert-action { flex: none; border: 1px solid var(--panel-border); border-radius: 10px; padding: 6px 11px; background: transparent; color: var(--fg); font: 600 13px var(--font-text); cursor: pointer; }
.alert-action.primary { border-color: transparent; background: var(--fg-strong); color: var(--bg); }
:is(.alert-action, .alerts-all)[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
/* A batch: one row for each file. Its numbers change many times a second: only --p and the row's detail. */
.alert-rows { grid-column: 2 / -1; display: grid; gap: 9px; margin: 8px 0 2px; padding: 0; list-style: none; }
.alert-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; column-gap: 10px; row-gap: 4px; font-size: 12.5px; }
.alert-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.alert-row .detail { color: var(--soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.alert-row-action { margin-left: 8px; padding: 0; border: 0; background: none; color: var(--caret); font: 500 12.5px/1.5 var(--font-text); cursor: pointer; }
/* The label beside a folder of the file tree while files are dragged over it (client/shell/tree-files.ts). */
.drop-chip { position: fixed; z-index: 60; display: flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px 0 8px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  background: var(--panel-bg); border: 1px solid var(--panel-border); box-shadow: var(--shadow); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); font: 500 12px/1 var(--font-text); color: var(--fg); }
.drop-chip[hidden] { display: none; }
.drop-chip svg { width: 14px; height: 14px; color: var(--caret); flex: none; }
.drop-chip span { color: var(--soft); font-weight: 400; }
/* A row's × (an upload's Cancel). */
.alert-row .side { min-width: 20px; }
.alert-row-action[data-action="cancel"] { display: block; width: 20px; height: 20px; margin: 0; border-radius: 6px; color: var(--chrome); font: 400 16px/1 var(--font-text); }
.alert-row-action[data-action="cancel"]:hover { color: var(--fg); }
.alert-bar { grid-column: 1 / 3; height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--chrome) 24%, transparent); overflow: hidden; }
.alert-bar::before { content: ""; display: block; width: calc(var(--p) * 100%); height: 100%; border-radius: 2px; background: var(--caret); }
.alert-row[data-state="waiting"] .alert-bar::before { background: var(--chrome); }
.alert-bar.unknown::before { width: 30%; animation: alert-run 1100ms ease-in-out infinite alternate; }
@keyframes alert-run { from { transform: translateX(0); } to { transform: translateX(233%); } }
.alert-row[data-state="done"] .detail { color: var(--ok); }
.alert-row[data-state="error"] .why { grid-column: 1 / -1; color: var(--bad); overflow-wrap: anywhere; }
/* A phone: the actions always under the text. */
@media (max-width: 520px) {
  .alerts-card { width: calc(100vw - 16px); max-height: 50vh; }
  .alert-actions { grid-column: 2 / -1; margin-top: 8px; }
}

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

@media (hover: none) {
  body.chrome-hidden .chrome-bottom { opacity: 0.55; }
  body.chrome-hidden .chrome-bottom > * { pointer-events: auto; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --hide-ms: 0ms; --show-ms: 0ms; }
  body, .toast, .help, button.copied, .alert-mark, .alert-bar::before { transition: none; animation: none; }
}

@media print {
  .chrome, .help, .notes { display: none !important; }
}

/* Resizing and docking an agent panel: the editor's and the admin pages'. The grip on the
   edge that faces the page shows its line on hover and while dragged; a panel dragged by its head is lifted,
   and the ghost shows the slot it will land in. Where each panel sits is the page's own. */
.agent-resize { position: absolute; top: 18px; bottom: 18px; right: -9px; width: 12px; cursor: col-resize; touch-action: none; z-index: 1; }
.agent-resize[data-side="right"] { right: auto; left: -9px; }
.agent-resize::after { content: ""; position: absolute; top: 0; bottom: 0; left: 5px; width: 2px; border-radius: 1px; background: var(--caret); opacity: 0; transform: scaleY(0.6); transition: opacity 160ms ease, transform 260ms cubic-bezier(0.45, 0, 0.15, 1); }
.agent-resize:hover::after, body.layout-resizing .agent-resize::after { opacity: 0.7; transform: none; transition-delay: 80ms; }
body.layout-resizing, body.layout-resizing * { cursor: col-resize !important; user-select: none; }
body.layout-dragging, body.layout-dragging * { cursor: grabbing !important; user-select: none; }
.layout-dragged { z-index: 40 !important; transition: none !important; }
.dock-ghost {
  position: fixed; z-index: 19;
  border: 2px dashed color-mix(in srgb, var(--caret) 55%, transparent); border-radius: 18px; box-sizing: border-box;
  background: color-mix(in srgb, var(--caret) 9%, transparent); pointer-events: none;
  transition: left 320ms cubic-bezier(0.45, 0, 0.15, 1), width 320ms cubic-bezier(0.45, 0, 0.15, 1), opacity 160ms ease;
  animation: dock-ghost-in 200ms cubic-bezier(0.45, 0, 0.15, 1);
}
.dock-ghost[hidden] { display: none; }
@keyframes dock-ghost-in { from { opacity: 0; transform: scale(0.97); } }

/* ---------- The agent panel's insides ----------
   Its head, the conversation and the box: the editor's panel (client/styles/editor.css places it) and
   the admin's on the admin pages both use them. */

.agent-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 18px; }
.agent-head .title { font-weight: 600; color: var(--fg-strong); }
.agent-head .model { color: var(--chrome); font-size: 12px; margin-left: 6px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-head .model select {
  appearance: none; -webkit-appearance: none; field-sizing: content; border: 0; margin: 0; cursor: pointer; max-width: 100%;
  font: inherit; color: inherit; border-radius: 6px; padding: 3px 18px 3px 6px;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239a9aa2' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 5px center / 9px 6px;
}
/* The menu's own padding lines its text up with a plain model name, inside .model's clip. */
.agent-head .model:has(select) { margin-left: 0; }
.agent-head .model select:hover { color: var(--chrome-hover); background-color: color-mix(in srgb, var(--chrome) 12%, transparent); }
/* Inset, so .model's clip can't cut it. */
.agent-head .model select:focus-visible:not(.by-pointer) { outline: 2px solid var(--caret); outline-offset: -2px; }
.agent-head .model select.by-pointer { outline: none; }
.agent-log { flex: 1; overflow-y: auto; padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg-user.pending { opacity: 0.55; }
.msg-user.failed { box-shadow: inset 0 0 0 1px #d0453a; }
.send-failed { display: block; margin-top: 4px; color: #d0453a; font-size: 12.5px; }
.send-failed button { border: 0; background: none; padding: 0; color: inherit; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.msg-user { align-self: flex-end; max-width: 88%; background: var(--code-bg); border-radius: 12px; padding: 7px 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-assistant { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-assistant code, .msg-tool code { font: 0.88em var(--font-mono); background: var(--code-bg); border-radius: 4px; padding: 0.1em 0.3em; }
.msg-thinking { color: var(--chrome); font-size: 12.5px; white-space: pre-wrap; max-height: 4.8em; overflow: hidden; -webkit-mask-image: linear-gradient(to bottom, transparent, #000 1.6em); mask-image: linear-gradient(to bottom, transparent, #000 1.6em); display: flex; flex-direction: column; justify-content: flex-end; }
.msg-tool { color: var(--soft); font-size: 12.5px; display: flex; gap: 7px; align-items: baseline; }
.msg-tool::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--chrome); transform: translateY(-1px); }
.msg-tool.running::before { background: var(--caret); animation: agent-pulse 1s ease-in-out infinite alternate; }
.msg-tool.error { color: #d0453a; }
.msg-tool.error::before { background: #d0453a; }
.msg-tool > span { min-width: 0; flex: 1; }
.msg-tool img.shot { display: block; max-width: 100%; max-height: 220px; object-fit: contain; object-position: left top; margin-top: 6px; border: 1px solid var(--rule); border-radius: 8px; background: #fff; }
.msg-tool.retried { color: var(--chrome); }
.msg-tool.retried::before { background: color-mix(in srgb, var(--chrome) 60%, transparent); }
.msg-tool.asking { color: var(--fg); flex-wrap: wrap; padding: 9px 10px; border-radius: 10px; background: var(--code-bg); }
.msg-tool.asking::before { background: var(--caret); }
.msg-tool.asking .detail { color: var(--fg-strong); font-weight: 600; font-size: 12.5px; opacity: 1; overflow-wrap: anywhere; }
.msg-tool .ask-acts { display: flex; justify-content: flex-end; gap: 6px; flex-basis: 100%; }
.msg-tool .ask-acts button { height: 28px; padding: 0 10px; border: 1px solid var(--rule); border-radius: 9px; background: transparent; color: var(--fg); font: 600 12.5px var(--font-text); cursor: pointer; }
.msg-tool .ask-acts button.run { border-color: transparent; background: var(--fg-strong); color: var(--bg); }
.msg-tool .ask-acts button:disabled { opacity: 0.5; cursor: default; }
.msg-tool .detail { display: block; white-space: pre-wrap; font-size: 12px; opacity: 0.85; }
/* The admin agent's panel, off for want of an Anthropic API key: the key, pasted in place. */
.agent-no-key a { color: var(--link); }
.agent-connect { margin-top: 8px; font-size: 12.5px; }
.agent-connect p { margin: 0 0 4px; color: var(--soft); }
.agent-connect pre { margin: 0 0 6px; padding: 6px 8px; border-radius: 7px; background: var(--code-bg); font: 12px/1.45 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.agent-connect button { height: 28px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 7px; background: var(--bg); color: var(--fg); font: 550 12.5px var(--font-text); cursor: pointer; }
.msg-error { color: #d0453a; white-space: pre-wrap; font-size: 13px; }
@keyframes agent-pulse { from { opacity: 0.35; } to { opacity: 1; } }
.agent-compose { padding: 10px; border-top: 1px solid var(--rule); display: flex; gap: 6px; align-items: flex-end; }
/* The box grows with what you type (field-sizing: content) and its
   wrapper eases to the new height, synced by a ResizeObserver in main.ts,
   so the height glides rather than snapping a line at a time. */
.agent-field { flex: 1; min-width: 0; align-self: flex-end; overflow: hidden; border-radius: 12px; transition: height 160ms cubic-bezier(0.2, 0, 0, 1); }
.agent-compose textarea {
  display: block; box-sizing: border-box; width: 100%; field-sizing: content;
  resize: none; border: 1px solid var(--rule); border-radius: 12px; padding: 8px 10px;
  font: inherit; color: var(--fg); background: var(--bg); max-height: 40vh; min-height: 38px; outline: none;
}
@media (prefers-reduced-motion: reduce) { .agent-field { transition: none; } }
.agent-compose textarea:focus { border-color: color-mix(in srgb, var(--caret) 60%, var(--rule)); }
.agent-send { flex: none; height: 38px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--fg-strong); color: var(--bg); font: 600 13px var(--font-text); cursor: pointer; }
.agent-send.stop { background: var(--code-bg); color: var(--fg); }
.agent-send[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }
/* Attachments: the paperclip, the chips above the box, the panel lit up while files are dragged over it, and the chips in a sent message. */
.agent-attach { flex: none; height: 38px; width: 34px; color: var(--soft); }
.agent-attach svg { width: 19px; height: 19px; }
.agent-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 0; border-top: 1px solid var(--rule); }
.agent-attachments[hidden] { display: none; }
.agent-attachments + .agent-compose { border-top: 0; }
.file-chip { position: relative; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; height: 30px; padding: 0 8px; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg); font-size: 12.5px; color: var(--fg); white-space: nowrap; }
.file-chip .name { overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 180px; }
.file-chip .size { color: var(--chrome); font-size: 11.5px; }
.file-chip.image { height: 56px; padding: 0; overflow: hidden; background: #fff; }
.file-chip.image img { display: block; height: 100%; width: auto; max-width: 160px; object-fit: cover; }
.file-chip.reading { color: var(--chrome); border-style: dashed; }
.file-chip button { flex: none; display: grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; background: var(--code-bg); color: var(--fg); font: 600 13px/1 var(--font-text); cursor: pointer; }
.file-chip.image button { position: absolute; top: 3px; right: 3px; background: color-mix(in srgb, var(--fg-strong) 75%, transparent); color: var(--bg); }
.file-chip button:hover { background: var(--fg-strong); color: var(--bg); }
.msg-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.msg-user > .msg-files:not(:first-child) { margin-top: 6px; }
.msg-files .file-chip.image { height: 96px; }
.msg-files .file-chip.image img { max-width: 220px; }
/* Files dragged over the panel (attach-ui.ts): the whole open panel lights up, with what a drop does in its middle. */
.agent-drop .agent-card::after {
  content: "Drop files to attach them"; position: absolute; inset: 6px; z-index: 5; display: grid; place-items: center; border-radius: 13px;
  background: color-mix(in srgb, var(--caret) 9%, transparent); outline: 2px dashed color-mix(in srgb, var(--caret) 70%, transparent); outline-offset: -2px;
  color: var(--fg-strong); font: 600 13px var(--font-text); pointer-events: none;
}
.agent-hint { margin: 0 10px 8px; padding: 7px 10px; border-radius: 10px; background: var(--code-bg); color: var(--soft); font-size: 12.5px; line-height: 1.45; }
.agent-hint.sticky { color: var(--fg); }
.agent-hint[hidden] { display: none; }
/* A comment with @erga written in the page: the person's click here runs it (person-agent.ts). */
.agent-ask { margin: 0 10px 8px; padding: 9px 10px; border-radius: 10px; background: var(--code-bg); font-size: 12.5px; line-height: 1.45; }
.agent-ask[hidden] { display: none; }
.agent-ask p { margin: 0; }
.agent-ask-q { color: var(--fg-strong); font-weight: 600; }
.agent-ask-text { margin-top: 4px !important; max-height: 7.25em; overflow: auto; color: var(--fg); white-space: pre-wrap; overflow-wrap: anywhere; }
.agent-ask-acts { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.agent-ask-acts button { height: 28px; padding: 0 10px; border: 1px solid var(--rule); border-radius: 9px; background: transparent; color: var(--fg); font: 600 12.5px var(--font-text); cursor: pointer; }
.agent-ask-acts button.run { border-color: transparent; background: var(--fg-strong); color: var(--bg); }
/* The end of the agent's turn (client/agent/turn-summary.ts): what it changed, See changes, Undo the turn. */
.agent-turn { margin: 0 10px 8px; padding: 7px 8px 7px 10px; border-radius: 10px; background: var(--code-bg); color: var(--fg); font-size: 12.5px; line-height: 1.45;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.agent-turn[hidden], .agent-turn [hidden] { display: none; }
.agent-turn span { flex: 1 1 auto; overflow-wrap: anywhere; }
.agent-turn button { border: 1px solid var(--panel-border); border-radius: 8px; padding: 3px 9px; background: transparent; color: var(--fg); font: 600 12px var(--font-text); cursor: pointer; }
.agent-turn button.undo { background: var(--fg-strong); border-color: var(--fg-strong); color: var(--bg); }
.agent-turn button:disabled { opacity: 0.5; cursor: default; }
dialog.agent-changes { width: min(760px, calc(100vw - 32px)); max-height: min(80vh, 720px); padding: 0; border: 1px solid var(--panel-border); border-radius: 14px;
  background: var(--bg); color: var(--fg); box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25); font-family: var(--font-text); }
dialog.agent-changes[open] { display: flex; flex-direction: column; }
dialog.agent-changes::backdrop { background: rgba(0, 0, 0, 0.25); }
dialog.agent-changes header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--panel-border); }
dialog.agent-changes h2 { margin: 0; font-size: 14px; font-weight: 600; }
dialog.agent-changes button.close { border: 1px solid var(--panel-border); border-radius: 8px; padding: 4px 10px; background: transparent; color: var(--fg); font: 600 12px var(--font-text); cursor: pointer; }
dialog.agent-changes pre { margin: 0; padding: 12px 14px; overflow: auto; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
dialog.agent-changes pre .add { background: color-mix(in srgb, #1a7f37 16%, transparent); }
dialog.agent-changes pre .del { background: color-mix(in srgb, #cf222e 14%, transparent); }
dialog.agent-changes pre .at { color: var(--soft); }
#agent-undo[aria-disabled="true"], #agent-redo[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }
/* Shown while you've scrolled back and the agent has written more below. */
.agent-jump {
  align-self: center; margin: -40px 0 8px; position: relative; z-index: 1; border: 1px solid var(--panel-border); border-radius: 999px;
  padding: 5px 12px; background: var(--bg); color: var(--fg); box-shadow: var(--shadow); font: 600 12px var(--font-text); cursor: pointer;
}
.agent-jump[hidden] { display: none; }
.agent-log { overflow-anchor: none; }
.agent-log:focus { outline: none; } /* focusable only so it can scroll by keyboard; the ring on a click is noise */

/* ---------- Each person's agent ----------
   On every page for someone signed in (server/pages/agent.ts): it floats beside the page as a panel of glass (the glass:
   client/inline/bars.css). Collapsed, it is the round "e" button in the lower corner on its side; the same element grows
   into the panel and shrinks back into it, and the page slides over to make room, on the same curve. In the editor,
   which side and how wide is the user's (layout.ts sets --agent-x, --agent-w, --fab-x, the frame's --frame-l and
   --frame-r, and the bottom row's --cb-l and --cb-r); these defaults are its usual place. */
:root {
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --agent-w: min(380px, calc(100vw - 32px));
  --agent-inset: 16px;
  --agent-left: max(var(--agent-inset), var(--safe-l));
  --agent-fab: 44px;
  --agent-ease: cubic-bezier(0.45, 0, 0.15, 1);
  --agent-ms: 560ms;
  --agent-x: var(--agent-left); --fab-x: var(--agent-left);
  --frame-l: var(--safe-l); --frame-r: var(--safe-r);
  --cb-l: calc(var(--agent-left) + var(--agent-fab) + 14px); --cb-r: 22px;
  --agent-top: max(8px, env(safe-area-inset-top));
  --agent-bottom: max(var(--agent-inset), env(safe-area-inset-bottom), calc(var(--kb, 0px) + var(--agent-inset)));
}
/* The agent's box (#agent) is where the open panel goes, top to bottom, and takes clicks only while it's open. Its glass
   (.agent-glass) is the one element that moves: 44px round, at the corner on the agent's side, closed; the whole box, open.
   It eases its width, height and corners (560ms), and keeps its shadow all the way. The panel's insides (.agent-card) keep
   the open panel's size, anchored at the same corner, and the glass crops them. Opening, the "e" fades out at once (120ms),
   then the insides fade in (200ms, from 120ms); closing, the insides fade out (240 to 440ms), then the "e" fades in, whole
   when the glass is the circle again. */
.agent {
  position: fixed; z-index: 20; left: var(--agent-x); top: var(--agent-top); bottom: var(--agent-bottom); width: var(--agent-w);
  container-type: size; pointer-events: none;
  transition: left var(--agent-ms) var(--agent-ease), width var(--agent-ms) var(--agent-ease);
}
body.agent-open .agent { pointer-events: auto; }
body:not(.agent-open) .agent-resize { display: none; }
.agent-glass {
  position: absolute; left: 0; bottom: 0; width: var(--agent-fab); height: var(--agent-fab); border-radius: calc(var(--agent-fab) / 2);
  overflow: hidden; pointer-events: auto; -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 90px), var(--glass-tinted), color-mix(in srgb, var(--glass-pg) 76%, transparent);
  /* (Its 0.5px edge is a ring inside it, not a border: the "e" and the insides start at its very edge.) */
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.07), var(--glass-edge), var(--glass-shadow);
  transition: width var(--agent-ms) var(--agent-ease), height var(--agent-ms) var(--agent-ease), border-radius var(--agent-ms) var(--agent-ease);
}
html.page-dark body:not(.source) .agent-glass {
  background: linear-gradient(rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0) 90px), color-mix(in srgb, var(--glass-pg) 70%, transparent);
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 2px 8px rgba(0, 0, 0, 0.4);
}
body.agent-open .agent-glass { width: 100%; height: 100%; border-radius: 18px; }
/* Right of the page, it grows out of the lower-right corner. */
body.agent-right :is(.agent-glass, .agent-card, .agent-fab) { left: auto; right: 0; }
.agent-card {
  position: absolute; left: 0; bottom: 0; width: 100cqw; height: 100cqh;
  display: flex; flex-direction: column;
  font: 14px/1.55 var(--font-text); color: var(--fg);
  opacity: 0; visibility: hidden;
  transition: opacity 200ms ease 240ms, visibility 0s linear 440ms;
}
body.agent-open .agent-card { opacity: 1; visibility: visible; transition: opacity 200ms ease 120ms, visibility 0s; }
.agent-fab {
  position: absolute; left: 0; bottom: 0; width: var(--agent-fab); height: var(--agent-fab);
  display: grid; place-items: center; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--chrome-hover); transition: opacity 120ms ease 440ms;
}
.agent-fab svg { width: 22px; height: 22px; }
.agent-fab:focus-visible { outline: 2px solid var(--caret); outline-offset: 2px; border-radius: 50%; }
.agent-fab.by-pointer { outline: none; }
.agent-fab.busy::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--caret); animation: agent-spin 0.9s linear infinite; }
@keyframes agent-spin { to { transform: rotate(360deg); } }
body.agent-open .agent-fab { opacity: 0; pointer-events: none; transition: opacity 120ms ease; }
@media (prefers-reduced-motion: reduce) { :is(.agent-card, .agent-fab) { transition: none !important; } }
/* Its insides on the glass: the box and your messages as faint fills of it, not white cards. */
.agent .agent-compose { border-top: 0; }
.agent .agent-compose textarea { background: rgba(255, 255, 255, 0.6); border-color: rgba(0, 0, 0, 0.08); }
.agent .msg-user { background: rgba(0, 0, 0, 0.045); }
html.page-dark body:not(.source) .agent .agent-compose textarea { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.12); }
html.page-dark body:not(.source) .agent .msg-user { background: rgba(255, 255, 255, 0.08); }
body.no-motion, body.no-motion * { transition: none !important; }
