/**
 * @file comfyplus-core.css
 * @description Design Tokens, Modern CSS Reset, Typography & Layout Architecture for ComfyPlus.
 * Engineered following senior frontend standards with CSS custom properties, fluid typography,
 * responsive flex/grid utilities, and WCAG 2.1 AA accessible contrast.
 */

:root {
  /* Brand Color Tokens - Warm Japanese Sumi, Cedar & Terracotta Amber */
  --cp-primary: #1f1c1a;
  --cp-primary-rgb: 31, 28, 26;
  --cp-primary-light: #2d2724;
  --cp-primary-dark: #141211;
  --cp-primary-gradient: linear-gradient(135deg, #1f1c1a 0%, #352d29 100%);

  /* Warm Biomechanical & Clinical Accents */
  --cp-accent: #c25e2e;
  --cp-accent-rgb: 194, 94, 46;
  --cp-accent-hover: #ab4f22;
  --cp-accent-amber: #d97706;
  --cp-accent-gold: #f59e0b;
  --cp-accent-gradient: linear-gradient(135deg, #c25e2e 0%, #e07a43 50%, #d97706 100%);
  --cp-accent-gradient-hover: linear-gradient(135deg, #ad5125 0%, #c86835 50%, #b45309 100%);
  --cp-accent-light: #fff7ed;
  --cp-accent-subtle: #ffedd5;

  --cp-secondary: #d97706;
  --cp-secondary-light: #fef3c7;
  --cp-amber: #f59e0b;
  --cp-amber-light: #fef3c7;
  --cp-rose: #dc4731;
  --cp-rose-light: #fee2e2;
  --cp-success: #227c44;
  --cp-success-light: #dcfce7;

  /* Surfaces & Backgrounds - Warm Cream, Linen & Pure White */
  --cp-bg: #faf7f2;
  --cp-surface: #ffffff;
  --cp-surface-muted: #f3eee5;
  --cp-surface-border: #e5ded2;
  --cp-surface-border-strong: #cfc5b4;

  /* Typography Colors - Warm Contrast */
  --cp-text: #1f1c1a;
  --cp-text-muted: #5c554e;
  --cp-text-subtle: #8c8276;
  --cp-text-on-dark: #fbf9f5;

  /* Typography Stack */
  --cp-font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --cp-font-body: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --cp-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Spacing Scale */
  --cp-space-1: 0.25rem;  /* 4px */
  --cp-space-2: 0.5rem;   /* 8px */
  --cp-space-3: 0.75rem;  /* 12px */
  --cp-space-4: 1rem;     /* 16px */
  --cp-space-5: 1.25rem;  /* 20px */
  --cp-space-6: 1.5rem;   /* 24px */
  --cp-space-8: 2rem;     /* 32px */
  --cp-space-10: 2.5rem;  /* 40px */
  --cp-space-12: 3rem;    /* 48px */
  --cp-space-16: 4rem;    /* 64px */
  --cp-space-20: 5rem;    /* 80px */

  /* Border Radii */
  --cp-radius-sm: 8px;
  --cp-radius-md: 12px;
  --cp-radius-lg: 18px;
  --cp-radius-xl: 28px;
  --cp-radius-pill: 9999px;

  /* Warm Elevation Shadows: Soft ambient depth & gentle warm diffusion */
  --cp-shadow-xs: 0 1px 3px 0 rgba(31, 28, 26, 0.05);
  --cp-shadow-sm: 0 2px 6px -1px rgba(31, 28, 26, 0.06), 0 1px 3px -1px rgba(31, 28, 26, 0.04);
  --cp-shadow-md: 0 6px 18px -3px rgba(31, 28, 26, 0.08), 0 2px 6px -1px rgba(31, 28, 26, 0.04);
  --cp-shadow-lg: 0 14px 30px -5px rgba(31, 28, 26, 0.10), 0 6px 14px -3px rgba(31, 28, 26, 0.05);
  --cp-shadow-xl: 0 24px 48px -8px rgba(31, 28, 26, 0.14), 0 10px 22px -4px rgba(31, 28, 26, 0.06);
  --cp-shadow-card: 0 2px 10px -2px rgba(31, 28, 26, 0.05), 0 0 0 1px rgba(229, 222, 210, 0.9);
  --cp-shadow-hover: 0 16px 36px -6px rgba(31, 28, 26, 0.13), 0 6px 16px -2px rgba(31, 28, 26, 0.06), 0 0 0 1px rgba(194, 94, 46, 0.35);
  --cp-shadow-glow: 0 6px 24px -2px rgba(194, 94, 46, 0.32);
  --cp-shadow-glow-warm: 0 6px 24px -2px rgba(217, 119, 6, 0.35);

  /* Layout Container & Fluid Transitions */
  --cp-container: 1240px;
  --cp-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --cp-ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --cp-transition-fast: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --cp-transition: 300ms cubic-bezier(0.16, 1, 0.3, 1);
  --cp-transition-slow: 500ms cubic-bezier(0.16, 1, 0.3, 1);

  /* iOS Safe Area & Mobile Layout Tokens */
  --cp-safe-top: env(safe-area-inset-top, 0px);
  --cp-safe-bottom: env(safe-area-inset-bottom, 0px);
  --cp-safe-left: env(safe-area-inset-left, 0px);
  --cp-safe-right: env(safe-area-inset-right, 0px);
  --cp-mobile-nav-height: 64px;
}

/* ==========================================================================
   Modern CSS Reset
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

body {
  font-family: var(--cp-font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--cp-text);
  background-color: var(--cp-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  position: relative;
}

@media (max-width: 767px) {
  body.has-bottom-nav {
    padding-bottom: calc(var(--cp-mobile-nav-height) + var(--cp-safe-bottom) + 12px);
  }
}

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

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

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

ul, ol {
  list-style: none;
}

/* ==========================================================================
   Typography Rules
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--cp-font-sans);
  color: var(--cp-text);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(2rem, 4vw + 1rem, 3.25rem); font-weight: 800; }
h2 { font-size: clamp(1.75rem, 3vw + 0.5rem, 2.35rem); }
h3 { font-size: clamp(1.35rem, 2vw + 0.5rem, 1.75rem); }
h4 { font-size: 1.25rem; font-weight: 700; }
h5 { font-size: 1.1rem; font-weight: 600; }
h6 { font-size: 0.95rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

p {
  color: var(--cp-text-muted);
}

/* ==========================================================================
   Layout Containers & Utilities
   ========================================================================== */

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

@media (min-width: 768px) {
  .cp-container {
    padding-left: var(--cp-space-6);
    padding-right: var(--cp-space-6);
  }
}

.cp-section {
  padding-top: var(--cp-space-12);
  padding-bottom: var(--cp-space-12);
}

@media (min-width: 992px) {
  .cp-section {
    padding-top: var(--cp-space-16);
    padding-bottom: var(--cp-space-16);
  }
}

/* Flex & Grid Utilities */
.cp-flex { display: flex; }
.cp-flex-col { display: flex; flex-direction: column; }
.cp-items-center { align-items: center; }
.cp-justify-between { justify-content: space-between; }
.cp-justify-center { justify-content: center; }
.cp-flex-wrap { flex-wrap: wrap; }
.cp-gap-2 { gap: var(--cp-space-2); }
.cp-gap-4 { gap: var(--cp-space-4); }
.cp-gap-6 { gap: var(--cp-space-6); }
.cp-gap-8 { gap: var(--cp-space-8); }

.cp-grid {
  display: grid;
}

.cp-grid-cols-2 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
@media (min-width: 640px) {
  .cp-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.cp-grid-cols-3 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
@media (min-width: 640px) {
  .cp-grid-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 992px) {
  .cp-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.cp-grid-cols-4 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
@media (min-width: 576px) {
  .cp-grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 992px) {
  .cp-grid-cols-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
  .cp-grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Visibility helpers */
.cp-d-none { display: none !important; }
@media (min-width: 768px) {
  .cp-d-md-block { display: block !important; }
  .cp-d-md-flex { display: flex !important; }
  .cp-d-md-none { display: none !important; }
}
@media (min-width: 992px) {
  .cp-d-lg-block { display: block !important; }
  .cp-d-lg-flex { display: flex !important; }
  .cp-d-lg-none { display: none !important; }
}

/* Text Alignment */
.cp-text-center { text-align: center; }
.cp-text-right { text-align: right; }

/* Screen Reader Only Accessible Utility */
.cp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ==========================================================================
   Mobile Ergonomics & Responsive Utilities
   ========================================================================== */

/* Responsive Table Container */
.cp-table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--cp-space-4);
  border-radius: var(--cp-radius-md);
}

/* 2-Column Mobile Catalog & Featured Grid */
@media (max-width: 575px) {
  .cp-grid-mobile-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }

  .cp-grid-mobile-2 .cp-product-card__thumb-wrap {
    position: relative;
  }

  .cp-grid-mobile-2 .cp-product-card__fav-btn {
    top: 8px !important;
    right: 8px !important;
    width: 30px !important;
    height: 30px !important;
  }

  .cp-grid-mobile-2 .cp-product-card__fav-btn svg {
    width: 14px !important;
    height: 14px !important;
  }

  .cp-grid-mobile-2 .cp-product-card__badge {
    top: auto !important;
    bottom: 8px !important;
    left: 8px !important;
    font-size: 9.5px !important;
    font-weight: 700 !important;
    padding: 3px 8px !important;
    letter-spacing: 0.02em !important;
    max-width: calc(100% - 16px) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08) !important;
    line-height: 1.2 !important;
  }
}

/* iOS Safari Input Auto-Zoom Prevention */
@media (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="search"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important; /* Critical: stops iOS from zooming viewport on tap */
  }

  .cp-container {
    padding-left: var(--cp-space-4);
    padding-right: var(--cp-space-4);
  }

  .cp-section {
    padding-top: var(--cp-space-8);
    padding-bottom: var(--cp-space-8);
  }
}

/* 44px Minimum Touch Target Rule for Mobile Accessibility */
.cp-touch-target {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
