/**
 * The Nutrition World — Apple-Grade Design System
 * Inspired by Apple.com: Restrained typography, intentional whitespace, near-monochrome palette.
 */

:root {
    /* 1. TYPOGRAPHY SCALE (Strict - no arbitrary values) */
    --font-primary: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
    
    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1rem;     /* 16px */
    --text-md: 1.1875rem;  /* 19px */
    --text-lg: 1.5rem;     /* 24px */
    --text-xl: 2rem;       /* 32px */
    --text-2xl: 3rem;      /* 48px */
    --text-3xl: 4rem;      /* 64px */
    --text-hero: clamp(2.5rem, 6vw + 1rem, 5.5rem); /* 56px to 88px fluid */

    --leading-tight: 1.08;
    --leading-snug: 1.25;
    --leading-normal: 1.55;
    --leading-loose: 1.7;

    --tracking-tighter: -0.03em;
    --tracking-tight: -0.015em;
    --tracking-normal: 0em;
    --tracking-wide: 0.04em;

    /* 2. COLOR PALETTE (Near-monochrome base + ONE accent) */
    --color-bg: #FFFFFF;
    --color-bg-subtle: #F5F5F7;       /* Apple light grey */
    --color-bg-alt: #FAFAFB;
    --color-surface: #FFFFFF;
    --color-surface-hover: #F8F8FA;
    
    --color-text-primary: #1D1D1F;   /* Dark Obsidian */
    --color-text-secondary: #6E6E73; /* Apple secondary graphite */
    --color-text-tertiary: #86868B;  /* Apple tertiary silver */
    --color-text-inverse: #FFFFFF;

    --color-border: rgba(0, 0, 0, 0.08);
    --color-border-hover: rgba(0, 0, 0, 0.18);
    --color-border-light: rgba(0, 0, 0, 0.04);

    /* ONE ACCENT COLOR (Apple Royal Blue) */
    --color-accent: #0071E3;
    --color-accent-hover: #0077ED;
    --color-accent-subtle: rgba(0, 113, 227, 0.08);

    /* SEMANTIC SYSTEM FEEDBACK */
    --color-success: #28CD41;
    --color-warning: #FF9500;
    --color-danger: #FF3B30;

    /* 3. ELEVATION & SHADOWS (Soft, featherweight Apple elevation) */
    --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 12px 32px rgba(0, 0, 0, 0.08);
    --shadow-dropdown: 0 16px 40px rgba(0, 0, 0, 0.12);

    /* 4. LAYOUT & SPACING */
    --container-max: 1380px;
    --container-narrow: 980px;
    --container-padding: clamp(0.875rem, 3.5vw, 2.25rem);
    
    --section-spacing: clamp(2.5rem, 5vw, 5rem);
    --section-spacing-sm: clamp(1.5rem, 3vw, 3rem);

    /* RESPONSIVE BREAKPOINT SYSTEM REFERENCE:
       Desktop:        > 1024px
       Tablet:         <= 1024px  (@media (max-width: 1024px))
       Mobile:         <= 767px   (@media (max-width: 767px))
       Compact Mobile: <= 479px   (@media (max-width: 479px))
    */

    /* 5. RADII & MOTION */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-pill: 980px;

    --transition-fast: 0.18s cubic-bezier(0.25, 0.1, 0.25, 1);
    --transition-smooth: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    --transition-bounce: 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* BASE RESETS */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
    overflow-x: clip;
    width: 100%;
    max-width: 100%;
}

body {
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg);
}

/* HEADINGS & TYPOGRAPHY */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tighter);
    color: var(--color-text-primary);
}

h1 {
    font-size: var(--text-hero);
    font-weight: 700;
    letter-spacing: var(--tracking-tighter);
}

h2 {
    font-size: clamp(2rem, 3.5vw, var(--text-2xl));
}

h3 {
    font-size: clamp(1.4rem, 2.2vw, var(--text-xl));
}

h4 {
    font-size: var(--text-lg);
}

