/**
 * myLogbook mega menu — Zone 1.
 */

.ml-mega-menu {
  /* visual treatment (bg/border) now lives on .ml-mega-menu-row, the
     actual flex container that also holds the search box */
}

.ml-mega-menu-row {
  display: flex;
  align-items: center;
  background-color: var(--ml-bg-surface);
  border-bottom: 1px solid var(--ml-border);
}

.ml-mega-menu-flex {
  flex: 1;
  min-width: 0;
}

.ml-mega-menu-bar {
  display: flex;
  align-items: stretch;
  list-style: none;
  margin: 0;
  padding: 0 var(--ml-space-lg);
  height: var(--ml-menubar-height);
  gap: var(--ml-space-3xs);
}

.ml-mega-menu-item {
  position: relative;
  display: flex;
}

.ml-mega-menu-trigger-group {
  display: flex;
  align-items: center;
  height: 100%;
}

.ml-mega-menu-trigger {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 0 0 var(--ml-space-sm);
  font-family: var(--ml-font-sans);
  font-size: var(--ml-text-sm);
  font-weight: 600;
  color: var(--ml-text-secondary);
  text-decoration: none;
  white-space: nowrap;
}

.ml-mega-menu-trigger-plain {
  padding-inline-end: var(--ml-space-sm);
}

.ml-mega-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 var(--ml-space-sm);
  background: none;
  border: none;
  color: var(--ml-text-secondary);
  cursor: pointer;
}

.ml-mega-menu-trigger:hover,
.ml-mega-menu-toggle:hover,
.ml-mega-menu-item.is-open .ml-mega-menu-trigger,
.ml-mega-menu-item.is-open .ml-mega-menu-toggle {
  color: var(--ml-accent);
}

.ml-mega-menu-caret {
  transition: transform var(--ml-dur-fast) var(--ml-ease);
  flex-shrink: 0;
}

.ml-mega-menu-item.is-open .ml-mega-menu-caret {
  transform: rotate(180deg);
}

.ml-mega-menu-panel {
  display: none;
  position: absolute;
  top: 100%;
  inset-inline-start: 0;
  background-color: var(--ml-bg-surface);
  border: 1px solid var(--ml-border);
  border-radius: 0 0 var(--ml-radius-md) var(--ml-radius-md);
  box-shadow: var(--ml-shadow-md);
  padding: var(--ml-space-md);
  z-index: 40;
  min-width: 220px;
}

.ml-mega-menu-panel.is-open {
  display: block;
}

.ml-mega-menu-panel.is-multi-col {
  min-width: 640px;
}

.ml-mega-menu-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--ml-space-lg);
}

.ml-mega-menu-column-heading {
  display: block;
  font-size: var(--ml-text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ml-accent);
  text-decoration: none;
  margin-bottom: var(--ml-space-xs);
}

.ml-mega-menu-column-heading:hover {
  text-decoration: underline;
}

.ml-mega-menu-column ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ml-mega-menu-simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 180px;
}

.ml-mega-menu-column a,
.ml-mega-menu-simple-list a,
.ml-mega-menu-column-link {
  display: block;
  padding: 4px 0;
  font-size: var(--ml-text-sm);
  color: var(--ml-text-secondary);
  text-decoration: none;
}

.ml-mega-menu-column a:hover,
.ml-mega-menu-simple-list a:hover,
.ml-mega-menu-column-link:hover {
  color: var(--ml-accent);
}

