/**
 * TruroWorks Elite CSS System
 * Central design system for Natalie Pullen website
 * 
 * Architecture: ITCSS layers
 * - Settings: Design tokens
 * - Tools: Mixins, functions
 * - Generic: Resets, normalize
 * - Elements: Base HTML elements
 * - Objects: Layout patterns
 * - Components: UI components
 * - Utilities: Helper classes
 */

/* ==========================================================================
   SETTINGS: Design Tokens
   ========================================================================== */

@layer settings {
  :root {
    /* TruroWorks Color System - Semantic naming */
    --tw-color-background: #FFFFFF;
    --tw-color-foreground: #18181B;
    --tw-color-muted: #F1F5F9;
    --tw-color-muted-foreground: #64748B;
    --tw-color-border: #E2E8F0;
    --tw-color-input: #E2E8F0;
    --tw-color-ring: #18181B;
    --tw-color-white: #FFFFFF;
    --tw-color-black: #000000;
    
    /* Gradient overlays */
    --tw-gradient-nav-light: linear-gradient(to bottom, rgba(0,0,0,0.3), rgba(0,0,0,0));
    --tw-gradient-nav-dark: linear-gradient(to bottom, rgba(0,0,0,0.7), rgba(0,0,0,0.3));
    
    /* Typography */
    --tw-font-sans: 'Inter', sans-serif;
    --tw-font-serif: 'Lora', serif;
    
    /* Spacing scale (logical properties) */
    --tw-space-xs: clamp(0.5rem, 2vw, 0.75rem);
    --tw-space-sm: clamp(0.75rem, 3vw, 1rem);
    --tw-space-md: clamp(1rem, 4vw, 1.5rem);
    --tw-space-lg: clamp(1.5rem, 6vw, 2rem);
    --tw-space-xl: clamp(2rem, 8vw, 3rem);
    
    /* Z-index scale */
    --tw-z-base: 10;
    --tw-z-nav: 20;
    --tw-z-mobile-menu: 30;
    --tw-z-sticky-nav: 40;
    
    /* Transitions */
    --tw-transition-fast: 0.15s ease;
    --tw-transition-base: 0.2s ease;
    --tw-transition-slow: 0.3s ease;
    
    /* Focus styles */
    --tw-focus-width: 2px;
    --tw-focus-offset: 2px;
    --tw-focus-radius: 4px;
    
    /* Shadows */
    --tw-shadow-text-light: 0 1px 3px rgba(0,0,0,0.5);
    --tw-shadow-text-medium: 0 2px 4px rgba(0,0,0,0.5);
  }

  html.dark {
    --tw-color-background: #09090B;
    --tw-color-foreground: #F8F9FA;
    --tw-color-muted: #27272A;
    --tw-color-muted-foreground: #A1A1AA;
    --tw-color-border: #27272A;
    --tw-color-input: #27272A;
    --tw-color-ring: #F8F9FA;
  }
}

/* ==========================================================================
   GENERIC: Base Styles
   ========================================================================== */

