/* Hotkey's popups (research/modals-audit.md, "Proposal"): one stylesheet for the console, the
   viewer and the hub's pages, drawn from design/tokens.css only. It reaches each surface through a
   symlink (web/console/shared/popups.css, web/viewer/popups.css), like tokens.css. design/popup.js
   opens and closes them.

   Five kinds:
   - dialog  <dialog class="pop">: a decision or a short form. Centered on a computer, a bottom
             sheet below 700 px. Blocks what is behind it (showModal), with the scrim.
   - menu    [popover].menu: a list of choices by the pointer or its button; a sheet of 44 px rows
             below 700 px.
   - offer   [popover].offer: something the person may take or ignore. Top right of the page on a
             computer, at the foot (above the keyboard) on a phone. One at a time.
   - notice  .notice: one line about the page, a pill at its top center. One at a time.
   - toast   .pop-toast in .pop-toasts: what just happened, at the foot, stacked with the page's
             statuses (an agent working), with one action at most.

   Anatomy: the title on the left and × at the top right; the actions in the foot, the secondary on
   the left and the primary (ink) on the right. A destructive primary is filled red. Amber and blue
   never fill a popup's button: amber is the ask, blue is an agent working. */

/* ---------- Buttons in popups: one primary, one secondary, at most one quiet choice. */
.pbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 16px; box-sizing: border-box;
  border-radius: var(--radius); border: 1px solid var(--color-line-strong); background: var(--color-popup); color: var(--color-text);
  font: 500 var(--font-size-14)/1.2 var(--font-family); text-decoration: none; cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent; }
.pbtn:hover { background: var(--color-hover); }
.pbtn.primary { background: var(--color-text); border-color: var(--color-text); color: var(--color-panel); }
.pbtn.primary:hover { background: color-mix(in srgb, var(--color-text) 86%, var(--color-panel)); }
.pbtn.danger { background: var(--color-danger-fill); border-color: var(--color-danger-fill); color: var(--color-on-danger); }
.pbtn.danger:hover { background: color-mix(in srgb, var(--color-danger-fill) 88%, #000); }
.pbtn.quiet { border-color: transparent; background: transparent; color: var(--color-text-2); padding: 0 8px; }
.pbtn.quiet:hover { background: var(--color-hover); }
.pbtn:disabled, .pbtn[aria-disabled="true"] { opacity: .45; cursor: default; }
.pbtn[hidden] { display: none; }
.pbtn:focus-visible, .pop-close:focus-visible, .pop-grab:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* ---------- Dialog */
dialog.pop { position: fixed; inset: 0; margin: auto; box-sizing: border-box; display: flex; flex-direction: column;
  width: min(var(--size-popup), calc(100% - 2 * var(--space-4))); max-width: none; height: fit-content;
  max-height: calc(var(--pop-vvh, 100dvh) - 2 * var(--space-4)); padding: 0; overflow: auto; overscroll-behavior: contain;
  border: 0; border-radius: var(--radius-popup); background: var(--color-popup); color: var(--color-text);
  box-shadow: var(--shadow-popup), 0 0 0 1px var(--color-popup-edge); font: var(--font-size-14)/1.45 var(--font-family);
  animation: pop-in var(--duration-popup-in) var(--ease-popup); }
dialog.pop:not([open]) { display: none; }
dialog.pop > form { display: contents; }
/* `hidden` wins over every display set here. */
:is(dialog.pop, .menu, .offer, .notice) [hidden] { display: none !important; }
dialog.pop:focus { outline: none; }
dialog.pop::backdrop { background: var(--color-scrim); opacity: var(--pop-scrim, 1); animation: pop-fade var(--duration-popup-in) var(--ease-popup); }
/* A second dialog over the first: one scrim, the first goes inert under it. */
dialog.pop[data-stacked]::backdrop { background: transparent; }
dialog.pop.wide { width: min(var(--size-popup-wide), calc(100% - 2 * var(--space-4))); height: min(860px, calc(100% - 2 * var(--space-4))); }
/* While the person's finger moves it, or as it slides away. */
dialog.pop.dragging { animation: none; transition: none; }
dialog.pop.settling { transition: transform var(--duration-popup-in) var(--ease-popup); }
dialog.pop.leaving { transition: transform var(--duration-popup-out) ease-in, opacity var(--duration-popup-out) linear; }
dialog.pop.nudge { animation: pop-nudge 220ms var(--ease-popup); }

.pop-grab { display: none; }
.pop-head { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-5) 0; }
.pop-title { flex: 1; min-width: 0; margin: 0; font-size: var(--font-size-18); font-weight: 600; line-height: 1.3; letter-spacing: -.01em; overflow-wrap: anywhere; }
.pop-title:focus { outline: none; }
/* Under the title: where it comes from (the username, "The page asked for one"). */
.pop-site { display: block; margin-top: 2px; font-size: var(--font-size-13); font-weight: 400; line-height: 1.35; color: var(--color-text-3); letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; }
.pop-close { flex: none; display: grid; place-items: center; width: 32px; height: 32px; margin: -4px -8px 0 0; padding: 0; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--color-text-3); cursor: pointer; }
.pop-close:hover { background: var(--color-hover); color: var(--color-text); }
.pop-close svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.pop-close[hidden] { display: none; }
.pop-body { padding: var(--space-2) var(--space-5) 0; color: var(--color-text-2); }
.pop-body > p, .pop-body .pop-text { margin: 0 0 var(--space-2); }
.pop-body .pop-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--color-text); }
.pop-body .pop-note { margin: var(--space-2) 0 0; color: var(--color-danger); font-size: var(--font-size-13); }
.pop-body .pop-note[hidden] { display: none; }
.pop-field { display: block; width: 100%; box-sizing: border-box; min-height: 40px; margin: var(--space-2) 0 0; padding: 8px var(--space-3); border: 1px solid var(--color-line-field);
  border-radius: var(--radius); background: var(--color-panel); color: var(--color-text); font: var(--font-size-14)/1.4 var(--font-family); }
