/* AI assistant: the face in the corner of every page but the workbench,
   the chat panel (beside the page, or the workbench's own chat) and the box
   to write in, which also sits on the workbench. */
/* ---- the face ---- */
.ai-avatar {
  position: fixed;
  z-index: var(--z-ai-avatar);
  right: 24px;
  bottom: 24px;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--label);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 5%), 0 6px 20px rgb(0 0 0 / 10%);
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, transform .16s ease, opacity .16s ease;
}
.ai-avatar[hidden] { display: none; }
.ai-avatar:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px rgb(0 0 0 / 6%), 0 8px 24px rgb(0 0 0 / 13%); }
.ai-avatar:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.ai-avatar.is-open { background: var(--accent); color: var(--label-inverse); }
.ai-avatar svg { display: block; }
.ai-avatar-tip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  padding: 5px 10px;
  border-radius: 7px;
  background: rgb(29 29 31 / 90%);
  color: var(--label-inverse);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(4px, -50%);
  transition: opacity .14s ease, transform .14s ease;
}
.ai-avatar:hover .ai-avatar-tip, .ai-avatar:focus-visible .ai-avatar-tip { opacity: 1; transform: translate(0, -50%); }
.ai-avatar.is-open .ai-avatar-tip { display: none; }
/* The workbench has its own chat. */
html[data-route="home"] .ai-avatar { display: none; }
/* Reading or writing a journal entry (or any other modal) gets the corner. */
html:has(dialog:modal) .ai-avatar { opacity: 0; pointer-events: none; }
/* The panel has its own close button. */
html.ai-open .ai-avatar { display: none; }
html.public-guest .ai-avatar, html.public-guest .ai-panel { display: none !important; }

/* ---- the panel ---- */
.ai-panel {
  position: fixed;
  z-index: var(--z-ai-panel);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--label);
  font-size: 14px;
  line-height: 1.65;
}
.ai-panel[hidden] { display: none; }
.ai-panel[data-mode="side"] { top: 0; right: 0; bottom: 0; width: var(--ai-side-w); border-left: 1px solid var(--separator); box-shadow: -8px 0 30px rgb(0 0 0 / 5%); }
/* The workbench's chat fills the page under the header (which keeps the
   chat list and the switch), behind the header's own menus. */
.ai-panel[data-mode="home"] { z-index: var(--z-ai-home); top: var(--header-h); right: 0; bottom: 0; left: var(--sidebar-w); background: var(--bg); }
.ai-panel[data-mode="home"] .ai-panel-head, .ai-panel[data-mode="home"] .ai-panel-handle { display: none; }
.ai-panel[data-mode="home"] .ai-panel-body, .ai-panel[data-mode="home"] .ai-panel-foot { padding-inline: max(18px, calc((100% - 760px) / 2)); }
.ai-panel[data-mode="home"] .ai-panel-body { padding-top: 12px; }
html.home-chatting, html.home-chatting body { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .ai-panel { animation: none !important; } .ai-avatar, .ai-avatar-tip { transition: none; } }
/* The side panel moves the page over when there is room for both. */
@media (min-width: 1100px) { html.ai-open.ai-mode-side .app-content { margin-right: var(--ai-side-w); } }

.ai-panel-handle { display: none; }
.ai-panel-head { position: relative; display: flex; align-items: center; gap: 4px; min-height: var(--header-h); padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--separator-soft); }
.ai-panel-face { display: grid; place-items: center; flex: none; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--label); cursor: pointer; }
.ai-panel-face:hover { background: var(--fill); }
.ai-panel-title, .ai-panel-title-input { flex: 1; min-width: 0; height: 30px; margin: 0 4px 0 2px; padding: 0 6px; border-radius: 7px; font: inherit; font-size: 14px; font-weight: 600; line-height: 30px; color: var(--label); }
.ai-panel-title { overflow: hidden; border: 0; background: transparent; text-align: left; white-space: nowrap; text-overflow: ellipsis; cursor: text; }
.ai-panel-title:hover:not(:disabled) { background: var(--fill); }
.ai-panel-title:disabled { color: var(--label); opacity: 1; cursor: default; }
.ai-panel-title-input { border: 1px solid var(--accent); background: var(--surface); outline: 0; }
.ai-panel-title-input[hidden], .ai-panel-title[hidden] { display: none; }
.ai-icon-button { position: relative; display: grid; place-items: center; flex: none; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--label-3); cursor: pointer; }
.ai-icon-button:hover, .ai-icon-button.is-active { background: var(--fill); color: var(--label); }
.ai-icon-button:focus-visible, .ai-panel button:focus-visible, .ai-panel-foot button:focus-visible, .ai-history button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ai-icon-button span, [data-ai-icon] { display: grid; place-items: center; }