@layer generic {
  html {
    scroll-behavior: smooth;
  }

  body {
    background-color: var(--tw-color-background);
    color: var(--tw-color-foreground);
    font-family: var(--tw-font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* ==========================================================================
   ELEMENTS: Focus States
   ========================================================================== */

@layer elements {
  .focusable:focus-visible {
    outline: var(--tw-focus-width) solid var(--tw-color-foreground);
    outline-offset: var(--tw-focus-offset);
    border-radius: var(--tw-focus-radius);
  }

  .focusable-white:focus-visible {
    outline: var(--tw-focus-width) solid var(--tw-color-white);
    outline-offset: var(--tw-focus-offset);
    border-radius: var(--tw-focus-radius);
  }
}

/* ==========================================================================
   COMPONENTS: Navigation
   ========================================================================== */

@layer components {
  /* Navigation Link Standard */
  .nav-link {
    color: var(--tw-color-muted-foreground);
    transition: color var(--tw-transition-base);
    text-decoration: none;
    font-weight: 500;
  }

  .nav-link:hover {
    color: var(--tw-color-foreground);
  }

  .nav-link[aria-current="page"],
  .nav-link.active,
  .nav-link-active {
    color: var(--tw-color-foreground);
    text-decoration: underline;
    text-underline-offset: 4px;
  }

  /* Transparent Navigation (Homepage) */
  .transparent-nav {
    position: fixed;
    inset-block-start: 0;
    inset-inline-start: 0;
    inline-size: 100%;
    z-index: var(--tw-z-nav);
    background: var(--tw-gradient-nav-light);
  }

  @media (max-width: 767px) {
    .transparent-nav {
      background: var(--tw-gradient-nav-dark);
    }
  }

  .transparent-nav .nav-link {
    color: var(--tw-color-white);
    text-shadow: var(--tw-shadow-text-light);
    transition: opacity var(--tw-transition-base);
  }

  .transparent-nav .nav-link:hover {
    opacity: 0.8;
  }
  
  /* Override active state for transparent nav */
  .transparent-nav .nav-link[aria-current="page"],
  .transparent-nav .nav-link.active {
    color: var(--tw-color-white);
    text-decoration-color: var(--tw-color-white);
  }

  /* Solid Navigation (Interior Pages) */
  .solid-nav {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--tw-z-sticky-nav);
    inline-size: 100%;
    border-block-end: 1px solid var(--tw-color-border);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
  }

  html.dark .solid-nav {
    background-color: rgba(9, 9, 11, 0.95);
  }

  @media (min-width: 768px) {
    /* Desktop: always show nav horizontally */
    #mobile-nav {
      position: static !important;
      background: transparent !important;
      backdrop-filter: none !important;
      -webkit-backdrop-filter: none !important;
      display: flex !important;
      flex-direction: row !important;
      align-items: center !important;
      gap: 1.5rem !important;
      padding: 0 !important;
      justify-content: flex-end !important;
      inset: auto !important;
      z-index: auto !important;
      width: auto !important;
      height: auto !important;
      top: auto !important;
      right: auto !important;
      bottom: auto !important;
      left: auto !important;
    }

    /* Override any mobile states on desktop */
    #mobile-nav[data-menu-state="open"],
    #mobile-nav[data-menu-state="closed"],
    #mobile-nav.hidden {
      position: static !important;
      display: flex !important;
      flex-direction: row !important;
      background: transparent !important;
      inset: auto !important;
      width: auto !important;
      height: auto !important;
      padding-block-start: 0 !important;
      padding-inline-start: 0 !important;
      padding-inline-end: 0 !important;
      padding-block-end: 0 !important;
      top: auto !important;
      right: auto !important;
      bottom: auto !important;
      left: auto !important;
    }

    #mobile-nav a {
      font-size: 0.875rem !important;
      letter-spacing: 0.1em !important;
      padding: 0 !important;
      border: none !important;
      inline-size: auto !important;
      display: inline-block !important;
      /* color: inherit !important;  -- Removing this to allow nav-link class to work */
      white-space: nowrap !important;
      text-transform: uppercase !important; /* Standardizing on Uppercase for consistency */
      font-weight: 500 !important;
    }

    .transparent-nav #mobile-nav a {
      color: var(--tw-color-white) !important;
    }

    .solid-nav #mobile-nav a {
      /* color: var(--tw-color-foreground) !important; -- Removing strict override */
    }

    .solid-nav #mobile-nav a.nav-link-active,
    .solid-nav #mobile-nav a[aria-current="page"] {
      color: var(--tw-color-foreground) !important;
      text-decoration: underline;
      text-underline-offset: 4px;
    }

    .solid-nav #mobile-nav a:not(.nav-link-active):not([aria-current="page"]) {
      color: var(--tw-color-muted-foreground) !important;
    }

    .solid-nav #mobile-nav a:not(.nav-link-active):not([aria-current="page"]):hover {
      color: var(--tw-color-foreground) !important;
    }
  }
}

/* ==========================================================================
   COMPONENTS: Slideshow (Homepage Specific)
   ========================================================================== */

@layer components {
  .slideshow {
    position: fixed;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    z-index: var(--tw-z-base);
  }

  .slideshow-image {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    background-size: cover;
    background-position: center;
    opacity: 0;
    animation: crossfade 40s infinite;
  }

  .slideshow-image:nth-child(1) {
    animation-delay: 0s;
  }

  .slideshow-image:nth-child(2) {
    animation-delay: 8s;
  }

  .slideshow-image:nth-child(3) {
    animation-delay: 16s;
  }

  .slideshow-image:nth-child(4) {
    animation-delay: 24s;
  }

  .slideshow-image:nth-child(5) {
    animation-delay: 32s;
  }

  @keyframes crossfade {
    0% { opacity: 0; }
    6% { opacity: 1; }
    20% { opacity: 1; }
    26% { opacity: 0; }
    100% { opacity: 0; }
  }
}

