/* Mobile Optimization for iPhone and Samsung Android devices */

/* iPhone specific optimizations */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari specific styles */
  body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  .navbar-nav .nav-link {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: rgba(220, 53, 69, 0.3);
  }
}

/* Enhanced viewport handling for all devices */
@viewport {
  width: device-width;
  initial-scale: 1;
  minimum-scale: 1;
  maximum-scale: 5;
  user-scalable: yes;
}

/* Hide title text that appears at the top of body */
body {
  font-size: 0 !important;
}

body * {
  font-size: 1rem;
}

/* Alternative approach - hide first text node */
body::first-line {
  display: none !important;
  font-size: 0 !important;
  line-height: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

/* Touch-friendly improvements */
.btn, .nav-link, .card, [role="button"] {
  min-height: 44px; /* Apple's recommended minimum touch target */
  min-width: 44px;
  touch-action: manipulation; /* Prevents double-tap zoom */
}

/* Table touch optimization */
.table-modern {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
}

.table-modern td, .table-modern th {
  min-height: 48px;
  padding: 0.75rem;
  white-space: nowrap;
}

/* Enhanced mobile navigation */
@media (max-width: 991.98px) {
  .navbar {
    padding: 0.5rem 0 !important;
    min-height: 60px;
  }
  
  .navbar-brand {
    font-size: 1rem !important;
  }
  
  .navbar-brand span {
    font-size: 1rem !important;
  }
  
  .navbar-brand small {
    font-size: 0.6rem !important;
  }
  
  /* Logo size optimization for mobile */
  .matrixcbsLogo img {
    max-height: 35px !important;
    width: auto;
  }
  
  /* Navbar brand layout for mobile */
  .navbar .container {
    justify-content: space-between;
    align-items: center;
  }
  
  .matrixcbsLogo {
    margin-right: 0.5rem;
  }
  
  /* Toggler styling for mobile */
  .navbar-toggler {
    padding: 0.4rem 0.6rem !important;
    margin-left: 0.5rem;
    margin-right: 0;
    border-radius: 6px;
  }
}
  
  .navbar-collapse {
    margin-top: 0.5rem;
    padding: 0.75rem;
    max-height: none;
    overflow: visible;
    width: 100%;
    order: 3;
  }
  
  .navbar-nav .nav-link {
    padding: 0.75rem 1rem !important;
    margin: 0.2rem 0;
    font-size: 1rem !important;
    border-radius: 8px;
  }
}

/* iPhone specific breakpoints */
@media screen and (max-width: 430px) {
  /* iPhone 14 Pro Max and smaller */
  .container, .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  /* Further optimize logo and brand for smaller screens */
  .matrixcbsLogo img {
    max-height: 28px !important;
  }
  
  .navbar-brand {
    font-size: 0.9rem !important;
  }
  
  .navbar-brand span {
    font-size: 0.9rem !important;
  }
  
  .navbar-brand small {
    font-size: 0.55rem !important;
  }
  
  /* Even smaller card header for small phones */
  .card-header h3 {
    font-size: 1.1rem !important;
  }
  
  .card-header .btn-group .btn {
    font-size: 0.9rem;
    padding: 0.6rem 0.8rem;
  }
  
  .hero-title {
    font-size: 2.2rem !important;
    line-height: 1.1;
  }
  
  .hero-subtitle {
    font-size: 1.1rem !important;
  }
  
  .card-modern .card-body {
    padding: 1rem;
  }
  
  .btn-modern {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    width: 100%;
    margin-bottom: 0.75rem;
  }
}

@media screen and (max-width: 390px) {
  /* iPhone 12 Pro and smaller */
  .navbar-brand {
    font-size: 1.1rem !important;
  }
  
  .hero-title {
    font-size: 2rem !important;
  }
  
  .display-4 {
    font-size: 1.8rem;
  }
  
  .lead {
    font-size: 1rem;
  }
}

@media screen and (max-width: 375px) {
  /* iPhone SE and smaller */
  .container, .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  .navbar-brand {
    font-size: 0.8rem !important;
  }
  
  .navbar-brand span {
    font-size: 0.8rem !important;
  }
  
  .navbar-brand small {
    font-size: 0.5rem !important;
  }
  
  /* Very small screen logo optimization */
  .matrixcbsLogo img {
    max-height: 25px !important;
  }
  
  .hero-title {
    font-size: 1.8rem !important;
  }
  
  h1 {
    font-size: 1.75rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
}

/* Samsung specific optimizations */
@media screen and (-webkit-device-pixel-ratio: 3) {
  /* High DPI Samsung devices */
  .table-modern {
    font-size: 0.95rem;
  }
  
  .navbar-nav .nav-link {
    letter-spacing: 0.2px;
  }
}

/* Landscape mobile optimizations */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .hero-modern {
    min-height: 100vh;
    padding: 2rem 0;
  }
  
  .navbar {
    padding: 0.25rem 0 !important;
    min-height: 50px;
  }
  
  .navbar-collapse {
    max-height: 60vh;
  }
  
  .hero-title {
    font-size: 2rem !important;
    margin-bottom: 1rem;
  }
  
  .hero-subtitle {
    font-size: 1rem !important;
    margin-bottom: 1.5rem;
  }
}

