/* ── agent ──
 * The note agent (src/agent.js): the face bottom-right and its floating window.
 * Every piece borrows a convention the app already has — the palette float's name on
 * its border, #fab-mic's frame, /learn's send button, /voice's print, the sidebar's
 * file badges — so it reads as part of the same app.
 * Linked from index.html in cascade order — the order is load-bearing. */

/* ── The bubble ── */
#agent-bubble {
  position: fixed; right: 22px; bottom: calc(var(--status-height) + 16px); z-index: 80;
  display: flex; align-items: center; gap: 10px;
  padding: 0; border: 0; background: none; cursor: pointer; font: inherit;
  transition: opacity .2s cubic-bezier(.2, .8, .2, 1) .1s, transform .3s cubic-bezier(.16, 1, .3, 1) .1s, visibility 0s linear 0s;
}
#agent-bubble:hover { transform: translateY(-2px); transition-delay: 0s; }
#agent-bubble:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 4px; border-radius: 999px; }
#agent-bubble.off {
  opacity: 0; transform: scale(.6); visibility: hidden; pointer-events: none;
  transition: opacity .1s cubic-bezier(.4, 0, 1, 1), transform .14s cubic-bezier(.4, 0, 1, 1), visibility 0s linear .14s;
}
.agent-face-wrap { position: relative; display: block; }
.agent-face { display: block; border-radius: 50%; background: #fdf6e8; }
#agent-bubble .agent-face { width: 52px; height: 52px; box-shadow: 0 0 0 1px var(--border), 0 14px 34px -12px rgba(0, 0, 0, .8); }
.agent-dot {
  position: absolute; right: 1px; top: 1px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--bg-page);
}
.agent-tip {
  padding: 6px 10px; border-radius: 6px; background: var(--bg-raised); border: 1px solid var(--border);
  color: var(--fg); font-size: 11.5px; white-space: nowrap;
  opacity: 0; transform: translateX(4px); transition: opacity .15s, transform .15s; pointer-events: none;
}
.agent-tip b { color: var(--fg-dim); font-weight: 500; }
#agent-bubble:hover .agent-tip, #agent-bubble:focus-visible .agent-tip { opacity: 1; transform: none; }

/* ── The window: grows out of the bubble's corner, shrinks back faster ── */
#agent {
  position: fixed; right: 22px; bottom: calc(var(--status-height) + 16px); z-index: 80;
  width: 400px; height: min(540px, calc(100vh - var(--status-height) - 60px));
  display: flex; flex-direction: column;
  background: var(--bg-raised); color: var(--fg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 1px var(--accent-soft);
  font-size: 12.5px;
  transform-origin: calc(100% - 26px) calc(100% - 26px);
  transition: opacity .2s cubic-bezier(.2, .8, .2, 1), transform .34s cubic-bezier(.16, 1, .3, 1), visibility 0s linear 0s;
}
#agent.off {
  opacity: 0; transform: translateY(8px) scale(.9); visibility: hidden; pointer-events: none;
  transition: opacity .14s cubic-bezier(.4, 0, 1, 1), transform .18s cubic-bezier(.4, 0, 1, 1), visibility 0s linear .18s;
}
/* Its name on the top border, as the palette's float windows wear theirs. */
#agent::before {
  content: "agent"; position: absolute; top: -9px; left: 22px; padding: 0 9px;
  background: var(--bg-raised); color: var(--accent); font-size: 12px; font-weight: 600; letter-spacing: .5px;
}
@media (prefers-reduced-motion: reduce) {
  #agent, #agent.off, #agent-bubble, #agent-bubble.off { transform: none !important; transition-property: opacity, visibility !important; }
}
/* Desktop only, and never in focus mode. It does show on the home screen, where people start.
   Stacking: 80 puts the agent
   over an expanded board (50), the share card (60) and live cursors (55), under the palette
   (100). #fab, at 90 in this same corner, shows on touch or at 700px and under, so the agent
   hides under that exact query rather than competing with it (tests/agent-css.test.js). */
body.island #agent-bubble, body.focus-mode :is(#agent, #agent-bubble) { display: none; }
/* The phone layout is a touch screen too, but it has its own button for the agent (#isl-agent) and
   shows the window as a card, so it is exempt from this query. */
