/*
 * =====================================================
 * COMPREHENSIVE RESPONSIVE SYSTEM - PROFESSIONAL GRADE
 * نظام شامل للتصميم المتجاوب بمستوى احترافي
 * =====================================================
 * Author: Professional Developer
 * Date: 2025
 * Purpose: Ensure 100% responsive design across ALL pages
 */

/* =====================================================
 * 1. FOUNDATION & RESET
 * ===================================================== */

/* Prevent horizontal scroll on ALL devices */
html,
body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
  position: relative;
}

/* Box sizing for all elements */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Prevent text size adjustment on orientation change (iOS) */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* =====================================================
 * 2. RESPONSIVE IMAGES & MEDIA
 * ===================================================== */

/* All images responsive by default */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Maintain aspect ratio for images */
img {
  object-fit: cover;
  image-rendering: -webkit-optimize-contrast;
}

/* Hero images responsive */
.hero-image,
.featured-image,
.banner-image {
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* =====================================================
 * 3. TYPOGRAPHY - FLUID & RESPONSIVE
 * ===================================================== */

/* Base font size - scales with viewport */
body {
  font-size: clamp(14px, 2vw, 16px);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings - Fluid typography */
h1 {
  font-size: clamp(1.75rem, 4vw + 0.5rem, 3.5rem);
  line-height: 1.2;
  margin-bottom: clamp(0.75rem, 2vw, 1.5rem);
}

h2 {
  font-size: clamp(1.5rem, 3vw + 0.5rem, 2.5rem);
  line-height: 1.3;
  margin-bottom: clamp(0.5rem, 1.5vw, 1.25rem);
}

h3 {
  font-size: clamp(1.25rem, 2.5vw + 0.5rem, 2rem);
  line-height: 1.3;
  margin-bottom: clamp(0.5rem, 1.5vw, 1rem);
}

h4 {
  font-size: clamp(1.125rem, 2vw + 0.25rem, 1.5rem);
  line-height: 1.4;
}

h5 {
  font-size: clamp(1rem, 1.5vw + 0.25rem, 1.25rem);
  line-height: 1.4;
}

h6 {
  font-size: clamp(0.875rem, 1.25vw + 0.25rem, 1.125rem);
  line-height: 1.5;
}

/* Paragraphs */
p {
  font-size: clamp(0.875rem, 1.5vw, 1rem);
  line-height: 1.7;
  margin-bottom: 1em;
  max-width: 75ch; /* Optimal reading width */
}

/* =====================================================
 * 4. LAYOUT SYSTEM - CONTAINERS
 * ===================================================== */

/* Container with responsive padding */
.container,
.container-fluid {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: clamp(1rem, 3vw, 2rem);
  padding-right: clamp(1rem, 3vw, 2rem);
}

/* Max-width containers for different content types */
.container {
  max-width: 1280px;
}

.container-sm {
  max-width: 640px;
}

.container-md {
  max-width: 768px;
}

.container-lg {
  max-width: 1024px;
}

.container-xl {
  max-width: 1280px;
}

/* Section padding - responsive */
.section,
section {
  padding-top: clamp(2rem, 5vw, 4rem);
  padding-bottom: clamp(2rem, 5vw, 4rem);
}

/* =====================================================
 * 5. GRID SYSTEM - MOBILE-FIRST
 * ===================================================== */

/* Base grid - mobile first */
.grid,
[class*="grid-cols"] {
  display: grid;
  gap: clamp(1rem, 2vw, 1.5rem);
  width: 100%;
}

/* Auto-responsive grid */
.grid-auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.grid-auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}

/* Mobile: 1 column */
@media (max-width: 639px) {
  [class*="grid-cols-"] {
    grid-template-columns: 1fr !important;
  }
  
  .grid-cols-1 {
    grid-template-columns: 1fr;
  }
}

/* Tablet: 2 columns */
@media (min-width: 640px) and (max-width: 1023px) {
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

/* =====================================================
 * 6. FLEXBOX UTILITIES - RESPONSIVE
 * ===================================================== */

.flex-responsive {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.75rem, 2vw, 1.25rem);
}

/* Mobile: column, Desktop: row */
.flex-col-mobile {
  flex-direction: column;
}

@media (min-width: 768px) {
  .flex-col-mobile {
    flex-direction: row;
  }
}

/* =====================================================
 * 7. BUTTONS - TOUCH-FRIENDLY
 * ===================================================== */

/* All buttons touch-friendly (44px minimum) */
button,
.btn,
[type="button"],
[type="submit"],
.button,
a[role="button"] {
  min-height: 44px;
  min-width: 44px;
  padding: clamp(0.625rem, 1.5vw, 0.875rem) clamp(1.25rem, 3vw, 2rem);
  font-size: clamp(0.875rem, 1.5vw, 1rem);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

/* Button responsive text */
button span,
.btn span {
  font-size: clamp(0.875rem, 1.5vw, 1rem);
}

/* Icon buttons - maintain square aspect ratio */
.icon-button,
.btn-icon {
  aspect-ratio: 1 / 1;
  padding: clamp(0.5rem, 1.5vw, 0.75rem);
}

/* =====================================================
 * 8. FORMS - RESPONSIVE & ACCESSIBLE
 * ===================================================== */

/* All form inputs touch-friendly */
input,
select,
textarea,
[type="text"],
[type="email"],
[type="password"],
[type="tel"],
[type="number"],
[type="date"] {
  width: 100%;
  min-height: 44px;
  padding: clamp(0.625rem, 1.5vw, 0.875rem) clamp(0.75rem, 2vw, 1rem);
  font-size: 16px; /* Prevent zoom on iOS */
  border-radius: 8px;
  border: 1px solid #d1d5db;
  transition: all 0.3s ease;
}

/* Textarea responsive height */
textarea {
  min-height: clamp(100px, 20vh, 200px);
  resize: vertical;
}

/* Form groups with responsive spacing */
.form-group,
.floating-label {
  margin-bottom: clamp(1rem, 2vw, 1.5rem);
  width: 100%;
}

/* Labels responsive */
label {
  font-size: clamp(0.875rem, 1.5vw, 1rem);
  margin-bottom: 0.5rem;
  display: block;
}

/* =====================================================
 * 9. CARDS - RESPONSIVE
 * ===================================================== */

.card,
.profile-card,
.stat-card,
.section {
  padding: clamp(1rem, 3vw, 2rem);
  border-radius: clamp(12px, 2vw, 16px);
  margin-bottom: clamp(1rem, 2vw, 1.5rem);
}

/* Card content spacing */
.card-body,
.card-content {
  padding: clamp(1rem, 2.5vw, 1.5rem);
}

/* Card title */
.card-title {
  font-size: clamp(1.125rem, 2vw, 1.5rem);
  margin-bottom: clamp(0.5rem, 1vw, 0.75rem);
}

/* =====================================================
 * 10. NAVIGATION - RESPONSIVE
 * ===================================================== */

/* Desktop navigation */
@media (min-width: 1280px) {
  nav,
  .navbar {
    padding: clamp(0.75rem, 1.5vw, 1.25rem) clamp(1rem, 3vw, 2rem);
  }
  
  nav a,
  .nav-link {
    padding: 0.5rem 1rem;
    font-size: clamp(0.875rem, 1.2vw, 1rem);
  }
}

/* Mobile navigation */
@media (max-width: 1279px) {
  .mobile-menu,
  .hamburger-menu {
    width: 100%;
    max-width: 320px;
    overflow-y: auto;
    max-height: calc(100vh - 100px);
  }
  
  .mobile-menu a {
    padding: clamp(0.875rem, 2vw, 1rem) clamp(1rem, 2.5vw, 1.25rem);
    font-size: clamp(0.9375rem, 1.5vw, 1.0625rem);
    min-height: 48px;
  }
  
  /* Sticky login button in mobile menu */
  .mobile-menu .login-button {
    position: sticky;
    bottom: 0;
    background: white;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    padding: 1rem;
    margin-top: auto;
  }
}

/* =====================================================
 * 11. TABLES - RESPONSIVE
 * ===================================================== */

/* Horizontal scroll on mobile */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
}

/* Stack table on very small screens */
@media (max-width: 639px) {
  .table-stack thead {
    display: none;
  }
  
  .table-stack tbody tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
  }
  
  .table-stack tbody td {
    display: block;
    text-align: right;
    padding: 0.5rem 0;
    border: none;
  }
  
  .table-stack tbody td::before {
    content: attr(data-label);
    float: left;
    font-weight: 600;
  }
}

