/* Dialog system (17 Nov). Compact, crafted dialogs for every #dlg in the prototype. Behaviour: dialog.js.
   Width tiers: 480 simple (default), 640 content (.wide, e.g. Publish ranking). At ≤560px every dialog is a bottom sheet.
   Anatomy: .dlg__h (title + one line, close ×) · .dlg__b (body, scrolls) · .dlg__f (note left, Cancel + primary right). */

#dlg {
  width: min(480px, calc(100vw - var(--space-8)));
  max-height: calc(100dvh - var(--space-12));
  padding: 0;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--color-bg-canvas);
  color: var(--color-text-primary);
  box-shadow: var(--elevation-dialog);
  font-family: var(--font-family-body);
  font-size: var(--font-size-13);
  line-height: 1.45;
  overflow: hidden;
  transform-origin: center;
}
#dlg[open] { display: flex; flex-direction: column; animation: dlg-in var(--motion-duration-base) var(--motion-easing-out); }
#dlg.wide { width: min(640px, calc(100vw - var(--space-8))); }
#dlg::backdrop { background: var(--color-scrim-soft); }
#dlg[open]::backdrop { animation: dlg-fade var(--motion-duration-base) var(--motion-easing-out); }
#dlg.is-closing { animation: dlg-out 140ms var(--motion-easing-exit) forwards; }
#dlg.is-closing::backdrop { animation: dlg-fade-out 140ms var(--motion-easing-exit) forwards; }
#dlg.is-instant, #dlg.is-instant::backdrop { animation: none; }
@keyframes dlg-in { from { opacity: 0; transform: scale(.97); } }
@keyframes dlg-out { to { opacity: 0; transform: scale(.98); } }
@keyframes dlg-fade { from { opacity: 0; } }
@keyframes dlg-fade-out { to { opacity: 0; } }

/* Header */
#dlg .dlg__h { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-4) 0 var(--space-5); }
#dlg .dlg__h > div { flex: 1; min-width: 0; }
#dlg .dlg__h h2 { margin: 0; font-family: var(--font-family-display); font-size: var(--font-size-14); font-weight: var(--font-weight-semibold); line-height: 1.4; letter-spacing: -0.005em; }
#dlg .dlg__h > h2 { flex: 1; padding-top: 2px; }
#dlg .dlg__h p { margin: var(--space-1) 0 0; color: var(--color-text-secondary); font-size: var(--font-size-13); }
#dlg .dlg__x { flex: none; width: 28px; height: 28px; margin: -4px 0 0 auto; color: var(--color-text-tertiary); }
#dlg .dlg__x:hover { color: var(--color-text-primary); }
#dlg .dlg__x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; }
/* Who header (Change status): photo + handle, then standing tag + rank */
#dlg .dlg__h--who { align-items: center; }
#dlg .dlg__h--who .face { --fs: 32px; }
#dlg .dlg__h--who p { display: flex; align-items: center; gap: var(--space-2); margin-top: 3px; color: var(--color-text-tertiary); font-size: var(--font-size-12); }
#dlg .dlg__h--who .st { height: 18px; padding: 0 6px; font-size: var(--font-size-11); }