/* menus */
.ai-menu-wrap { position: relative; flex: none; }
.ai-menu { position: absolute; z-index: 5; top: calc(100% + 6px); right: 0; padding: 5px; border: 0; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-pop); font-size: 13px; color: var(--label); }
.ai-menu[hidden] { display: none; }
.ai-menu:not([hidden]) { animation: ai-menu-in .16s cubic-bezier(.22, 1, .36, 1); }
@keyframes ai-menu-in { from { opacity: 0; transform: scale(.97); } }
.ai-history { width: 300px; }
.ai-history input[type="search"] { box-sizing: border-box; width: 100%; margin: 2px 0 4px; padding: 5px 9px; border: 1px solid var(--separator); border-radius: 6px; background: var(--surface); color: inherit; font: inherit; font-size: 12.5px; }
.ai-history input[type="search"]:focus { border-color: var(--accent); outline: 0; }
.ai-history-list { max-height: min(380px, 60vh); overflow: auto; }
.ai-menu-group { margin: 0; padding: 6px 10px 2px; color: var(--label-4); font-size: 11px; }
.ai-menu-note { margin: 0; padding: 10px; color: var(--label-3); font-size: 12.5px; text-align: center; }
.ai-history-row { display: flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 4px 0 0; border-radius: 6px; }
.ai-history-row:hover, .ai-history-row.is-current { background: var(--fill); }
.ai-history-open { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; padding: 6px 6px 6px 9px; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.ai-history-open svg { flex: none; color: var(--label-3); }
.ai-history-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ai-history-time { flex: none; color: var(--label-4); font-size: 11.5px; }
/* Hovering a row trades its time for rename and delete. */
.ai-history-actions { display: none; gap: 1px; }
.ai-history-row:hover .ai-history-actions, .ai-history-row:focus-within .ai-history-actions { display: flex; }
.ai-history-row:hover .ai-history-time, .ai-history-row:focus-within .ai-history-time { display: none; }
.ai-history-new { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 2px; padding: 7px 9px; border: 0; border-radius: 6px; background: transparent; color: var(--label); font: inherit; text-align: left; cursor: pointer; }
.ai-history-new:hover { background: var(--fill); }
.ai-history-new span { color: var(--label-3); }
.ai-row-action { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--label-4); cursor: pointer; }
.ai-row-action:hover { background: var(--fill-strong); color: var(--label); }
.ai-history-rename { flex: 1; min-width: 0; margin: 2px; padding: 4px 8px; border: 1px solid var(--accent); border-radius: 6px; font: inherit; outline: 0; }
.ai-history-confirm { flex: 1; padding-left: 10px; color: var(--label-3); font-size: 12.5px; }
.ai-history-row > button:not(.ai-history-open) { padding: 3px 8px; border: 0; border-radius: 5px; background: transparent; color: var(--label-3); font: inherit; font-size: 12px; cursor: pointer; }
.ai-history-row > .ai-history-delete { background: var(--danger); color: var(--label-inverse); }