/* =====================================================
 * 12. MODALS & DIALOGS - RESPONSIVE
 * ===================================================== */

.modal,
.dialog {
  width: 90%;
  max-width: clamp(320px, 90vw, 600px);
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
  padding: clamp(1.25rem, 3vw, 2rem);
  border-radius: clamp(12px, 2vw, 16px);
}

/* Modal content */
.modal-body {
  padding: clamp(1rem, 2vw, 1.5rem);
}

/* =====================================================
 * 13. HERO SECTIONS - RESPONSIVE
 * ===================================================== */

.hero,
.dashboard-hero,
.banner {
  min-height: clamp(300px, 50vh, 600px);
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 3vw, 2rem);
}

.hero-content {
  max-width: clamp(320px, 90vw, 800px);
  margin: 0 auto;
  text-align: center;
}

/* =====================================================
 * 14. FOOTER - RESPONSIVE
 * ===================================================== */

footer {
  padding: clamp(2rem, 4vw, 3rem) clamp(1rem, 3vw, 2rem);
}

/* Footer grid - mobile: 1 col, tablet: 2 cols, desktop: 4 cols */
.footer-grid {
  display: grid;
  gap: clamp(1.5rem, 3vw, 2rem);
}

@media (max-width: 639px) {
  .footer-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .footer-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* =====================================================
 * 15. SPACING SYSTEM - RESPONSIVE
 * ===================================================== */

/* Margin utilities */
.mb-responsive {
  margin-bottom: clamp(1rem, 2vw, 1.5rem);
}

.mt-responsive {
  margin-top: clamp(1rem, 2vw, 1.5rem);
}

.my-responsive {
  margin-top: clamp(1rem, 2vw, 1.5rem);
  margin-bottom: clamp(1rem, 2vw, 1.5rem);
}

/* Padding utilities */
.p-responsive {
  padding: clamp(1rem, 2.5vw, 2rem);
}

.py-responsive {
  padding-top: clamp(1rem, 2.5vw, 2rem);
  padding-bottom: clamp(1rem, 2.5vw, 2rem);
}

.px-responsive {
  padding-left: clamp(1rem, 3vw, 2rem);
  padding-right: clamp(1rem, 3vw, 2rem);
}

/* Gap utilities */
.gap-responsive {
  gap: clamp(0.75rem, 2vw, 1.5rem);
}

/* =====================================================
 * 16. TEXT UTILITIES - RESPONSIVE
 * ===================================================== */

/* Text alignment - responsive */
.text-center-mobile {
  text-align: center;
}

@media (min-width: 768px) {
  .text-center-mobile {
    text-align: left;
  }
}

/* Text truncation */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Line clamp (multi-line truncation) */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* =====================================================
 * 17. VISIBILITY UTILITIES
 * ===================================================== */

/* Hide on mobile */
@media (max-width: 767px) {
  .hide-mobile,
  .desktop-only {
    display: none !important;
  }
}

/* Hide on desktop */
@media (min-width: 768px) {
  .hide-desktop,
  .mobile-only {
    display: none !important;
  }
}

/* Show only on tablet */
.tablet-only {
  display: none;
}

@media (min-width: 640px) and (max-width: 1023px) {
  .tablet-only {
    display: block !important;
  }
}

/* =====================================================
 * 18. ACCOUNTS APP - SPECIFIC FIXES
 * ===================================================== */

/* Sign in / Sign up forms */
.form-container {
  width: 100%;
  max-width: clamp(320px, 95vw, 480px);
  margin: 0 auto;
  padding: clamp(1.5rem, 3vw, 2.5rem);
}

/* Profile page grid */
@media (max-width: 1023px) {
  .profile-layout {
    grid-template-columns: 1fr !important;
  }
}

/* Payment cards */
@media (max-width: 767px) {
  .payment-cards {
    grid-template-columns: 1fr !important;
  }
}

/* =====================================================
 * 19. BLOG APP - SPECIFIC FIXES
 * ===================================================== */

/* Blog grid */
.blog-grid {
  display: grid;
  gap: clamp(1.5rem, 3vw, 2rem);
}

@media (max-width: 639px) {
  .blog-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .blog-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1024px) {
  .blog-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Blog sidebar - stack on mobile */
@media (max-width: 1023px) {
  .blog-layout {
    grid-template-columns: 1fr !important;
  }
  
  .blog-sidebar {
    order: 2;
  }
}

/* =====================================================
 * 20. GALLERY APP - SPECIFIC FIXES
 * ===================================================== */

/* Gallery grid - responsive columns */
.gallery-grid {
  display: grid;
  gap: clamp(1rem, 2.5vw, 1.5rem);
}

@media (max-width: 639px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Gallery images - maintain aspect ratio */
.gallery-image {
  width: 100%;
  height: 0;
  padding-bottom: 100%; /* 1:1 aspect ratio */
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}

.gallery-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =====================================================
 * 21. PORTAL APP - SPECIFIC FIXES
 * ===================================================== */

/* Dashboard stats grid */
.stats-grid {
  display: grid;
  gap: clamp(1rem, 2.5vw, 1.5rem);
}

@media (max-width: 639px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* Portal cards */
.portal-card {
  padding: clamp(1.25rem, 2.5vw, 1.875rem);
  border-radius: clamp(12px, 2vw, 20px);
}

/* =====================================================
 * 22. PERFORMANCE OPTIMIZATIONS
 * ===================================================== */

/* Hardware acceleration for animations */
.animate-on-scroll,
.card-animate,
.hover-effect {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* =====================================================
 * 23. ACCESSIBILITY ENHANCEMENTS
 * ===================================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #003366;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Skip to main content link */
.skip-to-main {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.5rem;
  background: #003366;
  color: white;
  text-decoration: none;
  border-radius: 0 0 8px 8px;
  z-index: 10000;
  transition: top 0.3s ease;
}

.skip-to-main:focus {
  top: 0;
}

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

/* =====================================================
 * 24. PRINT STYLES
 * ===================================================== */

@media print {
  /* Hide navigation, footers, etc. */
  nav,
  footer,
  .no-print,
  .mobile-menu,
  .hamburger {
    display: none !important;
  }
  
  /* Ensure proper page breaks */
  .page-break {
    page-break-before: always;
  }
  
  /* Full width for print */
  .container {
    max-width: 100%;
    padding: 0;
  }
  
  /* Black text for print */
  body,
  p,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    color: black !important;
  }
  
  /* Remove backgrounds */
  * {
    background: white !important;
  }
}

/* =====================================================
 * 25. ORIENTATION HANDLING
 * ===================================================== */

/* Landscape on mobile */
@media (max-width: 767px) and (orientation: landscape) {
  .hero,
  .dashboard-hero {
    min-height: 100vh;
  }
  
  /* Reduce padding in landscape */
  .section {
    padding-top: clamp(1rem, 3vh, 2rem);
    padding-bottom: clamp(1rem, 3vh, 2rem);
  }
  
  /* Adjust navigation height */
  nav,
  .navbar {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }
}

/* =====================================================
 * 26. HIGH RESOLUTION DISPLAYS (RETINA)
 * ===================================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Slightly smaller fonts on high-DPI displays */
  body {
    font-size: 15px;
  }
  
  /* Sharper borders */
  button,
  input,
  select,
  textarea {
    border-width: 0.5px;
  }
}

/* =====================================================
 * 27. REDUCED MOTION (Accessibility)
 * ===================================================== */

@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;
  }
}

/* =====================================================
 * 28. DARK MODE SUPPORT (Future-ready)
 * ===================================================== */

@media (prefers-color-scheme: dark) {
  /* Dark mode will be implemented here if needed */
}

/* =====================================================
 * 29. ULTRA-WIDE SCREENS (> 1920px)
 * ===================================================== */

@media (min-width: 1920px) {
  .container {
    max-width: 1600px;
  }
  
  /* Larger gaps on ultra-wide */
  .grid,
  .stats-grid,
  .gallery-grid {
    gap: 2.5rem;
  }
}

/* =====================================================
 * 30. SMALL SCREENS (< 360px) - iPhone SE, old Androids
 * ===================================================== */

@media (max-width: 359px) {
  /* Extra small font size */
  body {
    font-size: 13px;
  }
  
  h1 {
    font-size: 1.5rem;
  }
  
  h2 {
    font-size: 1.25rem;
  }
  
  /* Tighter padding */
  .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  /* Smaller buttons */
  button,
  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
  }
}

/* =====================================================
 * 31. EDGE CASES & FIXES
 * ===================================================== */

/* Fix for iOS Safari bottom bar */
@supports (-webkit-touch-callout: none) {
  .mobile-menu {
    min-height: -webkit-fill-available;
  }
}

/* Fix for Firefox flexbox bug */
@-moz-document url-prefix() {
  .flex-responsive {
    min-width: 0;
  }
}

/* Fix for IE11 (if support needed) */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  .grid {
    display: -ms-flexbox;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
  }
}

/* =====================================================
 * END OF COMPREHENSIVE RESPONSIVE SYSTEM
 * ===================================================== */

/* 
 * This CSS file provides complete responsive coverage for:
 * - Mobile (320px - 767px)
 * - Tablet (768px - 1023px)
 * - Desktop (1024px - 1919px)
 * - Ultra-wide (1920px+)
 * 
 * All pages in accounts, blog, gallery, news, portal, and pages apps
 * are now fully responsive and professional.
 */
