/* Explain: Base styles, recipe card effects, filter UI, and approval-lock UI. */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--text-color);
    background: var(--background-color);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
}

.btn-primary-custom {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: white !important;
    transition: all 0.2s ease !important;
}

.btn-primary-custom:hover {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
}

.card-recipe {
    position: relative;
    isolation: isolate;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: none;
    transition: border-color 0.25s ease;
}

/* Thicker green frame drawn inside the card edge: shows on hover / keyboard focus
   without changing the card size, moving it or adding any shadow. */
.card-recipe::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 20;
    border: 1px solid var(--primary-color);
    border-radius: calc(1rem - 1px);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.card-recipe :where(h2, h3) {
    transition: color 0.25s ease;
}

.card-recipe:focus-visible {
    border-color: var(--primary-color);
}

.card-recipe:focus-visible::after {
    opacity: 1;
}

/* Hover: the card stays in place and casts no shadow. The frame turns green and gets bolder, and the title color changes. */
@media (hover: hover) {
    .card-recipe:hover {
        border-color: var(--primary-color);
    }

    .card-recipe:hover::after {
        opacity: 1;
    }

    .card-recipe:hover :where(h2, h3) {
        color: var(--primary-hover);
    }
}

@media (prefers-reduced-motion: reduce) {
    .card-recipe,
    .card-recipe::after,
    .card-recipe :where(h2, h3) {
        transition: none;
    }
}

.calc-chip {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.calc-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.calc-chip[aria-pressed="true"] {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #ffffff;
}

#calc-servings {
    -moz-appearance: textfield;
    appearance: textfield;
}

#calc-servings::-webkit-outer-spin-button,
#calc-servings::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.ing-amount {
    transition: background-color 0.25s ease;
}

.ing-amount.is-scaled {
    background: color-mix(in srgb, var(--accent-color) 14%, var(--surface-color));
}

.ing-amount.is-scaled .ing-qty {
    color: color-mix(in srgb, var(--accent-color) 75%, var(--text-color));
}

.privacy-toggle {
    --input-color: var(--text-muted);
}

.privacy-toggle:checked {
    --input-color: var(--primary-color);
    background-color: color-mix(in srgb, var(--primary-color) 14%, var(--surface-color));
}

/* Category pill on recipe cards and live previews (categories saved as "a, b"). */
.recipe-cat {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    max-width: 100%;
    padding: 0.125rem 0.625rem;
    border-radius: 9999px;
    background: color-mix(in srgb, var(--secondary-color) 45%, var(--surface-color));
    color: var(--text-color);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

/* Brand touches taken from the Cooklist logo: green lettering, a tomato dot and a hand-drawn tomato swash. */
.brand-eyebrow {
    border: 1px solid color-mix(in srgb, var(--primary-color) 22%, transparent);
    background: color-mix(in srgb, var(--primary-color) 9%, var(--surface-color));
    color: var(--primary-hover);
    line-height: 1.4;
}

.brand-dot {
    width: 0.5rem;
    height: 0.5rem;
    flex-shrink: 0;
    border-radius: 9999px;
    background: var(--accent-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color) 22%, transparent);
}

.brand-highlight {
    position: relative;
    display: inline-block;
    color: var(--primary-color);
    padding-bottom: 0.08em;
}

.brand-swash {
    position: absolute;
    left: -0.04em;
    bottom: -0.16em;
    width: calc(100% + 0.08em);
    height: 0.32em;
    overflow: visible;
    pointer-events: none;
}

