@tailwind base;
@tailwind components;
@tailwind utilities;

/* ------------------------------------------------------------------
   Global Styles - Unified Design System
-------------------------------------------------------------------*/

/* 1. CSS variables (light + dark) - Updated with consistent values */
:root {
  /* Primary brand colors */
  --color-primary: 221 83% 53%;  /* Blue 600 */
  --primary: 221 83% 53%;
  --color-secondary: #1e40af;    /* Blue 800 */
  --color-accent: #3b82f6;       /* Blue 500 */

  /* Semantic colors */
  --color-background: #ffffff;
  --color-surface: #f8fafc;      /* Slate 50 */
  --color-text: #1e293b;         /* Slate 800 */
  --color-text-secondary: #64748b; /* Slate 500 */
  --color-border: #e2e8f0;       /* Slate 200 */

  /* Status colors */
  --color-success: #10b981;      /* Emerald 500 */
  --color-warning: #f59e0b;      /* Amber 500 */
  --color-error: #ef4444;        /* Red 500 */

  /* Enhanced spacing system */
  --spacing-xs: 0.25rem;    /* 4px */
  --spacing-sm: 0.5rem;     /* 8px */
  --spacing-md: 1rem;       /* 16px */
  --spacing-lg: 1.5rem;     /* 24px */
  --spacing-xl: 2rem;       /* 32px */
  --spacing-2xl: 3rem;      /* 48px */
  --spacing-3xl: 4rem;      /* 64px */

  /* Unified border radius */
  --radius-xs: 0.125rem;    /* 2px */
  --radius-sm: 0.25rem;     /* 4px */
  --radius-md: 0.375rem;    /* 6px */
  --radius-lg: 0.5rem;      /* 8px */
  --radius-xl: 0.75rem;     /* 12px */
  --radius-2xl: 1rem;       /* 16px */
  --radius-3xl: 1.5rem;     /* 24px */

  /* Enhanced shadow system */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);

  /* Typography scale */
  --font-size-xs: 0.75rem;     /* 12px */
  --font-size-sm: 0.875rem;    /* 14px */
  --font-size-base: 1rem;      /* 16px */
  --font-size-lg: 1.125rem;    /* 18px */
  --font-size-xl: 1.25rem;     /* 20px */
  --font-size-2xl: 1.5rem;     /* 24px */
  --font-size-3xl: 1.875rem;   /* 30px */
  --font-size-4xl: 2.25rem;    /* 36px */
  --font-size-5xl: 3rem;       /* 48px */
  --font-size-6xl: 3.75rem;    /* 60px */
  --font-size-7xl: 4.5rem;     /* 72px */

  /* Chart palette (light) */
  --chart-1: 12 76% 61%;
  --chart-2: 173 58% 39%;
  --chart-3: 197 37% 24%;
  --chart-4: 43 74% 66%;
  --chart-5: 27 87% 67%;

  /* Brand gradients */
  --gradient-primary: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  --gradient-secondary: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  --gradient-hero: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);

  /* Container max-widths */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1280px;
  --container-2xl: 1536px;
  --container-3xl: 1920px;

  /* Fonts */
  --font-heading: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Z-index system - organized layers */
  --z-base: 0;
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-toast: 1080;
  --z-lightbox: 9999;
}

/* Dark theme overrides */
.dark {
  --color-background: #0f0f0f;
  --color-surface: #1c1c1c;
  --color-text: #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-border: #334155;

  /* Chart palette (dark) */
  --chart-1: 220 70% 50%;
  --chart-2: 160 60% 45%;
  --chart-3: 30 80% 55%;
  --chart-4: 280 65% 60%;
  --chart-5: 340 75% 55%;
}

