/* Shared, fixed-height navigation. Reading controls belong to the reader. */
.mley-site-header,
.mley-header-search-dialog,
.mley-reading-controls {
  font-family: var(--font-ui);
  color: var(--text-color);
}
.fixed-header.mley-site-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: none;
}
.mley-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 60px;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
}
.mley-header-control,
.mley-header-brand,
.mley-header-context,
.mley-reading-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-color);
  font: inherit;
  font-size: var(--text-small);
  line-height: var(--leading-heading);
  text-decoration: none;
  box-sizing: border-box;
}
.mley-header-control { cursor: pointer; }
.mley-header-row .mley-header-control { height: 44px; }
.mley-header-control:hover,
.mley-header-brand:hover,
.mley-header-context[href]:hover,
.mley-reading-controls button:not(:disabled):hover {
  color: var(--text-color);
  background: var(--bg-surface-2);
  text-decoration: none;
}
.mley-header-control[aria-expanded="true"] { background: var(--surface-accent); color: var(--accent-color); }
.mley-header-search-group {
  position: relative; display: flex; align-items: center;
  flex: 1 1 280px; min-width: 180px; max-width: 720px; height: 44px; margin-left: auto;
  border-radius: 8px; background: var(--bg-surface-2);
}
.mley-header-search-group::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  border: 1px solid var(--border-color); border-radius: inherit;
}
.mley-header-search-group:focus-within::after { border-color: var(--accent-color); }
.mley-header-explore { position: relative; flex: 0 0 44px; min-width: 44px; }
.mley-header-explore-trigger {
  position: relative; list-style: none; width: 44px; padding: 0;
  border: 0; border-radius: 0 8px 8px 0; color: var(--text-muted); cursor: pointer;
}
.mley-header-explore-trigger::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px;
  width: 1px; background: var(--border-color); pointer-events: none;
}
.mley-header-explore-trigger::-webkit-details-marker { display: none; }
.mley-header-explore-trigger::marker { content: ""; }
.mley-header-explore-trigger svg { flex-shrink: 0; }
.mley-header-explore[open] > summary {
  background: var(--surface-accent); color: var(--accent-color);
}
.mley-header-explore-trigger:hover { background: var(--surface-accent); color: var(--accent-color); }
.mley-header-explore-tooltip {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 1;
  width: max-content; padding: 6px 9px; pointer-events: none; visibility: hidden;
  border: 1px solid var(--border-color); border-radius: 6px;
  background: var(--bg-surface); color: var(--text-color);
  font-size: var(--text-caption); box-shadow: var(--shadow-card);
}
.mley-header-explore:not([open]) > summary:focus-visible .mley-header-explore-tooltip { visibility: visible; }
@media (hover: hover) {
  .mley-header-explore:not([open]) > summary:hover .mley-header-explore-tooltip { visibility: visible; }
}
.mley-header-explore-panel {
  position: absolute; top: calc(100% + 12px); right: 0; z-index: 1;
  width: 344px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 88px - env(safe-area-inset-bottom, 0px));
  padding: 12px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
  border: 1px solid var(--border-color); border-radius: 18px; box-sizing: border-box;
  background: var(--bg-surface); color: var(--text-color); box-shadow: var(--shadow-card);
}
.mley-header-explore:not([open]) > .mley-header-explore-panel { display: none; }
.mley-header-explore[open] > .mley-header-explore-panel { animation: mley-explore-enter 140ms ease-out; }
.mley-header-explore-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 0 8px 8px; }
.mley-header-explore-heading h2 { margin: 0; font: inherit; font-size: var(--text-small); font-weight: var(--weight-semibold); }
.mley-header-explore-panel .mley-site-navigation {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none;
}
.mley-header-explore-panel li { min-width: 0; margin: 0; }
.mley-header-explore-panel .mley-site-navigation a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-height: 80px; height: 100%; padding: 12px 8px; box-sizing: border-box;
  border: 1px solid var(--border-color); border-radius: 12px;
  background: var(--bg-surface); color: var(--text-color); font-size: var(--text-small);
  line-height: var(--leading-compact); text-align: center; text-decoration: none; overflow-wrap: anywhere;
}
.mley-header-explore-panel .mley-site-navigation a:hover,
.mley-header-explore-panel .mley-site-navigation a[aria-current] {
  border-color: var(--accent-color); background: var(--surface-accent); color: var(--accent-color);
}
.mley-header-explore-panel .mley-site-navigation a[aria-current] { font-weight: var(--weight-semibold); }
.mley-header-explore-panel .mley-navigation-icon { width: 22px; height: 22px; flex-basis: 22px; }
@keyframes mley-explore-enter { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .mley-header-explore[open] > .mley-header-explore-panel { animation: none; } }
.mley-site-header :is(a, button):focus-visible,
.mley-header-explore > summary:focus-visible,
.mley-header-search-dialog :is(button, input, select):focus-visible,
.mley-reading-controls button:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
.mley-header-brand { padding: 6px 12px 6px 4px; font-weight: var(--weight-bold); letter-spacing: -.03em; font-size: var(--text-body); }
.mley-header-brand__mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--surface-accent);
  color: var(--accent-color);
  font-size: 17px;
  letter-spacing: -.06em;
}
.mley-header-context {
  flex: 0 1 auto;
  justify-content: flex-start;
  min-width: 0;
  max-width: 240px;
  font-weight: var(--weight-semibold);
  border-radius: 4px;
}
.mley-header-context span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mley-header-context i { flex: 0 0 auto; font-size: 10px; }
.mley-header-search-group .mley-header-search-trigger {
  flex: 1 1 auto;
  justify-content: flex-start;
  min-width: 0;
  padding-inline: 14px;
  border-radius: 8px 0 0 8px;
  background: transparent;
  color: var(--text-muted);
}
.mley-header-search-group .mley-header-search-trigger:hover { color: var(--text-color); }
.mley-header-search-group .mley-header-search-trigger[aria-expanded="true"] { background: var(--surface-accent); color: var(--accent-color); }
.mley-header-search-group :is(a, summary):focus-visible { outline-offset: -2px; }
.mley-header-search-trigger__scope { margin-left: auto; font-size: var(--text-caption); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mley-header-row .mley-saved-toggle { min-width: 44px; padding: 8px; border: 0; border-radius: 8px; background: transparent; color: var(--text-color); }
.mley-header-row .mley-saved-toggle:hover { background: var(--bg-surface-2); }
.mley-header-row .mley-pdf-toggle { min-width: 44px; max-width: 44px; padding: 0; font-size: var(--text-caption); font-weight: var(--weight-bold); }
.mley-header-control[hidden], .mley-header-search-dialog[hidden], .mley-header-search-backdrop[hidden] { display: none; }
.mley-header-search-backdrop { position: fixed; inset: 0; z-index: 1100; background: rgb(0 0 0 / .28); }
.mley-header-search-dialog {
  position: fixed;
  top: max(76px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1101;
  width: min(620px, calc(100% - 32px));
  max-height: calc(100dvh - 100px);
  overflow: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  padding: 20px 24px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}
.mley-header-search-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.mley-header-search-heading h2 { margin: 0; font: inherit; font-size: var(--text-section); font-weight: var(--weight-bold); }
#mley-header-search-form label { display: block; font-size: var(--text-caption); font-weight: var(--weight-semibold); margin: 16px 0 8px; }
#mley-header-search-form :is(input[type="search"], select) {
  min-height: 48px;
  min-width: 0;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-surface-2);
  color: var(--text-color);
  font: inherit;
  font-size: var(--text-body);
}
.mley-header-query-row { display: flex; gap: 8px; }
.mley-header-search-submit { flex: 0 0 auto; min-height: 48px; padding: 10px 16px; border: 0; border-radius: 8px; background: var(--accent-color); color: var(--bg-surface); font: inherit; font-weight: var(--weight-semibold); cursor: pointer; }
.mley-header-search-submit:hover { filter: brightness(.92); }
.mley-header-search-hint { margin: 12px 0 0; color: var(--text-muted); font-size: var(--text-caption); line-height: var(--leading-ui); }
.mley-reading-controls { display: flex; justify-content: space-between; gap: 8px; margin: 12px 0; }
.mley-reading-controls button { font-size: var(--text-caption); cursor: pointer; }
.mley-reading-controls button:disabled { opacity: .5; cursor: default; }
#sidebar .mley-sidebar-site-menu { flex: 0 1 auto; overflow: auto; max-height: 48dvh; border-bottom: 1px solid var(--border-color); }
#sidebar .mley-sidebar-site-menu summary { min-height: 44px; padding: 12px 4px; box-sizing: border-box; font-size: var(--text-caption); font-weight: var(--weight-semibold); cursor: pointer; }
#sidebar .mley-sidebar-site-menu .mley-site-navigation { max-height: none; margin: 0; overflow: visible; border: 0; }
#sidebar .mley-sidebar-site-menu .mley-theme-toggle { min-height: 44px; width: 100%; padding: 8px 4px; border: 0; border-radius: 6px; justify-content: flex-start; color: var(--text-color); background: var(--bg-surface-2); font: inherit; font-size: var(--text-caption); }
@media (max-width: 1080px) { .mley-header-saved-label { display: none; } }
@media (max-width: 767px) {
  .mley-header-row { gap: 4px; padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
  .mley-header-brand { width: 44px; padding: 0; }
  .mley-header-brand__name { display: none; }
  .mley-header-context { flex: 1 1 0; max-width: none; gap: 4px; padding-inline: 2px; font-size: var(--text-caption); }
  .mley-header-context[data-law-index-open] { min-width: 44px; }
  .mley-header-search-group { flex: 0 0 88px; min-width: 88px; width: 88px; }
  .mley-header-row .mley-header-search-trigger { flex: 0 0 44px; min-width: 44px; width: 44px; padding: 0; justify-content: center; border: 0; background: transparent; color: var(--text-color); }
  .mley-header-search-trigger__text, .mley-header-search-trigger__scope { display: none; }
  .mley-header-search-dialog { padding: 12px 16px 20px; border-radius: 12px; }
  .mley-header-explore-panel {
    position: fixed; top: 70px;
    left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    width: auto; max-width: none;
  }
}
@media (max-width: 374px) {
  .mley-header-row:has([data-law-index-open]) .mley-header-brand { display: none; }
}
@media print { .mley-site-header, .mley-header-search-dialog, .mley-header-search-backdrop, .mley-reading-controls { display: none !important; } }

#sidebar.mley-app-sidebar { font-family: var(--font-ui); }
.mley-law-index-filter label { display: block; margin: 8px 0 6px; font-size: var(--text-caption); font-weight: var(--weight-semibold); }
.mley-law-index-filter input { box-sizing: border-box; width: 100%; min-height: 44px; padding: 8px; font: inherit; font-size: var(--text-body); border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-surface-2); color: var(--text-color); }
.mley-law-index-filter__status { margin: 6px 0; font-size: var(--text-caption); color: var(--text-muted); }
#mley-index-filter-results :is(a, button) { display: block; min-height: 44px; width: 100%; padding: 10px 4px; box-sizing: border-box; border: 0; border-bottom: 1px solid var(--border-color); background: transparent; text-align: left; font: inherit; font-size: var(--text-caption); color: var(--accent-color); }