.brand-swash path {
    fill: none;
    stroke: var(--accent-color);
    stroke-width: 4;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

/* Home search field and category filter: brand green focus frame. */
.brand-field:focus,
.brand-field:focus-within {
    --input-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Home recipe grid (js/home-recipes.js): until the script takes over, only the first page of 32 cards shows. */
.recipes-grid-preload > :nth-child(n+33) {
    display: none;
}

/* Home recipe pager: previous / page numbers / next. */
.recipes-pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    background: var(--surface-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.recipes-pager-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.recipes-pager-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.recipes-pager-btn[aria-current="page"] {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--surface-color);
    cursor: default;
}

.recipes-pager-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.recipes-pager-gap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Home "show more recipes" button under the pager (js/home-recipes.js). */
.recipes-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    max-width: 100%;
    min-height: 3rem;
    padding: 0.625rem 1.75rem;
    border: 1.5px solid var(--primary-color);
    border-radius: 9999px;
    background: var(--surface-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
    white-space: normal;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.recipes-more-btn i {
    color: var(--primary-hover);
}

.recipes-more-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

.recipes-more-btn:active:not([aria-busy="true"]) {
    transform: scale(0.97);
}

.recipes-more-btn[aria-busy="true"] {
    cursor: wait;
    opacity: 0.85;
}

@media (hover: hover) {
    .recipes-more-btn:hover:not([aria-busy="true"]) {
        background: color-mix(in srgb, var(--primary-color) 16%, var(--surface-color));
        border-color: var(--primary-hover);
    }
}

@media (prefers-reduced-motion: reduce) {
    .recipes-more-btn {
        transition: none;
    }

    .recipes-more-btn:active:not([aria-busy="true"]) {
        transform: none;
    }
}

@media (hover: hover) {
    .recipes-pager-btn:hover:not(:disabled):not([aria-current="page"]) {
        border-color: var(--primary-color);
        color: var(--primary-hover);
    }
}

@media (prefers-reduced-motion: reduce) {
    .recipes-pager-btn {
        transition: none;
    }

    .recipes-pager-btn:active:not(:disabled) {
        transform: none;
    }
}

.auth-hidden {
    display: none !important;
}

/* Recipe library opened with a category or search in the address (?app_cat= / ?app_q=):
   the list stays hidden until js/recipes-preset.js filters it, so the full list never flashes first. */
html.app-list-pending #recipeGrid,
html.app-list-pending #recipeCount,
html.app-list-pending #recipeEmpty {
    visibility: hidden;
}

/* Publishing locked while the account waits for the owner's approval (js/app.js):
   the control stays visible but dimmed, with a tooltip on hover, keyboard focus or tap. */
.approval-lock {
    position: relative;
    display: inline-flex;
    max-width: 100%;
}

.approval-lock-block {
    display: flex;
    width: 100%;
}

.is-approval-locked {
    opacity: 0.5;
    cursor: not-allowed !important;
    animation: none !important;
}

.is-approval-locked:active {
    transform: none !important;
}

.btn-primary-custom.is-approval-locked:hover {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.approval-tip {
    position: absolute;
    bottom: calc(100% + 0.625rem);
    left: 50%;
    z-index: 40;
    width: max-content;
    max-width: min(16rem, calc(100vw - 2rem));
    padding: 0.375rem 0.875rem;
    border-radius: 0.75rem;
    background: var(--text-color);
    color: #ffffff;
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, 4px);
    box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--text-color) 70%, transparent);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.approval-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: var(--text-color);
}

.approval-lock:hover .approval-tip,
.approval-lock:focus-within .approval-tip,
.approval-lock.is-open .approval-tip {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.approval-lock.is-dismissed:not(.is-open) .approval-tip {
    opacity: 0;
    visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .approval-tip {
        transition: none;
    }
}

/* Auth-aware nav: <html class="app-is-auth"> is set in the head before the page paints,
   so every page shows the right buttons from the first frame (no login-button flash). */
html.app-is-auth .auth-guest-only {
    display: none !important;
}

html:not(.app-is-auth) .auth-user-only {
    display: none !important;
}

.auth-tab {
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.auth-tab.active {
    background: var(--primary-color);
    color: #ffffff;
}

.auth-submit {
    min-height: 44px;
    height: auto;
    white-space: normal;
}

.auth-tab:active:not(:disabled),
.auth-submit:active:not(:disabled) {
    transform: scale(0.97);
}

.auth-submit[aria-busy="true"] {
    cursor: wait;
    opacity: 0.9;
}

.auth-submit:disabled:not([aria-busy="true"]) {
    cursor: not-allowed;
    opacity: 0.55;
}

.auth-tab:disabled {
    cursor: wait;
}

#loginForm:not(.hidden),
#registerForm:not(.hidden) {
    animation: auth-form-enter 240ms ease-out;
}

@keyframes auth-form-enter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Password reset (global/password-reset.html): step progress bars and step entrance. */
.reset-bar {
    flex: 1 1 0%;
    height: 0.375rem;
    border-radius: 9999px;
    background: var(--border-color);
    transition: background-color 0.3s ease;
}

.reset-bar.is-active {
    background: var(--primary-color);
}

.reset-step:not(.hidden) {
    animation: auth-form-enter 240ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .reset-step:not(.hidden) {
        animation: none;
    }

    .reset-bar {
        transition: none;
    }
}

.ingredient-row-enter,
.step-row-enter {
    animation: ingredient-row-enter 220ms ease-out;
}

@keyframes ingredient-row-enter {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ingredient-row-enter,
    .step-row-enter {
        animation: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #loginForm:not(.hidden),
    #registerForm:not(.hidden),
    .auth-submit [data-auth-spinner] {
        animation: none !important;
    }

    .auth-tab,
    .auth-submit {
        transition: none !important;
    }

    .auth-tab:active:not(:disabled),
    .auth-submit:active:not(:disabled) {
        transform: none;
    }
}