/* v5.4 mobile header controls and global modal/toast behavior */
html {
  scrollbar-gutter: stable;
}

.mobile-header-actions { display: contents; }
.mobile-filter-panel { display: contents; }
.mobile-filter-footer { display: contents; }
.mobile-filter-close { display: none; }

body.nb-modal-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.toast {
  z-index: 2147483001;
}

.toast.toast-leaving {
  animation: nb-toast-leave .22s ease-in forwards;
}

@keyframes nb-toast-leave {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}

@media (max-width: 760px) {
  .topbar {
    position: relative;
    z-index: 5;
  }

  .top-actions {
    display: block;
    width: 100%;
  }

  /* The expanded panel belongs to the header flow so page content moves down with it. */
  .top-actions.ux-filters-open {
    position: relative;
    inset: auto;
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .mobile-header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .mobile-header-actions > button {
    width: 100%;
    min-height: 44px;
    padding-inline: 8px;
    white-space: nowrap;
  }

  .mobile-header-actions #quickAdd {
    grid-column: 1 / -1;
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }

  .mobile-header-actions .nb-page-guide-button {
    display: inline-flex !important;
  }

  .mobile-filter-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-height: 0;
    margin-top: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-2px);
    pointer-events: none;
    transition: max-height .38s cubic-bezier(.22,.8,.3,1), margin-top .38s cubic-bezier(.22,.8,.3,1), opacity .28s ease, transform .38s cubic-bezier(.22,.8,.3,1);
  }

  .mobile-filter-panel.is-open {
    max-height: 190px;
    margin-top: 10px;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .mobile-filter-panel .filter-control {
    display: grid !important;
    min-width: 0;
    gap: 5px;
  }

  .mobile-filter-panel .filter-control select {
    width: 100%;
    min-width: 0;
  }

  .mobile-filter-footer {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .mobile-filter-footer .reset-filters,
  .mobile-filter-footer .mobile-filter-close {
    display: inline-flex;
    align-items: center;
    width: 100%;
    justify-content: center;
    min-height: 44px;
    line-height: 1.2;
  }

  .toast {
    top: max(10px, env(safe-area-inset-top));
    right: 12px;
    left: 12px;
    bottom: auto;
    width: auto;
    text-align: center;
    animation: nb-toast-enter .42s cubic-bezier(.2, 1.35, .35, 1) both;
  }

  .toast.show { transform: translateY(0); }

  @keyframes nb-toast-enter {
    0% { opacity: 0; transform: translateY(-22px) scale(.98); }
    65% { opacity: 1; transform: translateY(3px) scale(1.01); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
  }

  dialog .toast {
    position: fixed;
    z-index: 2147483001;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-filter-panel,
  .toast,
  .toast.toast-leaving { transition: none !important; animation: none !important; }
}
dialog {
  animation: nb-modal-in 180ms cubic-bezier(.22, 1, .36, 1) both;
}

dialog.nb-modal-closing {
  animation: nb-modal-out 180ms cubic-bezier(.4, 0, 1, 1) both;
  pointer-events: none;
}

dialog::backdrop {
  animation: nb-backdrop-in 180ms ease-out both;
}

dialog.nb-modal-closing::backdrop {
  animation: nb-backdrop-out 180ms ease-in both;
}

@keyframes nb-modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes nb-modal-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(8px) scale(.97); }
}

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

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

@media (prefers-reduced-motion: reduce) {
  dialog,
  dialog.nb-modal-closing,
  dialog::backdrop,
  dialog.nb-modal-closing::backdrop {
    animation: none !important;
  }
}
