/* Mobile PWA Optimizations */
/* Makes the app look and feel like a native mobile app */

/* =====================================================
   MOBILE-FIRST RESPONSIVE STYLES
   ===================================================== */

/* Only apply these styles on mobile devices */
@media only screen and (max-width: 768px) {
  
  /* ========== GENERAL MOBILE FIXES ========== */
  body {
    font-size: 16px; /* Prevent zoom on input focus */
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
  }

  /* Remove any unwanted scrollbars */
  .container-scroller {
    overflow-x: hidden;
  }

  /* ========== NAVBAR MOBILE OPTIMIZATION ========== */
  .navbar {
    height: 60px;
    padding: 0 10px;
  }

  .navbar-brand-wrapper {
    width: 60px;
    min-width: 60px;
  }

  .navbar-brand {
    padding: 8px;
  }

  .navbar-brand img {
    max-height: 35px;
    width: auto;
  }

  /* Make profile dropdown more touch-friendly */
  .nav-profile img {
    width: 35px;
    height: 35px;
  }

  /* Hide less important navbar items on mobile */
  .nav-user-status,
  .nav-date {
    display: none !important;
  }

  /* ========== SIDEBAR MOBILE OPTIMIZATION ========== */
  .sidebar {
    width: 100% !important;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .sidebar .nav-item {
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  }

  .sidebar .nav-link {
    padding: 15px 20px;
    font-size: 16px;
    min-height: 50px;
    display: flex;
    align-items: center;
  }

  .sidebar .menu-icon {
    font-size: 24px;
    margin-right: 15px;
  }

  /* ========== MAIN PANEL MOBILE LAYOUT ========== */
  .main-panel {
    width: 100% !important;
    margin-top: 60px;
  }

  .content-wrapper {
    padding: 15px 10px;
  }

  /* ========== CARDS & CONTENT ========== */
  .card {
    margin-bottom: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .card-body {
    padding: 15px;
  }

  /* Stack columns on mobile */
  .row > [class*="col-"] {
    width: 100%;
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 15px;
  }

  /* ========== BUTTONS - TOUCH FRIENDLY ========== */
  .btn {
    min-height: 48px; /* iOS recommended touch target */
    padding: 12px 20px;
    font-size: 16px;
    border-radius: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
    width: 100%;
  }

  .btn-sm {
    min-height: 40px;
    padding: 10px 15px;
    font-size: 14px;
  }

  .btn-icon-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .btn-icon-append {
    margin-left: auto;
  }

  /* ========== TABLES - MOBILE RESPONSIVE ========== */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 14px;
  }

  table th,
  table td {
    padding: 12px 8px;
    white-space: nowrap;
  }

  /* ========== FORMS - MOBILE FRIENDLY ========== */
  input,
  select,
  textarea,
  .form-control {
    min-height: 48px;
    padding: 12px 15px;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 8px;
  }

  .form-group {
    margin-bottom: 20px;
  }

  label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
  }

  /* ========== CHARTS - RESPONSIVE ========== */
  canvas {
    max-width: 100%;
    height: auto !important;
  }

  /* ========== FOOTER - MOBILE ========== */
  .footer {
    padding: 20px 15px;
    text-align: center;
  }

  .footer .d-sm-flex {
    display: block !important;
  }

  .footer span {
    display: block;
    margin: 10px 0;
    font-size: 12px;
  }

  /* ========== STATISTICS CARDS ========== */
  .grid-margin {
    margin-bottom: 15px;
  }

  .stretch-card {
    display: flex;
    flex-direction: column;
  }

  /* Make status numbers bigger on mobile */
  .card-body h1,
  .card-body h3,
  .card-body h4 {
    font-size: 28px;
    font-weight: 700;
  }

  .card-body h5 {
    font-size: 16px;
  }

  /* ========== DROPDOWNS - TOUCH FRIENDLY ========== */
  .dropdown-menu {
    min-width: 200px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }

  .dropdown-item {
    padding: 15px 20px;
    font-size: 16px;
  }

  /* ========== HIDE DESKTOP-ONLY ELEMENTS ========== */
  .settings-panel,
  #right-sidebar,
  .theme-setting-wrapper {
    display: none !important;
  }

  /* ========== PROJECT TABLE - MOBILE ========== */
  .project-orders-table {
    font-size: 13px;
  }

  .project-orders-table .btn {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
    margin: 2px;
    width: auto;
    display: inline-flex;
  }

  /* ========== TOUCH IMPROVEMENTS ========== */
  /* Larger tap targets */
  a, button, .clickable {
    min-height: 44px;
    min-width: 44px;
  }

  /* Remove hover effects on touch devices */
  @media (hover: none) {
    .btn:hover,
    .nav-link:hover {
      transform: none;
    }
  }

  /* Better scrolling */
  * {
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent text selection on buttons */
  button,
  .btn,
  .nav-link {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* ========== ONLINE/OFFLINE BADGE - MOBILE ========== */
  #online-status {
    top: 5px;
    right: 5px;
    padding: 4px 10px;
    font-size: 10px;
    z-index: 99999;
  }
}

/* =====================================================
   STANDALONE MODE (When installed as PWA)
   ===================================================== */

@media all and (display-mode: standalone) {
  
  /* Add app-like styling when installed */
  body {
    background: #f5f5f5;
  }

  /* Remove any lingering browser chrome */
  .navbar {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  }

  /* Add safe area for notched devices (iPhone X+) */
  .navbar {
    padding-top: env(safe-area-inset-top);
  }

  .main-panel {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Make install button invisible when already installed */
  #pwa-install-container {
    display: none !important;
  }

  /* Add app-like animations */
  .card {
    transition: transform 0.2s ease;
  }

  .card:active {
    transform: scale(0.98);
  }

  .btn:active {
    transform: scale(0.95);
  }
}

/* =====================================================
   LANDSCAPE MODE MOBILE
   ===================================================== */

@media only screen and (max-width: 768px) and (orientation: landscape) {
  
  .navbar {
    height: 50px;
  }

  .main-panel {
    margin-top: 50px;
  }

  .content-wrapper {
    padding: 10px;
  }

  .card-body {
    padding: 12px;
  }

  /* Make cards display in rows in landscape */
  .row {
    display: flex;
    flex-wrap: wrap;
  }

  .row > [class*="col-md-6"] {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

/* =====================================================
   SMALL PHONES (< 375px)
   ===================================================== */

@media only screen and (max-width: 375px) {
  
  .navbar {
    padding: 0 5px;
  }

  .content-wrapper {
    padding: 10px 5px;
  }

  .card-body {
    padding: 12px;
  }

  .btn {
    padding: 10px 15px;
    font-size: 14px;
  }

  table {
    font-size: 12px;
  }

  .card-body h1,
  .card-body h3 {
    font-size: 24px;
  }
}

/* =====================================================
   MOBILE NAVIGATION ENHANCEMENT
   ===================================================== */

@media only screen and (max-width: 768px) {
  
  /* Hamburger menu button */
  .navbar-toggler {
    display: flex !important;
    padding: 10px;
    border: none;
    background: transparent;
  }

  /* Mobile menu overlay */
  .sidebar-offcanvas {
    position: fixed;
    top: 60px;
    left: -100%;
    width: 80%;
    max-width: 300px;
    height: calc(100vh - 60px);
    background: white;
    z-index: 999;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
  }

  .sidebar-offcanvas.active {
    left: 0;
  }

  /* Backdrop when menu is open */
  .sidebar-backdrop {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    display: none;
  }

  .sidebar-backdrop.active {
    display: block;
  }
}

/* =====================================================
   PWA SPLASH SCREEN STYLES
   ===================================================== */

/* These styles show while the app is loading */
.pwa-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.pwa-loading-logo {
  width: 120px;
  height: 120px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

/* =====================================================
   ACCESSIBILITY IMPROVEMENTS FOR MOBILE
   ===================================================== */

/* Better focus indicators for keyboard navigation */
@media only screen and (max-width: 768px) {
  
  *:focus {
    outline: 2px solid #4B49AC;
    outline-offset: 2px;
  }

  /* Skip to content link for accessibility */
  .skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #4B49AC;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100000;
  }

  .skip-to-content:focus {
    top: 0;
  }
}

/* =====================================================
   DARK MODE SUPPORT (Respects system preference)
   ===================================================== */

@media (prefers-color-scheme: dark) and (max-width: 768px) {
  
  body {
    background: #1a1a1a;
    color: #ffffff;
  }

  .card {
    background: #2a2a2a;
    border-color: #3a3a3a;
  }

  .navbar {
    background: #2a2a2a !important;
  }

  .sidebar {
    background: #2a2a2a !important;
  }

  .btn {
    color: #ffffff;
  }

  input,
  select,
  textarea,
  .form-control {
    background: #3a3a3a;
    color: #ffffff;
    border-color: #4a4a4a;
  }
}