/* messages */
.ai-panel-body { flex: 1; min-height: 0; overflow: auto; padding: 20px 20px 8px; overscroll-behavior: contain; }
.ai-message { margin: 0 0 16px; overflow-wrap: anywhere; }
.ai-message-user { width: fit-content; max-width: 82%; margin-left: auto; padding: 8px 13px; border-radius: 18px; background: var(--fill); white-space: pre-wrap; }
.ai-message-context { margin-top: 5px; color: var(--label-3); font-size: 11px; line-height: 1.45; white-space: normal; }
.ai-thinking { margin: 0; color: var(--label-4); font-size: 12.5px; }
.ai-caret { display: inline-block; width: 7px; height: 15px; margin-left: 2px; border-radius: 1px; background: var(--accent); opacity: .8; vertical-align: -2px; animation: ai-caret 1s steps(2, start) infinite; }
@keyframes ai-caret { to { visibility: hidden; } }
.ai-message-error { margin: 4px 0 0; color: var(--danger); font-size: 13px; }
.ai-message-actions { display: flex; gap: 2px; margin: 2px 0 0 -7px; color: var(--label-4); }
.ai-message-actions button { display: flex; align-items: center; gap: 4px; padding: 3px 7px; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-size: 12px; cursor: pointer; }
.ai-message-actions button:hover { background: var(--fill); color: var(--label); }
.ai-message-actions button:disabled { cursor: default; opacity: .65; }
.ai-answer-link { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; }

/* answer text */
.ai-md > :first-child { margin-top: 0; }
.ai-md p { margin: 0 0 8px; }
.ai-md h3, .ai-md h4, .ai-md h5, .ai-md h6 { margin: 14px 0 4px; font-size: 14px; font-weight: 600; line-height: 1.5; }
.ai-md h3 { font-size: 15.5px; }
.ai-md ul, .ai-md ol { margin: 0 0 8px; padding-left: 20px; }
.ai-md li { margin: 2px 0; }
.ai-md li > ul, .ai-md li > ol, .ai-md li > p { margin-bottom: 2px; }
.ai-md blockquote { margin: 0 0 8px; padding: 0 0 0 10px; border-left: 3px solid var(--separator); color: var(--label-3); }
.ai-md hr { margin: 12px 0; border: 0; border-top: 1px solid var(--separator); }
.ai-md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.ai-md code { padding: 1px 5px; border-radius: 4px; background: var(--fill); font: 12.5px ui-monospace, Menlo, monospace; }
.ai-md pre { margin: 0 0 8px; padding: 10px 12px; overflow: auto; border-radius: 8px; background: #1d1d1f; color: #f5f5f7; font: 12px/1.6 ui-monospace, Menlo, monospace; }
.ai-md pre code { padding: 0; background: none; font: inherit; }
.ai-md-table { margin: 4px 0 10px; overflow-x: auto; }
.ai-md table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ai-md th, .ai-md td { padding: 4px 9px; border: 1px solid var(--separator); text-align: left; vertical-align: top; }
.ai-md th { background: var(--fill); font-weight: 600; }
/* formulas (KaTeX); a wide one scrolls on its own line */
.ai-md .ai-md-math { overflow-wrap: normal; }
.ai-md .ai-md-math.is-display { display: block; max-width: 100%; margin: 2px 0 8px; overflow-x: auto; overflow-y: hidden; }
.ai-md .ai-md-math .katex-display { margin: 0; padding: 4px 0; }
.ai-md .katex { font-size: 1.08em; }

/* empty and not-set-up states */
.ai-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 100%; padding: 0 18px; color: var(--label-3); text-align: center; }
.ai-empty svg { color: var(--label); }
.ai-empty h3 { margin: 6px 0 0; color: var(--label); font-size: 17px; font-weight: 600; }
.ai-empty p { max-width: 300px; margin: 0; font-size: 13px; }
.ai-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; max-width: 350px; margin-top: 9px; }
.ai-suggestion { padding: 6px 10px; border: 1px solid var(--separator); border-radius: 999px; background: transparent; color: var(--label); font: inherit; font-size: 12px; cursor: pointer; }
.ai-suggestion:hover { border-color: var(--accent); background: var(--fill); }
.ai-empty-action { margin-top: 10px; padding: 7px 16px; border: 0; border-radius: 7px; background: var(--accent); color: var(--label-inverse); font: inherit; font-size: 13px; cursor: pointer; }
.ai-empty-action:hover { background: var(--accent-hover); }

