/* Shared components: buttons, inputs, cards, menus, dialogs, toasts, badges */

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 550;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  white-space: nowrap;
}
/* A button may be an <a>: base.css's a:hover (0,1,1) would paint its text link-blue — invisible on a
   primary button. Each variant's :hover (0,2,0) restates its own colour, and a button is never underlined. */
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-fg); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); color: #fff; }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: var(--text-xs); border-radius: var(--r-sm); }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--r-md); font-size: 1.05rem; flex-shrink: 0; }
.btn-block { width: 100%; }

/* ── Inputs ─────────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  transition: border-color var(--dur) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { line-height: 1.5; min-height: 5.5em; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.field { margin-bottom: var(--sp-4); }
.field-label { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: 6px; }
.field-help { font-size: var(--text-xs); color: var(--text-muted); margin-top: 5px; }

.search-input-wrap { position: relative; }
.search-input-wrap .bi-search {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); font-size: .85rem; pointer-events: none;
}
.search-input-wrap .input { padding-left: 32px; }
.search-input-wrap .search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
}
.search-input-wrap .search-clear:hover { background: var(--surface-hover); color: var(--text); }

/* toggle switch */
.switch { position: relative; display: inline-flex; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: var(--r-full);
  background: var(--border-strong); transition: background var(--dur) var(--ease);
}
.switch .track::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: var(--r-full);
  background: #fff; transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}
.card-hover { transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease); }
.card-hover:hover { border-color: var(--border-strong); transform: translateY(-1px); }

/* ── Badges / chips ─────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--surface-hover);
  color: var(--text-muted);
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-hover); color: var(--text-muted); }

/* ── Popover menus ──────────────────────────────────────── */
.menu-anchor { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  font-weight: 400; /* never inherit the trigger bar's weight — stack items set their own */
  min-width: 230px;
  max-width: min(340px, calc(100vw - 24px));
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: var(--sp-1);
  z-index: 200;
  /* grow with the window — only scroll when the viewport genuinely can't fit it */
  max-height: calc(100vh - 90px);
  max-height: min(88vh, calc(100dvh - 90px));
  overflow-y: auto;
}
.menu--right { left: auto; right: 0; }
.menu--up { top: auto; bottom: calc(100% + 6px); }

/* In-place panel: fills the nearest positioned ancestor (the chat sidebar)
   instead of floating over it. Same .menu-item vocabulary, own scroll.
   No `display` here — the [hidden] attribute must keep working. */
.menu--sidebar {
  inset: 0;
  min-width: 0;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--bg-raised);
  padding: var(--sp-2);
  animation: menu-slide-up 160ms var(--ease, ease);
}
@keyframes menu-slide-up {
  from { opacity: 0; transform: translateY(14px); }
}
.menu-header--row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.menu-header--row .menu-header-who { min-width: 0; }
.menu-header--row .menu-header-sub { overflow-wrap: anywhere; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  color: var(--text);
  text-align: left;
}
.menu-item:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.menu-item.active { background: var(--accent-soft); color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-item .bi { flex-shrink: 0; width: 1.1em; text-align: center; color: var(--text-muted); }
.menu-item.danger .bi { color: var(--danger); }
.menu-sep { border-top: 1px solid var(--border); margin: var(--sp-1) 0; }
.menu-header { padding: 8px 10px 6px; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-1); }
.menu-header-name { font-weight: 650; font-size: var(--text-sm); }
.menu-header-sub { font-size: var(--text-xs); color: var(--text-muted); }
.menu-label {
  padding: 6px 10px 2px;
  font-size: var(--text-xs); font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint);
}

/* Markdown task lists in a reply — display only (see inertTaskBoxes). The tickable
   version is the notepad card; these just make "- [ ] item" read as a checklist. */