@media (hover: none), (max-width: 700px) { body:not(.island) #agent, #agent-bubble { display: none; } }

/* ── On the phone: a card above the pill and its buttons ── */
body.island #agent {
  left: 12px; right: 12px; width: auto;
  bottom: calc(var(--isl-safe-b) + 74px);
  height: min(480px, calc(100vh - var(--isl-safe-b) - 150px));
  height: min(480px, calc(100dvh - var(--isl-safe-b) - 150px));
  border-radius: 20px; transform-origin: calc(100% - 38px) 100%;
}
/* The keyboard is up and the pill has stepped aside: the card drops onto the keys, as the format strip does. */
body.island.isl-kb #agent { bottom: calc(var(--isl-kb-h, 0px) + 8px); height: min(480px, calc(100vh - var(--isl-kb-h, 0px) - 70px)); height: min(480px, calc(100dvh - var(--isl-kb-h, 0px) - 70px)); }
/* 16px, or iOS zooms the page when the box takes focus. */
body.island #agent-input { font-size: 16px; }

.agent-head {
  flex-shrink: 0; height: 46px; display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 0 14px; border-bottom: 1px solid var(--border-soft);
}
.agent-head .agent-face { width: 24px; height: 24px; }
.agent-head-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
#agent-open-name { font-size: 11.5px; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#agent-open-more { font-size: 10px; color: var(--fg-dim); }
#agent-new { margin-left: auto; }
.agent-ibtn {
  width: 28px; height: 28px; flex-shrink: 0; display: grid; place-items: center;
  border: 0; border-radius: 5px; background: none; color: var(--fg-dim); cursor: pointer; font: inherit; font-size: 15px;
}
.agent-ibtn svg { width: 14px; height: 14px; }
.agent-ibtn:hover { color: var(--fg); background: color-mix(in srgb, var(--fg) 6%, transparent); }
.agent-ibtn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* ── The thread: newest at the bottom, kept there ── */
#agent-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column-reverse; }
#agent-thread { padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 16px; }

