/* =============================================================================
   MASORANGE PLATFORM - UNIFIED RESPONSIVE SYSTEM
   
   This file contains all responsive design rules using a consistent 
   breakpoint system. Include this file after all other CSS files.
   ============================================================================= */

/* =============================================================================
   BREAKPOINT SYSTEM (Mobile First Approach)
   ============================================================================= */
/*
  xs: 0-575.98px    (Mobile)
  sm: 576-767.98px  (Mobile Large) 
  md: 768-991.98px  (Tablet)
  lg: 992-1199.98px (Desktop)
  xl: 1200px+       (Large Desktop)
*/

/* =============================================================================
   MOBILE FIRST: BASE STYLES (xs: 0-575px)
   ============================================================================= */

/* Ensure body never overflows horizontally */
body {
  overflow-x: hidden;
  min-width: 320px; /* Minimum supported screen width */
}

/* Make all containers responsive */
.container, .content-wrapper, .card-body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Base responsive images */
img {
  max-width: 100%;
  height: auto;
}

/* Hide mobile menu toggles by default (desktop) */
.mobile-menu-toggle,
.mobile-nav-toggle,
.toggle-sidebar {
  display: none;
}

/* =============================================================================
   MOBILE (xs: 0-575.98px)
   ============================================================================= */
@media (max-width: 575.98px) {
  
  /* === SIDEBAR MOBILE === */
  .sidebar {
    transform: translateX(-100%);
    position: fixed;
    z-index: 1001;
    transition: transform 0.3s ease;
    width: 280px; /* Slightly wider for mobile */
    height: 100vh;
  }
  
  .sidebar.active {
    transform: translateX(0);
  }
  
  /* Mobile overlay when sidebar is open */
  .sidebar.active::before {
    content: "";
    position: fixed;
    top: 0;
    left: 280px; /* Start after sidebar */
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    pointer-events: auto;
  }
  
  /* === MAIN CONTENT MOBILE === */
  .main-content {
    margin-left: 0;
    width: 100%;
  }
  
  /* === HEADER MOBILE === */
  .header {
    padding: 0 15px;
    height: auto;
    min-height: var(--header-height);
    flex-wrap: wrap;
  }
  
  .header-title {
    font-size: 1.2rem;
    flex: 1;
    margin-bottom: 5px;
  }
  
  .user-profile {
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
  
  .user-profile > div {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px !important;
  }
  
  /* === MOBILE TOGGLE BUTTONS === */
  .mobile-menu-toggle,
  .mobile-nav-toggle,
  .toggle-sidebar {
    display: block !important;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 8px;
    margin-right: 10px;
    order: -1; /* Show first */
  }
  
  .mobile-menu-toggle:hover,
  .mobile-nav-toggle:hover,
  .toggle-sidebar:hover {
    color: var(--primary-dark);
  }
  
  /* === BUTTONS MOBILE === */
  .btn-add-funds {
    font-size: 0.7rem;
    padding: 4px 8px;
  }
  
  #logoutBtn {
    padding: 3px 6px;
    font-size: 0.7rem;
  }
  
  /* === CONTENT WRAPPER MOBILE === */
  .content-wrapper {
    padding: 15px;
  }
  
  /* === FORMS MOBILE === */
  .login-container, .register-container {
    width: calc(100% - 40px) !important;
    margin: 20px !important;
    max-width: 400px !important;
    padding: 20px !important;
  }
  
  .register-container {
    max-width: 430px !important;
  }
  
  /* Phone input responsive */
  .phone-input-container {
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .country-select {
    min-width: 100% !important;
  }
  
  /* === CARDS MOBILE === */
  .card {
    margin-bottom: 15px;
  }
  
  .card-body {
    padding: 15px;
  }
  
  /* === ANALYTICS MOBILE === */
  .analytics-header {
    padding: 15px;
    text-align: center;
  }
  
  .analytics-header h2 {
    font-size: 1.8rem;
  }
  
  .analytics-header p {
    font-size: 1rem;
  }
  
  /* Executive summary mobile */
  .executive-summary-row {
    flex-direction: column !important;
    gap: 15px !important;
  }
  
  .executive-table-container {
    max-width: 100% !important;
  }
  
  .period-selector {
    flex-direction: row !important;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .period-btn {
    min-width: 80px;
    padding: 6px 12px;
    font-size: 0.8rem;
  }
  
  /* === CHARTS MOBILE === */
  .charts-grid {
    grid-template-columns: 1fr !important;
    gap: 15px;
  }
  
  .chart-card {
    padding: 15px;
  }
  
  .chart-card canvas {
    max-height: 250px !important;
  }
  
  /* === TABLES MOBILE === */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .table th, .table td, .table-cell {
    min-width: 100px;
    padding: 8px 6px;
    font-size: 0.8rem;
  }
  
  /* Simple table mobile */
  .simple-table {
    font-size: 0.8rem;
  }
  
  .table-cell {
    padding: 6px 8px;
    font-size: 0.8rem;
  }
  
  /* === GRID SYSTEM MOBILE === */
  .row {
    margin: 0 -8px;
  }
  
  .col-12, .col-8, .col-6, .col-4, .col-3 {
    width: 100% !important;
    padding: 0 8px;
    margin-bottom: 15px;
  }
  
  /* === MODAL MOBILE === */
  .modal-content {
    width: calc(100vw - 20px) !important;
    margin: 10px !important;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
  
  /* === CONTACT MANAGEMENT MOBILE === */
  .contact-header {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
  }
  
  .contact-actions {
    justify-content: space-between;
  }
  
  .contacts-table th, .contacts-table td {
    padding: 8px 6px;
    font-size: 0.8rem;
  }
  
  .pagination-container {
    flex-direction: column;
    gap: 10px;
  }
  
  /* === USER PROFILE MOBILE === */
  #userBalanceDisplay {
    font-size: 0.8rem;
  }
}

/* =============================================================================
   MOBILE LARGE (sm: 576-767.98px) 
   ============================================================================= */
@media (min-width: 576px) and (max-width: 767.98px) {
  
  .login-container, .register-container {
    width: 480px !important;
    margin: 20px auto !important;
  }
  
  .header-title {
    font-size: 1.4rem;
  }
  
  .analytics-header h2 {
    font-size: 2rem;
  }
  
  .btn-add-funds {
    font-size: 0.8rem;
    padding: 5px 10px;
  }
  
  .period-btn {
    min-width: 90px;
    padding: 8px 16px;
    font-size: 0.9rem;
  }
  
  .chart-card canvas {
    max-height: 300px !important;
  }
  
  /* Partial grid restoration */
  .col-6 {
    width: 50% !important;
  }
}

/* =============================================================================
   TABLET (md: 768-991.98px)
   ============================================================================= */
@media (min-width: 768px) and (max-width: 991.98px) {
  
  .sidebar {
    width: 220px;
  }
  
  .main-content {
    margin-left: 220px;
  }
  
  .header-title {
    font-size: 1.6rem;
  }
  
  .analytics-header h2 {
    font-size: 2.2rem;
  }
  
  .content-wrapper {
    padding: 18px;
  }
  
  /* Charts still single column for tablets */
  .charts-grid {
    grid-template-columns: 1fr !important;
    gap: 20px;
  }
  
  .chart-card canvas {
    max-height: 350px !important;
  }
  
  /* Executive summary can be side by side */
  .executive-summary-row {
    flex-direction: row !important;
    align-items: flex-start;
  }
  
  .executive-table-container {
    flex: 1;
    max-width: 60%;
  }
  
  /* Grid system restoration */
  .col-6 {
    width: 50% !important;
  }
  
  .col-4 {
    width: 33.3333% !important;
  }
  
  /* Mobile toggles should be hidden */
  .mobile-menu-toggle,
  .mobile-nav-toggle,
  .toggle-sidebar {
    display: none !important;
  }
}

/* =============================================================================
   DESKTOP (lg: 992-1199.98px)
   ============================================================================= */
@media (min-width: 992px) and (max-width: 1199.98px) {
  
  .sidebar {
    width: 240px;
  }
  
  .main-content {
    margin-left: 240px;
  }
  
  /* Charts can go back to 2 columns */
  .charts-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 20px;
  }
  
  .chart-card canvas {
    max-height: 320px !important;
  }
  
  .analytics-header h2 {
    font-size: 2.3rem;
  }
  
  /* Full grid system */
  .col-3 {
    width: 25% !important;
  }
  
  .col-4 {
    width: 33.3333% !important;
  }
  
  .col-6 {
    width: 50% !important;
  }
  
  .col-8 {
    width: 66.6667% !important;
  }
}

/* =============================================================================
   LARGE DESKTOP (xl: 1200px+)
   ============================================================================= */
@media (min-width: 1200px) {
  
  .sidebar {
    width: 250px; /* Back to default */
  }
  
  .main-content {
    margin-left: 250px;
  }
  
  .content-wrapper {
    padding: 20px;
    max-width: 1400px; /* Prevent content from stretching too wide */
  }
  
  .analytics-header h2 {
    font-size: 2.5rem; /* Full size */
  }
  
  .chart-card canvas {
    max-height: 400px !important; /* Full size */
  }
  
  /* Prevent forms from getting too wide on huge screens */
  .login-container, .register-container {
    max-width: 450px;
    margin: 20px auto;
  }
}

/* =============================================================================
   VERY LARGE SCREENS (1440px+)
   ============================================================================= */
@media (min-width: 1440px) {
  
  .content-wrapper {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 40px;
  }
  
  .analytics-header {
    padding: 25px;
  }
  
  /* Ensure proper spacing on very large screens */
  .charts-grid {
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* =============================================================================
   UTILITY CLASSES FOR RESPONSIVE BEHAVIOR
   ============================================================================= */

/* Hide elements on mobile */
.d-none-mobile {
  display: none !important;
}

@media (min-width: 768px) {
  .d-none-mobile {
    display: block !important;
  }
}

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

@media (min-width: 768px) {
  .d-mobile-only {
    display: none !important;
  }
}

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

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

/* =============================================================================
   ACCESSIBILITY AND TOUCH IMPROVEMENTS
   ============================================================================= */

/* Ensure minimum touch targets on mobile */
@media (max-width: 767.98px) {
  
  button, .btn, a.sidebar-menu-item {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Exception for small utility buttons */
  .btn-add-funds, #logoutBtn {
    min-height: 36px;
    min-width: auto;
  }
  
  /* Increase tap targets for sidebar menu */
  .sidebar-menu-item {
    padding: 16px 20px;
  }
}

/* =============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================= */

/* Use transform instead of changing layout properties when possible */
.sidebar {
  will-change: transform;
}

/* Improve scrolling performance on mobile */
@media (max-width: 767.98px) {
  .content-wrapper, .modal-content {
    -webkit-overflow-scrolling: touch;
  }
}

/* =============================================================================
   PRINT STYLES (Bonus)
   ============================================================================= */
@media print {
  .sidebar, .mobile-toggle, .user-profile {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  .chart-card, .analytics-section {
    break-inside: avoid;
  }
}