.md-body li:has(> .md-task) { list-style: none; margin-left: -1.15em; }
.md-task {
  display: inline-block;
  width: 13px; height: 13px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
}
.md-task[data-done="1"] {
  border-color: var(--success);
  background: var(--success);
  position: relative;
}
.md-task[data-done="1"]::after {
  content: '';
  position: absolute;
  left: 3px; top: 0px;
  width: 4px; height: 8px;
  border: solid var(--bg);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.md-body li:has(> .md-task[data-done="1"]) { color: var(--text-muted); }

/* ── Image lightbox ─────────────────────────────────────── */
dialog.lightbox {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 96vw;
  max-height: 96vh;
  outline: none;
}
dialog.lightbox::backdrop { background: rgba(0, 0, 0, .82); }
dialog.lightbox img {
  display: block;
  max-width: 96vw;
  max-height: 90vh;
  border-radius: var(--r-md);
  cursor: zoom-out;
}
dialog.lightbox .lb-close {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
dialog.lightbox .lb-close:hover { background: rgba(0, 0, 0, .85); }
/* Gallery (2026-10-17): ‹ › flip through the conversation's images; n / total under it. */
dialog.lightbox .lb-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
dialog.lightbox .lb-nav[hidden] { display: none; }
dialog.lightbox.is-gallery img { cursor: default; }
@media (min-width: 601px) { dialog.lightbox.is-gallery img { max-width: calc(100vw - 140px); } }   /* clear of ‹ › */
dialog.lightbox .lb-nav:hover { background: rgba(0, 0, 0, .85); }
dialog.lightbox .lb-prev { left: 14px; }
dialog.lightbox .lb-next { right: 14px; }
dialog.lightbox .lb-count {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}
dialog.lightbox .lb-count[hidden] { display: none; }
@media (max-width: 600px) {
  dialog.lightbox .lb-nav { width: 40px; height: 40px; font-size: 1.15rem; }
  dialog.lightbox .lb-prev { left: 6px; }
  dialog.lightbox .lb-next { right: 6px; }
}

/* ── Dialogs (desktop modal / mobile bottom sheet) ─────── */
dialog.dlg {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-overlay);
  color: var(--text);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  max-height: min(85vh, 85dvh);
  box-shadow: var(--shadow-2);
}
dialog.dlg::backdrop { background: var(--scrim); }
.dlg-body { padding: var(--sp-4); overflow-y: auto; max-height: calc(85dvh - 120px); }
.dlg-title { font-size: var(--text-lg); font-weight: 650; padding: var(--sp-4) var(--sp-4) 0; }
.dlg-actions {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
}
/* Title row with a close × (openDialog closeX). */
.dlg-head { display: flex; align-items: flex-start; gap: var(--sp-2); }
.dlg-head .dlg-title { flex: 1; min-width: 0; }
.dlg-x {
  flex: none; margin: var(--sp-3) var(--sp-3) 0 0; width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; border-radius: var(--r-full); color: var(--text-muted); cursor: pointer;
}
.dlg-x:hover { background: var(--surface-hover); color: var(--text); }
.dlg-x:focus:not(:focus-visible) { outline: none; }
/* openDialog({full:true}): the whole viewport, body stretches so its content can fill it. */
dialog.dlg.dlg-full { width: calc(100vw - 32px); max-width: none; height: calc(100dvh - 32px); max-height: none; }
dialog.dlg.dlg-full[open] { display: flex; flex-direction: column; }
dialog.dlg.dlg-full .dlg-body { flex: 1; min-height: 0; max-height: none; display: flex; flex-direction: column; }
/* Where the left menu is on screen (≥1024px), the full dialog covers only the content area beside it. */
@media (min-width: 1024px) {
  body.has-navrail dialog.dlg.dlg-full, body.has-sidebar dialog.dlg.dlg-full {
    width: calc(100vw - var(--sidebar-w) - 32px);
    margin: 16px 16px 16px calc(var(--sidebar-w) + 16px);
  }
}

@media (max-width: 639px) {
  dialog.dlg {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog.dlg.dlg-full { height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  dialog.dlg:not(.dlg-full)::before {
    content: "";
    display: block;
    width: 42px; height: 4px;
    border-radius: var(--r-full);
    background: var(--border-strong);
    margin: 8px auto 0;
  }
}

/* ── Toasts ─────────────────────────────────────────────── */
.toast-region {
  position: fixed;
  bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: 10px 14px;
  font-size: var(--text-sm);
  max-width: min(420px, calc(100vw - 32px));
  animation: toast-in 180ms var(--ease);
}
.toast--error { border-color: var(--danger); }
.toast--error .bi { color: var(--danger); }
.toast--success .bi { color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Page scaffolding (ported pages) ────────────────────── */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.page-head h1 { margin-bottom: 2px; }
.page-head .page-sub { color: var(--text-muted); margin: 0; }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}
.toolbar .search-input-wrap { max-width: 300px; flex: 1 1 200px; }
.toolbar-spacer { flex: 1; }

.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
  text-align: left;
  font-weight: 650;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tr.inactive { opacity: .55; }
.data-table tr.row-link { cursor: pointer; }
.data-table tr.row-link:hover .bi-chevron-right { color: var(--accent); }
.dt-actions { display: flex; gap: 2px; justify-content: flex-end; white-space: nowrap; }
.dt-num { text-align: right; font-variant-numeric: tabular-nums; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--sp-4); }
.form-grid .field-full { grid-column: 1 / -1; }
@media (max-width: 639px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Banners ────────────────────────────────────────────── */
.app-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--sp-4);
  background: var(--accent-soft);
  color: var(--text);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
}
.app-banner--warn { background: var(--warn-soft); }
.app-banner .bi { color: var(--accent); }
.app-banner--warn .bi { color: var(--warn); }
.app-banner-action { margin-left: auto; font-weight: 600; white-space: nowrap; }

/* non-interactive footer note inside menus */
.menu-note {
  padding: 8px 10px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: var(--sp-1);
  max-width: 260px;
}
.menu-note b { color: var(--warn); }

/* ── Slide-over panel (monitor drawer etc.) ─────────────── */
.slide-over {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(520px, 100vw);
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 200ms var(--ease);
}
.slide-over.open { transform: translateX(0); }
.slide-over-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.slide-over-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-4); }
.slide-over-foot { flex-shrink: 0; border-top: 1px solid var(--border); padding: var(--sp-3) var(--sp-4); display: flex; gap: var(--sp-2); }

