/*
  Global styles: fonts, design tokens, base elements and a few shared UI primitives.
  Component styles live next to their component in scoped .razor.css files.
  Admin pages use the MudBlazor theme (Components/Layout/AdminTheme.cs) and only take the fonts from here.
*/

/* ---------- Fonts (self-hosted, taken from the staging site; see docs/DESIGN.md) ---------- */

@font-face {
    font-family: "STIHL Contraface Text";
    src: url("fonts/STIHLContrafaceTextLight.otf") format("opentype");
    font-weight: 300;
    font-display: swap;
}

@font-face {
    font-family: "STIHL Contraface Text";
    src: url("fonts/STIHLContrafaceText.otf") format("opentype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "STIHL Contraface Text";
    src: url("fonts/STIHLContrafaceTextDemi.otf") format("opentype");
    font-weight: 600;
    font-display: swap;
}

@font-face {
    font-family: "STIHL Contraface Text";
    src: url("fonts/STIHLContrafaceText-Bold.otf") format("opentype");
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: "STIHL Contraface Text";
    src: url("fonts/STIHLContrafaceText-BoldItalic.otf") format("opentype");
    font-weight: 700;
    font-style: italic;
    font-display: swap;
}

/* the two display cuts have capitals only; styles using them also set text-transform: uppercase,
   so the fallback font looks the same while they load */
@font-face {
    font-family: "STIHL Contraface Titling";
    src: url("fonts/STIHLContrafaceDisplayTitling.otf") format("opentype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "STIHL Contraface Display";
    src: url("fonts/STIHLContrafaceDisplayMedium.otf") format("opentype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Univers";
    src: url("fonts/UniversLight.ttf") format("truetype");
    font-weight: 300;
    font-display: swap;
}

@font-face {
    font-family: "Univers";
    src: url("fonts/UniversRegular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Univers";
    src: url("fonts/UniversBold.ttf") format("truetype");
    font-weight: 700;
    font-display: swap;
}

/* ---------- Design tokens ---------- */

:root {
    /* brand colours (STIHL orange); AdminTheme.cs repeats them for MudBlazor */
    --color-brand: #f37a1f;
    --color-brand-dark: #c94f15;
    --color-ink: #1a1a1a;
    --color-ink-soft: #333333;
    --color-muted: #6b6b6b;
    --color-line: #e0e0dc;
    --color-line-strong: #d0d0d0;
    --color-surface: #ffffff;
    --color-surface-alt: #f5f5f3;
    --color-success: #a1bf43;
    --color-danger: #e2401c;

    /* fonts as the staging site uses them: UI text; headings, hero and big buttons (Titling);
       footer links and small labels (Display Medium); descriptions (Univers) */
    --font-text: "STIHL Contraface Text", "Segoe UI", Arial, sans-serif;
    --font-title: "STIHL Contraface Titling", "Arial Narrow", var(--font-text);
    --font-display: "STIHL Contraface Display", var(--font-text);
    --font-body: "Univers", "Segoe UI", Arial, sans-serif;

    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    --radius-sm: 4px;
    --radius: 8px;
    --radius-pill: 999px;

    --shadow-card: 0 1px 2px rgb(0 0 0 / 0.04), 0 12px 32px rgb(0 0 0 / 0.06);
    --focus-ring: 0 0 0 3px rgb(243 122 31 / 0.35);
    --control-height: 2.75rem;

    /* ---- storefront: the staging site's sizes at desktop width, a little smaller on phones ---- */
    --color-black: #000000;
    --color-faint: #737373;             /* the staging's #9b9b9b was too light to read (contrast 4.7:1 now) */
    --color-available: #468019;         /* a shade darker than the staging's, for contrast */
    --color-sale: #a1bf43;              /* the discount badge, as on the staging site */
    --color-unavailable: #d9001b;
    --color-glow: 243 122 31;                         /* the brand orange as r g b, for the glow under the menu */

    --container: 103.75rem;                           /* 1660 px */
    --gutter: clamp(1rem, 6.25vw, 6.25rem);

    --fs-hero: clamp(1.875rem, 3vw, 2.875rem);        /* 46 px, Titling */
    --fs-display: clamp(1.625rem, 2.6vw, 2.5rem);     /* 40 px, Titling: promo */
    --fs-title: clamp(1.5rem, 2.25vw, 2.25rem);       /* 36 px, Titling: page titles */
    --fs-section: 1.125rem;                           /* 18 px, Titling: section headings */
    --fs-nav: 0.9375rem;                              /* 15 px */
    --fs-lead: clamp(0.9375rem, 1.1vw, 1.0625rem);    /* 17 px, Univers: intros */
    --fs-text: 0.9375rem;                             /* 15 px, Univers: longer texts */
    --fs-card-name: 0.9375rem;                        /* 15 px */
    --fs-card-text: 0.75rem;                          /* 12 px, Univers */
    --fs-price: 1.25rem;                              /* 20 px */
    --fs-small: 0.75rem;                              /* 12 px */
    --fs-tiny: 0.6875rem;                             /* 11 px: DETAIL, old prices, badges */
    --section-gap: clamp(2.5rem, 4.5vw, 4.5rem);      /* space between home sections */

    /* the header stays on screen: its bar, then the category menu (from 1200 px) */
    --header-bar: clamp(4rem, 5.2vw, 5.1875rem);      /* 83 px */
    --header-menu: 2.5rem;
    --header-height: var(--header-bar);

    --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
    --ease-glide: cubic-bezier(0.3, 0, 0.15, 1);      /* page transitions: a soft start hides the new page's first frames */
    --ease-menu: cubic-bezier(0.58, 0.3, 0.005, 1);   /* the staging menu's easing */
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

@media (min-width: 75em) {
    :root {
        --header-height: calc(var(--header-bar) + var(--header-menu) + 2px);   /* the menu's two lines */
    }
}

html {
    -webkit-text-size-adjust: 100%;
}

/* shop pages: a link to a part of a page stops under the header */
html:has(.site-header) {
    scroll-padding-top: var(--header-height);
}

/* the page's own links down the page glide there (the contents of the legal texts, the cart's tips);
   coming from another page, it opens at the place right away instead of gliding down from the top */
html:has(.legal-toc, .courier__tips) {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-text);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--color-ink);
    background: var(--color-surface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4 {
    margin: 0 0 var(--space-4);
    font-weight: 700;
    line-height: 1.2;
    text-wrap: balance;
}

p {
    margin: 0 0 var(--space-4);
}

/* no lone word on a paragraph's last line */
p,
li {
    text-wrap: pretty;
}

a {
    color: var(--color-brand-dark);
    text-underline-offset: 0.2em;
}

a:hover {
    color: var(--color-ink);
}

img,
svg {
    max-width: 100%;
    height: auto;
}

code,
kbd {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.95em;
    padding: 0.1em 0.35em;
    border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
}

:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}

/* after each navigation admin moves the focus to the page heading (FocusOnNavigate) for screen readers; no ring for that */
h1[tabindex="-1"]:focus {
    outline: none;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;           /* at the page's end (cart.js's live region) it would add a white line under the footer */
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.muted {
    color: var(--color-muted);
}

/* ---------- Buttons ---------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-height);
    padding: 0 var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button--primary {
    background: var(--color-brand);
    color: #fff;
}

.button--primary:hover {
    background: var(--color-brand-dark);
    color: #fff;
}

.button--outline {
    background: transparent;
    border-color: var(--color-ink);
    color: var(--color-ink);
}

.button--outline:hover {
    background: var(--color-ink);
    color: #fff;
}

.button--danger {
    background: var(--color-danger);
    color: #fff;
}

.button--danger:hover {
    background: #b8300f;
    color: #fff;
}

.button--block {
    width: 100%;
}

/* a row of buttons */
.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-4);
}

/* ---------- Forms ---------- */

.form {
    display: grid;
    gap: var(--space-4);
}

.field {
    display: grid;
    gap: var(--space-1);
}

.field > label {
    font-size: var(--text-sm);
    font-weight: 600;
}

.field input:not([type="checkbox"], [type="radio"]),
.field select,
.field textarea {
    width: 100%;
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-ink);
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: var(--focus-ring);
}

.field input:disabled {
    background: var(--color-surface-alt);
    color: var(--color-muted);
}

/* Blazor adds .invalid to inputs that failed validation */
.field :is(input, select, textarea).invalid {
    border-color: var(--color-danger);
}

.field__hint {
    font-size: var(--text-sm);
    color: var(--color-muted);
}

.check {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    cursor: pointer;
}

.check input {
    width: 1.125rem;
    height: 1.125rem;
    margin: 0;
    accent-color: var(--color-brand);
}

/* Blazor's validation output */
.validation-message {
    font-size: var(--text-sm);
    color: #b8300f;
}

.validation-errors {
    margin: 0;
    padding-left: var(--space-5);
    color: #b8300f;
}

/* ---------- Alerts ---------- */

.alert {
    margin: 0 0 var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid;
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.alert > :last-child {
    margin-bottom: 0;
}

.alert--success {
    background: #f3f8e8;
    border-color: var(--color-success);
    color: #3e5510;
}

.alert--danger {
    background: #fdefeb;
    border-color: var(--color-danger);
    color: #9c2a10;
}

.alert--warning {
    background: #fff4ea;
    border-color: var(--color-brand);
    color: #7a3a0c;
}

/* ---------- Tables ---------- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.data-table th,
.data-table td {
    padding: var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--color-line);
    text-align: left;
    vertical-align: middle;
}

/* ---------- Storefront layout ---------- */

/* the page width of the design: 1660 px, with the sides shrinking on smaller screens */
.container {
    width: min(100% - 2 * var(--gutter), var(--container));
    margin-inline: auto;
}

/* "NAJPREDÁVANEJŠIE", "OBJAVUJ NOVINKY", ... */
.section-title {
    margin: 0 0 clamp(1.25rem, 2.5vw, 2.5rem);
    font-family: var(--font-title);
    font-size: var(--fs-section);
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1.2;
    text-align: center;
    text-transform: uppercase;
}

/* a big heading in the Titling cut (page titles, hero, promo) */
.title {
    font-family: var(--font-title);
    font-weight: 400;
    letter-spacing: 0.01em;
    line-height: 1.16;
    text-transform: uppercase;
}

/* a button's orange pill in the design's sizes: small (cards), medium, large (hero) */
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.45em 1.15em;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s var(--ease-out), color 0.2s var(--ease-out), border-color 0.2s var(--ease-out);
}

/* the hero's and promo's big buttons, in the Titling cut */
.pill--title {
    font-family: var(--font-title);
    font-weight: 400;
    letter-spacing: 0.02em;
}

.pill--orange {
    background: var(--color-brand);
    color: #fff;
}

.pill--orange:hover {
    background: var(--color-brand-dark);
    color: #fff;
}

.pill--black {
    background: var(--color-black);
    color: #fff;
}

.pill--black:hover {
    background: #333;
    color: #fff;
}

.pill--outline {
    background: #fff;
    border-color: var(--color-black);
    color: var(--color-black);
}

.pill--outline:hover {
    background: var(--color-black);
    color: #fff;
}

/* product descriptions and other text written in the admin (already sanitized) */
.rich-text > :first-child {
    margin-top: 0;
}

.rich-text p,
.rich-text ul,
.rich-text ol {
    margin: 0 0 1em;
}

.rich-text ul,
.rich-text ol {
    padding-left: 1.25em;
}

.rich-text li + li {
    margin-top: 0.3em;
}

.rich-text h2 {
    margin: 1.75em 0 0.7em;
    font-size: 1.2em;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.rich-text h3,
.rich-text h4 {
    margin: 1.5em 0 0.6em;
    font-size: 1.1em;
    text-transform: uppercase;
}

.rich-text a:not(.pill) {
    color: var(--color-brand-dark);
    overflow-wrap: anywhere;
}

/* ---------- Storefront forms (Kontakt, Servis): plain POST forms; square fields and button as on staging ---------- */

.shop-form {
    display: grid;
    gap: 0.75rem;
}

.shop-field {
    display: grid;
    gap: 0.3rem;
}

.shop-field input,
.shop-field textarea {
    width: 100%;
    min-height: 2.7rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-line-strong);
    border-radius: 0;
    background: #fff;
    color: var(--color-ink);
    font: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.shop-field textarea {
    resize: vertical;
}

.shop-field input::placeholder,
.shop-field textarea::placeholder {
    color: var(--color-faint);
}

.shop-field input:focus,
.shop-field textarea:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: var(--focus-ring);
}

.shop-field .invalid,
.shop-form .validation-message + .invalid {
    border-color: var(--color-danger);
}

.shop-form .validation-message {
    font-size: 0.8125rem;
}

/* a field only bots fill in: out of sight for people and screen readers */
.shop-form__trap {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.shop-form__note {
    margin: 0;
    color: var(--color-muted);
    font-size: 0.8125rem;
}

.shop-form__submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    min-height: 3rem;
    padding: 0.6rem 2rem;
    border: 0;
    border-radius: 0;
    background: var(--color-brand);
    color: #fff;
    font: inherit;
    font-size: 1.1875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 0.2s var(--ease-out), transform 0.15s var(--ease-out);
}

.shop-form__submit:hover {
    background: var(--color-brand-dark);
}

.shop-form__submit:active {
    transform: scale(0.99);
}

/* the design's black button (the checkout's steps before the last one) */
.shop-form__submit--dark {
    background: var(--color-black);
}

.shop-form__submit--dark:hover {
    background: #333;
}

/* an arrow after the label moves on a little when pointed at */
.shop-form__submit > .icon {
    flex: none;
    width: 1.15em;
    height: 1.15em;
    transition: transform 0.25s var(--ease-out);
}

.shop-form__submit:hover > .icon {
    transform: translateX(0.3rem);
}

/* the same button as a link ("Pokračovať k údajom") */
a.shop-form__submit {
    text-align: center;
    text-decoration: none;
}

.shop-check {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    font-size: 0.875rem;
    line-height: 1.45;
    cursor: pointer;
}

/* a box to tick, also inside a .shop-field (which styles text inputs) */
.shop-check input {
    flex: none;
    width: 1.1rem;
    height: 1.1rem;
    min-height: 0;
    margin: 0.1rem 0 0;
    padding: 0;
    accent-color: var(--color-brand);
}

/* what the page shows after a form was sent */
.form-sent {
    padding: 1.5rem 1.5rem 1.35rem;
    border: 1px solid #cfe3b6;
    border-radius: 4px;
    background: #f5faef;
}

.form-sent__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
    font-weight: 700;
}

.form-sent__title .icon {
    width: 1.3rem;
    height: 1.3rem;
    color: var(--color-available);
}

.form-sent p:not(.form-sent__title) {
    margin: 0 0 0.9rem;
    color: var(--color-ink-soft);
    font-family: var(--font-body);
    font-size: 0.9375rem;
}

/* ---------- Cart and checkout ---------- */

/* the steps' headings: "SÚHRN", "KONTAKTNÉ ÚDAJE", "SPÔSOB DOPRAVY", ... */
.checkout-heading {
    margin: 0 0 1rem;
    padding: 0;
    font-family: var(--font-title);
    font-size: clamp(1.125rem, 1.4vw, 1.375rem);
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1.2;
    text-transform: uppercase;
}

/* View transitions between pages (PageTransitions.razor, type "page") and into the cart (js/cart.js): the header
   stays, the steps' line scales, the content rises. Only transform and opacity animate (the graphics card's). */
@media (prefers-reduced-motion: no-preference) {
    ::view-transition-group(*) {
        animation-duration: 0.45s;
        animation-timing-function: var(--ease-glide);
    }

    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 0.25s;
    }

    /* Another page: the old one isn't shown - Chrome often keeps no picture of it, and a cross-fade from nothing
       blinked the whole page. The named parts move from their old places, the content rises in. */
    html:active-view-transition-type(page)::view-transition-old(*) {
        display: none;
    }

    html:active-view-transition-type(page)::view-transition-new(*) {
        animation: none;
    }

    html:active-view-transition-type(page)::view-transition-group(page-content) {
        animation: none;
    }

    html:active-view-transition-type(page)::view-transition-new(page-content) {
        animation: vt-rise 0.3s var(--ease-out) both;
    }

    /* into the cart from a product (js/cart.js): the product page fades away, the cart rises into place */
    html.cart-arriving::view-transition-old(root) {
        animation: vt-fade-out 0.15s ease-out both;
    }

    html.cart-arriving::view-transition-new(root) {
        animation: vt-rise 0.35s var(--ease-out) 0.08s both;
    }

    /* the steps' line: its picture scales from the old length to the new */
    ::view-transition-old(checkout-progress) {
        animation: none;
        opacity: 0;
    }

    ::view-transition-new(checkout-progress) {
        animation: none;
    }
}

