/* v0.1.25 grouped menus. Dropdowns from 768px. Phone sheet below that.
   Every row is at least 44px. Text stays at least 12px. No sideways scroll. */

.menu-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 8px 16px 0;
}

.menu-groups {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.menu-group {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.menu-sheet-btn,
.menu-group-btn,
.menu-item,
.menu-field input,
.menu-field select {
  min-height: 44px;
  min-width: 44px;
  box-sizing: border-box;
  font-size: 14px;
  line-height: 1.3;
  font-family: inherit;
}

.menu-group-btn,
.menu-sheet-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.menu-group-btn[aria-expanded="true"] {
  border-color: var(--text);
}

.menu-pop {
  position: absolute;
  z-index: 80;
  top: 100%;
  left: 0;
  min-width: 240px;
  max-width: min(360px, calc(100vw - 16px));
  overflow: auto;
  margin-top: 4px;
  padding: 6px 0;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
}

.menu-pop[hidden] {
  display: none;
}

.menu-pop[data-side="up"] {
  margin-top: 0;
  margin-bottom: 4px;
}

.menu-section-label {
  padding: 8px 14px 2px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
}

.menu-item[aria-checked="true"] {
  background: var(--tag-bg);
  font-weight: 600;
}

.menu-item:focus-visible,
.menu-group-btn:focus-visible,
.menu-sheet-btn:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.menu-count {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--text-muted);
}

.menu-field,
.menu-field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text);
}

.menu-field-row {
  flex-direction: row;
  align-items: flex-end;
}

.menu-field input,
.menu-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg, var(--card-bg));
  color: var(--text);
}

.where-line {
  margin: 0;
  padding: 8px 16px 4px;
  max-width: 100%;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-secondary, var(--text));
  overflow-wrap: anywhere;
}

body.dark-mode .menu-pop {
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

/* Wide desk: the six menus replace the scattered controls. Search, Ready to
   contact and Follow-ups due stay. Add contact stays in the sidebar. */
@media (min-width: 768px) {
  .menu-sheet-btn {
    display: none;
  }

  body.menus-wide #toolsToggle,
  body.menus-wide #toolsPanel,
  body.menus-wide .desk-tabs,
  body.menus-wide .sort-control,
  body.menus-wide #advFiltersToggle,
  body.menus-wide .view-switcher,
  body.menus-wide #commandPaletteBtn,
  body.menus-wide #darkModeToggle,
  body.menus-wide #namedPresetChips,
  body.menus-wide #photoFillCountBtn,
  body.menus-wide #newApplicationsChip,
  body.menus-wide
    #quickFilterChips
    .quick-chip:not([data-filter="readyToContact"]) {
    display: none !important;
  }
}

/* Phones keep the compact layout. The six groups are one bottom sheet. */
@media (max-width: 767px) {
  .menu-groups {
    display: none;
  }

  .menu-groups.is-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    max-height: calc(100vh - 72px);
    max-height: calc(100dvh - 72px);
    overflow: auto;
    padding: 8px 8px calc(12px + env(safe-area-inset-bottom));
    background: var(--card-bg);
    color: var(--text);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
  }

  .menu-groups.is-sheet .menu-group {
    position: static;
  }

  .menu-groups.is-sheet .menu-pop,
  .menu-groups.is-sheet .menu-pop[hidden] {
    display: block;
    position: static;
    max-height: none;
    max-width: 100%;
    min-width: 0;
    margin: 0 0 8px;
    box-shadow: none;
    overflow: visible;
  }
}
