/* ========================================
   MOBILE & RESPONSIVE OPTIMIZATION
   Fast, accessible, mobile-first design
   ======================================== */

/* ===== BASE MOBILE-FIRST STYLES ===== */
* {
  box-sizing: border-box;
}

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

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

/* ===== TOUCH-FRIENDLY BUTTONS ===== */
button, .btn, a.btn {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

/* ===== RESPONSIVE IMAGES ===== */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Lazy loading optimization - removed opacity to fix image display */
img[loading="lazy"] {
  /* Images show immediately, browser handles lazy loading */
  transition: opacity 0.3s;
}

/* ===== MOBILE NAVIGATION ===== */
@media (max-width: 991px) {
  .navbar-collapse {
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .navbar-nav {
    padding: 1rem 0;
  }
  
  .nav-item {
    padding: 0.5rem 0;
  }
  
  .dropdown-menu {
    border: none;
    box-shadow: none;
    background: rgba(255,255,255,0.05);
  }
}

/* ===== RESPONSIVE CARDS ===== */
@media (max-width: 767px) {
  .card {
    margin-bottom: 1rem;
  }
  
  .card-body {
    padding: 1rem;
  }
  
  .product-card {
    margin-bottom: 1.5rem;
  }
  
  .invoice-card {
    padding: 1rem;
  }
  
  .invoice-card .row {
    flex-direction: column;
  }
  
  .invoice-card .col-md-2,
  .invoice-card .col-md-3 {
    width: 100%;
    margin-bottom: 0.5rem;
    text-align: left !important;
  }
  
  .btn-action {
    margin: 0.25rem;
    font-size: 12px;
    padding: 4px 8px;
  }
}

/* ===== RESPONSIVE TABLES ===== */
@media (max-width: 767px) {
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    font-size: 14px;
  }
  
  th, td {
    padding: 0.5rem !important;
  }
}

/* ===== MOBILE FORMS ===== */
@media (max-width: 767px) {
  .form-control,
  .form-select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.75rem;
  }
  
  .input-group {
    flex-wrap: wrap;
  }
  
  .modal-dialog {
    margin: 0.5rem;
  }
  
  .modal-body {
    padding: 1rem;
  }
}

/* ===== RESPONSIVE GRID ===== */
@media (max-width: 575px) {
  .container {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  .row {
    margin-left: -10px;
    margin-right: -10px;
  }
  
  .col, [class*="col-"] {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* ===== MOBILE HERO SECTION ===== */
@media (max-width: 767px) {
  .hero-section {
    min-height: 50vh !important;
    padding: 2rem 0 !important;
  }
  
  .hero-section h1 {
    font-size: 1.75rem !important;
  }
  
  .hero-section p {
    font-size: 1rem !important;
  }
  
  .hero-badge {
    font-size: 0.875rem;
  }
}

/* ===== MOBILE STATS CARDS ===== */
@media (max-width: 767px) {
  .stats-card {
    margin-bottom: 1rem;
    padding: 1rem;
  }
  
  .stats-value {
    font-size: 24px !important;
  }
  
  .stats-label {
    font-size: 12px !important;
  }
}

/* ===== MOBILE PRODUCT GRID ===== */
@media (max-width: 767px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
  }
  
  .product-card {
    padding: 0.75rem;
  }
  
  .product-card h5 {
    font-size: 0.9rem;
  }
  
  .product-card .price {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ===== MOBILE FILTERS ===== */
@media (max-width: 767px) {
  .filter-section {
    position: sticky;
    top: 56px;
    z-index: 100;
    background: white;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
  
  .filter-section .row {
    gap: 0.5rem;
  }
  
  .filter-section .col-md-3,
  .filter-section .col-md-4 {
    width: 100%;
  }
}

/* ===== MOBILE CART & CHECKOUT ===== */
@media (max-width: 767px) {
  .cart-item {
    flex-direction: column;
    align-items: flex-start !important;
  }
  
  .cart-item img {
    width: 100%;
    max-width: 200px;
    margin-bottom: 1rem;
  }
  
  .quantity-controls {
    justify-content: flex-start;
    margin: 0.5rem 0;
  }
  
  .checkout-summary {
    position: static;
    margin-top: 2rem;
  }
}

/* ===== MOBILE DASHBOARD ===== */
@media (max-width: 767px) {
  .dashboard-sidebar {
    position: static;
    width: 100%;
    height: auto;
    margin-bottom: 1rem;
  }
  
  .dashboard-content {
    margin-left: 0;
    padding: 1rem;
  }
  
  .admin-header {
    padding: 1rem 0;
  }
  
  .admin-header h1 {
    font-size: 1.5rem;
  }
  
  .admin-header .btn {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
  }
}

/* ===== MOBILE INVOICE BUILDER ===== */
@media (max-width: 767px) {
  .invoice-preview {
    margin-top: 2rem;
  }
  
  .invoice-item-row {
    flex-direction: column;
  }
  
  .invoice-item-row input {
    margin-bottom: 0.5rem;
  }
}

/* ===== PERFORMANCE: REDUCE ANIMATIONS ON MOBILE ===== */
@media (max-width: 767px) {
  * {
    animation-duration: 0.1s !important;
    transition-duration: 0.1s !important;
  }
  
  .aos-animate {
    animation: none !important;
  }
}

/* ===== ACCESSIBILITY: FOCUS STATES ===== */
*:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* ===== MOBILE FOOTER ===== */
@media (max-width: 767px) {
  footer {
    text-align: center;
  }
  
  footer .row > div {
    margin-bottom: 2rem;
  }
  
  footer h5 {
    font-size: 1.1rem;
  }
  
  footer ul {
    padding-left: 0;
  }
}

/* ===== LOADING STATES ===== */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== MOBILE MODALS ===== */
@media (max-width: 767px) {
  .modal-dialog {
    max-width: 100%;
    margin: 0;
  }
  
  .modal-content {
    border-radius: 0;
    min-height: 100vh;
  }
  
  .modal-xl,
  .modal-lg {
    max-width: 100%;
  }
}

/* ===== TOUCH GESTURES ===== */
.swipeable {
  touch-action: pan-y pinch-zoom;
}

/* ===== MOBILE SEARCH ===== */
@media (max-width: 767px) {
  .search-bar {
    width: 100%;
  }
  
  .search-results {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .navbar,
  .footer,
  .btn,
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
  }
  
  .container {
    max-width: 100%;
  }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 767px) and (orientation: landscape) {
  .hero-section {
    min-height: 100vh !important;
  }
  
  .navbar-collapse {
    max-height: 60vh;
  }
}

/* ===== TABLET OPTIMIZATIONS ===== */
@media (min-width: 768px) and (max-width: 991px) {
  .product-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  
  .container {
    max-width: 720px;
  }
}

/* ===== PERFORMANCE: WILL-CHANGE ===== */
.navbar,
.modal,
.dropdown-menu {
  will-change: transform;
}

/* ===== 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));
  }
  
  .navbar {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* ===== 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;
  }
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }
  
  .card {
    border: 2px solid #000;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --card-bg: #2a2a2a;
  }
}