/* input */
.ai-panel-foot { position: relative; flex: none; padding: 6px 16px 14px; }
.ai-status { margin: 0 2px 6px; color: var(--label-3); font-size: 12px; }
.ai-status[hidden] { display: none; }
.ai-status[data-error="true"] { color: var(--danger); }
.ai-input { padding: 10px 10px 8px 14px; border: 0; border-radius: 18px; background: var(--surface); box-shadow: 0 0 0 1px var(--separator), 0 4px 16px rgb(0 0 0 / 5%); transition: border-color .14s ease; }
.ai-context-bar { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 2px 6px; }
.ai-context-chip-wrap { position: relative; display: inline-flex; align-items: center; max-width: 100%; border: 1px solid var(--separator); border-radius: 999px; background: var(--fill); }
.ai-context-chip { max-width: 260px; overflow: hidden; padding: 4px 5px 4px 9px; border: 0; background: transparent; color: var(--label); font: inherit; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.ai-context-remove { width: 24px; min-width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--label-3); font-size: 15px; line-height: 1; cursor: pointer; }
.ai-context-remove:hover { background: var(--fill); color: var(--label); }
.ai-context-preview { position: absolute; z-index: 3; right: 0; bottom: calc(100% + 7px); width: min(330px, 78vw); max-height: 220px; overflow: auto; padding: 9px 11px; border: 1px solid var(--separator); border-radius: 8px; background: var(--surface); box-shadow: 0 10px 30px rgb(0 0 0 / 11%); color: var(--label-3); font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
/* The plus button's menu, and the record search it opens, sit just above
   the button. */
.ai-plus-wrap { display: flex; }
.ai-plus { display: grid; place-items: center; flex: none; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--label-3); cursor: pointer; }
.ai-plus:hover, .ai-plus.is-active { background: var(--fill); color: var(--label); }
.ai-plus-menu { top: auto; right: auto; bottom: calc(100% + 8px); left: -4px; z-index: 10; min-width: 190px; }
.ai-plus-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; text-align: left; white-space: nowrap; cursor: pointer; }
.ai-plus-menu button:hover:not(:disabled) { background: var(--fill); }
.ai-plus-menu button:disabled { color: var(--label-4); cursor: default; }
.ai-plus-menu button > span:first-child { display: grid; color: var(--label-3); }
.ai-plus-menu small { margin-left: auto; padding-left: 10px; color: var(--label-4); font-size: 11px; }
.ai-plus-menu small:empty { display: none; }
.ai-context-picker { top: auto; right: auto; bottom: calc(100% + 8px); left: -4px; z-index: 10; display: grid; gap: 3px; width: min(340px, calc(100vw - 48px)); max-height: 320px; overflow: hidden; padding: 7px; }
.ai-context-picker[hidden] { display: none; }
.ai-context-search { box-sizing: border-box; width: 100%; margin-bottom: 4px; padding: 6px 8px; border: 1px solid var(--separator); border-radius: 6px; background: var(--surface); color: var(--label); font: inherit; font-size: 12px; }
.ai-context-search:focus { border-color: var(--accent); outline: 2px solid var(--focus-ring); outline-offset: 0; }
.ai-context-picker > [data-ai-context-results] { display: grid; gap: 3px; max-height: 245px; overflow: auto; }
.ai-context-picker p { margin: 3px 5px; color: var(--label-3); font-size: 12px; }
.ai-context-option { min-width: 0; overflow: hidden; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--label); font: inherit; font-size: 12px; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.ai-context-option:hover, .ai-context-option[aria-pressed="true"] { background: var(--fill); }
.ai-input:focus-within { box-shadow: 0 0 0 1px rgb(0 113 227 / 40%), 0 4px 16px rgb(0 0 0 / 6%); }
.ai-input textarea { display: block; box-sizing: border-box; width: 100%; min-height: 42px; max-height: 168px; margin: 0; padding: 0; overflow-y: auto; border: 0; outline: 0; resize: none; background: transparent; color: var(--label); font: inherit; font-size: 14px; line-height: 1.6; }
.ai-input textarea::placeholder { color: var(--label-5); }
.ai-input-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.ai-input-hint { color: var(--label-4); font-size: 12px; white-space: nowrap; opacity: 0; transition: opacity .2s ease; }
.ai-input-hint[hidden] { display: none; }
.ai-input:focus-within .ai-input-hint { opacity: 1; }
.ai-input-tools { display: flex; align-items: center; gap: 2px; min-width: 0; margin-right: auto; }
.ai-image-tray { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 2px 0 8px; }
.ai-image-tray[hidden] { display: none; }
.ai-image-thumb { position: relative; width: 56px; height: 56px; }
.ai-image-thumb img { display: block; width: 100%; height: 100%; border: 1px solid var(--separator); border-radius: 8px; object-fit: cover; }
.ai-image-remove { position: absolute; top: -6px; right: -6px; display: grid; place-items: center; width: 19px; height: 19px; padding: 0; border: 0; border-radius: 50%; background: var(--label); color: var(--label-inverse); font-size: 12px; line-height: 1; cursor: pointer; }
.ai-image-busy { color: var(--label-3); font-size: 12px; }
.ai-model-wrap { min-width: 0; }
.ai-model-wrap[hidden], .ai-note[hidden] { display: none; }
.ai-model-menu { top: auto; right: auto; bottom: calc(100% + 6px); left: 0; min-width: 200px; max-width: min(300px, 80vw); max-height: 320px; overflow: auto; }
.ai-model-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; text-align: left; white-space: nowrap; cursor: pointer; }
.ai-model-menu button:hover, .ai-model-menu [aria-checked="true"] { background: var(--fill); }
.ai-model-option-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ai-model-tag { flex: none; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; line-height: 18px; }
.ai-model-tag.is-warn { background: #fdecec; color: var(--danger); }
.ai-model-menu .ai-check { margin-left: auto; padding-left: 10px; color: var(--accent); visibility: hidden; }
.ai-model-menu [aria-checked="true"] .ai-check { visibility: visible; }
.ai-model-menu .ai-model-manage { margin-top: 4px; border-top: 1px solid var(--separator); border-radius: 0 0 6px 6px; color: var(--label-3); }
.ai-message-images { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; }
.ai-message-images a { display: block; }
.ai-message-images img { display: block; max-width: 180px; max-height: 180px; border-radius: 8px; object-fit: cover; }
.ai-model { display: flex; align-items: center; gap: 5px; min-width: 0; max-width: 100%; padding: 2px 6px 2px 2px; border: 0; border-radius: 6px; background: transparent; color: var(--label-4); font: inherit; font-size: 12px; cursor: pointer; }
.ai-model span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ai-model i { display: grid; flex: none; font-style: normal; }
.ai-model:hover { background: var(--fill); color: var(--label); }
.ai-send { display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: var(--accent); color: var(--label-inverse); cursor: pointer; transition: background-color .14s ease; }
.ai-send:disabled { background: var(--separator-strong); cursor: default; }
.ai-send.is-stop { background: var(--label); }
.ai-note { margin: 6px 0 0; color: var(--label-5); font-size: 11px; text-align: center; }

/* phones: the side panel is one full-screen sheet; the workbench's chat
   stops above the tab bar */
@media (max-width: 760px) {
  .ai-avatar { right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); }
  .ai-avatar-tip { display: none; }
  html.ai-open .ai-avatar { display: none; }
  .ai-panel[data-mode="side"] { inset: 0; width: auto; height: 100dvh; border: 0; border-radius: 0; box-shadow: none; padding-bottom: env(safe-area-inset-bottom); animation: ai-sheet .2s ease-out; overscroll-behavior: none; }
  /* The sheet follows the keyboard (see assistant/viewport.js); a swipe in
     it never moves the page behind. */
  html.ai-keyboard .ai-panel[data-mode="side"] { padding-bottom: 0; }
  html.ai-sheet-locked, html.ai-sheet-locked body { overflow: hidden; overscroll-behavior: none; }
  .ai-panel[data-mode="home"] { left: 0; bottom: calc(64px + env(safe-area-inset-bottom)); }
  .ai-panel-handle { display: block; flex: none; height: 18px; touch-action: none; cursor: grab; }
  .ai-panel-handle::before { content: ""; display: block; width: 38px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--separator); }
  .ai-mode-toggle { display: none; }
  .ai-input textarea { font-size: 16px; }
  .ai-history { width: min(300px, calc(100vw - 28px)); }
  .ai-history-actions { opacity: 1; }
}
@keyframes ai-sheet { from { transform: translateY(24px); opacity: 0; } }

