/* ─── Hub-wide scrollbar ────────────────────────────────────────────────────
 * ONE definition for every page: React routes link it from app/layout.tsx,
 * standalone HTML dashboards get it from _permission-gate.js. Don't restyle
 * scrollbars per dashboard — hide one (scrollbar-width:none / display:none on
 * a tab strip) if you must, but otherwise let this file own the look.
 *
 * Three states (Chrome / Edge / Safari, mouse or trackpad):
 *   idle      — slim 4px, light       (thumb inset by a transparent border)
 *   scrolling — 6px, stronger         (.hub-scrolling, set by hub-scrollbar.js
 *                                      for ~0.8s after each scroll event)
 *   hover     — 10px, dark slate      (pointer on the thumb, or dragging it)
 * The gutter is a fixed 12px; only the thumb's border changes, so hovering
 * never reflows the page. Touch screens get a slim 4px bar (no hover there).
 *
 * Firefox has no scrollbar pseudo-elements: it gets a thin bar in the same
 * colours that darkens while scrolling (no hover widening is possible there).
 * The @supports guard matters: in Chrome 121+, setting scrollbar-width or
 * scrollbar-color on an element DISABLES its ::-webkit-scrollbar styling.
 */
:root {
  --hub-sb-gutter: 12px;
  --hub-sb-idle: rgba(100, 116, 139, 0.38);     /* slate-500 @ 38% */
  --hub-sb-scrolling: rgba(100, 116, 139, 0.62);
  --hub-sb-hover: rgba(51, 65, 85, 0.88);       /* slate-700 */
  --hub-sb-active: rgba(30, 41, 59, 0.95);      /* slate-800 while dragging */
}

/* Touch screens (no hover, so no hover state to make room for): a slim 4px bar
   with no reserved gutter growth — horizontal tab strips stay their old height. */
::-webkit-scrollbar { width: 4px; height: 4px; background: transparent; }
::-webkit-scrollbar-track,
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--hub-sb-idle); border-radius: 999px; }
.hub-scrolling::-webkit-scrollbar-thumb { background-color: var(--hub-sb-scrolling); }

/* Mouse / trackpad: the full idle → scrolling → hover treatment. */
@media (hover: hover) and (pointer: fine) {
  ::-webkit-scrollbar { width: var(--hub-sb-gutter); height: var(--hub-sb-gutter); background: transparent; }
  ::-webkit-scrollbar-track,
  ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background-color: var(--hub-sb-idle);
    background-clip: padding-box;
    /* thumb = gutter minus 2× border: 4px idle, 6px scrolling, 10px hover at the
       default 12px gutter. Derived from the gutter, so an area that needs a
       narrower one (the hub sidebar) can set --hub-sb-gutter and keep the states. */
    border: max(0px, calc((var(--hub-sb-gutter) - 4px) / 2)) solid transparent;
    border-radius: 999px;
    min-height: 36px;
    min-width: 36px;
  }
  .hub-scrolling::-webkit-scrollbar-thumb {
    background-color: var(--hub-sb-scrolling);
    border-width: max(0px, calc((var(--hub-sb-gutter) - 6px) / 2));
  }
  ::-webkit-scrollbar-thumb:hover {
    background-color: var(--hub-sb-hover);
    border-width: max(0px, calc((var(--hub-sb-gutter) - 10px) / 2));
  }
  ::-webkit-scrollbar-thumb:active {
    background-color: var(--hub-sb-active);
    border-width: max(0px, calc((var(--hub-sb-gutter) - 10px) / 2));
  }
}

@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: var(--hub-sb-idle) transparent; }
  .hub-scrolling { scrollbar-color: var(--hub-sb-hover) transparent; }
}
