/*
 * Haya Mediterraan — design system foundation for EvD.Rental.Web.
 *
 * Theming: every color token uses light-dark(), so one definition serves both themes.
 *   - Auto (default): <html> has no data-theme; color-scheme "light dark" follows the OS setting.
 *   - Light / Dark: <html data-theme="light|dark"> pins color-scheme (set by the server from the
 *     theme-preference cookie and by js/theme.js before first paint, so there is never a flash).
 *
 * Layers keep specificity predictable: component styles (scoped .razor.css) win over base styles.
 */
@layer reset, tokens, base, layout, components, utilities;

/* Bottom fade of clamped long texts ([data-collapsible]); registered so it can transition. */
@property --collapsible-fade {
    syntax: "<percentage>";
    inherits: false;
    initial-value: 0%;
}

/* The @font-face rules (Plus Jakarta Sans) live in App.razor: there the font URLs are fingerprinted via Assets[...], so
   browsers may cache them for a year (a url() in this file would not be fingerprinted). */

@layer tokens {
    :root {
        color-scheme: light dark;

        /* Palette: whitewashed walls, sand, terracotta roofs, olive groves, deep sea. */
        --color-bg: light-dark(#fbf7f1, #15110e);
        --color-surface: light-dark(#ffffff, #1f1915);
        --color-surface-raised: light-dark(#ffffff, #29211c);
        --color-surface-sunken: light-dark(#f4ece1, #110e0b);
        --color-sand: light-dark(#efe3d2, #2e251f);
        --color-text: light-dark(#2a211b, #f4ece3);
        --color-text-muted: light-dark(#6e5f53, #b9aa9c);
        --color-border: light-dark(#e7dccd, #3a2f28);
        --color-border-strong: light-dark(#d2c2ae, #54453b);

        --color-primary: light-dark(#a84a29, #e48c62);
        --color-primary-hover: light-dark(#8c3b1f, #eda17d);
        --color-primary-soft: light-dark(#f8e3d7, #3b2219);
        --color-on-primary: light-dark(#ffffff, #1b110c);
        --color-olive: light-dark(#57662f, #a9b67f);
        --color-olive-soft: light-dark(#e9ecdc, #262b1a);
        --color-sea: light-dark(#1f4e5f, #86bccd);
        --color-sea-soft: light-dark(#dcebf0, #14262d);
        --color-danger: light-dark(#b3261e, #f2b8b5);
        --color-focus: light-dark(#1f4e5f, #86bccd);
        --color-scrim: rgb(20 14 10 / 0.55);
        --color-shadow: light-dark(rgb(74 48 28 / 0.12), rgb(0 0 0 / 0.45));

        /* Typography: an elegant serif for display, a neutral sans for reading. Self-hosted webfonts can be
           dropped in later (Fraunces / Inter); the stacks below render well without any download. */
        /* Plus Jakarta Sans (OFL, self-hosted in wwwroot/fonts): a contemporary geometric sans for headings and text. */
        --font-display: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        --font-body: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

        --text-xs: clamp(0.75rem, 0.72rem + 0.1vw, 0.8rem);
        --text-sm: clamp(0.875rem, 0.85rem + 0.1vw, 0.925rem);
        --text-md: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
        --text-lg: clamp(1.0625rem, 1rem + 0.25vw, 1.2rem);
        --text-xl: clamp(1.2rem, 1.1rem + 0.4vw, 1.45rem);
        --text-2xl: clamp(1.45rem, 1.25rem + 0.8vw, 1.95rem);
        --text-3xl: clamp(1.85rem, 1.5rem + 1.5vw, 2.75rem);
        --text-hero: clamp(2.25rem, 1.6rem + 2.9vw, 4.25rem);

        --leading-tight: 1.1;
        --leading-snug: 1.3;
        --leading-normal: 1.6;

        /* Spacing scale (4px base) and layout. */
        --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;
        --space-9: 6rem;
        --gutter: clamp(1rem, 0.6rem + 2vw, 2.5rem);
        --content-max: 76rem;
        --header-height: 4.25rem;

        --radius-sm: 0.5rem;
        --radius-md: 0.875rem;
        --radius-lg: 1.5rem;
        --radius-pill: 999px;

        --shadow-sm: 0 1px 2px var(--color-shadow);
        --shadow-md: 0 6px 20px -6px var(--color-shadow);
        --shadow-lg: 0 24px 48px -16px var(--color-shadow);

        --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
        --duration-fast: 150ms;
        --duration-normal: 280ms;

        --touch-target: 2.75rem;
    }

    :root[data-theme="light"] {
        color-scheme: light;
    }

    :root[data-theme="dark"] {
        color-scheme: dark;
    }
}

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

    * {
        margin: 0;
    }

    html {
        -webkit-text-size-adjust: none;
        text-size-adjust: none;
        hanging-punctuation: first last;
        interpolate-size: allow-keywords;
    }

    img, picture, svg, video {
        display: block;
        max-width: 100%;
    }

    input, button, textarea, select {
        font: inherit;
        color: inherit;
    }

    p, h1, h2, h3, h4, h5, h6 {
        overflow-wrap: break-word;
    }

    h1, h2, h3, h4 {
        text-wrap: balance;
    }

    p {
        text-wrap: pretty;
    }
}

@layer base {
    html {
        scroll-padding-top: calc(var(--header-height) + var(--space-4));
        scrollbar-gutter: stable;
    }

    /* While the full-screen photo viewer is open the page behind must not scroll or show its scrollbar (or the reserved
       gutter, which would leave an uncovered strip next to the viewer). Lives here because a component's scoped CSS
       cannot target <html>. */
    html:has(dialog.lightbox[open]) {
        overflow: hidden;
        scrollbar-gutter: auto;
    }

    /* No global `scroll-behavior: smooth`: it turns the jump to the top on page changes (Blazor enhanced navigation)
       and the scroll restoration into animations that can be cut off halfway. In-page anchors scroll smoothly via
       js/site.js. */

    body {
        min-height: 100dvh;
        background: var(--color-bg);
        color: var(--color-text);
        font-family: var(--font-body);
        font-size: var(--text-md);
        line-height: var(--leading-normal);
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    h1, h2, h3 {
        font-family: var(--font-display);
        font-weight: 700;
        line-height: var(--leading-tight);
        letter-spacing: -0.025em;
    }

    h1 {
        font-size: var(--text-3xl);
    }

    h2 {
        font-size: var(--text-2xl);
    }

    h3 {
        font-size: var(--text-xl);
        line-height: var(--leading-snug);
    }

    a {
        color: var(--color-primary);
        text-decoration-thickness: 1px;
        text-underline-offset: 0.2em;
    }

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

    :focus-visible {
        outline: 3px solid var(--color-focus);
        outline-offset: 3px;
        border-radius: var(--radius-sm);
    }

    /* Headings receive programmatic focus after navigation (FocusOnNavigate) so screen readers announce the
       new page; they are not interactive, so no focus ring. */
    h1:focus {
        outline: none;
    }

    ::selection {
        background: var(--color-primary-soft);
        color: var(--color-text);
    }

    /* Smooth cross-document page transitions for full page loads (progressive enhancement). */
    @view-transition {
        navigation: auto;
    }

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

        @view-transition {
            navigation: none;
        }
    }
}

@layer layout {
    .container {
        width: min(100% - 2 * var(--gutter), var(--content-max));
        margin-inline: auto;
    }

    .section {
        padding-block: clamp(var(--space-7), 6vw, var(--space-9));
    }

    /* Consecutive sections share one gap instead of stacking bottom + top padding. The favorites slot sits between
       two sections and may be empty, so it is looked through. */
    .section + .section,
    [data-favorites-src] + .section,
    [data-favorites-src] > .section {
        padding-block-start: 0;
    }

    .stack {
        display: flex;
        flex-direction: column;
        gap: var(--stack-gap, var(--space-4));
    }

    .cluster {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--cluster-gap, var(--space-3));
    }

    /* Section intro: eyebrow, heading and lead; the row variant puts an action next to the text. */
    .section-header {
        display: grid;
        gap: var(--space-3);
        margin-block-end: var(--space-6);
    }

    .section-header--row {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
    }

    @media (max-width: 40rem) {
        .section-header--row {
            grid-template-columns: minmax(0, 1fr);
        }
    }

    /* Responsive card grid for house listings (home, search, favorites). */
    .house-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
        gap: var(--space-6) var(--space-5);
    }

    .house-grid__skeleton {
        display: grid;
        gap: var(--space-3);
    }
}

@layer components {
    /* Buttons are shared by plain links and <button>; see DesignSystem/Primitives/Button.razor. */
    .btn {
        --btn-bg: var(--color-primary);
        --btn-fg: var(--color-on-primary);
        --btn-border: transparent;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-2);
        min-height: var(--touch-target);
        padding: var(--space-2) var(--space-5);
        border: 1px solid var(--btn-border);
        border-radius: var(--radius-pill);
        background: var(--btn-bg);
        color: var(--btn-fg);
        font-weight: 600;
        font-size: var(--text-sm);
        letter-spacing: 0.01em;
        text-decoration: none;
        cursor: pointer;
        transition: background-color var(--duration-fast) ease, transform var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
    }

    .btn:hover {
        --btn-bg: var(--color-primary-hover);
        color: var(--btn-fg);
        box-shadow: var(--shadow-md);
    }

    .btn:active {
        transform: translateY(1px);
    }

    .btn--secondary {
        --btn-bg: var(--color-surface);
        --btn-fg: var(--color-text);
        --btn-border: var(--color-border-strong);
    }

    .btn--secondary:hover {
        --btn-bg: var(--color-surface-sunken);
    }

    .btn--ghost {
        --btn-bg: transparent;
        --btn-fg: var(--color-text);
    }

    .btn--ghost:hover {
        --btn-bg: var(--color-surface-sunken);
        box-shadow: none;
    }

    .btn--on-image {
        --btn-bg: rgb(255 255 255 / 0.16);
        --btn-fg: #fff;
        --btn-border: rgb(255 255 255 / 0.55);
        backdrop-filter: blur(8px);
    }

    .btn--on-image:hover {
        --btn-bg: rgb(255 255 255 / 0.28);
    }

    .btn--sm {
        min-height: 2.25rem;
        padding: var(--space-1) var(--space-4);
        font-size: var(--text-xs);
    }

    .btn--lg {
        min-height: 3.25rem;
        padding: var(--space-3) var(--space-6);
        font-size: var(--text-md);
    }

    .btn--block {
        inline-size: 100%;
    }

    .btn:disabled {
        opacity: 0.55;
        cursor: not-allowed;
        box-shadow: none;
        transform: none;
    }

    .btn .btn__icon-end {
        transition: transform var(--duration-fast) var(--ease-out);
    }

    .btn:hover .btn__icon-end {
        transform: translateX(3px);
    }

    .btn__spinner {
        inline-size: 1em;
        block-size: 1em;
        border: 2px solid currentColor;
        border-inline-end-color: transparent;
        border-radius: 50%;
        animation: spin 700ms linear infinite;
    }

    @keyframes spin {
        to {
            rotate: 1turn;
        }
    }

    /* Chips */
    .chip {
        --chip-bg: var(--color-surface-sunken);
        --chip-fg: var(--color-text);
        --chip-border: var(--color-border);
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        min-block-size: 2rem;
        padding: var(--space-1) var(--space-3);
        border: 1px solid var(--chip-border);
        border-radius: var(--radius-pill);
        background: var(--chip-bg);
        color: var(--chip-fg);
        font-size: var(--text-sm);
        font-weight: 500;
        line-height: 1.2;
        text-decoration: none;
        white-space: nowrap;
    }

    .chip--primary {
        --chip-bg: var(--color-primary-soft);
        --chip-fg: var(--color-primary);
        --chip-border: transparent;
    }

    .chip--olive {
        --chip-bg: var(--color-olive-soft);
        --chip-fg: var(--color-olive);
        --chip-border: transparent;
    }

    .chip--sea {
        --chip-bg: var(--color-sea-soft);
        --chip-fg: var(--color-sea);
        --chip-border: transparent;
    }

    a.chip, button.chip {
        cursor: pointer;
        transition: border-color var(--duration-fast) ease, background-color var(--duration-fast) ease;
    }

    a.chip:hover, button.chip:hover {
        --chip-border: var(--color-border-strong);
        color: var(--chip-fg);
    }

    .chip--selected {
        --chip-bg: var(--color-text);
        --chip-fg: var(--color-bg);
        --chip-border: var(--color-text);
    }

    @media (pointer: coarse) {
        a.chip, button.chip {
            min-block-size: var(--touch-target);
        }
    }

    /* Skeleton */
    .skeleton {
        display: block;
        border-radius: var(--radius-sm);
        background: linear-gradient(90deg, var(--color-surface-sunken) 25%, var(--color-sand) 50%, var(--color-surface-sunken) 75%) 0 0 / 300% 100%;
        animation: shimmer 1.6s ease-in-out infinite;
    }

    .skeleton--circle {
        border-radius: 50%;
    }

    @keyframes shimmer {
        from {
            background-position: 100% 0;
        }

        to {
            background-position: 0 0;
        }
    }

    /* Rating */
    .rating {
        display: inline-flex;
        align-items: baseline;
        gap: var(--space-2);
        font-size: var(--text-sm);
    }

    .rating__stars {
        letter-spacing: 0.05em;
        background: linear-gradient(90deg, #e6a33e var(--rating-fill), var(--color-border-strong) var(--rating-fill));
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
    }

    .rating__value {
        font-weight: 700;
    }

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

    .icon-btn {
        display: inline-grid;
        place-items: center;
        inline-size: var(--touch-target);
        block-size: var(--touch-target);
        border: 0;
        border-radius: var(--radius-pill);
        background: transparent;
        color: inherit;
        cursor: pointer;
        transition: background-color var(--duration-fast) ease;
    }

    .icon-btn:hover {
        background: color-mix(in oklab, currentColor 10%, transparent);
    }

    .icon {
        inline-size: 1.25em;
        block-size: 1.25em;
        flex: none;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.75;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    /* Long text clamped by js/site.js ([data-collapsible]); without JavaScript it is simply shown in full. */
    /* The fade at the bottom is a registered property, so it fades in and out while js/site.js slides the height. */
    [data-collapsible-ready] {
        mask-image: linear-gradient(180deg, #000 calc(100% - var(--collapsible-fade)), transparent);
        transition: --collapsible-fade 400ms ease;
    }

    [data-collapsible].is-collapsed {
        --collapsible-fade: 40%;
        max-block-size: var(--collapsed-height, 14rem);
        overflow: hidden;
    }

    /* Secondary action under the clamped text: small, medium weight, with a thin, faint underline that firms up on
       hover, so it does not compete with the text it expands. */
    .collapsible-toggle {
        margin-block-start: var(--space-2);
        padding: 0;
        border: 0;
        background: none;
        color: var(--color-primary);
        font-size: var(--text-sm);
        font-weight: 600;
        cursor: pointer;
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-decoration-color: color-mix(in oklab, currentColor 40%, transparent);
        text-underline-offset: 0.25em;
        transition: text-decoration-color var(--duration-fast) ease;
    }

    .collapsible-toggle:hover {
        text-decoration-color: currentColor;
    }

    /* Rich text authored by hosts (sanitized server-side). */
    .prose {
        line-height: var(--leading-normal);
    }

    .prose > * + * {
        margin-block-start: var(--space-3);
    }

    .prose ul,
    .prose ol {
        padding-inline-start: var(--space-5);
    }

    /* Tables in rich text, such as the generated cancellation refund table: compact rows, quiet dividers. */
    .prose table {
        inline-size: 100%;
        border-collapse: collapse;
    }

    .prose th,
    .prose td {
        padding: var(--space-2) var(--space-3);
        border-block-end: 1px solid var(--color-border);
        text-align: start;
        vertical-align: top;
    }

    .prose th {
        color: var(--color-text-muted);
        font-size: var(--text-xs);
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .prose th:first-child,
    .prose td:first-child {
        padding-inline-start: 0;
    }

    .prose th:last-child,
    .prose td:last-child {
        padding-inline-end: 0;
        text-align: end;
        white-space: nowrap;
    }

    .prose tbody tr:last-child td {
        border-block-end: 0;
    }

    .eyebrow {
        font-size: var(--text-xs);
        font-weight: 700;
        letter-spacing: 0.14em;
        text-transform: uppercase;
        color: var(--color-olive);
    }

    .lead {
        font-size: var(--text-lg);
        color: var(--color-text-muted);
        max-inline-size: 60ch;
    }

    /* Form fields: global so <TextField> and hand-written textarea/select fields in forms look the same. */
    .field {
        display: grid;
        gap: var(--space-2);
    }

    .field__label {
        font-size: var(--text-sm);
        font-weight: 600;
    }

    .field__input {
        min-block-size: var(--touch-target);
        padding: var(--space-2) var(--space-4);
        border: 1px solid var(--color-border-strong);
        border-radius: var(--radius-md);
        background: var(--color-surface);
        color: var(--color-text);
        font: inherit;
        transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
    }

    textarea.field__input {
        padding-block: var(--space-3);
        resize: vertical;
        line-height: 1.5;
    }

    .field__input:hover {
        border-color: var(--color-text-muted);
    }

    .field__input:focus-visible {
        outline: none;
        border-color: var(--color-primary);
        box-shadow: 0 0 0 4px color-mix(in oklab, var(--color-primary) 22%, transparent);
    }

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

    .field--invalid .field__input {
        border-color: var(--color-danger);
    }

    .field__error {
        color: var(--color-danger);
        font-size: var(--text-sm);
        font-weight: 500;
    }
}

@layer utilities {
    /* Scroll-driven reveal for cards: progress follows the scroll position (no timers), so content is never stuck
       hidden; cards already in view at load are shown in their final state. Off for reduced motion and in browsers
       without scroll timelines. */
    @media (prefers-reduced-motion: no-preference) {
        @supports (animation-timeline: view()) {
            .house-grid > *,
            .themes__grid > li,
            .review-card {
                animation: reveal-up linear both;
                animation-timeline: view();
                animation-range: entry 0% entry 60%;
            }
        }
    }

    @keyframes reveal-up {
        from {
            opacity: 0.001;
            translate: 0 1.5rem;
            scale: 0.98;
        }
    }

    .visually-hidden {
        position: absolute !important;
        inline-size: 1px;
        block-size: 1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    .skip-link {
        position: fixed;
        inset-block-start: var(--space-3);
        inset-inline-start: var(--space-3);
        z-index: 100;
        padding: var(--space-2) var(--space-4);
        border-radius: var(--radius-pill);
        background: var(--color-primary);
        color: var(--color-on-primary);
        font-weight: 600;
        text-decoration: none;
        transform: translateY(-200%);
        transition: transform var(--duration-fast) ease;
    }

    .skip-link:focus-visible {
        transform: none;
        color: var(--color-on-primary);
    }
}

/* Blazor's unhandled error banner (shown by the framework when an interactive island fails). */
#blazor-error-ui {
    display: none;
    position: fixed;
    inset-inline: var(--space-4);
    inset-block-end: var(--space-4);
    z-index: 1000;
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    background: var(--color-surface-raised);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: inline-end;
}
