/* ========================================
   BOBA ROYAL - LAYOUT NORMALIZATION
   Fixes for UI distortion and consistency
   ======================================== */

/* ===== BOX SIZING RESET ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ===== PREVENT HORIZONTAL OVERFLOW ===== */
html,
body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  line-height: 1.5;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== RESPONSIVE IMAGES ===== */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ===== FORM ELEMENTS ===== */
input,
button,
textarea,
select {
  font: inherit;
}

/* Prevent text overflow */
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* ===== CONTAINER WIDTHS ===== */
.container-max {
  max-width: 1440px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 768px) {
  .container-max {
    padding-left: 2.5rem;
    padding-right: 2.5rem;
  }
}

@media (min-width: 1024px) {
  .container-max {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* ===== GRID/FLEX FIXES ===== */
.grid {
  display: grid;
}

.flex {
  display: flex;
}

/* Prevent flex items from shrinking too much */
.flex > * {
  min-width: 0;
}

.grid > * {
  min-width: 0;
}

/* ===== ASPECT RATIO FIXES ===== */
.aspect-square {
  aspect-ratio: 1 / 1;
}

.aspect-video {
  aspect-ratio: 16 / 9;
}

/* ===== PREVENT LAYOUT SHIFTS ===== */
.sticky,
.fixed {
  transform: translateZ(0);
  will-change: transform;
}

/* ===== SMOOTH TRANSITIONS ===== */
/* Removed global transitions to prevent layout shifts */

/* ===== Z-INDEX LAYERS ===== */
.z-header {
  z-index: 50;
}

.z-modal {
  z-index: 100;
}

.z-toast {
  z-index: 150;
}

/* ===== RESPONSIVE SPACING ===== */
.section-padding {
  padding-top: 2rem;
  padding-bottom: 2rem;
}

@media (min-width: 768px) {
  .section-padding {
    padding-top: 3rem;
    padding-bottom: 3rem;
  }
}

@media (min-width: 1024px) {
  .section-padding {
    padding-top: 4rem;
    padding-bottom: 4rem;
  }
}

/* ===== CARD CONSISTENCY ===== */
.card {
  background-color: var(--color-surface-light);
  border-radius: 0.75rem;
  overflow: hidden;
}

.dark .card {
  background-color: var(--color-surface-dark);
}

/* ===== BUTTON CONSISTENCY ===== */
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== TABLE OVERFLOW FIX ===== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 100%;
}

/* ===== MOBILE MENU FIX ===== */
@media (max-width: 768px) {
  .mobile-menu-hidden {
    display: none !important;
  }
}

/* ===== RESPONSIVE UTILITIES ===== */
/* Mobile-first responsive helpers */

/* Touch-friendly minimum sizes */
@media (max-width: 768px) {
  button,
  a.btn,
  [role="button"],
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Ensure forms are usable */
  input,
  select,
  textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
}

/* Responsive text that doesn't break layouts */
.text-responsive {
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Safe area padding for notched devices */
@supports (padding: max(0px)) {
  .safe-area-inset {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Responsive container that prevents overflow */
.container-responsive {
  width: 100%;
  max-width: 100%;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container-responsive {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container-responsive {
    padding-left: 2.5rem;
    padding-right: 2.5rem;
  }
}

/* Hide on specific breakpoints */
@media (max-width: 639px) {
  .hide-mobile { display: none !important; }
}

@media (min-width: 640px) and (max-width: 767px) {
  .hide-sm { display: none !important; }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .hide-md { display: none !important; }
}

@media (min-width: 1024px) {
  .hide-lg { display: none !important; }
}

/* Show only on specific breakpoints */
@media (min-width: 640px) {
  .show-mobile-only { display: none !important; }
}

@media (max-width: 767px) {
  .show-tablet-up { display: none !important; }
}

@media (max-width: 1023px) {
  .show-desktop-only { display: none !important; }
}

/* Responsive grid helpers */
.grid-responsive {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-responsive {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-responsive {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1280px) {
  .grid-responsive {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Responsive flex stack */
.flex-responsive {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 768px) {
  .flex-responsive {
    flex-direction: row;
  }
}

/* Prevent content from causing horizontal scroll */
.no-overflow {
  max-width: 100%;
  overflow-x: hidden;
}

/* Mobile navigation overlay */
.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.mobile-nav-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Mobile navigation drawer */
.mobile-nav-drawer {
  position: fixed;
  top: 0;
  right: -100%;
  width: 80%;
  max-width: 320px;
  height: 100%;
  background: var(--color-surface-light, #ffffff);
  z-index: 50;
  transition: right 0.3s ease-in-out;
  overflow-y: auto;
}

.dark .mobile-nav-drawer {
  background: var(--color-surface-dark, #331822);
}

.mobile-nav-drawer.active {
  right: 0;
}

/* ===== PREVENT FOUC (Flash of Unstyled Content) ===== */
/* Disabled to prevent white page issue */
/* 
html:not(.fonts-loaded) {
  visibility: hidden;
}

html.fonts-loaded {
  visibility: visible;
}
*/

/* ===== SCROLLBAR STYLING (OPTIONAL) ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.dark ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ===== FOCUS VISIBLE ===== */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ===== PRINT STYLES ===== */
@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  img {
    page-break-inside: avoid;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}
