/*
 * material.css — the glass, described once.
 *
 * A translucent surface is four things, not one: what is inside it (tint), what
 * bends the light behind it (blur), what catches the light on its edge
 * (refraction), and how far it sits above the page (shadow). This file composes
 * those four into a small number of named distances so components ask for "a
 * card" or "a menu" instead of assembling a fill, a border and three shadows
 * each time and getting a slightly different answer.
 *
 * THE COST RULE. `backdrop-filter` is spent only where something genuinely
 * floats over moving content: popovers, dialogs, tooltips and sticky chrome.
 * Everywhere else the fill, the edge and the shadow do the work on their own.
 * Two reasons, both practical: a filter is the most expensive thing on the page
 * while scrolling, and — the trap the landing's glass.css documents at length —
 * an element with `backdrop-filter` becomes a *backdrop root*, so a filtered
 * panel nested inside it silently goes inert. A card inside the sidebar does not
 * need a filter; it needs to look like it is in front.
 *
 * DEPTH IS SHADOW, NOT OPACITY. Making a surface more transparent to make it
 * feel "lighter" is how foreground text ends up fighting the page behind it. The
 * distances below climb through shadow, and the tints only ever move *towards*
 * more opacity as content gets more important.
 */

/* ── The base: a surface with thickness ───────────────────────────────────── */

.sf-surface {
    position: relative;
    isolation: isolate;
    background: var(--glass-bg);
    /* The pale border used by the older glass was invisible on a pale page: on
       white, rgba(255,255,255,.5) is white. The hairline is the shape; the inset
       highlight above is the light catching it. */
    border: 1px solid var(--glass-edge-line);
    border-radius: var(--radius-lg);
    box-shadow:
        var(--glass-inset-highlight),
        inset 0 -1px 0 var(--glass-thickness),
        var(--glass-shadow);
    color: var(--ink);
    transition:
        background-color var(--duration-fast) var(--ease-glide),
        border-color var(--duration-fast) var(--ease-glide),
        box-shadow var(--duration-fast) var(--ease-glide),
        transform var(--duration-fast) var(--ease-press);
}

/*
 * Light landing on the top face, gathering along the bottom edge. These two are
 * what make a rectangle read as a slab with thickness instead of a rectangle
 * with a tint — and they are also the cheapest possible hint of refraction,
 * because they are painted, not filtered.
 *
 * `z-index: -1` inside the isolated context keeps them above the fill and below
 * whatever the component puts inside, so the sheen never washes over text.
 */
.sf-surface::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    background: var(--glass-refraction);
    opacity: 1;
    pointer-events: none;
    transition: opacity var(--duration-fast) var(--ease-glide);
}

/* A surface that holds text gets the frosted tint: enough body that a paragraph
   over a busy photograph is still a paragraph. */
.sf-surface--frost {
    background: var(--glass-tint-frost);
}

/* A surface that merely groups or frames can stay clear, so the page shows
   through and the shape does the work. */
.sf-surface--clear {
    background: var(--glass-tint-clear);
}

/* An opaque surface, for the things that are not layers: a form card, a settings
   panel, a well. The material's two translucent fills are for content that has
   something behind it; a form has nothing behind it and should not pretend
   otherwise. Same radius, same hairline, no sheen. */
.sf-surface--solid {
    background: var(--surface);
    box-shadow: none;
}

.sf-surface--solid::before {
    content: none;
}

/* Sticky chrome — the sidebar band, the top bar, a table header pinned to the
   top. Lighter than a text panel on purpose: the page is meant to keep moving
   underneath, so foreground labels sit on a blurred smear rather than on paper.
   Use this with --blur; without the filter it becomes an illegible window. */
.sf-surface--band {
    background: var(--glass-band);
}

/* Panels that sit under content — table headers, wells, inset rows. No lift, so
   they read as part of the page rather than floating above it. */
.sf-surface--flat {
    box-shadow:
        var(--glass-inset-highlight),
        inset 0 -1px 0 var(--glass-thickness);
}

/* ── Three distances ──────────────────────────────────────────────────────── */

/* Picked up: a card, a list row under the pointer. */
.sf-surface--raised {
    box-shadow:
        var(--glass-inset-highlight),
        inset 0 -1px 0 var(--glass-thickness),
        var(--glass-shadow-raise);
}

/* Over the page: a menu, a dialog, a tooltip. This is where a blur is earned,
   because there is content moving underneath that the panel must not hide. */
.sf-surface--float {
    box-shadow:
        var(--glass-inset-highlight),
        inset 0 -1px 0 var(--glass-thickness),
        var(--glass-shadow-float);
}