/* ── Tool requirements checklist panel ──────────────────── */
.req-panel {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  padding: var(--sp-3);
  margin-top: var(--sp-2);
}
.req-title { font-size: var(--text-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: var(--sp-2); }
.req-section-label { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); margin: var(--sp-2) 0 4px; }
.req-optional { font-weight: 400; color: var(--text-faint); }
/* align-items:flex-start so a note that wraps to 2+ lines (e.g. the coding-
   sandbox read-only rows) grows the row cleanly instead of overlapping the
   next one; single-line rows look identical. */
.req-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.req-status { flex-shrink: 0; width: 1em; text-align: center; font-size: .9rem; line-height: 1.5; }
.req-var { font-family: var(--font-mono); font-size: var(--text-sm); min-width: 90px; flex-shrink: 0; line-height: 1.5; word-break: break-all; }
/* min-width:0 lets the note wrap within the flex track instead of overflowing;
   it sits beside a possibly-long var name, so both need to share the row. */
.req-note { font-size: var(--text-xs); color: var(--text-muted); flex: 1; min-width: 0; line-height: 1.4; padding-top: 1px; }
.req-input { flex: 1; padding: 5px 10px; font-size: var(--text-sm); }
/* eye toggle beside a masked credential input — sized to the compact req row */
.req-reveal { width: 30px; height: 30px; font-size: .95rem; }
.req-inherited { background: var(--surface-hover); color: var(--text-muted); }
.req-status-line { margin-top: var(--sp-2); font-size: var(--text-sm); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.req-status-line.ready { color: var(--success); }
.req-status-line.not-ready { color: var(--warn); }

/* Transfer Call (811) destination editor — tool-requirements.js renderTransferEditor */
.xfer-help { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.45; margin: 0 0 6px; }
.xfer-help.warn { color: var(--warn); }
.xfer-agents { border: 1px solid var(--border); border-radius: var(--r-md); max-height: 220px; overflow-y: auto; background: var(--surface); }
.xfer-agents table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.xfer-agents th { position: sticky; top: 0; background: var(--surface); font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); text-align: center; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.xfer-agents th:first-child, .xfer-agents td:first-child { text-align: left; width: 100%; }
.xfer-agents td { padding: 4px 8px; text-align: center; border-bottom: 1px solid var(--border); }
.xfer-agents tr:last-child td { border-bottom: 0; }
.xfer-agents td.ghost { color: var(--danger); font-size: var(--text-xs); }
.xfer-agents input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.xfer-num-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.xfer-num-row .xfer-label { flex: 1 1 45%; min-width: 0; }
.xfer-num-row .xfer-number { flex: 1 1 55%; min-width: 0; font-family: var(--font-mono); }
.xfer-num-row .btn-icon { flex-shrink: 0; width: 30px; height: 30px; }
.req-advanced { margin-top: var(--sp-2); }
.req-advanced > summary { cursor: pointer; font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); }

