/* Store design → Look and feel, shared by the storefront (index.html) and the admin console (admin.html).
   Each page's applyTheme sets :root[data-look] to square-2d (the Industry blueprint look, no rules here),
   square-3d, rounded-2d or rounded-3d. "rounded-*" rounds controls and blocks; "*-3d" adds shadows,
   recessed fields and lift. Many controls are styled inline, so the "bordered" selectors match the
   browser-serialised style attribute of a full 1px border. An inline border-radius, box-shadow or
   transform always wins over these rules. */
:root[data-look^="rounded"] {
    --look-r-ctl: 8px;
    --look-r-box: 14px;
}

/* — rounded — */
:root[data-look^="rounded"] .blueprint > .corner {
    display: none;
}

:root[data-look^="rounded"] :is(.btn, .input, .seg, .tag, button, select, textarea, input:not([type="checkbox"], [type="radio"], [type="range"]), [style*="border: 1px solid"], [style*="border:1px solid"]) {
    border-radius: var(--look-r-ctl);
}

:root[data-look^="rounded"] :is(.blueprint:not(.btn), .dialog) {
    border-radius: var(--look-r-box);
}

/* Blocks clip their content to the rounded corners, except while a menu or popover inside them is open. */
:root[data-look^="rounded"] :is(.blueprint:not(.btn), .dialog):not(:has([aria-expanded="true"])) {
    overflow: clip;
}

/* Segmented groups (a bordered flex row of buttons, no padding): the frame rounds and clips, its segments stay square. */
:root[data-look^="rounded"] :is([style*="border: 1px solid"], [style*="border:1px solid"])[style*="display: flex"]:not([style*="padding"]) {
    overflow: clip;
}

:root[data-look^="rounded"] :is([style*="border: 1px solid"], [style*="border:1px solid"])[style*="display: flex"]:not([style*="padding"]) > :is(button, input, select) {
    border-radius: 0;
}

/* — 3D — */
:root[data-look$="-3d"] header[style*="position: sticky"] {
    box-shadow: var(--shadow-sm);
}