/* what changes from page to page under the header and the checkout's steps (PageTransitions) */
.page-content {
    view-transition-name: page-content;
}

/* arriving in the cart, the steps and the content rise with the rest of it */
html.cart-arriving .page-content,
html.cart-arriving .steps__fill,
html.cart-arriving .steps__dot {
    view-transition-name: none !important;
}

/* "Do košíka" away from the cart (js/cart.js): the product's picture flying into the header's cart, and a
   word under the cart for a moment */
.cart-flight {
    position: fixed;
    z-index: 60;
    pointer-events: none;
}

.cart-flight__riser,
.cart-flight__drop {
    width: 100%;
    height: 100%;
}

.cart-flight__drop {
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--color-line);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 28px rgb(0 0 0 / 0.16);
}

.cart-flight__drop img {
    width: 84%;
    height: 84%;
    object-fit: contain;
}

.cart-note {
    position: fixed;
    z-index: 60;
    display: grid;
    gap: 0.1rem;
    max-width: calc(100vw - 1.5rem);
    padding: 0.7rem 1rem;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 30px rgb(0 0 0 / 0.14);
    color: var(--color-ink);
    font-size: 0.875rem;
    line-height: 1.35;
    text-decoration: none;
}

.cart-note span {
    color: var(--color-brand-dark);
    font-weight: 700;
}

.cart-note:hover span {
    text-decoration: underline;
}

/* js/cart.js is posting a change in the background; links and buttons only (they set their own cursor),
   not "*", which made the browser restyle the whole page right as the transition started */
html.cart-busy,
html.cart-busy a,
html.cart-busy button {
    cursor: progress !important;
}

/* ... and has just put the new cart in: its buttons take their hover colour at once */
html.cart-fresh main a,
html.cart-fresh main button {
    transition: none !important;
}

@keyframes vt-fade-out {
    to {
        opacity: 0;
    }
}

@keyframes vt-rise {
    from {
        opacity: 0;
        transform: translateY(0.75rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