.agent-empty { padding: 40px 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.agent-empty .agent-face { width: 64px; height: 64px; box-shadow: 0 0 0 1px var(--border); }
.agent-empty-title { font-size: 14px; font-weight: 600; }
.agent-empty-line { font-size: 12px; color: var(--fg-dim); line-height: 1.55; max-width: 290px; }
.agent-suggests { display: flex; flex-direction: column; gap: 6px; width: 100%; margin-top: 10px; }
.agent-suggest, .agent-nokey {
  text-align: left; padding: 9px 12px; border: 1px solid var(--border-soft); border-radius: 6px;
  background: var(--bg-page); color: var(--fg-dim); font: inherit; font-size: 12px; cursor: pointer;
}
.agent-suggest::before, .agent-nokey::before { content: "› "; color: var(--accent); }
.agent-suggest:hover, .agent-nokey:hover { border-color: var(--accent-line); color: var(--fg); }

.agent-you {
  align-self: flex-end; max-width: 86%; padding: 8px 12px; border-radius: 8px 8px 2px 8px;
  background: var(--bg-code); border: 1px solid var(--border-soft); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}
.agent-msg { display: flex; gap: 10px; align-items: flex-start; }
.agent-msg > .agent-face { width: 22px; height: 22px; flex-shrink: 0; margin-top: 1px; }
.agent-msg-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.agent-text { line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.agent-step { font-size: 11px; color: var(--fg-dim); }
.agent-step::before { content: "↳ "; color: var(--fg-faint); }

/* What it did: one card per action, with its undo. */
.agent-card {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border: 1px solid var(--border-soft); border-radius: 6px; background: var(--bg-page); font-size: 11.5px;
}
.agent-card-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-card-state { color: var(--fg-dim); }
.agent-undo, .agent-open, .agent-undo-all, .agent-flip {
  padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 11px; cursor: pointer;
}
.agent-undo:hover, .agent-open:hover, .agent-undo-all:hover, .agent-flip:hover { text-decoration: underline; }
.agent-undo-all { align-self: flex-start; }

.agent-scope { font-size: 10.5px; color: var(--fg-dim); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.agent-scope .agent-flip { font-size: 10.5px; }
.agent-cites { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-cite {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border: 1px solid var(--border-soft); border-radius: 4px;
  background: none; color: var(--fg-dim); font: inherit; font-size: 11px; cursor: pointer;
}
.agent-cite:hover { border-color: var(--accent-line); color: var(--fg); }
.agent-cite-badge { font-weight: 700; font-size: 9.5px; }

/* The quiz (src/agent-quiz.js): every question at once, options to tap, feedback as you pick. */
.agent-quiz { display: flex; flex-direction: column; gap: 12px; padding: 10px 12px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg-page); }
.agent-quiz-title { font-size: 10.5px; color: var(--fg-dim); text-transform: lowercase; }
.agent-quiz-q { display: flex; flex-direction: column; gap: 6px; }
.agent-quiz-qtext { font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; }
.agent-quiz-opt {
  display: flex; gap: 8px; align-items: baseline; text-align: left; padding: 6px 10px; border: 1px solid var(--border-soft);
  border-radius: 6px; background: none; color: var(--fg-dim); font: inherit; font-size: 12px; line-height: 1.45; cursor: pointer; overflow-wrap: anywhere;
}
.agent-quiz-opt:not(:disabled):hover { border-color: var(--accent-line); color: var(--fg); }
.agent-quiz-opt:disabled { cursor: default; }
.agent-quiz-key { flex-shrink: 0; font-weight: 700; font-size: 10.5px; color: var(--fg-faint); }
.agent-quiz-opt.right { border-color: var(--accent); color: var(--fg); background: var(--accent-line); }
.agent-quiz-opt.right .agent-quiz-key { color: var(--accent); }
.agent-quiz-opt.wrong { border-color: var(--danger); color: var(--fg); }
.agent-quiz-opt.wrong .agent-quiz-key { color: var(--danger); }
.agent-quiz-feedback { font-size: 11px; }
.agent-quiz-feedback.right { color: var(--accent); }
.agent-quiz-feedback.wrong { color: var(--danger); }
.agent-quiz-score { font-size: 12px; font-weight: 600; color: var(--accent); }
.agent-busy { display: flex; gap: 10px; align-items: center; color: var(--fg-dim); font-size: 12px; }
.agent-busy .agent-face { width: 22px; height: 22px; }
.agent-blink { width: 7px; height: 14px; background: var(--accent); display: inline-block; animation: agent-blink 1s steps(1) infinite; }
@keyframes agent-blink { 50% { opacity: 0; } }

/* ── Asking: the box, the mic (#fab-mic in small), send (/learn's .lrn-send) ── */
.agent-compose { flex-shrink: 0; padding: 10px 12px 12px; border-top: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 8px; }
.agent-row { display: flex; gap: 8px; align-items: flex-end; }
#agent-input {
  flex: 1; min-width: 0; resize: none; min-height: 38px; max-height: 120px; padding: 8px 12px;
  background: var(--bg-page); color: var(--fg); border: 1px solid var(--border); border-radius: 6px;
  font: inherit; font-size: 12.5px; line-height: 1.5;
}
#agent-input:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-soft); }
#agent-input::placeholder { color: var(--fg-faint); }
#agent-mic {
  width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center; padding: 0; cursor: pointer;
  border: 1px solid var(--accent-line); border-radius: 6px; background: var(--bg-raised); color: var(--accent);
}
#agent-mic[hidden] { display: none; }
#agent-mic svg { width: 16px; height: 16px; }
#agent-mic:hover { background: var(--accent-soft); }
#agent-mic.live { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
#agent-mic .agent-stop { width: 12px; height: 12px; border-radius: 3px; background: var(--danger); display: block; }
#agent-send {
  height: 38px; flex-shrink: 0; padding: 0 16px; border: 0; border-radius: 6px;
  background: var(--accent); color: var(--bg-page); font: inherit; font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
#agent-send:disabled { opacity: .35; cursor: default; }
#agent-mic:focus-visible, #agent-send:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* While the mic listens: /voice's panel stays out of sight (the agent shows the words in
   its box), and its print draws in a strip that slides open under the box. */
body.agent-rec #voice-panel { display: none !important; }
#agent-print {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px;
  border: 1px solid var(--border-soft); border-radius: 6px; background: var(--bg-page); font-size: 11px; color: var(--fg-dim);
  transition: opacity .18s ease, height .28s cubic-bezier(.16, 1, .3, 1);
}
#agent-print.off { height: 0; opacity: 0; border-width: 0; overflow: hidden; }
.agent-rec-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; animation: agent-rec 1.4s ease-in-out infinite; }
@keyframes agent-rec { 50% { opacity: .35; } }
.agent-rec-label { color: var(--fg); flex-shrink: 0; }
#agent-print-canvas { flex: 1; min-width: 0; height: 22px; display: block; }
#agent-rec-time { flex-shrink: 0; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .agent-rec-dot, .agent-blink { animation: none; } }