:root[data-look$="-3d"] .btn:not(.btn-ghost) {
    box-shadow: var(--shadow-sm), inset 0 1px 0 color-mix(in srgb, #fff 14%, transparent);
    transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
}

:root[data-look$="-3d"] .btn-primary {
    background-image: linear-gradient(to bottom, color-mix(in srgb, #fff 16%, transparent), transparent 55%, color-mix(in srgb, #000 10%, transparent));
}

:root[data-look$="-3d"] .btn:not(.btn-ghost):not(:disabled):hover {
    box-shadow: var(--shadow-md), inset 0 1px 0 color-mix(in srgb, #fff 14%, transparent);
}

:root[data-look$="-3d"] .btn:not(.btn-ghost):not(:disabled):active {
    box-shadow: inset 0 2px 4px color-mix(in srgb, #000 22%, transparent);
}

:root[data-look$="-3d"] button:is([style*="border: 1px solid"], [style*="border:1px solid"]):not(.btn):not(.blueprint) {
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease;
}

:root[data-look$="-3d"] button:is([style*="border: 1px solid"], [style*="border:1px solid"]):not(.btn):not(.blueprint):not(:disabled):hover {
    box-shadow: var(--shadow-md);
}

:root[data-look$="-3d"] :is(.input, select, textarea) {
    box-shadow: inset 0 1px 3px color-mix(in srgb, #000 16%, transparent);
}

:root[data-look$="-3d"] .tag {
    box-shadow: var(--shadow-sm);
}

:root[data-look$="-3d"] .blueprint:not(.btn) {
    box-shadow: var(--shadow-sm), inset 0 1px 0 color-mix(in srgb, #fff 8%, transparent);
    transition: box-shadow .2s ease;
}

/* Blocks rise on hover by their shadow alone (a transform would re-anchor fixed overlays inside them); clickable cards lift. */
:root[data-look$="-3d"] .blueprint:not(.btn):not(.dialog):hover {
    box-shadow: var(--shadow-md), inset 0 1px 0 color-mix(in srgb, #fff 8%, transparent);
}

:root[data-look$="-3d"] :is(button, a, [role="link"]).blueprint:not(.btn) {
    transition: transform .2s ease, box-shadow .2s ease, border-color .15s ease !important;
}

:root[data-look$="-3d"] :is(button, a, [role="link"]).blueprint:not(.btn):hover {
    box-shadow: var(--shadow-lg);
}

:root[data-look$="-3d"] :is(button, a, [role="link"]).blueprint:not(.btn):active {
    box-shadow: var(--shadow-md);
}

:root[data-look$="-3d"] .dialog {
    box-shadow: var(--shadow-lg);
}

/* — dropdowns (every <select class="input"> of both pages) —
   A native dropdown's open list is drawn by the browser, which paints the option under the pointer in the system
   highlight colour whatever the theme. Where the browser supports customizable selects (appearance: base-select),
   the list is ours to style: hover, keyboard focus and the chosen option take the theme's accent, and the list
   follows the look and feel. Elsewhere the list stays native, with the theme's colours on its options. */
select.input option, select.input optgroup {
    background-color: var(--color-bg);
    color: var(--color-text);
}

:root[data-theme="dark"] select.input {
    background-color: var(--color-surface) !important;
    color: var(--color-text);
}

:root[data-theme="dark"] select.input option:checked {
    background-color: var(--color-accent-300);
    color: #fff;
}

@supports (appearance: base-select) {
    select.input, select.input::picker(select) {
        appearance: base-select;
    }

    /* A base-select is a flex box that stretches its parts: in a field taller than its text, the text would sit at the
       top and the arrow's box fill the height, so turning the arrow flipped it from top to bottom. Centred, both stay put. */
    select.input {
        align-items: center;
    }

    select.input::picker-icon {
        color: color-mix(in srgb, var(--color-text) 70%, transparent);
        transition: rotate .15s ease;
    }

    select.input:open::picker-icon {
        rotate: 180deg;
    }

    select.input::picker(select) {
        margin-block: 4px;
        padding: 4px;
        background: var(--color-bg);
        color: var(--color-text);
        border: 1px solid var(--color-divider);
        border-radius: 0;
        box-shadow: var(--shadow-md);
    }

    select.input option {
        padding: 7px 10px;
        gap: 8px;
        background: transparent;
        color: var(--color-text);
        border-radius: 0;
        outline: none;
        cursor: pointer;
    }

    /* Mixed from the accent itself, not the ramp: some themes' lightest step equals their ground. */
    select.input option:checked,
    :root[data-theme="dark"] select.input option:checked {
        background: color-mix(in srgb, var(--color-accent) 14%, transparent);
        color: var(--color-text);
    }

    select.input option:is(:hover, :focus-visible) {
        background: color-mix(in srgb, var(--color-accent) 24%, transparent);
        color: var(--color-text);
    }

    select.input option:checked:is(:hover, :focus-visible) {
        background: color-mix(in srgb, var(--color-accent) 32%, transparent);
    }

    select.input option:disabled {
        background: transparent;
        color: color-mix(in srgb, var(--color-text) 45%, transparent);
        cursor: default;
    }

    select.input optgroup {
        background: transparent;
        font-weight: 600;
    }

    :root[data-look^="rounded"] select.input::picker(select) {
        border-radius: var(--look-r-ctl);
    }

    :root[data-look^="rounded"] select.input option {
        border-radius: calc(var(--look-r-ctl) - 3px);
    }

    :root[data-look$="-3d"] select.input::picker(select) {
        box-shadow: var(--shadow-lg);
    }
}

/* The lift itself, only when the viewer allows motion. */
@media (prefers-reduced-motion: no-preference) {
    :root[data-look$="-3d"] .btn:not(.btn-ghost):not(:disabled):hover,
    :root[data-look$="-3d"] button:is([style*="border: 1px solid"], [style*="border:1px solid"]):not(.btn):not(.blueprint):not(:disabled):hover {
        transform: translateY(-1px);
    }

    :root[data-look$="-3d"] .btn:not(.btn-ghost):not(:disabled):active {
        transform: translateY(1px);
    }

    :root[data-look$="-3d"] :is(button, a, [role="link"]).blueprint:not(.btn):hover {
        transform: translateY(-4px);
    }

    :root[data-look$="-3d"] :is(button, a, [role="link"]).blueprint:not(.btn):active {
        transform: translateY(-1px);
    }
}