/* ==========================================================================
   COMPONENTS: Gallery (Elite Standard)
   ========================================================================== */

@layer components {
  /* Masonry Layout */
  .gallery-masonry {
    column-count: 1;
    column-gap: 2.5rem;
  }

  @media (min-width: 640px) {
    .gallery-masonry {
      column-count: 2;
    }
  }

  @media (min-width: 1024px) {
    .gallery-masonry {
      column-count: 3;
    }
  }

  .gallery-item {
    break-inside: avoid;
    margin-bottom: 4rem;
    position: relative;
  }

  /* Image Hover Effect - Subtle & Premium */
  .gallery-image-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 0.5rem; /* rounded-lg consistency */
    transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .gallery-image {
    display: block;
    width: 100%;
    height: auto;
    transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.5s ease;
  }

  .gallery-item:hover .gallery-image {
    transform: scale(1.03);
  }

  /* Reveal Animation */
  .reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
  }

  .reveal.active {
    opacity: 1;
    transform: translateY(0);
  }

  /* Lightbox - Premium Backdrop */
  .lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: rgba(10, 10, 10, 0.85); /* Darker, more neutral */
    backdrop-filter: blur(12px); /* Frosted glass effect */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
  }

  .lightbox[aria-hidden="false"] {
    opacity: 1;
    pointer-events: auto;
  }

  .lightbox-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    transform: scale(0.96);
    transition: all 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .lightbox[aria-hidden="false"] .lightbox-content {
    opacity: 1;
    transform: scale(1);
    transition-delay: 0.1s;
  }

  .lightbox-image {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.5); /* Deep shadow for depth */
  }

  .lightbox-caption {
    color: var(--tw-color-white);
    margin-top: 1.5rem;
    text-align: center;
    font-family: var(--tw-font-sans);
    font-weight: 300;
    letter-spacing: 0.02em;
    max-width: 60ch;
    line-height: 1.6;
  }

  .lightbox-close {
    position: absolute;
    top: 2rem;
    right: 2rem;
    color: rgba(255, 255, 255, 0.7);
    background: none;
    border: none;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 101;
    transition: color 0.3s ease, transform 0.3s ease;
  }

  .lightbox-close:hover {
    color: white;
    transform: rotate(90deg);
  }

  .lightbox-close svg {
    width: 24px;
    height: 24px;
  }
}

/* ==========================================================================
   MOBILE NAVIGATION: Full-screen Menu (Outside @layer for cascade priority)
   ========================================================================== */

@media (max-width: 767px) {
  /* Hide menu by default on mobile */
  #mobile-nav {
    display: none !important;
    position: static !important;
  }

  /* Show menu when open - fullscreen black overlay */
  #mobile-nav[data-menu-state="open"] {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 50 !important;
    background: #000000 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
    padding-top: clamp(5rem, 12vh, 7rem) !important;
    padding-left: clamp(1.5rem, 6vw, 3rem) !important;
    padding-right: clamp(1.5rem, 6vw, 3rem) !important;
    padding-bottom: 2rem !important;
    width: 100vw !important;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
  }

  #mobile-nav[data-menu-state="open"] a {
    font-size: clamp(1.25rem, 5vw, 1.75rem) !important;
    letter-spacing: 0.15em !important;
    text-transform: uppercase !important;
    font-weight: 500 !important;
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15) !important;
    width: 100% !important;
    display: block !important;
    color: #FFFFFF !important;
    text-align: left !important;
    line-height: 1.5 !important;
    text-shadow: none !important;
    text-decoration: none !important;
  }

  #mobile-nav[data-menu-state="open"] a:last-child {
    border-bottom: none !important;
  }

  #mobile-nav[data-menu-state="open"] a:hover {
    opacity: 0.7 !important;
  }

  /* Mobile menu toggle button - ensure it's above the menu */
  #mobile-menu-toggle {
    z-index: 51 !important;
  }
}
