/* =====================================================================
   CODLAB SHARED POLISH LAYER
   Universal a11y, motion, form, scrollbar primitives shared across
   the 7 Riservati-connected tenant themes. Each theme overrides
   --focus-ring-color and --polish-accent-rgb in its own base.html.
   ===================================================================== */

:root {
    --focus-ring-width: 2px;
    --focus-ring-offset: 2px;
    --focus-ring-color: currentColor; /* themes override */
    --polish-accent-rgb: 0 0 0;       /* themes override */
}

/* ─────────────  Focus visible (WCAG 2.1 AA)  ───────────── */

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    border-radius: 2px;
}

/* Drop default :focus when not keyboard */
:focus:not(:focus-visible) {
    outline: none;
}

/* ─────────────  Skip link  ───────────── */

.skip-link,
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 0;
    padding: 10px 18px;
    background: var(--focus-ring-color);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
    z-index: 10001;
    border-radius: 0 0 6px 0;
    transition: top 0.2s ease;
}
.skip-link:focus,
.skip-to-content:focus {
    top: 0;
    outline: none;
}

/* ─────────────  Touch targets (mobile WCAG 2.1 AAA)  ───────────── */

@media (pointer: coarse) {
    a, button, input[type="button"], input[type="submit"], [role="button"] {
        min-height: 44px;
    }
}

/* ─────────────  Custom scrollbar (visible, branded)  ───────────── */

* {
    scrollbar-width: thin;
    scrollbar-color: rgb(var(--polish-accent-rgb) / 0.55) transparent;
}
::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgb(var(--polish-accent-rgb) / 0.45);
    border-radius: 6px;
    transition: background-color 0.18s ease;
}
::-webkit-scrollbar-thumb:hover {
    background: rgb(var(--polish-accent-rgb) / 0.75);
}

/* ─────────────  Scroll reveal primitives (GPU-accelerated)  ───────────── */

.reveal-up,
.reveal-fade,
.reveal-left,
.reveal-right,
.reveal-scale {
    opacity: 0;
    will-change: transform, opacity;
}
.reveal-up    { transform: translate3d(0, 28px, 0); }
.reveal-left  { transform: translate3d(-32px, 0, 0); }
.reveal-right { transform: translate3d(32px, 0, 0); }
.reveal-scale { transform: scale3d(0.96, 0.96, 1); }

.reveal-up.is-visible,
.reveal-fade.is-visible,
.reveal-left.is-visible,
.reveal-right.is-visible,
.reveal-scale.is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
    transition:
        opacity 0.7s cubic-bezier(0.22, 0.61, 0.36, 1),
        transform 0.85s cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Stagger helpers (8 tiers) */
.reveal-d1.is-visible { transition-delay: 0.06s; }
.reveal-d2.is-visible { transition-delay: 0.12s; }
.reveal-d3.is-visible { transition-delay: 0.18s; }
.reveal-d4.is-visible { transition-delay: 0.24s; }
.reveal-d5.is-visible { transition-delay: 0.30s; }
.reveal-d6.is-visible { transition-delay: 0.36s; }
.reveal-d7.is-visible { transition-delay: 0.42s; }
.reveal-d8.is-visible { transition-delay: 0.48s; }

/* ─────────────  Form input states (universal)  ───────────── */

input:not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="checkbox"]):not([type="radio"]),
textarea,
select {
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    box-shadow: 0 0 0 3px rgb(var(--polish-accent-rgb) / 0.18);
}
input:user-invalid,
textarea:user-invalid {
    border-color: #b3261e;
}
input:user-invalid:focus-visible,
textarea:user-invalid:focus-visible {
    box-shadow: 0 0 0 3px rgb(179 38 30 / 0.18);
}
input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ─────────────  Selection  ───────────── */

::selection {
    background: rgb(var(--polish-accent-rgb) / 0.25);
    color: inherit;
}

/* ─────────────  Reduced motion (universal)  ───────────── */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .reveal-up,
    .reveal-fade,
    .reveal-left,
    .reveal-right,
    .reveal-scale {
        opacity: 1;
        transform: none;
    }
}

/* ─────────────  Image render quality (Safari/Chrome consistency)  ───────────── */

img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}
@supports (image-rendering: auto) {
    img { image-rendering: auto; }
}