p {
    line-height: var(--leading-normal);
    color: var(--color-text-secondary);
}

a {
    color: inherit;
    text-decoration: none;
    transition: color var(--transition-fast);
}

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

/* Prevent text from causing horizontal overflow */
p, h1, h2, h3, h4, h5, h6, li, span, a {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* GRID & CONTAINERS */
.container {
    width: 100%;
    max-width: var(--container-max);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--container-padding);
    padding-right: var(--container-padding);
    overflow-x: clip;
}

.container-narrow {
    width: 100%;
    max-width: var(--container-narrow);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--container-padding);
    padding-right: var(--container-padding);
}

.grid-12 {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
}

.grid-12 > * {
    min-width: 0;
}

/* BUTTONS — Maximum 2 variants site-wide (Apple standard) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1;
    padding: 0.85rem 1.6rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
    text-align: center;
    border: 1px solid transparent;
    transition: all var(--transition-smooth);
    user-select: none;
    white-space: nowrap;
}

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

/* Primary Button (Apple pill blue) */
.btn-primary {
    background-color: var(--color-accent);
    color: var(--color-text-inverse);
    border-color: var(--color-accent);
}

.btn-primary:hover {
    background-color: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 113, 227, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Secondary Button (Monochrome subtle outline / pill) */
.btn-secondary {
    background-color: transparent;
    color: var(--color-text-primary);
    border-color: var(--color-border-hover);
}

.btn-secondary:hover {
    background-color: var(--color-bg-subtle);
    border-color: var(--color-text-primary);
}

.btn-secondary:active {
    background-color: rgba(0, 0, 0, 0.05);
}

.btn-sm {
    font-size: var(--text-xs);
    padding: 0.55rem 1rem;
}

.btn-lg {
    font-size: var(--text-base);
    padding: 1rem 2.2rem;
}

.btn-block {
    width: 100%;
}

/* BADGES & PILLS */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-pill);
}

.badge-stock {
    background-color: rgba(40, 205, 65, 0.12);
    color: #1a8f2e;
}

.badge-low-stock {
    background-color: rgba(255, 149, 0, 0.14);
    color: #bf6f00;
}

.badge-out-of-stock {
    background-color: rgba(255, 59, 48, 0.12);
    color: #c92319;
}

.badge-featured {
    background-color: #F0F7FF;
    color: #0071E3;
    border: 1px solid #BAE0FF;
    box-shadow: 0 2px 4px rgba(0, 113, 227, 0.08);
}

.badge-hot-deal {
    background-color: #FFF2F2;
    color: #D70015;
    border: 1px solid #FFCCC7;
    box-shadow: 0 2px 5px rgba(215, 0, 21, 0.12);
}

/* SCROLL REVEAL UTILITIES (IntersectionObserver) */
.reveal-on-scroll {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1), transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: opacity, transform;
}

.reveal-on-scroll.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* FORM ELEMENTS */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    font-family: inherit;
    font-size: var(--text-base);
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.form-input::placeholder {
    color: var(--color-text-tertiary);
}

/* TOAST NOTIFICATION */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: #1D1D1F;
    color: #FFFFFF;
    padding: 0.9rem 1.4rem;
    border-radius: var(--radius-pill);
    font-size: var(--text-sm);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: toastSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast.toast-error {
    background: #FF3B30;
}

@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive: collapse grid-12 cart/checkout layouts on mobile */
@media (max-width: 767px) {
    .grid-12 {
        grid-template-columns: 1fr !important;
    }
    .grid-12 > [style*="grid-column: span 8"],
    .grid-12 > [style*="grid-column: span 4"],
    .grid-12 > [style*="grid-column: span 6"],
    .grid-12 > [style*="grid-column: span 12"] {
        grid-column: span 1 !important;
    }
    .toast-container {
        bottom: 1rem;
        right: 0.75rem;
        left: 0.75rem;
        align-items: stretch;
    }
    .toast {
        font-size: 0.85rem;
    }
    .toast-container {
        max-width: calc(100vw - 1.5rem);
    }
}