textarea.pop-field { resize: vertical; min-height: 72px; }
.pop-field:focus { outline: none; border-color: var(--color-text-3); }
.pop-label { display: block; margin-top: var(--space-3); color: var(--color-text); font-weight: 500; }
.pop-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding: var(--space-5); }
.pop-actions[hidden] { display: none; }
/* A third, quiet choice ("Never for this site", "Fill in, don't submit"): far left on a computer. */
.pop-actions .tertiary { margin-right: auto; }

/* ---------- Menu */
.menu { box-sizing: border-box; min-width: var(--size-menu); max-width: min(360px, calc(100vw - 16px)); max-height: calc(var(--pop-vvh, 100dvh) - 16px); margin: 0; padding: 6px; overflow: auto; overscroll-behavior: contain;
  border: 0; border-radius: var(--radius-menu); background: var(--color-popup); color: var(--color-text);
  box-shadow: var(--shadow-popup), 0 0 0 1px var(--color-popup-edge); font: var(--font-size-14)/1.3 var(--font-family); }
.menu[popover] { position: fixed; inset: auto; }
.menu:popover-open { animation: pop-in var(--duration-popup-in) var(--ease-popup); }
.menu::backdrop { background: transparent; }
.menu-item { display: flex; align-items: center; gap: var(--space-3); width: 100%; box-sizing: border-box; min-height: 32px; padding: 6px var(--space-3); border: 0; border-radius: var(--radius-sm);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.menu-item:hover, .menu-item.on, .menu-item:focus-visible { background: var(--color-hover); outline: none; }
.menu-item[aria-checked="true"]::after, .menu-item[aria-selected="true"]::after { content: ''; flex: none; margin-left: auto; width: 12px; height: 6px;
  border: solid var(--color-text); border-width: 0 0 2px 2px; transform: rotate(-45deg) translateY(-2px); }
.menu-item[aria-disabled="true"] { opacity: .45; cursor: default; }
.menu-item.danger { color: var(--color-danger); }
.menu-sep { height: 1px; margin: 6px 0; border: 0; background: var(--color-line); }
.menu-title { margin: 0; padding: 8px var(--space-3) 4px; font-size: var(--font-size-12); font-weight: 600; color: var(--color-text-3); overflow-wrap: anywhere; }

/* ---------- Offer */
.offer { box-sizing: border-box; width: min(var(--size-offer), calc(100% - 24px)); margin: 0; padding: var(--space-4); border: 0;
  border-radius: var(--radius-lg); background: var(--color-popup); color: var(--color-text);
  box-shadow: var(--shadow-popup), 0 0 0 1px var(--color-popup-edge); font: var(--font-size-14)/1.45 var(--font-family); }
.offer[popover] { position: fixed; inset: 12px 12px auto auto; overflow: visible; }
.offer:popover-open { animation: pop-in var(--duration-popup-in) var(--ease-popup); }
.offer .pop-head { padding: 0; align-items: center; }
.offer .pop-title { font-size: var(--font-size-16); }
.offer .pop-close { margin: -6px -8px -6px 0; }
.offer .pop-body { padding: var(--space-2) 0 0; font-size: var(--font-size-13); }
.offer .pop-actions { padding: var(--space-3) 0 0; }
.offer .pbtn { min-height: 32px; font-size: var(--font-size-13); padding: 0 12px; }
.offer .pop-icon { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius); background: var(--color-sunk); color: var(--color-text-2); }
.offer .pop-icon svg { width: 18px; height: 18px; }

