/* ============================================= */
/* UNIVERSAL MOBILE RESPONSIVE CSS */
/* For Track IQ System - Preserves All Existing Layout */
/* ============================================= */

/* Mobile First Approach */
@media screen and (max-width: 768px) {
  
  /* Mobile Header */
  .mobile-header {
    display: flex;
    background: var(--sidebar-background, #1e2126);
    color: white;
    padding: 12px 15px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    height: 60px;
  }

  .mobile-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .mobile-menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
    margin: 0;
  }

  .mobile-logout-btn {
    background: var(--danger-color, #dc3545);
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Mobile Overlay */
  .mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
  }

  .mobile-overlay.active {
    display: block;
  }

  /* Sidebar Mobile Transform */
  .mobile-sidebar {
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    border-radius: 0;
    padding-top: 70px;
  }

  .mobile-sidebar.active {
    transform: translateX(0);
  }

  /* Main Content Mobile Adjustments - REDUCED RIGHT PADDING */
  .mobile-main {
    margin-left: 0 !important;
    padding: 80px 0 20px 0 !important;
    width: 100%;
    max-width: 100%;
    overflow-x: visible;
  }

  /* Add padding to content sections instead - REDUCED RIGHT PADDING */
  .mobile-main > * {
    padding-left: 15px;
    padding-right: 3px !important; /* Reduced from 5px to 3px */
  }

  /* Prevent body scroll when menu is open */
  body.menu-open {
    overflow: hidden;
  }

  /* Widgets Mobile Layout - FIXED: Minimal right gap */
  .mobile-widgets {
    grid-template-columns: 1fr !important;
    gap: 15px;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .mobile-card {
    width: 100% !important;
    height: 180px;
    margin: 0 auto;
  }

  /* NEW: Status Toggle Mobile Styles */
  .status-toggle-container {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: 15px 0 10px 0;
  }

  .status-toggle-btn {
    width: 90%;
    min-height: 44px;
    padding: 12px 16px;
    font-size: 14px;
    margin: 2px 0;
  }

  /* Table Responsive Container - FIXED: Minimal right gap */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 15px 0;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 8px;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .table-container table {
    min-width: 600px;
  }

  /* Audit Log Table Specific Mobile Styles - NEW */
  .audit-log-table-container {
    max-height: 500px;
    margin: 15px 0;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 8px;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .audit-log-table-container table {
    min-width: 800px; /* Increased to accommodate Date & Time column */
  }

  .audit-log-table-container th,
  .audit-log-table-container td {
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Adjust column widths for mobile */
  .audit-log-table-container th:nth-child(1),
  .audit-log-table-container td:nth-child(1) {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
  }

  .audit-log-table-container th:nth-child(2),
  .audit-log-table-container td:nth-child(2) {
    width: 140px;
    min-width: 140px;
    max-width: 140px;
  }

  .audit-log-table-container th:nth-child(3),
  .audit-log-table-container td:nth-child(3) {
    width: 100px;
    min-width: 100px;
    max-width: 100px;
  }

  .audit-log-table-container th:nth-child(4),
  .audit-log-table-container td:nth-child(4) {
    width: 180px;
    min-width: 180px;
    max-width: 180px;
  }

  .audit-log-table-container th:nth-child(5),
  .audit-log-table-container td:nth-child(5) {
    width: auto;
    min-width: 200px;
  }

  /* MOBILE SUPPORT ICONS - ARRANGED IN COLUMN */
  .whatsapp-support.mobile-support {
    position: fixed;
    right: 15px;
    bottom: 85px;
    width: 50px;
    height: 50px;
    background: #25D366;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 999;
    font-size: 1.5rem;
    transition: transform 0.2s ease;
  }

  .email-support.mobile-support {
    position: fixed;
    right: 15px;
    bottom: 15px;
    width: 50px;
    height: 50px;
    background: var(--primary-color, #003366);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 999;
    font-size: 1.3rem;
    cursor: pointer;
    transition: transform 0.2s ease;
    border: none;
  }

  .whatsapp-support.mobile-support:hover,
  .email-support.mobile-support:hover {
    transform: scale(1.1);
  }

  /* Support tooltips */
  .whatsapp-tooltip,
  .email-tooltip {
    position: absolute;
    right: 60px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .whatsapp-tooltip {
    bottom: 10px;
  }

  .email-tooltip {
    bottom: 10px;
  }

  .whatsapp-support.mobile-support:hover .whatsapp-tooltip,
  .email-support.mobile-support:hover .email-tooltip {
    opacity: 1;
  }

  /* Button Sizes for Touch */
  .report-btn, .delete-btn, #notifyBtn, #searchBtn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px !important;
  }

  /* Form Elements Touch Friendly */
  input, select, textarea {
    min-height: 44px;
    font-size: 16px !important;
  }

  /* Chart Container Mobile - FIXED: Minimal right gap */
  .chart-container {
    padding: 15px;
    margin: 10px 0;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  /* Calendar Mobile - FIXED: Minimal right gap */
  #calendar {
    max-width: 100% !important;
    padding: 15px !important;
    margin-right: 0 !important;
  }

  /* Notification Section Mobile - FIXED: Minimal right gap */
  .notifications-section {
    padding: 15px;
    margin-top: 20px;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .notify-label {
    font-size: 1.2rem;
  }

  #notifyBtn {
    width: 100%;
  }

  /* Devices Section Mobile - FIXED: Minimal right gap */
  .devices-section {
    padding: 15px;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  /* Modal Mobile */
  .modal-content {
    width: 95% !important;
    margin: 20px;
    max-width: none !important;
  }

  /* Analytics Insights Mobile - NEW */
  .analytics-insights {
    padding: 12px;
    margin: 15px 0;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }
  
  .insight-item {
    font-size: 13px;
    padding: 6px 10px;
    margin: 3px 0;
  }
}

/* Tablet Styles - REDUCED RIGHT PADDING */
@media screen and (min-width: 769px) and (max-width: 1024px) {
  .mobile-header {
    display: none;
  }
  
  .mobile-main {
    margin-left: 200px !important;
    padding: 30px 0 !important;
    max-width: calc(100vw - 200px);
  }

  /* Add padding to content sections instead - REDUCED RIGHT PADDING */
  .mobile-main > * {
    padding-left: 20px;
    padding-right: 5px !important; /* Reduced from 8px to 5px */
  }

  .mobile-widgets {
    grid-template-columns: repeat(2, 1fr) !important;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  /* NEW: Status Toggle Tablet Styles */
  .status-toggle-container {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .status-toggle-btn {
    min-width: 140px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .table-container {
    overflow-x: auto;
    margin-right: 0 !important;
  }

  /* Audit Log Table Specific Tablet Styles - NEW */
  .audit-log-table-container {
    max-height: 400px;
    margin: 15px 0;
  }

  .audit-log-table-container table {
    min-width: 800px;
  }

  .audit-log-table-container th,
  .audit-log-table-container td {
    padding: 10px 12px;
    font-size: 14px;
  }

  /* Tablet Support Icons - Column Layout */
  .whatsapp-support.mobile-support {
    right: 20px;
    bottom: 90px;
  }

  .email-support.mobile-support {
    right: 20px;
    bottom: 20px;
  }

  /* Analytics Insights Tablet - NEW */
  .analytics-insights {
    margin-right: 0 !important;
    padding-right: 0 !important;
  }
}

/* Desktop Enhancement - REDUCED RIGHT PADDING */
@media screen and (min-width: 1025px) {
  .mobile-header {
    display: none;
  }

  /* MAIN FIX: Prevent horizontal overflow and reduce right gap */
  .mobile-main {
    margin-left: 200px !important;
    padding: 30px 0 !important;
    max-width: calc(100vw - 200px);
    box-sizing: border-box;
    width: 100%;
  }

  /* Add padding to content sections instead - REDUCED RIGHT PADDING */
  .mobile-main > * {
    padding-left: 30px;
    padding-right: 5px !important; /* Reduced from 10px to 5px */
  }

  /* NEW: Status Toggle Desktop Styles */
  .status-toggle-container {
    justify-content: center;
    gap: 15px;
    margin: 20px 0 15px 0;
  }

  .status-toggle-btn {
    min-width: 120px;
    padding: 10px 20px;
    font-size: 14px;
    transition: all 0.3s ease;
  }

  .status-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }

  /* Ensure content doesn't exceed viewport - FIXED: Minimal right gap */
  .widgets {
    max-width: 100%;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .chart-analysis-container {
    max-width: 100%;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .devices-section {
    max-width: 100%;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  /* Table container for desktop - FIXED: Minimal right gap */
  .table-container {
    overflow-x: auto;
    max-width: 100%;
    margin-right: 0 !important;
  }

  /* Audit Log Table Specific Desktop Styles - NEW */
  .audit-log-table-container {
    max-height: 400px;
    margin: 15px 0;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
  }

  .audit-log-table-container table {
    width: 100%;
    min-width: 800px;
  }

  .audit-log-table-container th,
  .audit-log-table-container td {
    padding: 10px 12px;
    border: 1px solid var(--border-color, #ddd);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .audit-log-table-container thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--header-bg, #1e3a6d);
  }

  /* Desktop Support Icons - Column Layout */
  .whatsapp-support.mobile-support {
    display: block !important;
    right: 25px;
    bottom: 100px;
    width: 55px;
    height: 55px;
  }

  .email-support.mobile-support {
    display: block !important;
    right: 25px;
    bottom: 25px;
    width: 55px;
    height: 55px;
  }

  /* Analytics Insights Desktop - NEW */
  .analytics-insights {
    margin-right: 0 !important;
    padding-right: 0 !important;
  }
}

/* Large Desktop Screens - REDUCED RIGHT PADDING */
@media screen and (min-width: 1440px) {
  .mobile-main {
    max-width: min(calc(100vw - 200px), 1400px);
    margin-left: 200px !important;
    padding: 30px 0 !important;
  }

  /* Add padding to content sections instead - REDUCED RIGHT PADDING */
  .mobile-main > * {
    padding-left: 40px;
    padding-right: 8px !important; /* Reduced from 15px to 8px */
  }

  /* NEW: Status Toggle Large Desktop Styles */
  .status-toggle-container {
    gap: 20px;
  }

  .status-toggle-btn {
    min-width: 140px;
    padding: 12px 24px;
    font-size: 15px;
  }

  .widgets {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  /* Audit Log Table Large Desktop Styles - NEW */
  .audit-log-table-container {
    max-height: 500px;
  }

  .audit-log-table-container th,
  .audit-log-table-container td {
    padding: 12px 15px;
  }

  /* Large Screen Support Icons */
  .whatsapp-support.mobile-support {
    right: 30px;
    bottom: 110px;
  }

  .email-support.mobile-support {
    right: 30px;
    bottom: 35px;
  }
}

/* Extra Large Screens - REDUCED RIGHT PADDING */
@media screen and (min-width: 1920px) {
  .mobile-main {
    max-width: min(calc(100vw - 200px), 1600px);
    margin: 0 auto 0 200px !important;
    padding: 30px 0 !important;
  }

  /* Add padding to content sections instead - REDUCED RIGHT PADDING */
  .mobile-main > * {
    padding-left: 40px;
    padding-right: 8px !important; /* Reduced from 15px to 8px */
  }

  /* NEW: Status Toggle Extra Large Styles */
  .status-toggle-container {
    gap: 25px;
  }

  .status-toggle-btn {
    min-width: 150px;
    padding: 14px 28px;
    font-size: 16px;
  }

  /* Audit Log Table Extra Large Styles - NEW */
  .audit-log-table-container {
    max-height: 600px;
  }

  .audit-log-table-container th,
  .audit-log-table-container td {
    padding: 14px 18px;
    font-size: 15px;
  }

  /* Extra Large Screen Support Icons */
  .whatsapp-support.mobile-support {
    right: 40px;
    bottom: 120px;
  }

  .email-support.mobile-support {
    right: 40px;
    bottom: 45px;
  }
}

/* NEW: Status Toggle Animation Enhancements */
.status-toggle-btn {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.status-toggle-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  transition: width 0.3s, height 0.3s, top 0.3s, left 0.3s;
  transform: translate(-50%, -50%);
}

.status-toggle-btn:active::after {
  width: 100px;
  height: 100px;
}

/* NEW: Filter Controls Responsive Layout */
.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 15px;
}

@media screen and (max-width: 768px) {
  .table-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .table-controls input,
  .table-controls button {
    width: 100%;
    margin: 2px 0;
  }
  
  .table-controls > * {
    flex: 1 1 100%;
  }
}

@media screen and (min-width: 769px) and (max-width: 1024px) {
  .table-controls {
    gap: 8px;
  }
  
  .table-controls input {
    flex: 1;
    min-width: 120px;
  }
}

/* NEW: Pagination Responsive Styles */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 15px 0;
  flex-wrap: wrap;
}

@media screen and (max-width: 768px) {
  .pagination {
    gap: 8px;
  }
  
  .pagination button {
    min-width: 80px;
    padding: 10px 12px;
  }
  
  #pageInfo {
    font-size: 14px;
    margin: 0 5px;
  }
}

/* Universal Mobile Hide/Show Helpers */
.mobile-only {
  display: none;
}

@media screen and (max-width: 768px) {
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
}

/* Print Styles */
@media print {
  .mobile-header,
  .sidebar,
  .whatsapp-support,
  .email-support,
  .button-bar,
  .status-toggle-container,
  .table-controls,
  .pagination {
    display: none !important;
  }
  
  .mobile-main {
    margin-left: 0 !important;
    padding: 20px !important;
  }

  .audit-log-table-container {
    max-height: none !important;
    border: none !important;
  }
}

/* NEW: Enhanced Loading States for Status Toggle */
.status-toggle-container.loading .status-toggle-btn {
  opacity: 0.6;
  pointer-events: none;
}

.status-toggle-container.loading::before {
  content: 'Loading...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  z-index: 10;
}

/* NEW: Focus States for Accessibility */
.status-toggle-btn:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.table-controls input:focus,
.table-controls button:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 1px;
}

/* NEW: High Contrast Mode Support */
@media (prefers-contrast: high) {
  .status-toggle-btn {
    border-width: 2px;
  }
  
  .status-toggle-btn.active {
    border-width: 3px;
  }
}

/* NEW: Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .status-toggle-btn {
    transition: none;
  }
  
  .status-toggle-btn::after {
    display: none;
  }
}
