/**
 * ZADI - Responsive CSS
 * Mobile breakpoints, touch optimizations, responsive utilities
 */

/* ============================================
   BREAKPOINTS
   ============================================ */
/* 
  Mobile: < 768px
  Tablet: 768px - 1024px
  Desktop: > 1024px
*/

/* ============================================
   MOBILE FIRST RESPONSIVE UTILITIES
   ============================================ */

/* Hide/Show utilities */
.d-mobile-none { display: none !important; }
.d-mobile-block { display: block !important; }
.d-mobile-flex { display: flex !important; }

.d-tablet-none { display: none !important; }
.d-tablet-block { display: block !important; }
.d-tablet-flex { display: flex !important; }

.d-desktop-none { display: none !important; }
.d-desktop-block { display: block !important; }
.d-desktop-flex { display: flex !important; }

/* Text alignment */
.text-mobile-center { text-align: center !important; }
.text-mobile-left { text-align: left !important; }

.text-tablet-center { text-align: center !important; }
.text-tablet-left { text-align: left !important; }

.text-desktop-center { text-align: center !important; }
.text-desktop-left { text-align: left !important; }

/* Spacing utilities */
.m-mobile-0 { margin: 0 !important; }
.m-mobile-1 { margin: var(--spacing-1) !important; }
.m-mobile-2 { margin: var(--spacing-2) !important; }
.m-mobile-3 { margin: var(--spacing-3) !important; }

.p-mobile-0 { padding: 0 !important; }
.p-mobile-1 { padding: var(--spacing-1) !important; }
.p-mobile-2 { padding: var(--spacing-2) !important; }
.p-mobile-3 { padding: var(--spacing-3) !important; }

/* ============================================
   CONTAINER RESPONSIVE
   ============================================ */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-3);
}

@media (min-width: 768px) {
  .container {
    padding: 0 var(--spacing-4);
  }
}

@media (min-width: 1024px) {
  .container {
    padding: 0 var(--spacing-5);
  }
}

/* ============================================
   GRID SYSTEM
   ============================================ */
.row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 calc(-1 * var(--spacing-2));
}

.col {
  flex: 1;
  padding: 0 var(--spacing-2);
}

.col-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }
.col-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
.col-3 { flex: 0 0 25%; max-width: 25%; }
.col-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
.col-5 { flex: 0 0 41.666667%; max-width: 41.666667%; }
.col-6 { flex: 0 0 50%; max-width: 50%; }
.col-7 { flex: 0 0 58.333333%; max-width: 58.333333%; }
.col-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
.col-9 { flex: 0 0 75%; max-width: 75%; }
.col-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
.col-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
.col-12 { flex: 0 0 100%; max-width: 100%; }