/* ---------- One surface for everything that floats over a page (2026-11-29, PRODUCT.md "One stack
   of toasts"): notices at the page's top, toasts and statuses at its foot. Always dark, since it may
   sit on a page of any colour; the same radius, shadow, type, 16 px lead, action and close. */
.notice, .pop-toast { color-scheme: dark; display: flex; align-items: center; gap: 10px; box-sizing: border-box; min-height: 40px; padding: 4px 4px 4px 14px;
  border: 0; border-radius: var(--radius-lg); background: var(--color-popup); color: var(--color-text); box-shadow: var(--shadow-popup-dark), 0 0 0 1px var(--color-popup-edge);
  font: 500 var(--font-size-13)/1.35 var(--font-family); }
.notice { max-width: calc(100% - 24px); }
.notice[hidden] { display: none !important; }
.notice .notice-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:is(.notice, .pop-toast) .pbtn { flex: none; min-height: 32px; padding: 0 12px; font-size: var(--font-size-13); font-weight: 600; border-radius: var(--radius); border-color: transparent;
  background: var(--color-sunk); color: var(--color-text); text-decoration: none; }
:is(.notice, .pop-toast) .pbtn:hover { background: var(--color-line-strong); }
:is(.notice, .pop-toast) .pbtn.danger { background: var(--color-danger-fill); color: var(--color-on-danger); }
.notice .pop-close, .pop-toast-x { flex: none; display: grid; place-items: center; width: 32px; height: 32px; margin: 0; padding: 0; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--color-text-3); cursor: pointer; }
.notice .pop-close:hover, .pop-toast-x:hover { background: var(--color-hover); color: var(--color-text); }
.pop-toast-x:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.pop-toast-x svg, .notice .pop-close svg { width: 16px; height: 16px; }
.notice .dot, .pop-toast-dot { flex: none; width: 8px; height: 8px; margin: 0 4px; border-radius: 50%; background: var(--color-text-3); }
.notice .dot { background: var(--color-danger); }

/* ---------- The stack (popup.js toast() and status()): over the page's foot, centred, newest
   nearest the foot, statuses at the foot. The region takes no clicks, its items do. */
.pop-toasts { position: fixed; inset: auto 0 calc(var(--pop-toast-lift, 24px) + env(safe-area-inset-bottom)) 0; z-index: var(--z-toast); width: auto; height: auto; max-height: none;
  margin: 0; padding: 0 16px; border: 0; background: transparent; overflow: visible; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pop-toasts:not(:popover-open):not(.on) { display: none; }
.pop-toast { pointer-events: auto; max-width: min(480px, 100%); touch-action: none; transition: translate .12s ease-out; animation: toast-in var(--duration-popup-in) var(--ease-popup); }
.pop-toast[hidden] { display: none; }
.pop-toast.pop-status { animation: none; white-space: nowrap; }
.pop-toast:not(:has(.pop-toast-x, .pbtn)) { padding-right: 14px; }
.pop-toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pop-status .pop-toast-text, .pop-status > span:not(.dot) { overflow: hidden; text-overflow: ellipsis; }
.pop-toast-count { flex: none; min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--color-sunk); color: var(--color-text-2); font-size: var(--font-size-12); text-align: center; line-height: 20px; }
.pop-toast-icon { flex: none; display: grid; place-items: center; width: 16px; height: 16px; color: var(--color-text-2); }
.pop-toast-icon svg { width: 16px; height: 16px; }
/* Colour only by meaning (design/BRAND.md): an error's dot, blue while an agent works, amber for
   what needs the person, the pause colour while paused. */
.pop-toast.tone-error .pop-toast-dot { background: var(--color-toast-danger); }
.pop-toast.tone-work .pop-toast-dot, .pop-status .dot { flex: none; width: 8px; height: 8px; margin: 0 4px; border-radius: 50%; background: var(--color-viewer-work); }
.pop-toast.tone-wait .pop-toast-dot { background: var(--color-wait); }
.pop-toast.tone-pause .pop-toast-dot, .pop-status.paused .dot { background: var(--color-pause); }
.pop-toast.tone-ok .pop-toast-icon { color: var(--color-ok); }

/* ---------- Phones: a dialog and a menu become a bottom sheet with a grabber, above the keyboard and
   the home bar; the actions share the foot's width. popup.js drags them (research/modals-audit.md,
   "Bottom sheet gestures"). */
