/* Keep mobile topbar, account menu, and bottom navbar balanced across every
   account role and tab count (including 4-tab and 5-tab farmer/admin bars). */
@media (max-width: 767px) {
  header.topbar {
    overflow: visible !important;
    gap: clamp(4px, 2vw, 10px) !important;
    min-height: 54px !important;
    height: auto !important;
    max-height: none !important;
    padding: 6px 10px !important;
  }

  .topbar .page-title-section {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  .actions-section.topbar-right {
    display: flex !important;
    align-items: center;
    flex: 0 0 auto;
    gap: 6px !important;
    min-width: max-content;
    margin-left: auto;
  }

  .profile-menu {
    position: relative !important;
    z-index: 95 !important;
    flex: 0 0 auto;
  }

  .profile-pill-btn {
    min-width: 44px !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 3px 8px 3px 4px !important;
    touch-action: manipulation;
  }

  .profile-dropdown:not(.notif-dropdown) {
    position: fixed !important;
    inset-block-start: calc(env(safe-area-inset-top, 0px) + 66px) !important;
    inset-inline-start: auto !important;
    inset-inline-end: max(12px, env(safe-area-inset-right, 12px)) !important;
    width: min(280px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 84px) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    z-index: 1101 !important;
  }

  .profile-dropdown .pd-header p {
    overflow-wrap: anywhere;
  }

  /* Adapt columns automatically to the rendered tab count (4 or 5 items)
     so non-CCTV farmer accounts never show an empty 5th column on the right. */
  nav.mobile-bottom-nav {
    display: grid !important;
    grid-template-columns: none !important;
    grid-auto-flow: column !important;
    grid-auto-columns: minmax(0, 1fr) !important;
    align-items: center !important;
    justify-items: center !important;
    padding: 6px 8px !important;
    bottom: max(12px, calc(8px + env(safe-area-inset-bottom, 0px))) !important;
  }

  nav.mobile-bottom-nav .mobile-nav-item {
    width: 100% !important;
    max-width: 84px !important;
    min-width: 0 !important;
    justify-self: center !important;
  }
}

/* Uploaded farmer photos should fill the round account avatar without distortion. */
.profile-pill-btn .profile-avatar {
  overflow: hidden !important;
  flex: 0 0 auto;
}

.profile-pill-btn .profile-avatar img {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  border-radius: 50% !important;
}