/* Mobile: Stack all columns */
@media (max-width: 767px) {
  .col,
  .col-1, .col-2, .col-3, .col-4, .col-5, .col-6,
  .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: var(--spacing-3);
  }
  
  .row {
    margin: 0;
  }
  
  .col,
  .col-1, .col-2, .col-3, .col-4, .col-5, .col-6,
  .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
    padding: 0;
  }
  
  /* Fix horizontal scrolling */
  .container {
    padding: 0 var(--spacing-2) !important;
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  /* Hero section mobile optimizations */
  .hero-section {
    padding: 2rem 0 3rem 0 !important;
    text-align: center;
  }
  
  .hero-content {
    text-align: center;
  }
  
  .hero-title {
    font-size: 1.75rem !important;
    line-height: 1.3 !important;
    margin-bottom: 1rem !important;
  }
  
  .hero-description {
    font-size: 1rem !important;
    line-height: 1.5 !important;
    margin-bottom: 1.5rem !important;
    opacity: 0.95;
  }
  
  .hero-search {
    margin-bottom: 1rem !important;
  }
  
  /* White search box on mobile for better visibility */
  .hero-search .form-control {
    background-color: #ffffff !important;
    color: #333 !important;
    border: 2px solid #ffffff !important;
  }
  
  .hero-search .form-control::placeholder {
    color: #999 !important;
  }
  
  .hero-search .btn-primary {
    background-color: #ffffff !important;
    color: #ff1844 !important;
    border: 2px solid #ffffff !important;
    font-weight: 600;
  }
  
  .hero-search .btn-primary:hover {
    background-color: #f8f9fa !important;
  }
  
  /* Hide floating cards on mobile */
  .hero-image {
    display: none !important;
  }
  
  /* Hide stats section on mobile for cleaner, shorter hero */
  .hero-stats {
    display: none !important;
  }
  
  /* Ensure cards don't overflow */
  .card-grid {
    gap: var(--spacing-2) !important;
  }
  
  .coupon-card {
    max-width: 100%;
    overflow: hidden;
  }
  
  /* Fix text overflow */
  .card-title {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  
  .vendor-name, .vendor-location {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
}

/* ============================================
   HAMBURGER MENU & MOBILE NAVIGATION
   ============================================ */
@media (max-width: 991px) {
  /* Hamburger menu styling */
  .navbar-toggler {
    border: 2px solid #ff1844 !important;
    padding: 0.5rem 0.75rem;
    z-index: 1050;
  }
  
  .navbar-toggler:focus {
    box-shadow: 0 0 0 0.25rem rgba(255, 24, 68, 0.25);
    outline: none;
  }
  
  .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(255, 24, 68, 1)' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important;
  }
  
  /* Mobile menu dropdown */
  .navbar-collapse {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 1040;
    padding: 1rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
  }
  
  .navbar-collapse.show {
    display: block !important;
    max-height: 80vh;
    overflow-y: auto;
  }
  
  /* Mobile menu items */
  .navbar-nav .nav-link {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    display: block;
  }
  
  .navbar-nav .nav-link:hover {
    background-color: #f8f9fa;
    color: #ff1844;
  }
  
  .navbar-nav .nav-item:last-child .nav-link {
    border-bottom: none;
  }
  
  /* Mobile dropdown menus */
  .navbar-nav .dropdown-menu {
    position: static;
    float: none;
    border: none;
    box-shadow: none;
    padding-left: 1rem;
    background-color: #f8f9fa;
  }
  
  .navbar-nav .dropdown-item {
    padding: 0.5rem 1rem;
  }
  
  /* Buttons in mobile menu */
  .navbar-nav .btn {
    width: 100%;
    margin-top: 0.5rem;
    text-align: center;
  }
}

/* Tablet: 2 columns max */
@media (min-width: 768px) and (max-width: 1023px) {
  .col-md-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }
  .col-md-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
  .col-md-3 { flex: 0 0 25%; max-width: 25%; }
  .col-md-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-md-5 { flex: 0 0 41.666667%; max-width: 41.666667%; }
  .col-md-6 { flex: 0 0 50%; max-width: 50%; }
  .col-md-7 { flex: 0 0 58.333333%; max-width: 58.333333%; }
  .col-md-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-md-9 { flex: 0 0 75%; max-width: 75%; }
  .col-md-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
  .col-md-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
  .col-md-12 { flex: 0 0 100%; max-width: 100%; }
}

/* Desktop: Full grid */
@media (min-width: 1024px) {
  .col-lg-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }
  .col-lg-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
  .col-lg-3 { flex: 0 0 25%; max-width: 25%; }
  .col-lg-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-lg-5 { flex: 0 0 41.666667%; max-width: 41.666667%; }
  .col-lg-6 { flex: 0 0 50%; max-width: 50%; }
  .col-lg-7 { flex: 0 0 58.333333%; max-width: 58.333333%; }
  .col-lg-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-lg-9 { flex: 0 0 75%; max-width: 75%; }
  .col-lg-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
  .col-lg-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
  .col-lg-12 { flex: 0 0 100%; max-width: 100%; }
}

/* ============================================
   NAVBAR RESPONSIVE
   ============================================ */
.navbar {
  position: relative;
}

.navbar-toggler {
  display: none;
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--zadi-text-primary);
  font-size: var(--font-size-lg);
}

.navbar-collapse {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
}

/* Mobile navbar */
@media (max-width: 767px) {
  .navbar-toggler {
    display: block;
  }
  
  .navbar-collapse {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--zadi-surface);
    border-top: 1px solid var(--zadi-border);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
    align-items: stretch;
    padding: var(--spacing-3);
    gap: 0;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
  }
  
  .navbar-collapse.show {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }
  
  .navbar-nav {
    flex-direction: column;
    width: 100%;
    gap: 0;
  }
  
  .nav-link {
    padding: var(--spacing-2) 0;
    border-bottom: 1px solid var(--zadi-border);
    text-align: center;
  }
  
  .nav-link:last-child {
    border-bottom: none;
  }
}

/* ============================================
   CARDS RESPONSIVE
   ============================================ */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-3);
}

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

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

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

/* ============================================
   FORMS RESPONSIVE
   ============================================ */
.form-row {
  display: flex;
  gap: var(--spacing-3);
  margin-bottom: var(--spacing-3);
}

.form-col {
  flex: 1;
}

@media (max-width: 767px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .form-col {
    margin-bottom: var(--spacing-3);
  }
}