@media (max-width: 699px) {
  dialog.pop { inset: auto 0 var(--pop-kb, 0px) 0; margin: 0; width: 100%; max-height: calc(var(--pop-vvh, 100dvh) - 24px);
    border-radius: var(--radius-popup) var(--radius-popup) 0 0; animation-name: sheet-in;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  :root.pop-kb dialog.pop { padding-bottom: 0; }
  dialog.pop.wide { height: 100%; max-height: none; inset: 0; border-radius: 0; padding: 0; }
  .pop-grab { display: block; position: sticky; top: 0; z-index: 1; flex: none; width: 100%; height: 20px; margin: 0 0 -8px; padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none; }
  .pop-grab::before { content: ''; display: block; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--color-line-strong); }
  dialog.pop.wide .pop-grab { display: none; }
  .pop-head { padding: var(--space-3) var(--space-4) 0; touch-action: pan-x; }
  .pop-close { width: var(--size-target); height: var(--size-target); margin: -10px -12px -6px 0; }
  .pop-body { padding: var(--space-2) var(--space-4) 0; }
  .pop-field { min-height: var(--size-target); font-size: var(--font-size-16); }
  .pop-actions { padding: var(--space-4); flex-wrap: wrap; }
  .pop-actions .pbtn:not(.tertiary) { flex: 1 1 0; min-height: var(--size-target); font-size: var(--font-size-16); }
  .pop-actions .tertiary { order: 3; flex: 1 0 100%; margin: 0; min-height: 40px; }
  .menu.as-sheet { inset: auto 0 var(--pop-kb, 0px) 0; width: 100%; max-width: none; min-width: 0; max-height: calc(var(--pop-vvh, 100dvh) - 24px);
    padding: 8px calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
    border-radius: var(--radius-popup) var(--radius-popup) 0 0; }
  .menu.as-sheet:popover-open { animation-name: sheet-in; }
  .menu.as-sheet::backdrop { background: var(--color-scrim); }
  .menu.as-sheet .menu-item { min-height: var(--size-target); font-size: var(--font-size-16); }
  .menu.as-sheet .menu-title { font-size: var(--font-size-13); padding: 8px var(--space-3); }
  .offer[popover] { inset: auto 8px calc(var(--pop-kb, 0px) + 8px + env(safe-area-inset-bottom)) 8px; width: auto; }
  .offer .pbtn:not(.tertiary) { min-height: 40px; }
  .pop-toast, .notice { min-height: 44px; }
  :is(.notice, .pop-toast) .pbtn { min-height: 36px; }
  .notice .pop-close, .pop-toast-x { width: 36px; height: 36px; }
}

/* The same bottom sheet at any width, for a surface whose own phone layout starts wider (the
   console's, below 900 px). */
dialog.pop.as-sheet { inset: auto 0 var(--pop-kb, 0px) 0; margin: 0; width: 100%; max-height: calc(var(--pop-vvh, 100dvh) - 24px);
  border-radius: var(--radius-popup) var(--radius-popup) 0 0; animation-name: sheet-in;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
:root.pop-kb dialog.pop.as-sheet { padding-bottom: 0; }
dialog.pop.as-sheet .pop-grab { display: block; position: sticky; top: 0; z-index: 1; flex: none; width: 100%; height: 20px; margin: 0 0 -8px; padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none; }
dialog.pop.as-sheet .pop-grab::before { content: ''; display: block; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--color-line-strong); }
dialog.pop.as-sheet .pop-head { padding: var(--space-3) var(--space-4) 0; touch-action: pan-x; }
dialog.pop.as-sheet .pop-close { width: var(--size-target); height: var(--size-target); margin: -10px -12px -6px 0; }
dialog.pop.as-sheet .pop-body { padding: var(--space-2) var(--space-4) 0; }
dialog.pop.as-sheet .pop-actions { padding: var(--space-4); flex-wrap: wrap; }
dialog.pop.as-sheet .pop-actions .pbtn:not(.tertiary) { flex: 1 1 0; min-height: var(--size-target); font-size: var(--font-size-16); }
dialog.pop.as-sheet .pop-actions .tertiary { order: 3; flex: 1 0 100%; margin: 0; min-height: 40px; }
/* A dialog never sits over a phone sheet: the one opened from it takes its place until it closes. */
dialog.pop[data-covered] { visibility: hidden; }

/* An icon button's name while a finger holds it (holdLabel in popup.js). */
.pop-tip { position: fixed; z-index: var(--z-toast); max-width: calc(100vw - 16px); padding: 6px 10px; border-radius: var(--radius); background: var(--color-text); color: var(--color-panel);
  font: 500 var(--font-size-13)/1.3 var(--font-family); pointer-events: none; box-shadow: var(--shadow-popup); }
.pop-tip[hidden] { display: none; }

@keyframes pop-fade { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.98) translateY(4px); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } }
@keyframes pop-nudge { 40% { translate: 0 -4px; } }
@media (prefers-reduced-motion: reduce) {
  dialog.pop, dialog.pop::backdrop, .menu:popover-open, .offer:popover-open, .pop-toast { animation: pop-fade var(--duration-popup-in) linear; }
  .pop-toast { transition: none; }
  dialog.pop.nudge { animation: none; }
}
