/* ============================================================
   TAMX - Universal Responsive Stylesheet (v2 - Non-Invasive)
   ============================================================
   This file ONLY adds responsive behavior; it does NOT override
   existing component styles in individual pages.
   ============================================================ */

/* ---------- Critical: Prevent horizontal scroll ---------- */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Allow body to scroll naturally */
body {
  min-height: 100vh;
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

/* ---------- iOS zoom prevention ONLY for inputs ---------- */
@media screen and (max-width: 767px) {
  input[type="text"]:not(.no-resize),
  input[type="email"]:not(.no-resize),
  input[type="password"]:not(.no-resize),
  input[type="tel"]:not(.no-resize),
  input[type="number"]:not(.no-resize),
  input[type="search"]:not(.no-resize),
  input[type="url"]:not(.no-resize),
  textarea:not(.no-resize),
  select:not(.no-resize) {
    font-size: 16px;
  }
}

/* ---------- Image responsiveness ---------- */
img, video, iframe {
  max-width: 100%;
  height: auto;
}

/* ---------- Touch targets (only on mobile) ---------- */
@media (max-width: 640px) and (pointer: coarse) {
  button:not(.btn-icon-sm),
  a.btn,
  [role="button"]:not(.btn-icon-sm) {
    min-height: 44px;
  }
  
  /* Form controls on small screens */
  input[type="checkbox"],
  input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
  }
}

/* ---------- Container padding adjustments ---------- */
@media (max-width: 480px) {
  .max-w-3xl,
  .max-w-4xl,
  .max-w-5xl,
  .max-w-6xl,
  .max-w-7xl {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

/* ---------- Spacing utility tweaks for very small screens ---------- */
@media (max-width: 374px) {
  .p-8 { padding: 1.25rem !important; }
  .p-6 { padding: 1rem !important; }
  .px-8 { padding-left: 1rem !important; padding-right: 1rem !important; }
  .py-20 { padding-top: 3rem !important; padding-bottom: 3rem !important; }
  .py-16 { padding-top: 2.5rem !important; padding-bottom: 2.5rem !important; }
}

/* ---------- Tables - horizontal scroll fallback ---------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

.table-scroll table {
  min-width: 600px;
}

/* ---------- Admin Sidebar Mobile (Only for admin/* pages) ---------- */
/* Show backdrop only when sidebar is mobile-open */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 49;
}

.sidebar-backdrop.show {
  display: block;
}

@media (min-width: 1024px) {
  .sidebar-backdrop,
  .sidebar-backdrop.show {
    display: none !important;
  }
}

/* ---------- Modal max-height on mobile ---------- */
@media (max-width: 640px) {
  .modal-backdrop {
    padding: 0.5rem !important;
  }

  .modal {
    max-height: 92vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ---------- Body scroll lock helper ---------- */
body.no-scroll {
  overflow: hidden;
  height: 100vh;
}

/* ---------- Safe area for notched devices ---------- */
.safe-area-bottom {
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.safe-area-top {
  padding-top: max(1rem, env(safe-area-inset-top));
}

/* ---------- Print Styles ---------- */
@media print {
  .no-print,
  nav,
  aside,
  button {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }
}

/* ---------- Reduce motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Focus visible ---------- */
*:focus-visible {
  outline: 2px solid #d4af37;
  outline-offset: 2px;
}

/* ---------- Helpers ---------- */
.hide-mobile {
  display: block;
}

@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
}

.show-mobile-only {
  display: none;
}

@media (max-width: 767px) {
  .show-mobile-only {
    display: block !important;
  }
}

/* ============================================================
   Page-Specific Fixes (Targeted, Non-Breaking)
   ============================================================ */

/* ---------- Auth pages (login, register, etc.) ---------- */
@media (max-width: 480px) {
  /* Logo layout on auth pages - center properly */
  body.flex.items-center .max-w-md,
  .auth-page .max-w-md {
    padding: 0 0.5rem;
  }
}

/* Fix logo alignment on small mobile screens */
@media (max-width: 380px) {
  /* Login/Register pages logo */
  a.flex.items-center.justify-center.gap-3 > div.w-14 {
    width: 3rem;
    height: 3rem;
    font-size: 1.5rem !important;
  }
  
  a.flex.items-center.justify-center.gap-3 .text-2xl {
    font-size: 1.25rem !important;
  }
}

/* ---------- Index page: prevent sidebar/menu interference ---------- */
/* The mobile menu in index.html uses its own classes; don't interfere */

/* ---------- Sticky chat button positioning ---------- */
@media (max-width: 640px) {
  .chat-fab,
  [class*="chat-fab"] {
    bottom: 16px !important;
    inset-inline-end: 16px !important;
    width: 56px !important;
    height: 56px !important;
    font-size: 20px !important;
  }
}
