/* BioQ shared UI components (public/static/js/ui.js). Loaded on every page right after bioq.css, so every colour, radius, shadow and font here is one of
   bioq.css's own variables and both themes follow without a rule of their own. Contents:
     1. scrollbars      thin, theme-aware, quiet until the pointer is over them (standard properties; the ::-webkit-scrollbar rules only for engines without them)
     2. confirm dialog  <dialog class="bq-dlg">, centred on a desk, a bottom sheet on a phone
     3. toasts          fixed to the window, bottom, stacked
     4. tooltips        data-tip="..."
     5. select          the custom listbox that stands in for <select data-bq-select>
     6. native widgets  <details> markers, checkboxes, number arrows, the invalid-field mark
   Motion only where prefers-reduced-motion allows it. */

:root {
  --on-bad: #ffffff;
  --sb-idle: color-mix(in srgb, var(--ink) 18%, transparent);
  --sb-hover: color-mix(in srgb, var(--ink) 40%, transparent);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --on-bad: #1c0a12; } }
:root[data-theme="dark"] { --on-bad: #1c0a12; }

/* ── 1. scrollbars ──────────────────────────────────────────────────────── */
html { scrollbar-color: var(--sb-idle) transparent; }
* { scrollbar-width: thin; }
:hover { scrollbar-color: var(--sb-hover) transparent; }
/* the dark code blocks sit on a dark band in both themes: a light thumb */
.code, .code-card pre { scrollbar-color: rgba(233, 237, 249, .24) transparent; }
.code:hover, .code-card pre:hover { scrollbar-color: rgba(233, 237, 249, .55) transparent; }
/* the section jump bar scrolls sideways without a bar (it did before: ::-webkit-scrollbar in bioq.css, which Chrome ignores once scrollbar-width is set) */
.jump { scrollbar-width: none; }
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar { width: 9px; height: 9px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--sb-idle); border: 2px solid transparent; background-clip: content-box; border-radius: 9px; }
  :hover::-webkit-scrollbar-thumb { background: var(--sb-hover); background-clip: content-box; }
  .code::-webkit-scrollbar-thumb, .code-card pre::-webkit-scrollbar-thumb { background: rgba(233, 237, 249, .24); background-clip: content-box; }
  .code:hover::-webkit-scrollbar-thumb, .code-card pre:hover::-webkit-scrollbar-thumb { background: rgba(233, 237, 249, .55); background-clip: content-box; }
}