/* ============================================
   TABLES RESPONSIVE
   ============================================ */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
  .table-responsive {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
  }
  
  .table-responsive table {
    min-width: 600px;
  }
  
  /* Stack table rows on mobile */
  .table-stack-mobile {
    display: block;
  }
  
  .table-stack-mobile thead {
    display: none;
  }
  
  .table-stack-mobile tbody,
  .table-stack-mobile tr,
  .table-stack-mobile td {
    display: block;
  }
  
  .table-stack-mobile tr {
    background-color: var(--zadi-surface);
    border: 1px solid var(--zadi-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-3);
    padding: var(--spacing-3);
  }
  
  .table-stack-mobile td {
    border: none;
    padding: 0.5rem 0;
    text-align: left;
  }
  
  .table-stack-mobile td:before {
    content: attr(data-label) ": ";
    font-weight: var(--font-weight-semibold);
    color: var(--zadi-text-primary);
    display: inline-block;
    width: 120px;
  }
}

/* ============================================
   TOUCH OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* Touch devices */
  
  /* Larger touch targets */
  .btn {
    min-height: 48px;
    padding: 0.875rem 1.75rem;
  }
  
  .btn-sm {
    min-height: 44px;
    padding: 0.75rem 1.25rem;
  }
  
  .nav-link {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .form-control {
    min-height: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  .form-check {
    min-height: 48px;
  }
  
  /* Remove hover effects on touch */
  .btn:hover {
    transform: none;
    box-shadow: var(--shadow-md);
  }
  
  .card:hover {
    transform: none;
    box-shadow: var(--shadow-md);
  }
  
  /* Add active states for touch */
  .btn:active {
    transform: scale(0.98);
  }
  
  .card:active {
    transform: scale(0.99);
  }
}

/* ============================================
   PRINT RESPONSIVE
   ============================================ */
@media print {
  .d-print-none {
    display: none !important;
  }
  
  .d-print-block {
    display: block !important;
  }
  
  .d-print-inline {
    display: inline !important;
  }
  
  .d-print-inline-block {
    display: inline-block !important;
  }
  
  /* Hide navigation and sidebars */
  .navbar,
  .dashboard-sidebar,
  .mobile-bottom-nav {
    display: none !important;
  }
  
  /* Adjust main content */
  .dashboard-main {
    margin-left: 0 !important;
  }
  
  .dashboard-content {
    padding: 0 !important;
  }
  
  /* Stack cards vertically */
  .card-grid {
    grid-template-columns: 1fr !important;
  }
  
  /* Show table data */
  .table-responsive {
    overflow: visible !important;
  }
  
  .table-responsive table {
    min-width: auto !important;
  }
}

/* ============================================
   ACCESSIBILITY RESPONSIVE
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-color-scheme: dark) {
  /* Dark mode support can be added here in the future */
  /* For now, we maintain light theme */
}

/* ============================================
   HIGH DPI DISPLAYS
   ============================================ */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Optimize for retina displays */
  .card-img-top,
  .user-avatar,
  .stat-card-icon {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
  .navbar {
    padding: var(--spacing-1) 0;
  }
  
  .hero-section {
    padding: var(--spacing-4) 0;
  }
  
  .dashboard-header {
    padding: var(--spacing-2) var(--spacing-3);
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   UTILITY CLASSES FOR RESPONSIVE
   ============================================ */
.w-mobile-full { width: 100% !important; }
.w-tablet-auto { width: auto !important; }
.w-desktop-auto { width: auto !important; }

.h-mobile-auto { height: auto !important; }
.h-tablet-auto { height: auto !important; }
.h-desktop-auto { height: auto !important; }

.overflow-mobile-hidden { overflow: hidden !important; }
.overflow-tablet-auto { overflow: auto !important; }
.overflow-desktop-auto { overflow: auto !important; }

/* ============================================
   RESPONSIVE TYPOGRAPHY
   ============================================ */
@media (max-width: 767px) {
  h1 { font-size: var(--font-size-2xl); }
  h2 { font-size: var(--font-size-xl); }
  h3 { font-size: var(--font-size-lg); }
  
  .display-4 { font-size: var(--font-size-3xl); }
  .lead { font-size: var(--font-size-base); }
}

@media (min-width: 768px) {
  h1 { font-size: var(--font-size-3xl); }
  h2 { font-size: var(--font-size-2xl); }
  h3 { font-size: var(--font-size-xl); }
  
  .display-4 { font-size: var(--font-size-4xl); }
  .lead { font-size: var(--font-size-lg); }
}

/* ========================================
   MOBILE MODAL IMPROVEMENTS
   ======================================== */

@media (max-width: 576px) {
  .modal-dialog {
    margin: 0.5rem;
  }
  
  .modal-content {
    border-radius: 15px;
  }
  
  .modal-header {
    border-bottom: 1px solid #dee2e6;
    padding: 1rem 1.5rem;
  }
  
  .modal-body {
    padding: 1.5rem;
  }
  
  .modal-footer {
    border-top: 1px solid #dee2e6;
    padding: 1rem 1.5rem;
  }
  
  .btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
  }
}

