/**
 * Mobile Optimization CSS - IoT Edge Platform
 * تحسينات شاملة للموبايل لجميع الصفحات
 * 
 * الأجهزة المستهدفة:
 * - iPhone SE: 375px × 667px
 * - iPhone 13: 390px × 844px
 * - iPad: 768px × 1024px
 * - Samsung Galaxy: 360px × 800px
 */

/* =====================================
   1. Base Mobile Improvements
   ===================================== */

/* تحسين Touch Targets - min 48×48px */
@media (max-width: 768px) {
  /* جميع الأزرار */
  button,
  .cta-button,
  .demo-button,
  .primary-button,
  .secondary-button,
  input[type="submit"],
  input[type="button"] {
    min-height: 48px !important;
    min-width: 48px;
    padding: 12px 24px;
    font-size: 16px; /* يمنع iPhone من zoom على النقر */
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }

  /* الروابط */
  a {
    min-height: 44px;
    display: inline-block;
    padding: 8px 0;
  }

  /* Checkbox و Radio بحجم أكبر */
  input[type="checkbox"],
  input[type="radio"] {
    min-width: 24px !important;
    min-height: 24px !important;
    margin: 8px;
  }

  /* Form Inputs - min 44px height */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  textarea,
  select {
    min-height: 44px !important;
    font-size: 16px !important; /* يمنع auto-zoom على iOS */
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    width: 100%;
    box-sizing: border-box;
  }

  /* Textarea خاص */
  textarea {
    min-height: 100px;
    resize: vertical;
  }

  /* Select dropdown */
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    padding-right: 40px;
  }
}

/* =====================================
   2. Typography Optimization
   ===================================== */

@media (max-width: 768px) {
  /* Base font size */
  body {
    font-size: 16px !important;
    line-height: 1.6;
  }

  /* Headings */
  h1 {
    font-size: clamp(28px, 6vw, 36px);
    line-height: 1.2;
    margin-bottom: 16px;
  }

  h2 {
    font-size: clamp(24px, 5vw, 30px);
    line-height: 1.3;
    margin-bottom: 12px;
  }

  h3 {
    font-size: clamp(20px, 4vw, 24px);
    line-height: 1.4;
    margin-bottom: 10px;
  }

  h4 {
    font-size: 18px;
    line-height: 1.4;
  }

  p {
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 16px;
  }

  /* Lists */
  ul, ol {
    padding-right: 24px;
    margin-bottom: 16px;
  }

  li {
    margin-bottom: 8px;
    line-height: 1.6;
  }
}

/* =====================================
   3. Layout & Spacing
   ===================================== */

@media (max-width: 768px) {
  /* Container padding */
  .container,
  .section {
    padding: 20px;
    max-width: 100%;
  }

  /* Sections spacing */
  section {
    padding: 40px 20px;
    margin: 0;
  }

  /* Grid to Stack */
  .grid,
  .features-grid,
  .stats-grid,
  .pricing-grid {
    grid-template-columns: 1fr !important;
    gap: 24px;
  }

  /* Flex to Column */
  .flex-row,
  .two-column {
    flex-direction: column;
    gap: 24px;
  }

  /* Remove horizontal scroll */
  body {
    overflow-x: hidden;
  }

  * {
    max-width: 100%;
  }

  /* Images responsive */
  img {
    max-width: 100%;
    height: auto;
    display: block;
  }
}

/* =====================================
   4. Navigation Improvements
   ===================================== */

@media (max-width: 768px) {
  /* Header/Navbar */
  header,
  nav {
    padding: 12px 20px;
  }

  /* Logo size */
  .logo {
    max-width: 120px;
    height: auto;
  }

  /* Menu items */
  nav a,
  .nav-link {
    min-height: 48px;
    padding: 12px 16px;
    display: block;
    font-size: 16px;
  }

  /* Hamburger menu (if exists) */
  .menu-toggle {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
  }

  /* Mobile menu */
  .mobile-menu {
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: white;
    z-index: 1000;
    padding: 20px;
  }

  /* Menu items in mobile */
  .mobile-menu a {
    display: block;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
  }
}

/* =====================================
   5. Forms Optimization
   ===================================== */

@media (max-width: 768px) {
  /* Form container */
  form {
    width: 100%;
    padding: 20px;
  }

  /* Form groups */
  .form-group,
  .input-group {
    margin-bottom: 20px;
  }

  /* Labels */
  label {
    display: block;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #374151;
  }

  /* Required indicator */
  label .required,
  label .required-star {
    color: #ef4444;
  }

  /* Input focus state */
  input:focus,
  textarea:focus,
  select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  }

  /* Error state */
  input.error,
  textarea.error,
  select.error {
    border-color: #ef4444;
  }

  /* Error message */
  .error-message {
    color: #ef4444;
    font-size: 14px;
    margin-top: 4px;
    display: block;
  }

  /* Success state */
  input.success,
  textarea.success,
  select.success {
    border-color: #10b981;
  }

  /* Submit button */
  button[type="submit"],
  input[type="submit"] {
    width: 100%;
    min-height: 48px;
    font-size: 18px;
    font-weight: 600;
    margin-top: 24px;
  }

  /* Two-column form to single */
  .form-row {
    flex-direction: column;
    gap: 20px;
  }
}

