/* Mobile app-shell fixes loaded last. */

@media (max-width: 768px) {
  :root {
    --page-shell-side: 0.75rem;
    --page-shell-content-top: 0.65rem;
  }

  .navbar {
    height: 64px;
    gap: 0.5rem;
    padding: 0 0.6rem;
  }

  .navbar .logo {
    margin-right: 0;
  }

  .navbar .logo-image {
    width: 44px;
    height: 44px;
  }

  .nav-menu-wrapper {
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible !important;
    -webkit-mask-image: none !important;
    mask-image: none !important;
  }

  .main-menu {
    align-items: center;
    display: flex;
    gap: 0.35rem;
    min-width: 0;
    width: 100%;
  }

  .main-menu > li {
    border-radius: 14px;
    min-height: 44px;
    min-width: 44px;
    padding: 0.55rem;
  }

  .main-menu > li span {
    display: none !important;
  }

  .main-menu > li i {
    font-size: 1.05rem;
  }

  .main-menu > li.more-dropdown {
    display: inline-flex !important;
    position: relative;
  }

  .main-menu > li.more-dropdown .dropdown-menu {
    left: 0.75rem;
    right: 0.75rem;
    top: 72px;
    position: fixed;
    transform: translateY(-8px);
    width: auto;
    max-height: min(68vh, 520px);
    overflow-y: auto;
    z-index: 3000;
  }

  .main-menu > li.more-dropdown.open .dropdown-menu,
  .main-menu > li.more-dropdown:focus-within .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .dropdown-menu li {
    min-height: 44px;
    opacity: 1;
  }

  .theme-toggle-btn,
  .fullscreen-toggle-btn,
  .logout-btn {
    border-radius: 14px;
    height: 44px;
    min-width: 44px;
    width: 44px;
  }

  .logout-btn {
    padding: 0;
  }

  .home-bg > main.main-content {
    padding-left: var(--page-shell-side) !important;
    padding-right: var(--page-shell-side) !important;
    overflow-x: hidden;
  }

  .profile-container,
  .dashboard-container,
  .reports-container,
  .question-bank-container,
  .subject-container,
  .users-container {
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  .analytics-section,
  .dashboard-charts-section {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 0.9rem !important;
  }

  .chart-card,
  .dashboard-charts-section .dashboard-card {
    height: clamp(260px, 62vh, 360px) !important;
    min-width: 0 !important;
    padding: 0.85rem !important;
  }

  .chart-container {
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .reports-table-container,
  .subjects-table-container,
  .users-table-container,
  .table-container,
  [class*="table-container"] {
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }

  .reports-table,
  .question-table,
  .subjects-table,
  .users-table,
  .user-table {
    min-width: 720px;
  }

  .profile-header {
    border-radius: 14px !important;
    margin-bottom: 0.85rem !important;
  }

  .profile-card {
    border-radius: 14px !important;
    margin-bottom: 0.85rem !important;
  }

  .profile-card .info-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .profile-card .info-item,
  .profile-card .stat-box {
    min-width: 0;
  }

  .profile-card .info-value,
  .profile-card .info-text,
  .profile-card .timeline-text {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media (max-width: 480px) {
  .reports-table,
  .question-table,
  .subjects-table,
  .users-table,
  .user-table {
    min-width: 660px;
  }

  .profile-card .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .profile-card .stat-box:nth-child(3) {
    grid-column: 1 / -1;
  }
}

html[data-theme="light"] .profile-container {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
}

html[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 20% 20%, rgba(129, 140, 248, 0.05) 0%, transparent 50%),
    linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%) !important;
}

html[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --text-primary: #e6edf3;
  --text-secondary: #94a3b8;
  --border-color: #334155;
}

html[data-theme="light"] .home-bg {
  background: linear-gradient(135deg, #eef4fb 0%, #dfeaf4 100%) !important;
}

html[data-theme="dark"] .home-bg {
  background:
    radial-gradient(circle at 20% 20%, rgba(129, 140, 248, 0.05) 0%, transparent 50%),
    linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%) !important;
}

html[data-theme="dark"] .profile-container {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --text-primary: #e6edf3;
  --text-secondary: #94a3b8;
  --border-color: #334155;
  --gray-50: #0f172a;
  --gray-100: #1e293b;
  --gray-200: #334155;
  --gray-500: #94a3b8;
  --gray-700: #e2e8f0;
  --gray-900: #f8fafc;
}

html[data-theme="light"] .profile-card {
  background: #ffffff !important;
  border-color: rgba(129, 140, 248, 0.15) !important;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1) !important;
}

html[data-theme="light"] .profile-card .card-title {
  background: #eef2ff !important;
  color: #334155 !important;
  border-bottom-color: #dbe3f3 !important;
}

html[data-theme="light"] .profile-card .stat-box,
html[data-theme="light"] .profile-card .info-item {
  border-color: #eef2f7 !important;
}

html[data-theme="light"] .profile-card .info-value,
html[data-theme="light"] .profile-card .timeline-text {
  color: #1e293b !important;
}

html[data-theme="dark"] .profile-card {
  background: #1e293b !important;
  border-color: rgba(129, 140, 248, 0.18) !important;
}

html[data-theme="dark"] .profile-card .card-title {
  background: rgba(129, 140, 248, 0.15) !important;
  color: #f8fafc !important;
}