/* 2. Scrollbar / layout‑shift fixes */
html {
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

body {
  overflow-y: scroll; /* ensure vertical scrollbar always present (fallback) */
}

body[data-scroll-locked] {
  padding-right: var(--removed-body-scroll-bar-size, 0);
}

/* 3. Base styles */
@layer base {
  * {
    @apply border-border;
  }

  body {
    font-family: var(--font-body);
    @apply bg-[color:var(--color-background)]
           text-[color:var(--color-text)]
           antialiased transition-colors duration-300
           motion-safe:transition-none;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-family: var(--font-heading);
    @apply font-semibold text-[color:var(--color-text)];
  }
}

/* 4. Utilities */
@layer utilities {
  .text-balance {
    text-wrap: balance;
  }

  /* Safe prose */
  .safe-prose {
    @apply prose prose-sm md:prose-base lg:prose-lg xl:prose-xl
                       prose-slate max-w-none leading-relaxed;
  }

  /* fade-in (เดิม) */
  /* .animate-fadeUp {
    animation: fadeUp 0.6s ease-out forwards;
  }
  .animate-fadeScale {
    animation: fadeScale 250ms ease-out both;
  }
  @keyframes fadeUp {
    0% {
      opacity: 0;
      transform: translateY(20px);
    }
    100% {
      opacity: 1;
      transform: translateY(0);
    }
  }
  @keyframes fadeScale {
    0% {
      opacity: 0;
      transform: scale(0.96);
    }
    100% {
      opacity: 1;
      transform: scale(1);
    }
  } */

  /* Hover-lift utility (ใช้คู่ shadow-* บนการ์ด / ปุ่ม) */
  .hover-lift {
    @apply motion-safe:transition-all duration-200;
  }
  .hover-lift:hover {
    @apply -translate-y-[2px] shadow-lg;
  }
  .hover-lift:active {
    @apply translate-y-0   shadow-md;
  }

  /* Radix Select dropdown width fix */
  [data-radix-select-content] {
    width: var(--radix-select-trigger-width) !important;
    padding: 5.5rem 0;
  }

  /* 7. Image loading animations */
  @keyframes shimmer {
    0% {
      transform: translateX(-100%);
    }
    100% {
      transform: translateX(100%);
    }
  }

  .animate-shimmer {
    animation: shimmer 2s infinite;
  }

  /* Error handling styles */
  .image-error {
    @apply bg-muted flex items-center justify-center text-muted-foreground;
  }

  /* Performance optimizations */
  img {
    content-visibility: auto;
  }

  /* Reduced motion support */
  @media (prefers-reduced-motion: reduce) {
    .animate-shimmer,
    .animate-pulse,
    .animate-bounce,
    .transition-transform {
      animation: none !important;
      transition: none !important;
    }
  }

  /* Touch and scrollbar utilities for better mobile UX */
  .touch-manipulation {
    touch-action: manipulation;
  }

  .scrollbar-hide {
    -ms-overflow-style: none;  /* Internet Explorer 10+ */
    scrollbar-width: none;  /* Firefox */
  }

  .scrollbar-hide::-webkit-scrollbar { 
    display: none;  /* Safari and Chrome */
  }

  /* Mobile touch improvements */
  @media (hover: none) and (pointer: coarse) {
    .touch-manipulation {
      min-height: 44px;
      min-width: 44px;
    }
  }

  /* Z-index utilities for lightbox */
  .z-lightbox {
    z-index: 9999;
  }

  /* Comprehensive z-index utilities to fix layering conflicts */
  .z-\[9999\] {
    z-index: 9999;
  }

  .z-\[99999\] {
    z-index: 99999;
  }

  .z-\[30\] {
    z-index: 30;
  }

  .z-\[40\] {
    z-index: 40;
  }

  .z-\[50\] {
    z-index: 50;
  }

  /* Lightbox specific z-index */
  .lightbox-overlay {
    z-index: 99999;
  }

  .lightbox-content {
    z-index: 100000;
  }

  /* Modal and dialog z-index hierarchy */
  .modal-overlay {
    z-index: 9998;
  }

  .modal-content {
    z-index: 9999;
  }

  /* Filter modal specific */
  .filter-modal {
    z-index: 9997;
  }

  /* Dropdown and popover */
  .dropdown-content {
    z-index: 1000;
  }

  /* Sticky headers */
  .sticky-header {
    z-index: 100;
  }

  /* Fixed elements */
  .fixed-element {
    z-index: 200;
  }

  /* Backdrop blur utilities */
  .backdrop-blur-strong {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  /* Additional scale utilities for smooth interactions */
  .hover\:scale-102:hover {
    transform: scale(1.02);
  }

  .scale-105 {
    transform: scale(1.05);
  }

  /* Better touch feedback */
  .active\:bg-white\/20:active {
    background-color: rgba(255, 255, 255, 0.2);
  }

  /* Pointer events utility */
  .pointer-events-none {
    pointer-events: none;
  }

  /* Responsive sizing for thumbnails */
  .w-18 {
    width: 4.5rem;
  }
  
  .h-13 {
    height: 3.25rem;
  }

  /* Safe area padding for mobile */
  .pb-safe {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* 5. Components / custom classes */
.btn-primary {
  background-color: var(--color-primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius-md);
  font-family: var(--font-body);
  @apply hover-lift shadow-md;
}
.btn-outline-primary {
  @apply border border-primary text-primary bg-transparent hover:bg-primary/10;
  @apply hover-lift;
}

.theme-card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: calc(1rem * var(--spacing-scale));
  @apply shadow-sm hover-lift;
}

/* Theme switcher scrollbar */
.theme-switcher-scroll::-webkit-scrollbar {
  width: 6px;
}
.theme-switcher-scroll::-webkit-scrollbar-track {
  background: var(--color-surface);
}
.theme-switcher-scroll::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}
.theme-switcher-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}

/* 6. Responsive root scaling */
@media (max-width: 768px) {
  :root {
    --spacing-scale: 0.9;
  }
}
@media (max-width: 480px) {
  :root {
    --spacing-scale: 0.8;
  }
}
.prose h2 {
  @apply text-2xl font-bold mt-8 mb-4;
}
.prose h3 {
  @apply text-xl font-bold mt-6 mb-3;
}
.prose img {
  @apply rounded-lg my-6;
}

.btn-share {
  @apply w-10 h-10 flex items-center justify-center rounded border hover:bg-gray-100;
}

/* 8. Hero Section Animations */
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes gradient {
  0%, 100% {
    background-size: 200% 200%;
    background-position: left center;
  }
  50% {
    background-size: 200% 200%;
    background-position: right center;
  }
}

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

@keyframes floatUp {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

.animate-fadeIn {
  animation: fadeIn 0.8s ease-out forwards;
}

.animate-gradient {
  animation: gradient 3s ease infinite;
}

.animate-slideInUp {
  animation: slideInUp 0.6s ease-out forwards;
}

.animate-floatUp {
  animation: floatUp 3s ease-in-out infinite;
}

/* Enhanced animations for sale page */
.animate-float-slow {
  animation: floatSlow 6s ease-in-out infinite;
}

.animate-float-1 {
  animation: float1 4s ease-in-out infinite;
}

.animate-float-2 {
  animation: float2 5s ease-in-out infinite;
}

.animate-float-3 {
  animation: float3 6s ease-in-out infinite;
}

.animate-float-4 {
  animation: float4 4.5s ease-in-out infinite;
}

.animate-float-5 {
  animation: float5 3.5s ease-in-out infinite;
}

.animate-pulse-slow {
  animation: pulseSlow 4s ease-in-out infinite;
}

.animate-fade-in-up {
  animation: fadeInUp 1s ease-out forwards;
}

.animate-slide-down {
  animation: slideDown 0.8s ease-out forwards;
}

.animate-scale-up {
  animation: scaleUp 1s ease-out forwards;
}

.animate-slide-up {
  animation: slideUp 0.8s ease-out forwards;
}

.animate-bounce-subtle {
  animation: bounceSubtle 1.5s ease-out forwards;
}

.animate-fade-in {
  animation: fadeIn 1s ease-out forwards;
}

.animate-gradient-x {
  animation: gradientX 3s ease infinite;
}

.animate-bounce-slow {
  animation: bounceSlow 2s ease-in-out infinite;
}

/* Enhanced keyframes */
@keyframes floatSlow {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

@keyframes float1 {
  0%, 100% { transform: translateY(0px) translateX(0px); }
  33% { transform: translateY(-15px) translateX(10px); }
  66% { transform: translateY(-10px) translateX(-10px); }
}

@keyframes float2 {
  0%, 100% { transform: translateY(0px) translateX(0px) scale(1); }
  50% { transform: translateY(-25px) translateX(15px) scale(1.1); }
}

@keyframes float3 {
  0%, 100% { transform: translateY(0px) translateX(0px); }
  25% { transform: translateY(-20px) translateX(-15px); }
  75% { transform: translateY(-30px) translateX(20px); }
}

@keyframes float4 {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-18px) rotate(180deg); }
}

@keyframes float5 {
  0%, 100% { transform: translateY(0px) scale(1); }
  50% { transform: translateY(-12px) scale(1.2); }
}

@keyframes pulseSlow {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

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

@keyframes slideDown {
  0% { opacity: 0; transform: translateY(-30px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes scaleUp {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

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

@keyframes bounceSubtle {
  0% { opacity: 0; transform: translateY(20px); }
  60% { opacity: 1; transform: translateY(-5px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes gradientX {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes bounceSlow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Animation delay utilities for staggered effects */
.\[animation-delay\:0\.3s\] {
  animation-delay: 0.3s;
}

.\[animation-delay\:0\.5s\] {
  animation-delay: 0.5s;
}

.\[animation-delay\:0\.7s\] {
  animation-delay: 0.7s;
}

.\[animation-delay\:0\.9s\] {
  animation-delay: 0.9s;
}
@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 0 0% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 0 0% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 0 0% 3.9%;
    --primary: 0 0% 9%;
    --primary-foreground: 0 0% 98%;
    --secondary: 0 0% 96.1%;
    --secondary-foreground: 0 0% 9%;
    --muted: 0 0% 96.1%;
    --muted-foreground: 0 0% 45.1%;
    --accent: 0 0% 96.1%;
    --accent-foreground: 0 0% 9%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --border: 0 0% 89.8%;
    --input: 0 0% 89.8%;
    --ring: 0 0% 3.9%;
    --chart-1: 12 76% 61%;
    --chart-2: 173 58% 39%;
    --chart-3: 197 37% 24%;
    --chart-4: 43 74% 66%;
    --chart-5: 27 87% 67%;
    --radius: 0.5rem;
    --sidebar-background: 0 0% 98%;
    --sidebar-foreground: 240 5.3% 26.1%;
    --sidebar-primary: 240 5.9% 10%;
    --sidebar-primary-foreground: 0 0% 98%;
    --sidebar-accent: 240 4.8% 95.9%;
    --sidebar-accent-foreground: 240 5.9% 10%;
    --sidebar-border: 220 13% 91%;
    --sidebar-ring: 217.2 91.2% 59.8%;
  }
  .dark {
    --background: 0 0% 3.9%;
    --foreground: 0 0% 98%;
    --card: 0 0% 3.9%;
    --card-foreground: 0 0% 98%;
    --popover: 0 0% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 0 0% 9%;
    --secondary: 0 0% 14.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 0 0% 14.9%;
    --muted-foreground: 0 0% 63.9%;
    --accent: 0 0% 14.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 0 0% 98%;
    --border: 0 0% 14.9%;
    --input: 0 0% 14.9%;
    --ring: 0 0% 83.1%;
    --chart-1: 220 70% 50%;
    --chart-2: 160 60% 45%;
    --chart-3: 30 80% 55%;
    --chart-4: 280 65% 60%;
    --chart-5: 340 75% 55%;
    --sidebar-background: 240 5.9% 10%;
    --sidebar-foreground: 240 4.8% 95.9%;
    --sidebar-primary: 224.3 76.3% 48%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 240 3.7% 15.9%;
    --sidebar-accent-foreground: 240 4.8% 95.9%;
    --sidebar-border: 240 3.7% 15.9%;
    --sidebar-ring: 217.2 91.2% 59.8%;
  }
}

@layer base {
  * {
    @apply border-border;
  }
  body {
    @apply bg-background text-foreground;
  }
}

/* Immersive fullscreen lightbox */
.lightbox-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  background-color: #000000 !important;
  cursor: none; /* Hide cursor for immersive experience */
}

/* Show cursor when controls are visible */
.lightbox-overlay:hover {
  cursor: default;
}

/* Prevent scrolling when lightbox is open */
body.lightbox-open {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
}

/* Enhanced fullscreen image display */
.lightbox-overlay img {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Floating controls with smooth transitions */
.lightbox-overlay button,
.lightbox-overlay .lightbox-thumbnails {
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* Better mobile fullscreen support */
@media (max-width: 768px) {
  .lightbox-overlay {
    height: 100dvh !important; /* Dynamic viewport height */
  }
}

/* Hide scrollbars completely */
.lightbox-thumbnails::-webkit-scrollbar {
  display: none;
}

.lightbox-thumbnails {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Enhanced focus styles for accessibility */
.lightbox-overlay button:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.8);
  outline-offset: 3px;
}

/* Smooth transitions for immersive experience */
.lightbox-overlay * {
  transition-property: opacity, transform, background-color, border-color;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 300ms;
}

/* Auto-hide cursor after inactivity */
.lightbox-overlay.hide-cursor {
  cursor: none !important;
}

.lightbox-overlay.hide-cursor * {
  cursor: none !important;
}
/* thumbnail scroll hidden (ถ้ายังใช้) */
.thumbnail-scroll::-webkit-scrollbar { display:none; }
.thumbnail-scroll { scrollbar-width:none; -ms-overflow-style:none; }

/* ลด pure-black บน hero เพื่อหลีก banding */
.hero-img::after{
  content:"";
  position:absolute; inset:0;
  background:linear-gradient(0deg,rgba(0,0,0,.35),rgba(0,0,0,0));
}

/* ✅ เพิ่ม CSS สำหรับ thumbnail scroll */
.thumbnail-container {
  scroll-behavior: smooth;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.thumbnail-container::-webkit-scrollbar {
  display: none;
}

/* ✅ ปรับปรุง z-index layers */
.hero-img-container {
  position: relative;
  isolation: isolate;
}

/* ✅ Ensure buttons are clickable */
.hero-img-container .pointer-events-auto {
  pointer-events: auto !important;
}

.hero-img-container .pointer-events-none {
  pointer-events: none !important;
}

/* ✅ Smooth thumbnail transitions */
.thumbnail-container button {
  will-change: transform;
}

/* ✅ เพิ่ม focus styles สำหรับ accessibility */
.thumbnail-container button:focus-visible {
  outline: 3px solid hsl(var(--primary));
  outline-offset: 2px;
}

.hero-img-container button:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* ✅ Font Performance - next/font handles this automatically now */
/* Removed @font-face declarations that caused OTS parsing errors */
/* Next.js next/font will inject proper font preloads automatically */
