/* =============================================
   SCREEN.CSS - Universal Mobile-Friendly Styles
   for Phytelix Platform
   ============================================= */

/* ============= BASE RESPONSIVE SETUP ============= */

/* Ensure proper box-sizing */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Prevent horizontal scroll */
html {
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%; /* Prevent text scaling on mobile */
}

body {
  overflow-x: hidden;
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  position: relative;
}

/* ============= RESPONSIVE IMAGES ============= */

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Responsive iframes */
iframe {
  max-width: 100%;
}

/* ============= RESPONSIVE TYPOGRAPHY ============= */

/* Base font size adjusts to screen */
html {
  font-size: 16px;
}

@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 13px;
  }
}

/* Responsive headings */
h1 {
  font-size: clamp(1.75rem, 5vw, 3rem);
  line-height: 1.2;
  margin: 0 0 1rem;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  line-height: 1.3;
  margin: 0 0 0.875rem;
}

h3 {
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1.4;
  margin: 0 0 0.75rem;
}

h4 {
  font-size: clamp(1.125rem, 2.5vw, 1.5rem);
  line-height: 1.4;
}

/* Responsive paragraphs */
p {
  font-size: clamp(0.875rem, 2vw, 1rem);
  line-height: 1.6;
  margin: 0 0 1rem;
}

/* ============= RESPONSIVE CONTAINERS ============= */