/* ─────────────  Universal heading hierarchy (responsive clamp)  ───────────── */

.polish-display { font-size: clamp(2.25rem, 5.5vw, 4.25rem); line-height: 1.04; letter-spacing: -0.02em; }
.polish-h1      { font-size: clamp(1.75rem, 4vw, 3rem);     line-height: 1.10; letter-spacing: -0.018em; }
.polish-h2      { font-size: clamp(1.4rem, 2.6vw, 2rem);    line-height: 1.18; letter-spacing: -0.012em; }
.polish-h3      { font-size: clamp(1.18rem, 1.8vw, 1.5rem); line-height: 1.25; letter-spacing: -0.008em; }
.polish-lead    { font-size: clamp(1rem, 1.4vw, 1.18rem);   line-height: 1.55; }
.polish-kicker  { font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; font-weight: 500; }

/* ─────────────  Inline link hover (universal)  ───────────── */

.polish-link {
    position: relative;
    color: rgb(var(--polish-accent-rgb));
    text-decoration: none;
    background-image: linear-gradient(currentColor, currentColor);
    background-size: 0% 1px;
    background-repeat: no-repeat;
    background-position: 0 100%;
    transition: background-size 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.polish-link:hover,
.polish-link:focus-visible {
    background-size: 100% 1px;
}

/* ─────────────  Button ripple-like press feedback  ───────────── */

.polish-press { transition: transform 0.16s ease, box-shadow 0.16s ease; }
.polish-press:active { transform: scale(0.97); }

/* ─────────────  Marquee GPU optimisation hint  ───────────── */

.marquee-track,
.marquee-text,
[class*="marquee"] {
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* ─────────────  Section divider hairline (editorial)  ───────────── */

.polish-divider {
    border: 0;
    height: 1px;
    background-image: linear-gradient(90deg, transparent 0%, rgb(var(--polish-accent-rgb) / 0.45) 50%, transparent 100%);
    margin: 0 auto;
    max-width: 720px;
}

/* ─────────────  Hero image LCP-friendly defaults  ───────────── */

.polish-hero-img,
img.polish-hero {
    max-width: 100%;
    height: auto;
    object-fit: cover;
    object-position: center;
}

/* ─────────────  Hamburger menu staggered enter  ───────────── */

@keyframes polishMenuEnter {
    0%   { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.polish-stagger > * {
    opacity: 0;
    animation: polishMenuEnter 0.42s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}
.polish-stagger > *:nth-child(1) { animation-delay: 0.04s; }
.polish-stagger > *:nth-child(2) { animation-delay: 0.10s; }
.polish-stagger > *:nth-child(3) { animation-delay: 0.16s; }
.polish-stagger > *:nth-child(4) { animation-delay: 0.22s; }
.polish-stagger > *:nth-child(5) { animation-delay: 0.28s; }
.polish-stagger > *:nth-child(6) { animation-delay: 0.34s; }
.polish-stagger > *:nth-child(7) { animation-delay: 0.40s; }
.polish-stagger > *:nth-child(8) { animation-delay: 0.46s; }

/* ─────────────  Image lazy fade-in (avoids LCP/jank flash)  ───────────── */

img.polish-fade,
img[data-polish-fade] {
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}
img.polish-fade.loaded,
img[data-polish-fade].loaded {
    opacity: 1;
}

/* ─────────────  Subtle tilt for cards on hover (no transform-style 3d hard) ───────────── */

@media (hover: hover) and (pointer: fine) {
    .polish-tilt {
        transition: transform 0.4s cubic-bezier(0.22, 0.61, 0.36, 1),
                    box-shadow 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
        will-change: transform;
    }
    .polish-tilt:hover {
        transform: translate3d(0, -4px, 0) rotate(-0.25deg);
        box-shadow: 0 18px 48px -12px rgb(var(--polish-accent-rgb) / 0.30),
                    0 8px 16px -8px rgb(var(--polish-accent-rgb) / 0.20);
    }
}

/* ─────────────  Universal smooth scroll  ───────────── */

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

/* ─────────────  Print friendliness (no widget, dark→light)  ───────────── */

@media print {
    #riservati-widget,
    #booking-chat-close,
    .ax-cookie-consent,
    #cookie-consent {
        display: none !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
        color: #555;
    }
}