/* ── Inline audio player (markdown.js enhanceAudioLinks) ── */
/* Inline video player (markdown.js buildVideoPlayer) — our own controls since 2026-10-21.
   TWIN: html/share.php carries this block byte-identical (tests/test-video-player.php). */
/* VIDEO-PLAYER-CSS:BEGIN */
.video-player {
  position: relative;
  display: inline-block;
  max-width: min(480px, 100%);
  margin: 6px 0;
  vertical-align: middle;
  line-height: 0;
  border-radius: var(--r-md);
  overflow: hidden;
  /* the corners are clipped HERE (clip-path is anti-aliased); a rounded <video> layer is not */
  clip-path: inset(0 round var(--r-md));
  isolation: isolate;
  background: #000;
  box-shadow: 0 0 0 1px var(--border), 0 6px 22px rgb(0 0 0 / .10);
  outline: none;
}
.video-player:focus-visible { box-shadow: 0 0 0 2px var(--accent), 0 6px 22px rgb(0 0 0 / .10); }
.video-player.is-wide { display: block; max-width: min(860px, 100%); }
.video-player video { display: block; width: 100%; max-height: 70vh; background: #000; cursor: pointer; }
.video-player.is-fullscreen { max-width: none; border-radius: 0; clip-path: none; display: flex; align-items: center; justify-content: center; }
.video-player.is-fullscreen video { max-height: 100vh; height: 100%; }
.video-player .vp-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border: 0; border-radius: var(--r-full);
  background: transparent; color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
  transition: background .15s ease, transform .15s ease; text-decoration: none;
}
.video-player .vp-btn:hover { background: rgb(255 255 255 / .16); }
.video-player .vp-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.video-player .vp-big {
  position: absolute; left: 50%; top: 50%; width: 68px; height: 68px; margin: -34px 0 0 -34px;
  background: var(--accent); color: var(--accent-fg); font-size: 34px;
  box-shadow: 0 8px 26px rgb(0 0 0 / .28); transition: opacity .2s ease, transform .2s ease;
}
.video-player .vp-big i { margin-left: 3px; }
.video-player.is-ended .vp-big i { margin-left: 0; }
.video-player .vp-big:hover { background: var(--accent-hover); transform: scale(1.07); }
.video-player:not(.is-paused) .vp-big { opacity: 0; pointer-events: none; transform: scale(.85); }
.video-player .vp-bar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 4px;
  padding: 26px 10px 8px; line-height: 1;
  background: linear-gradient(to top, rgb(0 0 0 / .62), rgb(0 0 0 / .28) 55%, transparent);
  transition: opacity .25s ease, transform .25s ease;
}
.video-player.is-idle .vp-bar { opacity: 0; transform: translateY(6px); pointer-events: none; }
.video-player.is-idle { cursor: none; }
.video-player .vp-time { color: #fff; font-size: 12.5px; font-variant-numeric: tabular-nums; margin: 0 8px 0 2px; white-space: nowrap; opacity: .92; }
.video-player .vp-track { position: relative; flex: 1; height: 18px; display: flex; align-items: center; cursor: pointer; touch-action: none; min-width: 60px; margin: 0 6px; outline: none; }
.video-player .vp-track::before { content: ''; position: absolute; left: 0; right: 0; height: 4px; border-radius: 4px; background: rgb(255 255 255 / .28); transition: height .15s ease; }
.video-player .vp-buf, .video-player .vp-fill { position: absolute; left: 0; height: 4px; border-radius: 4px; transition: height .15s ease; }
.video-player .vp-buf { background: rgb(255 255 255 / .35); }
.video-player .vp-fill { background: var(--accent); }
.video-player .vp-thumb { position: absolute; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / .4); transform: scale(0); transition: transform .15s ease; }
.video-player .vp-track:hover::before, .video-player .vp-track:hover .vp-buf, .video-player .vp-track:hover .vp-fill,
.video-player.is-scrubbing .vp-track::before, .video-player.is-scrubbing .vp-buf, .video-player.is-scrubbing .vp-fill { height: 6px; }
.video-player .vp-track:hover .vp-thumb, .video-player .vp-track:focus-visible .vp-thumb, .video-player.is-scrubbing .vp-thumb { transform: scale(1); }
.video-player .vp-rate { width: auto; min-width: 34px; padding: 0 7px; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .video-player .vp-rate, .video-player .vp-time { display: none; } }
/* a subtitle file beside a video — a chip, not a bare link */
.media-chip {
  display: inline-flex; align-items: center; gap: 6px; margin: 2px 0 6px; padding: 4px 11px 4px 9px;
  border: 1px solid var(--border); border-radius: var(--r-full); background: var(--surface);
  color: var(--text); font-size: 13px; line-height: 1.4; text-decoration: none; transition: background .15s ease, border-color .15s ease;
}
.media-chip:hover { background: var(--surface-hover); border-color: var(--accent); text-decoration: none; }
.media-chip .bi { font-size: 15px; color: var(--accent); }
.media-chip .media-chip-ext { color: var(--text-muted); font-size: 12px; }
/* VIDEO-PLAYER-CSS:END */