.ml-mega-menu-search {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ml-mega-menu-search input[type="search"] {
  width: 180px;
  max-width: 40vw;
  font-family: var(--ml-font-sans);
  font-size: var(--ml-text-sm);
  padding: var(--ml-space-3xs) var(--ml-space-sm);
  border: 1px solid var(--ml-border-strong);
  border-radius: var(--ml-radius-sm);
  background-color: var(--ml-bg-page);
  color: var(--ml-text-primary);
}

/* Hamburger toggle for the top-level category bar — this, not the left
   "Browse" sidebar, was the actual menu filling the whole screen on
   phones: every top-level category listed vertically with no collapse
   behavior at all (only the dropdown panels collapsed). Hidden on
   desktop; JS (assets/js/mega-menu.js) toggles [data-mega-menu-open] on
   <html> when tapped. */
.ml-mega-menu-hamburger {
  display: none;
  align-items: center;
  gap: var(--ml-space-xs);
  width: 100%;
  padding: var(--ml-space-sm) var(--ml-space-lg);
  background: none;
  border: none;
  border-bottom: 1px solid var(--ml-border);
  font-family: var(--ml-font-sans);
  font-size: var(--ml-text-sm);
  font-weight: 700;
  color: var(--ml-text-primary);
  cursor: pointer;
  text-align: start;
}

/* Basic responsive collapse — inline accordion instead of dropdown panels. */
@media (max-width: 900px) {
  .ml-mega-menu-hamburger {
    display: flex;
  }

  .ml-mega-menu-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ml-mega-menu-bar {
    display: none;
    flex-direction: column;
    height: auto;
    overflow-x: visible;
    padding: var(--ml-space-xs) 0;
  }

  html[data-mega-menu-open] .ml-mega-menu-bar {
    display: flex;
  }

  .ml-mega-menu-item {
    flex-direction: column;
  }

  .ml-mega-menu-trigger-group {
    justify-content: space-between;
  }

  .ml-mega-menu-trigger {
    height: auto;
    padding: var(--ml-space-xs) var(--ml-space-lg);
  }

  .ml-mega-menu-toggle {
    height: auto;
    padding: var(--ml-space-xs) var(--ml-space-lg);
  }

  .ml-mega-menu-panel {
    display: none;
    position: static;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: var(--ml-space-2xs) var(--ml-space-lg) var(--ml-space-sm) calc(var(--ml-space-lg) + var(--ml-space-sm));
    min-width: 0;
  }

  .ml-mega-menu-panel.is-open {
    display: block;
  }

  .ml-mega-menu-panel.is-multi-col {
    min-width: 0;
  }

  .ml-mega-menu-columns {
    grid-template-columns: 1fr;
    gap: var(--ml-space-md);
  }

  .ml-mega-menu-search {
    margin-inline-start: 0;
    padding: var(--ml-space-xs) var(--ml-space-lg);
  }

  .ml-mega-menu-search input[type="search"] {
    width: 100%;
    max-width: none;
  }
}

/* Same rules as the @media (max-width: 900px) block above, forced on
   regardless of actual viewport width — see grid.css for the toolbar's
   "📱 Mobile" preview toggle mechanism. */
html[data-force-mobile] .ml-mega-menu-hamburger {
  display: flex;
}

html[data-force-mobile] .ml-mega-menu-row {
  flex-direction: column;
  align-items: stretch;
}

html[data-force-mobile] .ml-mega-menu-bar {
  display: none;
  flex-direction: column;
  height: auto;
  overflow-x: visible;
  padding: var(--ml-space-xs) 0;
}

html[data-force-mobile][data-mega-menu-open] .ml-mega-menu-bar {
  display: flex;
}

html[data-force-mobile] .ml-mega-menu-item {
  flex-direction: column;
}

html[data-force-mobile] .ml-mega-menu-trigger-group {
  justify-content: space-between;
}

html[data-force-mobile] .ml-mega-menu-trigger,
html[data-force-mobile] .ml-mega-menu-toggle {
  height: auto;
  padding: var(--ml-space-xs) var(--ml-space-lg);
}

html[data-force-mobile] .ml-mega-menu-panel {
  display: none;
  position: static;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: var(--ml-space-2xs) var(--ml-space-lg) var(--ml-space-sm) calc(var(--ml-space-lg) + var(--ml-space-sm));
  min-width: 0;
}

html[data-force-mobile] .ml-mega-menu-panel.is-open {
  display: block;
}

html[data-force-mobile] .ml-mega-menu-panel.is-multi-col {
  min-width: 0;
}

html[data-force-mobile] .ml-mega-menu-columns {
  grid-template-columns: 1fr;
  gap: var(--ml-space-md);
}

html[data-force-mobile] .ml-mega-menu-search {
  margin-inline-start: 0;
  padding: var(--ml-space-xs) var(--ml-space-lg);
}

html[data-force-mobile] .ml-mega-menu-search input[type="search"] {
  width: 100%;
  max-width: none;
}

[data-mode="dark"] .ml-mega-menu-search input[type="search"] {
  background-color: var(--ml-bg-muted);
}

/* Shared with the sidebar browse tree (inc/sidebar-tree-render.php) —
   deliberately muted/small so it reads as supplementary info, not
   competing with the actual label text for attention. */
.ml-menu-count {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--ml-text-muted);
  opacity: 0.8;
}
