@media (max-width: 768px) {

  /* Hide desktop UI */
  .sidebar { display: none; }
  .filter-bar { display: none; }

  /* Make space for mobile header */
  .app-shell {
    grid-template-columns: 1fr;
    padding-top: 56px;
  }

  /* ---------------------- */
  /* MOBILE HEADER          */
  /* ---------------------- */
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--card-border);
  }

  .mobile-hamburger {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 0;
    cursor: pointer;
  }

  .mobile-hamburger span {
    height: 2px;
    width: 20px;
    background: var(--text-main);
    border-radius: 999px;
  }

  .mobile-logo img {
    height: 28px;
    object-fit: contain;
  }

  .mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 9999;
  }

  .mobile-theme-toggle {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
  }

  .mobile-avatar-wrapper {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
  }

  .mobile-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* ---------------------- */
  /* DRAWER                 */
  /* ---------------------- */
  .mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10000;
  }

  .mobile-drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--card-border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 10001;
    overflow-y: auto;
  }

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

  /* Make cloned sidebar visible */
  .mobile-drawer .sidebar {
    display: block !important;
  }

  /* ---------------------- */
  /* FILTER BUTTON + SHEET  */
  /* ---------------------- */
  #mobileFilterButton {
    position: sticky;
    top: 48px;
    z-index: 9998;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-elevated);
    color: var(--text-main);
    border: none;
    border-bottom: 1px solid var(--card-border);
    text-align: left;
    cursor: pointer;
  }

  .mobile-filter-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10000;
  }

  .mobile-filter-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-filter-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-elevated);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    transform: translateY(100%);
    transition: transform 0.2s ease;
    z-index: 10001;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
  }

  .mobile-filter-sheet.active {
    transform: translateY(0);
  }

  .sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--card-border);
  }

  .sheet-content {
    padding: 12px 16px;
    overflow-y: auto;
  }

  .sheet-footer {
    padding: 12px 16px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid var(--card-border);
  }

  .sheet-close {
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 18px;
    cursor: pointer;
  }

  .sheet-clear {
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
  }

  .sheet-apply {
    background: #ffc800;
    color: #000;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
  }

  /* Make filter bar visible inside sheet */
  .mobile-filter-sheet .filter-bar {
    display: block !important;
  }

  /* ---------------------- */
  /* KPI GRID (2×2)         */
  /* ---------------------- */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }

  .kpi-card {
    padding: 12px !important;
  }

  /* ---------------------- */
  /* GRAPHS — FIXED         */
  /* ---------------------- */

  /* Force grid to one column */
  .content-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  /* Force each graph card to fit the viewport */
  .content-grid > .card {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  /* Prevent inner content from pushing width */
  .card-body {
    padding: 12px !important;
    overflow-x: hidden !important;
  }

  /* Make canvas scale properly */
  .card-body canvas {
    width: 100% !important;
    height: 220px !important;
    max-width: 100% !important;
    display: block !important;
  }

    .content-grid .leaderboard-card {
    grid-column: 1 / -1 !important;
  }

    /* Leaderboard scroll container */
  .leaderboard-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px; /* space for scrollbar */
  }

  /* Ensure the table is wider than the viewport */
  .leaderboard-scroll table {
    min-width: 900px; /* adjust if needed */
    width: max-content;
  }

  /* Keep the card frame fixed */
  .leaderboard-card {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

    /* Allow horizontal scrolling inside leaderboard */
  .leaderboard-card .card-body {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }

  /* Make the table wider than the viewport */
  .leaderboard-card .card-body table {
    width: max-content !important;
    min-width: 900px !important;
  }

  /* ---------------------- */
  /* Card polish            */
  /* ---------------------- */
  .card {
    border-radius: 10px;
  }
}