/* ── 2. confirm dialog ──────────────────────────────────────────────────── */
.btn-danger { background: var(--bad); color: var(--on-bad); }
.btn-danger:hover { filter: brightness(.92); }
.bq-dlg { padding: 0; border: 1px solid var(--line); border-radius: var(--r-window); background: var(--surface); color: var(--text); box-shadow: var(--shadow-window); width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain; }
.bq-dlg::backdrop { background: rgba(10, 15, 31, .55); }
.bq-dlg-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px 16px; padding: 24px 24px 20px; }
.bq-dlg-ic { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.bq-dlg.danger .bq-dlg-ic { background: var(--bad-soft); color: var(--bad); }
.bq-dlg-ic svg { width: 20px; height: 20px; }
.bq-dlg-tx { display: grid; gap: 6px; align-content: start; min-width: 0; padding-top: 1px; }
.bq-dlg-t { margin: 0; font-family: var(--font-ui); font-size: 18px; line-height: 1.4; font-weight: 700; color: var(--ink); }
.bq-dlg-d { margin: 0; font-size: 14.5px; line-height: 1.65; color: var(--text); overflow-wrap: anywhere; }
.bq-dlg.plain .bq-dlg-d { font-size: 15.5px; font-weight: 500; color: var(--ink); line-height: 1.6; }
.bq-dlg-n { margin: 6px 0 0; justify-self: start; padding: 5px 10px; border-radius: 8px; background: var(--gel); color: var(--ink); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bq-dlg-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.bq-dlg .btn { height: 42px; min-width: 96px; }
@media (max-width: 560px), (pointer: coarse) { .bq-dlg .btn { height: 48px; } }
/* on a phone it is a sheet from the bottom edge, buttons side by side, each a full 48 px target */
@media (max-width: 560px) {
  .bq-dlg { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: var(--r-window) var(--r-window) 0 0; border-bottom: 0; }
  .bq-dlg-card { padding: 22px 18px calc(16px + env(safe-area-inset-bottom)); }
  .bq-dlg-actions .btn { flex: 1 1 0; min-width: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .bq-dlg[open] { animation: bq-pop .16s ease-out; }
  .bq-dlg[open]::backdrop { animation: bq-fade .16s ease-out; }
  @media (max-width: 560px) { .bq-dlg[open] { animation-name: bq-sheet; } }
}
@keyframes bq-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes bq-sheet { from { transform: translateY(40px); opacity: .6; } }
@keyframes bq-fade { from { opacity: 0; } }

/* ── 3. toasts ──────────────────────────────────────────────────────────── */
.bq-toasts { position: fixed; z-index: 2400; left: 0; right: 0; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 12px; pointer-events: none; }
.bq-toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: min(460px, 100%); padding: 10px 14px 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); font-size: 14px; line-height: 1.45; }
.bq-toast-ic { display: inline-flex; flex: none; color: var(--primary); }
.bq-toast-ic svg { width: 18px; height: 18px; }
.bq-toast.success .bq-toast-ic { color: var(--ok); }
.bq-toast.error { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.bq-toast.error .bq-toast-ic { color: var(--bad); }
.bq-toast-m { min-width: 0; overflow-wrap: anywhere; }
.bq-toast-x { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; margin: -4px -6px -4px 2px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.bq-toast-x:hover { background: var(--gel); color: var(--ink); }
.bq-toast-x svg { width: 16px; height: 16px; }
@media (max-width: 560px) { .bq-toast { width: 100%; max-width: none; } .bq-toast-x { width: 44px; height: 44px; margin: -12px -10px -12px 0; } }
@media (prefers-reduced-motion: no-preference) {
  .bq-toast { animation: bq-toast-in .18s ease-out; transition: opacity .18s, transform .18s; }
  .bq-toast.out { opacity: 0; transform: translateY(6px); }
}
@keyframes bq-toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── 4. tooltips ────────────────────────────────────────────────────────── */
.bq-tip { position: fixed; z-index: 2500; max-width: min(300px, calc(100vw - 16px)); padding: 7px 10px; border-radius: 8px; background: var(--ink); color: var(--paper); font-size: 12.5px; line-height: 1.5; font-weight: 500; white-space: pre-line; overflow-wrap: anywhere; box-shadow: var(--shadow-pop); }
.bq-tip.bad { background: var(--bad); color: var(--on-bad); }
@media (prefers-reduced-motion: no-preference) { .bq-tip { animation: bq-fade .12s ease-out; } }
[data-tip-click] { cursor: help; }
/* the small «i» that opens a tip: a 20 px glyph with a 44 px target around it */
.bq-info { position: relative; display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.bq-info::before { content: ""; position: absolute; inset: -12px; }
.bq-info svg { width: 16px; height: 16px; }
.bq-info:hover, .bq-info[aria-describedby] { color: var(--ink); }

/* ── 5. select ──────────────────────────────────────────────────────────── */
.bq-sel { position: relative; display: block; min-width: 0; }
.bq-sel > select.bq-sel-native { position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; overflow: hidden; }
.bq-sel-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; height: 44px; padding: 0 12px; border-radius: var(--r-input); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; text-align: left; cursor: pointer; }
.bq-sel-btn:hover { border-color: var(--ink); }
.bq-sel-btn:focus-visible, .bq-sel.open .bq-sel-btn { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.bq-sel-btn:disabled { opacity: .55; cursor: not-allowed; }
.bq-sel-val { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bq-sel-chev { display: inline-flex; flex: none; color: var(--muted); transition: transform .15s; }
.bq-sel-chev svg { width: 16px; height: 16px; }
.bq-sel.open .bq-sel-chev { transform: rotate(180deg); }
.sv-ctl .bq-sel-btn { height: 36px; border-radius: 8px; padding: 0 10px; font-size: 13.5px; }
.bq-sel-list { position: fixed; z-index: 2600; margin: 0; padding: 4px; list-style: none; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); font-size: 15px; }
.bq-sel-opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 8px 10px; border-radius: 8px; color: var(--text); cursor: pointer; line-height: 1.35; }
.bq-sel-opt.on { background: var(--gel); color: var(--ink); }
.bq-sel-opt[aria-selected="true"] { color: var(--primary); font-weight: 600; }
.bq-sel-opt[aria-selected="true"]::after { content: ""; flex: none; width: 5px; height: 9px; margin-right: 3px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.bq-sel-opt[aria-disabled="true"] { opacity: .45; cursor: default; }

/* ── 6. native widgets ──────────────────────────────────────────────────── */
/* <details>: the browser's own triangle goes, one chevron of ours takes its place (it turns when the block opens) */
details.sample > summary, .ov-axis > summary, details.raw > summary { list-style: none; }
details.sample > summary::-webkit-details-marker, .ov-axis > summary::-webkit-details-marker, details.raw > summary::-webkit-details-marker { display: none; }
details.sample > summary::before, .ov-axis > summary::before, details.raw > summary::before { content: ""; display: inline-block; width: .42em; height: .42em; margin: 0 .65em .12em 2px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg); transition: transform .15s; vertical-align: middle; }
details[open].sample > summary::before, .ov-axis[open] > summary::before, details.raw[open] > summary::before { transform: rotate(45deg); }
details > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { .bq-sel-chev, details > summary::before { transition: none; } }
/* checkboxes in the app (the structure viewer's layer list and its dimming switch): drawn with the site's colours */
.app input[type="checkbox"] { -webkit-appearance: none; appearance: none; display: inline-grid; place-content: center; flex: none; width: 17px; height: 17px; margin: 0; border: 1.5px solid var(--line-strong); border-radius: 5px; background: var(--surface); cursor: pointer; vertical-align: middle; }
.app input[type="checkbox"]::after { content: ""; width: 9px; height: 5px; border-left: 2px solid var(--primary-ink); border-bottom: 2px solid var(--primary-ink); transform: translateY(-1px) rotate(-45deg) scale(0); transition: transform .1s; }
.app input[type="checkbox"]:checked { background: var(--primary); border-color: var(--primary); }
.app input[type="checkbox"]:checked::after { transform: translateY(-1px) rotate(-45deg) scale(1); }
.app input[type="checkbox"]:disabled { opacity: .5; cursor: default; }
.app input[type="checkbox"]:hover:not(:disabled) { border-color: var(--primary); }
.app input[type="checkbox"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* number fields in the public forms: the browser's own up/down arrows go (the field is typed into) */
.field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.field input[type="number"]::-webkit-outer-spin-button, .field input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
/* a tap on a button of ours is not painted with the browser's own highlight */
.bq-dlg, .bq-toast, .bq-sel-btn, .bq-sel-list, .bq-info, .hist-lock { -webkit-tap-highlight-color: transparent; }
/* a field the form refused (data-bq-validate) */
input[aria-invalid="true"], textarea[aria-invalid="true"], .bq-sel-btn[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