/* An open modal dialog owns the top layer. An assistant moved inside one
   stays clickable above its backdrop. */
dialog.ai-assistant-host > .ai-panel { z-index: 80; }

/* Proposed changes to records (static/js/assistant/edits.js). */
.ai-edits { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 8px; margin-top: 8px; }
.ai-edit { min-width: 0; padding: 10px 12px; border: 1px solid var(--separator); border-radius: 10px; background: var(--surface); font-size: 13px; }
.ai-edit-head { display: flex; min-width: 0; align-items: baseline; justify-content: space-between; gap: 8px; }
.ai-edit-head strong { min-width: 0; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.ai-edit-head span { flex: none; color: var(--label-4); font-size: 12px; }
.ai-edit-summary { margin: 4px 0 0; color: var(--label-3); }
.ai-edit-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; margin-top: 6px; }
.ai-edit-row > span:first-child { color: var(--label-4); font-size: 12px; }
.ai-edit del, .ai-diff-line.is-del { background: color-mix(in srgb, var(--danger) 12%, transparent); color: inherit; }
.ai-edit ins, .ai-diff-line.is-add { background: color-mix(in srgb, var(--success) 14%, transparent); color: inherit; text-decoration: none; }
.ai-edit-row del, .ai-edit-row ins { padding: 0 4px; border-radius: 4px; }
.ai-diff { max-height: 320px; margin-top: 8px; overflow: auto; overscroll-behavior: contain; border-radius: 6px; background: var(--fill); font-size: 12.5px; line-height: 1.55; }
.ai-diff-line { padding: 1px 8px 1px 18px; white-space: pre-wrap; overflow-wrap: anywhere; position: relative; }
.ai-diff-line.is-del::before, .ai-diff-line.is-add::before { position: absolute; left: 6px; color: var(--label-4); }
.ai-diff-line.is-del::before { content: "−"; }
.ai-diff-line.is-add::before { content: "+"; }
.ai-diff-line mark { border-radius: 2px; color: inherit; }
.ai-diff-line.is-del mark { background: color-mix(in srgb, var(--danger) 30%, transparent); text-decoration: line-through; }
.ai-diff-line.is-add mark { background: color-mix(in srgb, var(--success) 32%, transparent); }
.ai-diff-gap { padding: 2px 8px; color: var(--label-4); font-size: 11.5px; text-align: center; }
.ai-edit-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.ai-edit-foot button { padding: 5px 14px; border: 0; border-radius: 7px; font: inherit; font-size: 12.5px; cursor: pointer; }
.ai-edit-apply { background: var(--accent); color: var(--label-inverse); }
.ai-edit-apply:hover { background: var(--accent-hover); }
.ai-edit-dismiss { background: var(--fill); color: var(--label); }
.ai-edit-foot button:disabled { cursor: default; opacity: .6; }
.ai-edit-foot button[aria-disabled="true"] { cursor: wait; opacity: .6; }
.ai-edit-content { max-height: 240px; overflow: auto; overscroll-behavior: contain; margin-top: 8px; }
.ai-edit-records { max-height: 200px; overflow: auto; margin: 8px 0 0; padding-left: 20px; }
.ai-edits-all { justify-content: flex-start; min-width: 0; margin-top: 0; }
.ai-edit-state { color: var(--label-3); font-size: 12px; }
.ai-edit.is-stale .ai-edit-state { color: var(--danger); }
.ai-edit.is-dismissed { opacity: .7; }