/* Improved scrolling performance */
.navbar-collapse,
.table-responsive,
.card-body {
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
}

/* Card header improvements for mobile */
@media (max-width: 768px) {
  .card-header .d-flex {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 1rem;
  }
  
  .card-header h3 {
    font-size: 1.25rem !important;
    margin-bottom: 0 !important;
  }
  
  .card-header .btn-group {
    width: 100%;
    display: flex;
  }
  
  .card-header .btn-group .btn {
    flex: 1;
    font-size: 1rem;
    padding: 0.75rem 1rem;
  }
}

/* Form improvements for mobile */
@media (max-width: 768px) {
  .form-control {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.875rem 1rem;
    border-radius: 8px;
  }
  
  .form-control:focus {
    transform: none; /* Remove transform on mobile for better performance */
  }
}

/* Table responsiveness improvements */
@media (max-width: 768px) {
  .table-responsive {
    border: none;
    margin-bottom: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .table-modern {
    margin-bottom: 0;
    font-size: 0.85rem;
    min-width: 100%;
  }
  
  /* Sticky first column (date) */
  .table-modern td:first-child,
  .table-modern th:first-child {
    position: sticky;
    left: 0;
    background: white;
    z-index: 2;
    border-right: 2px solid #dee2e6;
    min-width: 80px;
    max-width: 80px;
    font-size: 0.8rem;
  }
  
  /* Sticky header */
  .table-modern thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    font-size: 0.8rem;
    padding: 0.5rem 0.3rem;
  }
  
  .table-modern thead th:first-child {
    z-index: 4;
  }
  
  /* Mobile-optimized table cells */
  .table-modern td {
    padding: 0.4rem 0.3rem;
    vertical-align: top;
    min-width: 120px;
    font-size: 0.8rem;
    line-height: 1.3;
  }
  
  /* Make exam type badges smaller on mobile */
  .table-modern .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
  }
  
  /* Improve button spacing */
  .table-modern .btn {
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
    margin: 0.1rem 0;
  }
  
  /* Better flag icon sizing */
  .flag-icon {
    width: 1rem;
    height: auto;
  }
  
  /* Compact exam status icons */
  .table-modern .fas {
    font-size: 0.8rem;
  }
}

/* Extra small phones - even more compact */
@media (max-width: 430px) {
  .table-modern {
    font-size: 0.75rem;
  }
  
  .table-modern td:first-child,
  .table-modern th:first-child {
    min-width: 70px;
    max-width: 70px;
    font-size: 0.7rem;
  }
  
  .table-modern td {
    padding: 0.3rem 0.2rem;
    min-width: 100px;
    font-size: 0.75rem;
  }
  
  .table-modern thead th {
    padding: 0.4rem 0.2rem;
    font-size: 0.7rem;
  }
  
  .table-modern .badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.3rem;
  }
  
  .table-modern .btn {
    font-size: 0.7rem;
    padding: 0.25rem 0.4rem;
  }
}

/* Performance improvements */
* {
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.card-modern,
.btn-modern,
.navbar-nav .nav-link {
  will-change: transform;
  backface-visibility: hidden;
}

/* Dark mode adjustments for mobile */
@media (prefers-color-scheme: dark) {
  [data-bs-theme="dark"] .table-modern td:first-child,
  [data-bs-theme="dark"] .table-modern th:first-child {
    background: var(--bs-body-bg);
  }
  
  [data-bs-theme="dark"] .navbar-collapse {
    background: var(--bs-body-bg);
    border-color: var(--bs-border-color);
  }
}

/* Accessibility improvements for mobile */
@media (prefers-reduced-motion: reduce) {
  .card-modern,
  .btn-modern,
  .navbar-nav .nav-link {
    transition: none;
    animation: none;
    transform: none;
  }
  
  .card-modern:hover {
    transform: none;
  }
  
  .navbar-nav .nav-link:hover {
    transform: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn-modern {
    border-width: 2px;
  }
  
  .card-modern {
    border: 2px solid var(--bs-border-color);
  }
  
  .navbar-nav .nav-link {
    border: 1px solid transparent;
  }
  
  .navbar-nav .nav-link:hover,
  .navbar-nav .nav-link.active {
    border-color: currentColor;
  }
}

/* Improved focus indicators for mobile */
.btn:focus,
.nav-link:focus,
.card:focus,
[tabindex]:focus {
  outline: 3px solid rgba(220, 53, 69, 0.6);
  outline-offset: 2px;
}

/* Sticky positioning improvements */
@supports (position: sticky) {
  .navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
  }
}

/* Safe area adjustments for notched devices */
@supports (padding: max(0px)) {
  .navbar {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  .container, .container-fluid {
    padding-left: max(15px, env(safe-area-inset-left));
    padding-right: max(15px, env(safe-area-inset-right));
  }
}