/* ==========================================================================
   GLOBAL RESET, RESPONSIVE GRID & LAYOUT RULES (5-Breakpoints Mobile-First)
   ========================================================================== */

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

html {
  font-family: var(--font-family-base);
  font-size: 16px;
  line-height: var(--line-height-normal);
  color: var(--color-gray-900);
  background-color: var(--color-bg-page);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  max-width: 100vw;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Accessibility Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--color-primary-600);
  color: var(--color-white);
  padding: 0.75rem 1.25rem;
  z-index: var(--z-modal);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: 1rem;
}

/* Container System */
.container {
  width: 100%;
  max-width: var(--container-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--container-padding);
  padding-right: var(--container-padding);
}

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

/* Section Padding Mobile-First */
.site-section {
  padding-top: var(--space-10);
  padding-bottom: var(--space-10);
  width: 100%;
  position: relative;
}

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

@media (min-width: 1024px) {
  .site-section {
    padding-top: var(--space-24);
    padding-bottom: var(--space-24);
  }
}

.site-section-compact {
  padding-top: var(--space-8);
  padding-bottom: var(--space-8);
}
@media (min-width: 768px) {
  .site-section-compact {
    padding-top: var(--space-12);
    padding-bottom: var(--space-12);
  }
}

/* Background Variations */
.bg-white { background-color: var(--color-white); }
.bg-light { background-color: var(--color-bg-page); }
.bg-dark { background-color: var(--color-gray-900); color: var(--color-white); }

/* Responsive Grid System (Mobile-First) */
.grid-2-responsive,
.grid-3-responsive,
.grid-4-responsive {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--grid-gap-md);
  width: 100%;
}

/* Breakpoint 2: Mobile Large (480px) */
@media (min-width: 480px) {
  .grid-4-responsive {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Breakpoint 3: Tablet (768px) */
@media (min-width: 768px) {
  .grid-2-responsive {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--grid-gap-lg);
  }
  .grid-3-responsive {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--grid-gap-lg);
  }
  .grid-4-responsive {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--grid-gap-lg);
  }
}

/* Breakpoint 4: Desktop Small (1024px) */
@media (min-width: 1024px) {
  .grid-3-responsive {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid-4-responsive {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Equal Height Cards & Alignment */
.card-equal-height {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.card-equal-height > .card-footer,
.card-equal-height > .c-button,
.card-equal-height > .c-service-card__link,
.card-equal-height > .c-testimonial-card__author {
  margin-top: auto;
}

/* Fluid Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-base);
  color: var(--color-gray-900);
  line-height: var(--line-height-snug);
  letter-spacing: -0.02em;
  word-break: break-word;
}

.text-gradient {
  background: var(--color-gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Responsive Media */
img, video, iframe, svg {
  max-width: 100%;
  height: auto;
}

img {
  display: block;
  object-fit: cover;
}

/* Accessibility Focus States */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-primary-600);
  outline-offset: 2px;
}

/* ==========================================================================
   PAGE TRANSITIONS
   Fade the page in on load and fade it out just before navigating away, so
   full-page reloads feel like a smooth transition. Opacity only — a transform
   on <body> would turn it into the containing block for the fixed FAB.
   Disabled automatically when the user prefers reduced motion.
   ========================================================================== */
@media (prefers-reduced-motion: no-preference) {
  @keyframes tng-page-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  body {
    animation: tng-page-in 380ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
  }

  /* `backwards` (not `forwards`) is deliberate: it holds the start frame before
     the animation runs but releases <body> back to its base opacity afterwards,
     so the leaving transition below is not blocked by a locked animation value. */
  body.tng-is-leaving {
    opacity: 0 !important;
    transition: opacity 260ms ease;
  }
}

/* ==========================================================================
   LANGUAGE FLASH PREVENTION
   The export pages are served in Vietnamese and translated in the browser. When
   a non-Vietnamese language is stored, an inline head script adds
   `tng-lang-pending` so the page stays hidden until the translation is applied
   (then JS adds `tng-lang-ready`). This prevents the Vietnamese source text
   from flashing on every page navigation. Kept outside the reduced-motion query
   on purpose — hiding the flash is a correctness fix, not decoration.
   ========================================================================== */
html.tng-lang-pending body {
  visibility: hidden;
}

html.tng-lang-pending.tng-lang-ready body {
  visibility: visible;
}