/* ---- the face drawing: hats and held things reach past its box ---- */
svg.ai-face { display: block; flex: none; overflow: visible; pointer-events: none; }

/* ---- 个性化小助手 ---- */
.ai-persona { width: min(480px, calc(100vw - 24px)); padding: 0; overflow-x: hidden; overscroll-behavior: contain; }
.ai-persona-form { display: grid; gap: 14px; padding: 18px 22px 20px; }
.ai-persona-head { display: flex; align-items: center; justify-content: space-between; margin: 0 -6px -4px 0; }
.ai-persona-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.ai-persona-stage { display: flex; align-items: center; justify-content: center; gap: 18px; padding-top: 6px; }
.ai-persona-preview { display: grid; place-items: center; width: 128px; height: 128px; border-radius: 50%; background: var(--fill); color: var(--label); }
.ai-persona-preview svg.ai-face { transform: translateY(6px); }
.ai-persona-arrow { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--separator); border-radius: 50%; background: var(--surface); color: var(--label-2); cursor: pointer; }
.ai-persona-arrow:hover { background: var(--fill); color: var(--label); }
.ai-persona-face-name { margin: -6px 0 0; color: var(--label-3); font-size: 12px; text-align: center; }
.ai-persona-field { display: grid; gap: 6px; color: var(--label-2); font-size: 13px; font-weight: 600; }
.ai-persona-field input, .ai-persona-field textarea { width: 100%; box-sizing: border-box; padding: 9px 11px; border: 1px solid var(--separator-strong); border-radius: 10px; background: var(--surface); color: var(--label); font: inherit; font-size: 14px; font-weight: 400; }
.ai-persona-field textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.ai-persona-field input:focus, .ai-persona-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.ai-persona-hint { display: flex; justify-content: space-between; gap: 10px; margin: -8px 0 0; color: var(--label-4); font-size: 12px; }
.ai-persona-accessories { margin: 0; padding: 0; border: 0; min-width: 0; }
.ai-persona-accessories legend { margin-bottom: 8px; padding: 0; color: var(--label-2); font-size: 13px; font-weight: 600; }
.ai-persona-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.ai-persona-choice { display: grid; place-items: center; aspect-ratio: 1; padding: 0; border: 1px solid transparent; border-radius: 10px; background: var(--fill); color: var(--label-2); cursor: pointer; transition: background-color .16s ease, border-color .16s ease; }
.ai-persona-item * { stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.ai-persona-choice:hover { background: var(--fill-strong); color: var(--label); }
.ai-persona-choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.ai-persona-choice:focus-visible, .ai-persona-arrow:focus-visible, .ai-panel-face:focus-visible, .header-ai-face:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ai-persona .ai-status { margin: -6px 0 0; min-height: 0; font-size: 12px; color: var(--label-3); }
.ai-persona .ai-status:empty { display: none; }
.ai-persona .ai-status.is-error { color: var(--danger); }
.ai-persona-actions { display: flex; justify-content: space-between; gap: 10px; }
.ai-persona-actions button { min-width: 88px; padding: 8px 18px; }
.ai-persona-entry { display: inline-flex; align-items: center; gap: 8px; justify-self: start; }
.ai-persona-entry > span { display: grid; }
@media (max-width: 480px) {
  .ai-persona-form { padding: 16px 16px 18px; gap: 12px; }
  .ai-persona-preview { width: 100px; height: 100px; }
  .ai-persona-grid { grid-template-columns: repeat(5, 1fr); }
  .ai-persona-choice { aspect-ratio: auto; height: 44px; }
}
@media (prefers-reduced-motion: reduce) { .ai-persona-choice { transition: none; } }

.ai-message-usage { margin: 8px 0 0; color: var(--label-4); font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; }
.ai-message-usage summary { cursor: pointer; width: fit-content; max-width: 100%; }
.ai-message-usage p { margin: 4px 0 0; }
.ai-message-usage summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }
