/* 04_VISUAL/xwui/xwui-lib/xwui-lib-basic/src/core/XWUIScrollArea/XWUIScrollArea.css */
/**
 * XWUIScrollArea Component Styles
 * Structure and behavior only - colors come from CSS variables
 * 
 * Style Dependencies:
 * - Base: reset.css, typography.css, utilities.css
 */

/* The host is a custom element (inline by default): block, so a height or
   width given to <xwui-scroll-area> reaches the area inside it. */
xwui-scroll-area {
    display: block;
}

.xwui-scroll-area {
    position: relative;
    overflow: hidden;
    /* Fill a sized host; with an unsized host this is auto (no change). */
    height: 100%;
}

.xwui-scroll-area-viewport {
    width: 100%;
    height: 100%;
    /* config.maxHeight caps the root; the viewport takes the same cap, so
       content grows until it, then scrolls. */
    max-height: inherit;
    overflow: auto;
}

/* config.fill: the area and its scroller take the container's whole block
   size. min-block-size 0 is the point: as a flex or grid child the area's
   automatic minimum is its content height, so without it a long list pushes
   the container open instead of scrolling inside it. */
.xwui-scroll-area-fill,
.xwui-scroll-area-fill > .xwui-scroll-area-viewport {
    block-size: 100%;
    min-block-size: 0;
}

/* Scrollbar skin: the native (classic) scrollbar of the viewport, set through
   the standard properties only. Styling ::-webkit-scrollbar would switch
   Chromium to custom bars for every area, so it is never touched here.
   --xwui-scroll-area-scrollbar-size takes the scrollbar-width keywords
   (auto | thin), which is all the standard property accepts.
   WHY no literal default for the colours: scrollbar-color only takes `auto`
   or TWO colours. With both tokens unset the value is `auto transparent`,
   which is invalid at computed-value time and so behaves as `unset`; the
   property is inherited, so the viewport inherits exactly as it did before
   this rule existed. Set the thumb alone and the track is transparent. */
.xwui-scroll-area-viewport {
    scrollbar-width: var(--xwui-scroll-area-scrollbar-size, auto);
    scrollbar-color: var(--xwui-scroll-area-thumb, auto) var(--xwui-scroll-area-track, transparent);
}

/* Orientation */
.xwui-scroll-area-vertical .xwui-scroll-area-viewport {
    overflow-x: hidden;
    overflow-y: auto;
}

.xwui-scroll-area-horizontal .xwui-scroll-area-viewport {
    overflow-x: auto;
    overflow-y: hidden;
}

.xwui-scroll-area-both .xwui-scroll-area-viewport {
    overflow: auto;
}

/* Hide scrollbar */
.xwui-scroll-area-hide-scrollbar .xwui-scroll-area-viewport {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.xwui-scroll-area-hide-scrollbar .xwui-scroll-area-viewport::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Overscroll: the SCROLLING element is the viewport, not the root, so the
   property lives here. contain stops a scroll chain at the end of this area. */
.xwui-scroll-area-overscroll-contain .xwui-scroll-area-viewport {
    overscroll-behavior: contain;
}

.xwui-scroll-area-overscroll-auto .xwui-scroll-area-viewport {
    overscroll-behavior: auto;
}

/* Keyboard stop (config.focusable): the root clips overflow, so a ring drawn
   outside the viewport (the global offset is positive) would be cut off. Draw
   it inside the box instead. Four classes of specificity beat the global
   `:root[data-style] *:focus-visible` offset without !important. */
.xwui-scroll-area.xwui-scroll-area > .xwui-scroll-area-viewport:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: calc(var(--focus-ring-width) * -1);
}

/* Scroll snap: the type sits on the viewport (the scroller), the alignment on
   its targets. Proximity unless snap-strict. */
.xwui-scroll-area-snap-x .xwui-scroll-area-viewport {
    scroll-snap-type: x proximity;
}

.xwui-scroll-area-snap-y .xwui-scroll-area-viewport {
    scroll-snap-type: y proximity;
}

.xwui-scroll-area-snap-both .xwui-scroll-area-viewport {
    scroll-snap-type: both proximity;
}

.xwui-scroll-area-snap-x.xwui-scroll-area-snap-strict .xwui-scroll-area-viewport {
    scroll-snap-type: x mandatory;
}

.xwui-scroll-area-snap-y.xwui-scroll-area-snap-strict .xwui-scroll-area-viewport {
    scroll-snap-type: y mandatory;
}

.xwui-scroll-area-snap-both.xwui-scroll-area-snap-strict .xwui-scroll-area-viewport {
    scroll-snap-type: both mandatory;
}

/* Targets are the children of the content: the viewport's own children for an
   HTML string, one level further for a caller element (snap-nested). :where()
   keeps specificity at zero so an element that sets its own scroll-snap-align
   (a card that wants center) always wins. */
:where(.xwui-scroll-area-snap-align-start:not(.xwui-scroll-area-snap-nested) > .xwui-scroll-area-viewport > *),
:where(.xwui-scroll-area-snap-align-start.xwui-scroll-area-snap-nested > .xwui-scroll-area-viewport > * > *) {
    scroll-snap-align: start;
}

:where(.xwui-scroll-area-snap-align-center:not(.xwui-scroll-area-snap-nested) > .xwui-scroll-area-viewport > *),
:where(.xwui-scroll-area-snap-align-center.xwui-scroll-area-snap-nested > .xwui-scroll-area-viewport > * > *) {
    scroll-snap-align: center;
}

:where(.xwui-scroll-area-snap-align-end:not(.xwui-scroll-area-snap-nested) > .xwui-scroll-area-viewport > *),
:where(.xwui-scroll-area-snap-align-end.xwui-scroll-area-snap-nested > .xwui-scroll-area-viewport > * > *) {
    scroll-snap-align: end;
}

/* Nothing here animates; this only stops a page-level smooth-scroll rule from
   turning snapping and scrollToBottom into motion for someone who asked for none. */
@media (prefers-reduced-motion: reduce) {
    .xwui-scroll-area-viewport {
        scroll-behavior: auto;
    }
}

/* Print: on paper there is nothing to scroll, so the area flows and prints
   all of its content. Without this a page inside a scroll area printed only
   the part in view (xwerp: a list lost every row below the fold).
   WHY !important on max-height only: config.maxHeight is written inline on
   the root, and an inline style yields to a stylesheet only that way. */
@media print {
    .xwui-scroll-area,
    .xwui-scroll-area .xwui-scroll-area-viewport {
        height: auto;
        max-height: none !important;
        overflow: visible;
    }
}