/* ── Inline page preview (markdown.js enhancePageLinks) ── */
/* A generated HTML page as a card: scaled thumbnail of the live page + title bar;
   a click opens dialog.page-viewer. The thumbnail iframe is inert (pointer-events
   none) so the whole card is one click target. */
.page-preview {
  display: inline-flex;
  flex-direction: column;
  width: min(520px, 100%);
  margin: 6px 0;
  vertical-align: middle;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.page-preview:hover, .page-preview:focus-visible { border-color: var(--accent, #4b7bec); box-shadow: 0 2px 12px rgba(0,0,0,.12); outline: none; }
.page-preview .pp-thumb { position: relative; display: block; height: 260px; overflow: hidden; background: #fff; }
.page-preview .pp-thumb iframe { position: absolute; top: 0; left: 0; border: 0; transform-origin: 0 0; pointer-events: none; }
.page-preview .pp-hint {
  position: absolute; right: 10px; bottom: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--r-full);
  background: rgba(0,0,0,.6); color: #fff; font-size: .8rem;
  opacity: 0; transition: opacity .15s ease;
}
.page-preview:hover .pp-hint, .page-preview:focus-visible .pp-hint { opacity: 1; }
.page-preview .pp-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--border); line-height: 1.3; }
.page-preview .pp-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.page-preview .pp-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--r-full); color: var(--text-muted); text-decoration: none; }
.page-preview .pp-btn:hover { background: var(--border); color: var(--text); }

dialog.page-viewer {
  width: 96vw; height: 92vh; max-width: 96vw; max-height: 92vh;
  padding: 0; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  display: none; flex-direction: column; overflow: hidden;
}
dialog.page-viewer[open] { display: flex; }
dialog.page-viewer::backdrop { background: rgba(0, 0, 0, .7); }
dialog.page-viewer .pv-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
dialog.page-viewer .pv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
dialog.page-viewer .pv-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; border-radius: var(--r-full); background: transparent; color: var(--text-muted); text-decoration: none; cursor: pointer; font-size: 1rem; }
dialog.page-viewer .pv-btn:hover { background: var(--border); color: var(--text); }
dialog.page-viewer .pv-body { flex: 1; min-height: 0; background: #fff; }
dialog.page-viewer .pv-body iframe { display: block; width: 100%; height: 100%; border: 0; }
@media (max-width: 640px) {
  .page-preview .pp-thumb { height: 200px; }
  dialog.page-viewer { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; border-radius: 0; border: 0; }
}

.audio-player {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: min(420px, 100%);
  padding: 8px 10px;
  margin: 4px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  vertical-align: middle;
}
.audio-play {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-fg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background var(--dur) var(--ease);
}
.audio-play:hover { background: var(--accent-hover); }
.audio-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.audio-name {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.audio-bar {
  display: block;
  height: 5px;
  border-radius: var(--r-full);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
}
.audio-bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width 120ms linear;
}
.audio-time {
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
.audio-dl {
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}
.audio-dl:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.audio-player.audio-error { border-color: var(--danger); }

/* ── Leemo portal link pill (markdown.js enhanceLeemoLinks) ── */
.leemo-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 10px;
  margin: 1px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text);
  text-decoration: none;
  vertical-align: middle;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.leemo-link:hover { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.leemo-link i { color: var(--accent); font-size: .95em; line-height: 1; }
.leemo-link .leemo-brand {
  color: var(--accent);
  font-weight: 700;
  font-size: var(--text-xs);
  letter-spacing: .04em;
  text-transform: uppercase;
  padding-right: 6px;
  border-right: 1px solid var(--border);
}
.leemo-link .leemo-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Misc ───────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: var(--sp-8) var(--sp-4);
}
.empty-state .bi { font-size: 2rem; color: var(--text-faint); display: block; margin-bottom: var(--sp-3); }

.avatar-img {
  border-radius: var(--r-full);
  object-fit: cover;
  background: var(--surface-hover);
  flex-shrink: 0;
}
.avatar-fallback {
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── First-run guided tour (js/tour.js) ─────────────────────
   Fixed card, bottom-right, below slide-overs (150) and toasts (500) but above
   page content. On the chat page it sits above the composer. Collapsible to a
   pill; all colors via tokens so both themes work. */
.tour-card {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 140;
  width: min(340px, calc(100vw - 24px));
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  transition: opacity 0.7s var(--ease);
}
body.page-chat .tour-card { bottom: 96px; }        /* clear the composer */
.tour-card.tour-fade { opacity: 0; }
.tour-card .tour-pill { display: none; }
.tour-card.tour-collapsed .tour-body { display: none; }
.tour-card.tour-collapsed {
  width: auto;
  border-radius: var(--r-full);
}
.tour-card.tour-collapsed .tour-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
}
.tour-card.tour-collapsed .tour-pill .bi { color: var(--accent); }
.tour-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.tour-title { font-weight: 600; font-size: 0.95rem; display: inline-flex; align-items: center; gap: var(--sp-2); }
.tour-title .bi { color: var(--accent); }
.tour-steps { padding: var(--sp-2); display: flex; flex-direction: column; gap: 2px; }
.tour-step {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text);
  text-decoration: none;
}
/* Rows are anchors, so the global a:hover (base.css) would paint them link-blue +
   underlined on hover. Re-assert the row's own look — highlight the background only. */