/* Body */
#dlg .dlg__b { flex: 1 1 auto; min-height: 0; max-height: none; overflow: auto; padding: var(--space-4) var(--space-5) var(--space-5); scrollbar-width: none; }
#dlg .dlg__b::-webkit-scrollbar { display: none; }
#dlg .dlg__b > :first-child { margin-top: 0; }
#dlg .lbl { margin: 0 0 var(--space-2); padding: 0; font-size: var(--font-size-12); font-weight: var(--font-weight-medium); color: var(--color-text-secondary); }
#dlg .field { gap: 6px; margin-top: var(--space-4); font-size: var(--font-size-12); font-weight: var(--font-weight-medium); color: var(--color-text-secondary); }
#dlg .field input, #dlg .field textarea { height: 34px; padding: 6px 10px; font-size: var(--font-size-13); color: var(--color-text-primary); border-color: var(--color-border-default); transition: border-color var(--motion-duration-fast) var(--motion-easing-standard), box-shadow var(--motion-duration-fast) var(--motion-easing-standard); }
#dlg .field textarea { height: auto; min-height: 0; line-height: 1.45; resize: none; }
#dlg .field input:hover, #dlg .field textarea:hover { border-color: var(--color-border-control); }
/* Focus (18 Nov, colour pass): 1px ink border + a faint 3px neutral halo, same on inputs, the note and the select trigger. */
#dlg .field input:focus, #dlg .field textarea:focus, #dlg .field .msel--field:focus-visible, #dlg .field .msel--field[aria-expanded="true"] { outline: none; border-color: var(--color-text-primary); box-shadow: 0 0 0 3px var(--color-alpha-black-8); }
#dlg .field .msel--field { transition: border-color var(--motion-duration-fast) var(--motion-easing-standard), box-shadow var(--motion-duration-fast) var(--motion-easing-standard); }
#dlg .field .msel--field[aria-expanded="true"] { background-color: var(--color-bg-canvas); }
#dlg .field .msel--field { min-height: 34px; padding-top: 5px; padding-bottom: 5px; font-size: var(--font-size-13); border-color: var(--color-border-default); color: var(--color-text-primary); }
#dlg .field small { font-size: var(--font-size-12); }
#dlg .dlg-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-top: var(--space-4); }
#dlg .dlg-row .field { margin-top: 0; }
#dlg .note { margin: 0 0 var(--space-4); padding: var(--space-2) var(--space-3); font-size: var(--font-size-12); }
#dlg .pre { font-size: var(--font-size-12); line-height: 1.6; max-height: 280px; padding: var(--space-3); border: 1px solid var(--color-border-subtle); scrollbar-width: none; }
#dlg .dlg__b > p.tiny { font-size: var(--font-size-12); }
#dlg table.screen td { padding: 6px 0; font-size: var(--font-size-13); }
/* Swap: the two boxes become one slim before → after strip */
#dlg .cmp { grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--color-border-subtle); border-radius: var(--radius-sm); overflow: hidden; }
#dlg .cmp > div { border: 0; border-radius: 0; padding: var(--space-2) var(--space-3); font-size: var(--font-size-12); color: var(--color-text-tertiary); }
#dlg .cmp > div.after { border-left: 1px solid var(--color-border-subtle); background: var(--color-bg-surface); }
#dlg .cmp h4 { font-size: var(--font-size-11); margin: 0 0 2px; }
#dlg .cmp b { font-size: var(--font-size-13); font-weight: var(--font-weight-medium); color: var(--color-text-primary); }

/* Option rows: radio list with keyboard arrows (native radio group) */
#dlg .opts { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: 2px; }
#dlg .opts legend.lbl { float: left; width: 100%; }
#dlg .opt { position: relative; display: grid; grid-template-columns: 16px 1fr; column-gap: var(--space-3); row-gap: 1px; align-items: center; padding: var(--space-2) var(--space-3); margin: 0 calc(-1 * var(--space-3)); border-radius: var(--radius-sm); cursor: pointer; transition: background-color var(--motion-duration-fast) var(--motion-easing-standard); }
#dlg .opt:hover { background: var(--color-bg-surface); }
#dlg .opt:has(input:checked) { background: var(--color-bg-surface); }
#dlg .opt:has(input:focus-visible) { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: -2px; }
#dlg .opt input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
#dlg .opt__dot { --c: var(--color-text-primary); grid-row: 1 / 3; align-self: start; margin-top: 2px; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--color-border-control); box-sizing: border-box; display: grid; place-items: center; transition: border-color var(--motion-duration-fast) var(--motion-easing-standard); }
#dlg .opt__dot::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); transform: scale(0); transition: transform var(--motion-duration-fast) var(--motion-easing-out); }
#dlg .opt input:checked + .opt__dot { border-color: var(--c); border-width: 5px; }
#dlg .opt input:checked + .opt__dot::after { transform: scale(0); }
#dlg .opt--dq .opt__dot { --c: var(--color-status-danger-solid); }
#dlg .opt--reinstate .opt__dot { --c: var(--color-status-success-solid); }
#dlg .opt__t { font-size: var(--font-size-13); font-weight: var(--font-weight-medium); color: var(--color-text-primary); line-height: 1.35; }
#dlg .opt__q { grid-column: 2; font-size: var(--font-size-12); color: var(--color-text-tertiary); line-height: 1.4; }
#dlg .opt--dq:has(input:checked) .opt__t { color: var(--color-status-danger-fg); }

/* Impact: one slim before → after line */
#dlg .dlg-imp { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-3) 0 0; padding: var(--space-2) 0 0; border-top: 1px solid var(--color-border-subtle); font-size: var(--font-size-12); color: var(--color-text-tertiary); }
#dlg .dlg-imp[hidden] { display: none; }
#dlg .dlg-imp > span { display: inline-flex; align-items: center; gap: var(--space-2); }
#dlg .dlg-imp__b { color: var(--color-text-primary); font-weight: var(--font-weight-medium); }
#dlg .dlg-imp__to { color: var(--color-text-tertiary); }
#dlg .dlg-imp .st { height: 18px; padding: 0 6px; font-size: var(--font-size-11); }
#dlg:not(.is-instant) .dlg-imp__b { animation: dlg-fade var(--motion-duration-fast) var(--motion-easing-out); }

/* Reason + quick-fill presets: plain text buttons, no pills */
#dlg .dlg-why > span:first-child { color: var(--color-text-secondary); }
#dlg .dlg-why label { color: var(--color-text-secondary); }
#dlg .dlg-pre { display: flex; flex-wrap: wrap; gap: 0 var(--space-3); margin: 0 0 2px; }
#dlg .dlg-pre button { padding: 2px 0; border: 0; background: none; font: inherit; font-size: var(--font-size-12); font-weight: var(--font-weight-regular); color: var(--color-text-tertiary); cursor: pointer; text-decoration: underline; text-decoration-color: var(--color-border-default); text-underline-offset: 3px; transition: color var(--motion-duration-fast) var(--motion-easing-standard), text-decoration-color var(--motion-duration-fast) var(--motion-easing-standard); }
#dlg .dlg-pre button:hover { color: var(--color-text-primary); text-decoration-color: currentColor; }
#dlg .dlg-pre button:focus-visible { outline-offset: 1px; border-radius: 2px; }

/* Footer */
#dlg .dlg__f { flex: none; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4) var(--space-3) var(--space-5); border-top: 1px solid var(--color-border-subtle); }
#dlg .dlg__f .hint { flex: 1; min-width: 0; margin: 0; display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0 4px; font-size: var(--font-size-12); color: var(--color-text-tertiary); }
#dlg .dlg__f .hint:has(kbd) { flex-wrap: nowrap; white-space: nowrap; }
#dlg .dlg__f .hint.dlg__kb { font-size: var(--font-size-11); color: var(--color-text-disabled); gap: 0 3px; }
#dlg .dlg__f .hint kbd { min-width: 16px; padding: 1px 3px; border-color: var(--color-border-subtle); background: none; font-size: var(--font-size-11); color: var(--color-text-tertiary); text-align: center; }
#dlg .dlg__f .b { height: 32px; padding: 0 12px; font-size: var(--font-size-13); }
#dlg .dlg__f .b:active:not(:disabled) { transform: scale(.97); }

/* Danger primary + hold to confirm (Emil Kowalski's pattern): a clip-path overlay fills over 1.2s while pressed, snaps back in 200ms */
#dlg .b--hold { position: relative; overflow: hidden; min-width: 150px; user-select: none; -webkit-user-select: none; touch-action: none; transition: transform var(--motion-duration-fast) var(--motion-easing-out); }
#dlg .b--hold .hold__fill, #dlg .b--hold .hold__arm { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#dlg .b--hold .hold__fill { background: linear-gradient(var(--color-alpha-black-45), var(--color-alpha-black-45)), var(--color-status-danger-solid); color: var(--color-status-danger-on-solid); clip-path: inset(0 100% 0 0); transition: clip-path 200ms var(--motion-easing-out); }
#dlg .b--hold.is-holding { transform: scale(.97); }
#dlg .b--hold.is-holding .hold__fill { clip-path: inset(0 0 0 0); transition: clip-path 1200ms linear; }
#dlg .b--hold .hold__arm { visibility: hidden; background: inherit; }
#dlg .b--hold.is-armed .hold__arm { visibility: visible; }
#dlg .b--hold.is-nudge { animation: dlg-nudge 320ms var(--motion-easing-out); }
@keyframes dlg-nudge { 30% { transform: translateX(-2px); } 60% { transform: translateX(2px); } }

/* Phone: bottom sheet with safe margins */
@media (max-width: 560px) {
  #dlg, #dlg.wide { width: 100%; max-width: 100%; max-height: calc(100dvh - var(--space-8)); margin: auto 0 0; border-width: 1px 0 0; border-radius: var(--radius-md) var(--radius-md) 0 0; transform-origin: bottom center; }
  #dlg[open] { animation-name: dlg-sheet-in; animation-duration: 260ms; animation-timing-function: var(--motion-easing-out-ios); }
  #dlg.is-closing { animation: dlg-sheet-out 180ms var(--motion-easing-exit) forwards; }
  #dlg .dlg__h { padding: var(--space-5) var(--space-3) 0 var(--space-4); }
  #dlg .dlg__b { padding: var(--space-4); }
  #dlg .dlg__f { flex-wrap: wrap; padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom)); }
  #dlg .dlg__f .hint { flex-basis: 100%; margin-bottom: var(--space-1); }
  #dlg .dlg__f .dlg__kb, #dlg .dlg__f .hint:has(kbd) { display: none; }
  #dlg .dlg__f .b { flex: 1 1 0; height: 40px; }
  #dlg .dlg__f .b--ghost { flex: 0 0 auto; }
  #dlg .opt { padding: 10px var(--space-3); }
  #dlg .dlg-row { grid-template-columns: 1fr; }
  #dlg .field input, #dlg .field textarea { font-size: var(--font-size-16); }
}
@keyframes dlg-sheet-in { from { transform: translateY(100%); } }
@keyframes dlg-sheet-out { to { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  #dlg[open], #dlg[open]::backdrop, #dlg.is-closing, #dlg.is-closing::backdrop, #dlg .dlg-imp__b, #dlg .b--hold.is-nudge { animation: none; }
  #dlg .opt__dot, #dlg .opt__dot::after, #dlg .b--hold { transition: none; }
}

/* Disqualify evidence (required): one compact line under the reason */
#dlg .field[hidden] { display: none; }
#dlg .dlg-ev { grid-template-columns: auto 1fr; align-items: center; column-gap: var(--space-3); margin-top: var(--space-3); }
#dlg .dlg-ev label { color: var(--color-text-secondary); white-space: nowrap; }
#dlg .b--hold:disabled .hold__fill { display: none; }
@media (max-width: 560px) { #dlg .dlg-ev { grid-template-columns: 1fr; row-gap: var(--space-1); } }

/* Success state (18 Nov): the confirm dialog morphs into the outcome; approve opens it straight away. Icon + one line + Undo / Next. */
#dlg.dlg--ok { width: min(400px, calc(100vw - var(--space-8))); }
#dlg .dlg-ok { display: grid; justify-items: center; gap: var(--space-1); padding: var(--space-6) var(--space-5) var(--space-5); text-align: center; }
#dlg .dlg-ok__ic { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: var(--space-2); border-radius: 50%; background: var(--color-status-success-bg); color: var(--color-status-success-fg); }
#dlg .dlg-ok__ic--bad { background: var(--color-status-danger-bg); color: var(--color-status-danger-fg); }
#dlg .dlg-ok__ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
#dlg .dlg-ok h2 { margin: 0; font-family: var(--font-family-display); font-size: var(--font-size-16); font-weight: var(--font-weight-semibold); line-height: 1.35; }
#dlg .dlg-ok p { margin: 0; max-width: 34ch; color: var(--color-text-secondary); font-size: var(--font-size-13); text-wrap: pretty; }
#dlg .dlg-ok p b { color: var(--color-text-primary); font-weight: var(--font-weight-medium); }
#dlg .dlg-ok + .dlg__f { justify-content: flex-end; }
#dlg .dlg-ok + .dlg__f .hint { flex: 1; }
#dlg .dlg-ok__in { animation: dlg-fade var(--motion-duration-base) var(--motion-easing-out); }
@media (max-width: 560px) {
  #dlg.dlg--ok { width: calc(100% - var(--space-8)); margin: auto; border-width: 1px; border-radius: var(--radius-sm); transform-origin: center; }
  #dlg.dlg--ok[open] { animation: dlg-in var(--motion-duration-base) var(--motion-easing-out); }
  #dlg.dlg--ok.is-closing { animation: dlg-out 140ms var(--motion-easing-exit) forwards; }
}
@media (prefers-reduced-motion: reduce) { #dlg .dlg-ok__in { animation: none; } }
#dlg .dlg__f { justify-content: flex-end; }   /* 18 Nov: no hint on the left, buttons sit right */