/* Main container with proper padding */
.container,
.max-w-7xl,
.mx-auto {
  width: 100%;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container,
  .max-w-7xl,
  .mx-auto {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container,
  .max-w-7xl,
  .mx-auto {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* ============= RESPONSIVE GRIDS ============= */

/* Auto-responsive grid */
.responsive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

@media (max-width: 640px) {
  .responsive-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* Force single column on mobile for specific grids */
@media (max-width: 768px) {
  .grid.md\:grid-cols-2,
  .grid.md\:grid-cols-3,
  .grid.md\:grid-cols-4,
  .grid.lg\:grid-cols-2,
  .grid.lg\:grid-cols-3,
  .grid.lg\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }
}

/* ============= RESPONSIVE FLEX ============= */

/* Stack flex items on mobile */
@media (max-width: 640px) {
  .flex.sm\:flex-row,
  .flex.md\:flex-row {
    flex-direction: column !important;
  }
  
  .flex > * {
    width: 100%;
  }
}

/* ============= RESPONSIVE BUTTONS ============= */

button, .btn, a.btn {
  min-height: 44px; /* Touch-friendly minimum */
  min-width: 44px;
  padding: 0.75rem 1.5rem;
  font-size: clamp(0.875rem, 2vw, 1rem);
  cursor: pointer;
  touch-action: manipulation; /* Prevent double-tap zoom */
}

@media (max-width: 640px) {
  button, .btn, a.btn {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
  }
}

/* ============= RESPONSIVE FORMS ============= */

input, textarea, select {
  font-size: 16px !important; /* Prevent iOS zoom */
  min-height: 44px;
  padding: 0.75rem;
  width: 100%;
  max-width: 100%;
}

@media (max-width: 640px) {
  input, textarea, select {
    font-size: 16px !important;
    padding: 1rem;
  }
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: clamp(0.875rem, 2vw, 1rem);
}

/* ============= RESPONSIVE TABLES ============= */

table {
  width: 100%;
  border-collapse: collapse;
}

@media (max-width: 768px) {
  /* Stack table on mobile */
  table, thead, tbody, th, td, tr {
    display: block;
  }
  
  thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  
  tr {
    margin-bottom: 1rem;
    border: 1px solid #ddd;
    border-radius: 0.5rem;
    padding: 0.5rem;
  }
  
  td {
    border: none;
    position: relative;
    padding-left: 50%;
    text-align: right;
  }
  
  td:before {
    position: absolute;
    left: 6px;
    width: 45%;
    padding-right: 10px;
    white-space: nowrap;
    text-align: left;
    font-weight: bold;
    content: attr(data-label);
  }
}

/* ============= RESPONSIVE NAVIGATION ============= */

nav {
  width: 100%;
}

/* Mobile menu toggle */
@media (max-width: 768px) {
  .nav-desktop {
    display: none !important;
  }
  
  .nav-mobile {
    display: block !important;
  }
}

@media (min-width: 769px) {
  .nav-mobile {
    display: none !important;
  }
  
  .nav-desktop {
    display: flex !important;
  }
}

/* ============= RESPONSIVE MODALS ============= */

.modal, [id*="modal"] {
  position: fixed;
  inset: 0;
  z-index: 9999;
  padding: 1rem;
  overflow-y: auto;
}

.modal-content,
.modal > div:not(.absolute) {
  width: 100%;
  max-width: min(90vw, 1200px);
  max-height: 90vh;
  margin: auto;
  overflow-y: auto;
}

@media (max-width: 640px) {
  .modal-content,
  .modal > div:not(.absolute) {
    max-width: 100%;
    max-height: 95vh;
    border-radius: 1rem 1rem 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }
}

/* ============= RESPONSIVE CARDS ============= */

.card, article, [class*="card"] {
  padding: 1rem;
  margin-bottom: 1rem;
}

@media (min-width: 640px) {
  .card, article, [class*="card"] {
    padding: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .card, article, [class*="card"] {
    padding: 2rem;
  }
}

/* ============= RESPONSIVE SPACING ============= */

/* Reduce spacing on mobile */
@media (max-width: 640px) {
  section {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }
  
  .py-16, .py-24 {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }
  
  .gap-8, .gap-10, .gap-12 {
    gap: 1rem !important;
  }
  
  .space-y-6 > * + * {
    margin-top: 1rem !important;
  }
}

/* ============= HIDE/SHOW ON MOBILE ============= */

@media (max-width: 640px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 641px) {
  .show-mobile-only {
    display: none !important;
  }
}

/* ============= RESPONSIVE TEXT ALIGNMENT ============= */

@media (max-width: 640px) {
  .text-center-mobile {
    text-align: center !important;
  }
  
  .text-left-mobile {
    text-align: left !important;
  }
}

/* ============= TOUCH OPTIMIZATION ============= */

/* Larger tap targets */
a, button, input, select, textarea, [role="button"] {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
}

/* Prevent double-tap zoom on specific elements */
button, input[type="submit"], input[type="button"] {
  touch-action: manipulation;
}

/* ============= RESPONSIVE OVERFLOW ============= */

/* Prevent overflow issues */
pre, code {
  max-width: 100%;
  overflow-x: auto;
  word-wrap: break-word;
}

/* ============= RESPONSIVE HERO SECTIONS ============= */

.hero, [class*="hero"] {
  padding: 2rem 1rem;
}

@media (min-width: 768px) {
  .hero, [class*="hero"] {
    padding: 4rem 2rem;
  }
}

@media (min-width: 1024px) {
  .hero, [class*="hero"] {
    padding: 6rem 2rem;
  }
}

/* ============= RESPONSIVE UTILITIES ============= */

/* Full width on mobile */
@media (max-width: 640px) {
  .w-full-mobile {
    width: 100% !important;
  }
  
  .max-w-full-mobile {
    max-width: 100% !important;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

/* ============= PRINT STYLES ============= */

@media print {
  body {
    background: white !important;
    color: black !important;
  }
  
  .no-print, nav, footer, button {
    display: none !important;
  }
  
  a {
    text-decoration: underline;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
  }
}

/* ============= ACCESSIBILITY ============= */

/* Focus indicators */
*:focus {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============= PERFORMANCE OPTIMIZATIONS ============= */

/* GPU acceleration for smoother animations */
.animate, [class*="transition"], [class*="animate"] {
  transform: translateZ(0);
  will-change: transform, opacity;
}

/* Lazy load images */
img[loading="lazy"] {
  content-visibility: auto;
}

/* ============= RESPONSIVE BREAKPOINT HELPERS ============= */

/* 
Mobile-first breakpoints:
- xs: 0-479px (default)
- sm: 480-639px
- md: 640-767px
- lg: 768-1023px
- xl: 1024-1279px
- 2xl: 1280px+
*/