/* =====================================
   6. Cards & Content Boxes
   ===================================== */

@media (max-width: 768px) {
  /* Cards */
  .card,
  .feature-card,
  .stat-card,
  .pricing-card {
    padding: 24px;
    margin-bottom: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  /* Card title */
  .card-title {
    font-size: 20px;
    margin-bottom: 12px;
  }

  /* Card content */
  .card-content {
    font-size: 16px;
    line-height: 1.6;
  }

  /* CTA inside card */
  .card .cta-button {
    width: 100%;
    margin-top: 16px;
  }
}

/* =====================================
   7. Tables → Cards on Mobile
   ===================================== */

@media (max-width: 768px) {
  /* Hide table headers */
  table thead {
    display: none;
  }

  /* Table as block */
  table,
  table tbody,
  table tr,
  table td {
    display: block;
    width: 100%;
  }

  /* Each row as card */
  table tr {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  /* Table cell */
  table td {
    padding: 8px 0;
    border: none;
    position: relative;
    padding-right: 50%;
  }

  /* Add data label */
  table td:before {
    content: attr(data-label);
    position: absolute;
    right: 0;
    top: 8px;
    font-weight: 600;
    color: #6b7280;
    font-size: 14px;
  }
}

/* =====================================
   8. Modal Improvements
   ===================================== */

@media (max-width: 768px) {
  /* Modal overlay */
  .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
  }

  /* Modal container */
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    overflow-y: auto;
    background: white;
  }

  /* Modal content */
  .modal-content {
    padding: 20px;
    max-height: 100vh;
    overflow-y: auto;
  }

  /* Modal close button */
  .modal-close {
    position: fixed;
    top: 12px;
    right: 12px;
    min-width: 48px;
    min-height: 48px;
    z-index: 10000;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }
}

/* =====================================
   9. Performance Optimizations
   ===================================== */

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

  /* Lazy loading images */
  img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
  }

  img[loading="lazy"].loaded {
    opacity: 1;
  }

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

/* =====================================
   10. Utility Classes
   ===================================== */

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

  /* Show only on mobile */
  .show-mobile {
    display: block !important;
  }

  /* Full width on mobile */
  .mobile-full-width {
    width: 100% !important;
  }

  /* No padding on mobile */
  .mobile-no-padding {
    padding: 0 !important;
  }

  /* Stack on mobile */
  .mobile-stack {
    flex-direction: column !important;
  }

  /* Center on mobile */
  .mobile-center {
    text-align: center !important;
  }
}

/* =====================================
   11. Specific Page Fixes
   ===================================== */

/* Demo Form Page */
@media (max-width: 768px) {
  #demoForm .two-column {
    flex-direction: column;
  }

  #demoForm .benefits-sidebar {
    margin-top: 32px;
    padding: 24px;
  }
}

/* Checklist Page */
@media (max-width: 768px) {
  .checklist-item {
    padding: 16px;
    margin-bottom: 16px;
  }

  .checklist-item input[type="checkbox"] {
    min-width: 28px;
    min-height: 28px;
  }

  .print-button {
    width: 100%;
    margin-bottom: 20px;
  }
}

/* ROI Calculator */
@media (max-width: 768px) {
  .calculator-input-group {
    grid-template-columns: 1fr;
  }

  .calculator-result {
    font-size: 32px;
    padding: 24px;
  }
}

/* Pricing Table */
@media (max-width: 768px) {
  .pricing-tier {
    margin-bottom: 32px;
  }

  .pricing-features {
    padding: 20px;
  }

  .pricing-cta {
    width: 100%;
  }
}

/* Case Studies */
@media (max-width: 768px) {
  .case-study-stats {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .stat-box {
    padding: 20px;
    text-align: center;
  }
}

/* =====================================
   12. Print Styles (for checklist)
   ===================================== */

@media print {
  /* Hide unnecessary elements */
  header,
  nav,
  .cta-button,
  .print-button,
  .hide-print {
    display: none !important;
  }

  /* Full width */
  body {
    width: 100%;
    margin: 0;
    padding: 20px;
  }

  /* Page breaks */
  .checklist-section {
    page-break-inside: avoid;
  }

  /* Ensure checkboxes print */
  input[type="checkbox"] {
    -webkit-appearance: checkbox;
    appearance: checkbox;
  }
}

/* =====================================
   13. Accessibility Improvements
   ===================================== */

@media (max-width: 768px) {
  /* Focus visible */
  *:focus-visible {
    outline: 3px solid #3b82f6;
    outline-offset: 2px;
  }

  /* Skip to content link */
  .skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #3b82f6;
    color: white;
    padding: 12px 24px;
    z-index: 10001;
  }

  .skip-link:focus {
    top: 0;
  }

  /* High contrast mode support */
  @media (prefers-contrast: high) {
    button,
    input,
    select,
    textarea {
      border: 2px solid currentColor;
    }
  }
}

/* =====================================
   14. Dark Mode Support (Optional)
   ===================================== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
  body {
    background: #1f2937;
    color: #f9fafb;
  }

  .card,
  .modal {
    background: #374151;
    border-color: #4b5563;
  }

  input,
  textarea,
  select {
    background: #4b5563;
    border-color: #6b7280;
    color: #f9fafb;
  }

  button,
  .cta-button {
    background: #3b82f6;
    color: white;
  }
}