.sf-surface--blur {
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

.sf-surface--blur-soft {
    backdrop-filter: var(--glass-blur-medium);
    -webkit-backdrop-filter: var(--glass-blur-medium);
}

/* ── Material that answers a touch ────────────────────────────────────────── */

/*
 * The material is responsive, not decorative: it brightens when the pointer
 * arrives, lifts a hair when it is picked up, and compresses when it is pressed.
 * The compression is deliberately tiny — a press should feel like a surface
 * taking weight, not like a button running away from the cursor.
 */
.sf-surface--interactive {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* These selectors are two classes deep on purpose. The material sheet loads
   before each app's own CSS, and legacy component rules — `.stats > div`,
   `.card` — set `transition: border-color` at (0,1,1), which quietly replaces
   the multi-property transition on the very elements that move. Declaring the
   transition again on the state rules (0,2,0) puts it back where it matters. */
.sf-surface--interactive:hover,
.sf-surface--interactive:active,
.sf-surface--interactive:focus-visible {
    transition-property: background-color, border-color, box-shadow, transform;
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease-glide);
}

.sf-surface--interactive:hover {
    background-color: var(--glass-bg-hover);
}

/* Hover must always be a step towards the reader. On a frosted surface the
   generic hover fill is a step *down* from frost, so the row that answers the
   pointer recedes instead of lifting — the opposite of the intent. */
.sf-surface--frost.sf-surface--interactive:hover {
    background-color: var(--glass-bg-strong);
}

.sf-surface--interactive:hover::before {
    opacity: 0.7;
}

.sf-surface--interactive.sf-surface--raised:hover {
    transform: var(--glass-lift);
    box-shadow:
        var(--glass-inset-highlight),
        inset 0 -1px 0 var(--glass-thickness),
        var(--glass-shadow-float);
}

/* The raised variant carries the hover, and hover outranks :active on
   specificity, so the press has to name it too — otherwise a surface only
   compresses when the pointer is somewhere else. */
.sf-surface--interactive:active,
.sf-surface--interactive.sf-surface--raised:active,
.sf-surface--interactive.sf-surface--float:active {
    transform: var(--glass-press);
    transition-duration: var(--duration-fast);
}

.sf-surface--interactive:active::before {
    opacity: 1;
}

/* A row being dragged is the one thing on the page that is definitely in front,
   so it gets the furthest shadow and a slight tilt off the page plane. */
.sf-surface--lifted {
    transform: var(--glass-lift);
    box-shadow:
        var(--glass-inset-highlight),
        inset 0 -1px 0 var(--glass-thickness),
        var(--glass-shadow-float);
}

/* ── Disclosure: the answer to a busy screen ────────────────────────────────
 *
 * Most clutter is not too much content, it is content that is permanently on
 * display. A filter bar with nine controls, a form with four optional fields, a
 * sidebar with nineteen links — all of them correct, and all of them shouting at
 * once. The fix is not to delete them but to make them askable: visible on
 * request, absent the rest of the time.
 *
 * This is deliberately built on <details>/<summary> rather than a script. The
 * browser owns the state, the keyboard works (Enter and Space toggle, the summary
 * is focusable and announced), find-in-page can still reach what is inside, and
 * nothing breaks when JavaScript does not arrive. A component that hides content
 * must never be the only way to reach it.
 *
 * The chevron is drawn with borders instead of an icon so it inherits the text
 * colour and needs no asset; it rotates on open and stops rotating under
 * `prefers-reduced-motion` while the open state stays legible, because the glyph
 * still turns — only the animation goes.
 */

.sf-disclosure {
    border: 1px solid var(--glass-edge-line);
    border-radius: var(--radius-md);
    background: var(--glass-tint-clear);
}

.sf-disclosure > summary {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    border-radius: inherit;
    cursor: pointer;
    list-style: none;
    color: var(--ink);
    transition: background-color var(--duration-fast) var(--ease-glide);
}

/* Safari and Chrome still draw their own marker unless it is removed explicitly. */
.sf-disclosure > summary::-webkit-details-marker {
    display: none;
}

.sf-disclosure > summary:hover {
    background-color: var(--glass-bg-hover);
}

.sf-disclosure > summary:focus-visible {
    outline: 2px solid var(--accent-text);
    outline-offset: 2px;
}

.sf-disclosure > summary::after {
    content: "";
    margin-inline-start: auto;
    inline-size: 0.5rem;
    block-size: 0.5rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform var(--duration-fast) var(--ease-glide);
}

.sf-disclosure[open] > summary::after {
    transform: rotate(-135deg);
}

/* A count of what is waiting inside, so a closed disclosure is not a mystery:
   "Filters (3)" tells someone there is something to come back for. */
.sf-disclosure__count {
    color: var(--text-muted);
}

.sf-disclosure[open] > summary {
    border-end-start-radius: 0;
    border-end-end-radius: 0;
}

@media (prefers-reduced-motion: reduce) {
    .sf-disclosure > summary,
    .sf-disclosure > summary::after {
        transition: none;
    }
}

/* ── Honest fallbacks ─────────────────────────────────────────────────────── */

/*
 * Without a usable backdrop filter, translucency over moving content is a
 * legibility problem rather than a material. The tint steps up to the solid
 * value, the layout is identical, and nothing else changes.
 */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .sf-surface--blur,
    .sf-surface--blur-soft {
        background-color: var(--glass-bg-strong-solid);
    }
}

/*
 * Motion here is feedback — brighten, lift, compress — so removing it must not
 * remove the feedback itself. Hover and press still change the fill and the
 * border; only the movement goes.
 */
@media (prefers-reduced-motion: reduce) {
    .sf-surface,
    .sf-surface::before {
        transition: none;
    }

    /* The raised and float variants are named because their hover rules carry a
       higher specificity than the flat one: without them the lift survives the
       preference and the surface still moves for someone who asked it not to. */
    .sf-surface--interactive:hover,
    .sf-surface--interactive:active,
    .sf-surface--interactive.sf-surface--raised:hover,
    .sf-surface--interactive.sf-surface--float:hover,
    .sf-surface--lifted {
        transform: none;
    }
}
