/* ============================================
   modal.css: .bl-modal on native <dialog> (owner A1, see .claude/md files/redesign-spec.md section 3)

   <dialog class="bl-modal" id="filters" aria-labelledby="filters-title">
     <div class="bl-modal__header">
       <h2 class="bl-modal__title" id="filters-title">Filters</h2>
       <button type="button" class="bl-btn bl-btn--icon bl-btn--ghost bl-modal__close"
               data-modal-close aria-label="Close"><svg …></button>
     </div>
     <div class="bl-modal__body">…</div>
     <div class="bl-modal__footer">…</div>
   </dialog>
   <button type="button" data-modal-open="filters">Filters</button>

   Phones (<768px): a bottom sheet sliding up. ≥768px: a centred card.
   Modifiers: --lg (wider card, 760px), --full (full-screen on phones, e.g. the search sheet).
   ui.js adds .is-closing for the exit animation and html.bl-scroll-lock while open.
   ============================================ */

.bl-modal {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-modal);
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  max-height: calc(100dvh - var(--safe-top) - var(--space-6));
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background-color: var(--color-surface);
  color: var(--color-text-body);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  overscroll-behavior: contain;
}

.bl-modal[open] {
  display: flex;
  animation: bl-sheet-in var(--duration-base) var(--ease-out) both;
}

.bl-modal.is-closing {
  animation: bl-sheet-out var(--duration-fast) var(--ease-out) both;
  pointer-events: none;
}

/* The grey behind dialogs: --color-scrim by value (custom properties do not reach ::backdrop
   in every browser yet). */
.bl-modal::backdrop {
  background-color: rgba(0, 0, 0, 0.45);
}

.bl-modal[open]::backdrop {
  animation: bl-backdrop-in var(--duration-base) var(--ease-out) both;
}

.bl-modal.is-closing::backdrop {
  animation: bl-backdrop-out var(--duration-fast) var(--ease-out) both;
}

.bl-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex: none;
  min-height: 64px;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
}

/* Title takes the free space; an optional back button can sit before it. */
.bl-modal__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--color-ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.bl-modal__close {
  flex: none;
  margin-left: auto;
}

.bl-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-5);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.bl-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex: none;
  padding: var(--space-3) var(--space-5) calc(var(--space-3) + var(--safe-bottom));
  border-top: 1px solid var(--color-border-light);
  background-color: var(--color-surface);
}

/* A lone footer action spans the sheet on phones. */
.bl-modal__footer > .bl-btn:only-child {
  flex: 1;
}

/* Full-screen on phones (search sheet). */
.bl-modal--full {
  inset: 0;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  padding-top: var(--safe-top);
}

/* --- Centred card from 768px --- */
@media (min-width: 768px) {
  .bl-modal,
  .bl-modal--full {
    inset: 0;
    width: min(560px, calc(100% - var(--space-12)));
    height: fit-content;
    max-height: min(86vh, 860px);
    margin: auto;
    padding-top: 0;
    border-radius: var(--radius-xl);
  }

  .bl-modal--lg {
    width: min(760px, calc(100% - var(--space-12)));
  }

  .bl-modal[open] {
    animation-name: bl-modal-in;
  }

  .bl-modal.is-closing {
    animation-name: bl-modal-out;
  }

  .bl-modal__header {
    padding-left: var(--space-6);
  }

  .bl-modal__body {
    padding: var(--space-6);
  }

  .bl-modal__footer {
    padding: var(--space-4) var(--space-6);
  }

  .bl-modal__footer > .bl-btn:only-child {
    flex: none;
    margin-left: auto;
  }
}

@keyframes bl-sheet-in {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@keyframes bl-sheet-out {
  from { transform: none; }
  to { transform: translateY(100%); }
}

@keyframes bl-modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@keyframes bl-modal-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(6px) scale(0.98); }
}

@keyframes bl-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes bl-backdrop-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes bl-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes bl-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .bl-modal[open]:not(.is-closing) {
    animation-name: bl-fade-in;
    animation-duration: var(--duration-fast);
  }

  .bl-modal.is-closing {
    animation-name: bl-fade-out;
    animation-duration: var(--duration-fast);
  }
}

/* Body scroll lock while a modal is open (ui.js). The padding stands in for the scrollbar
   so the page does not jump sideways on desktop.
   Only <body> gets overflow, never <html>: with <html> left visible, body's overflow is handed
   to the viewport, which stops scrolling but stays the scroll container. Setting it on <html>
   too keeps body's overflow (layout.css's overflow-x: hidden) on body itself, which turns body
   into a scroll container: the sticky header then sticks to body, not the viewport, and jumps
   out of sight on a scrolled page while a modal (the menu drawer) is open. */
html.bl-scroll-lock body {
  overflow: hidden;
  padding-right: var(--bl-scrollbar-comp, 0px);
}