.tour-step:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.tour-step .bi { margin-top: 2px; color: var(--text-muted); }
.tour-step.done .bi { color: var(--success); }
.tour-step.done .tour-step-label { text-decoration: line-through; color: var(--text-muted); }
.tour-step-text { display: flex; flex-direction: column; gap: 1px; }
.tour-step-label { font-size: 0.9rem; font-weight: 500; }
.tour-step-hint { font-size: 0.78rem; color: var(--text-muted); }
.tour-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-4) var(--sp-3);
}
.tour-progress { font-size: 0.78rem; color: var(--text-muted); }
.tour-done-note { padding: var(--sp-3) var(--sp-4) var(--sp-4); font-size: 0.9rem; color: var(--text-muted); }

/* ── Mermaid diagrams (2026-08-31) — server-rendered PNG inside the codeblock wrap ── */
.mermaid-fig { padding: 8px 10px; background: var(--surface); }
.mermaid-fig img { max-width: 100%; height: auto; border-radius: 8px; display: block; }
.codeblock pre.mermaid-src-hidden { display: none; }

/* ── Tabs (js/ui/tabs.js) ───────────────────────────────── */
.tabs {
  display: flex; gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  font-size: var(--text-sm); font-weight: 550;
  color: var(--text-muted);
  white-space: nowrap;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tab-btn:hover { color: var(--text); background: var(--surface-hover); }
.tab-btn.active { color: var(--text); }
.tab-btn::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
  transform: scaleX(0); transition: transform var(--dur) var(--ease);
}
.tab-btn.active::after { transform: scaleX(1); }
.tab-kbd, .kbd {
  font-family: var(--font-mono); font-size: .68rem; line-height: 1;
  padding: 2px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 4px; color: var(--text-faint); background: var(--bg);
}
.tab-btn.active .tab-kbd { color: var(--text-muted); }

/* ── JSON tree (js/ui/jsonview.js) ──────────────────────── */
.jsonview {
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.5;
  overflow-x: auto; overflow-wrap: anywhere;
}
.jv-node { padding-left: 0; }
.jv-children { padding-left: 18px; border-left: 1px solid var(--border); margin-left: 7px; }
.jv-line { display: flex; align-items: baseline; gap: 2px; padding: 1px 4px; border-radius: 4px; min-width: 0; }
.jv-line:hover { background: var(--surface-hover); }
.jv-line.jv-hit { background: var(--mark-bg); }
.jv-toggle {
  width: 16px; height: 16px; flex: 0 0 16px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: .7rem; align-self: center;
}
.jv-toggle:hover { color: var(--text); }
.jv-key { color: var(--accent); flex-shrink: 0; }
.jv-colon { color: var(--text-faint); }
.jv-sum { color: var(--text-faint); cursor: pointer; }
.jv-empty { color: var(--text-faint); }
.jv-str { white-space: pre-wrap; }
.jv-more {
  margin-left: 6px; font-size: .7rem; padding: 0 6px; border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent); font-family: var(--font-sans);
}

/* Menu item with a leading avatar (openMenu item.face — agent pickers). */
.menu-face { flex-shrink: 0; display: inline-flex; width: 24px; height: 28px; }
.menu-face .agent-row-avatar.agent-row-avatar { width: 24px; height: 28px; font-size: .65rem; border-radius: 6px; object-position: 50% 22%; }
.menu-face .avatar-fallback--pa { background: var(--accent); color: #fff; }

/* Phone-voice picker + demo play button (js/voice-demo.js) */
.voice-demo-row { display: flex; align-items: center; gap: var(--sp-2); }
.voice-demo-row .select { flex: 1; min-width: 0; }
