/*!
 * NEXTLOGIC cookie-consent banner (DESIGN.md §2, §5).
 * Markup: templates/nextlogic/snippets/consent_banner.html, behaviour: js/consent.js.
 * Footer links and the auth forms: css/legal.css.
 *
 * Loads after the theme bundle. The first line repeats the theme's layer order: it
 * is a no-op once css/nextlogic.css has declared it, and it keeps `nl.components`
 * below `nl.utilities` and above `ckan` if this file ever loads first. Everything
 * is in `nl.components` and uses the theme tokens, so the dark tokens apply.
 */
@layer nlfix, ckan, nl.tokens, nl.base, nl.ckan, nl.components, nl.utilities;

@layer nl.components {
  /* `hidden` is the server-side default; nothing sets display while it is present. */
  .nl-consent:not([hidden]) {
    position: fixed;
    /* below the Filters sheet (1045) and modals (1055) so it never covers "Show results" */
    z-index: 1035;
    left: var(--gutter); right: var(--gutter);
    bottom: max(var(--space-3), env(safe-area-inset-bottom));
    margin-inline: auto;
    max-width: min(60rem, 100% - 2 * var(--gutter));
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--card);
    color: var(--card-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
  }
  /* an open offcanvas sheet or menu takes the screen: the banner steps aside */
  body:has(.offcanvas.show) .nl-consent { display: none; }

  /* Phone: a compact bar, about 165px: title + Settings link, two lines of text, one row of buttons. */
  .nl-consent__body {
    display: grid; gap: var(--space-1) var(--space-2); padding: var(--space-3);
  }
  @media (min-width: 768px) {
    .nl-consent__body { gap: var(--space-3); padding: var(--space-5); }
  }

  .nl-consent__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 44px; }
  .nl-consent__title { margin: 0; font-size: var(--text-lg); font-weight: 650; letter-spacing: -.01em; }
  .nl-consent__title:focus { outline: none; }
  .nl-consent__toggle { flex: none; margin-inline-end: calc(-1 * var(--space-2)); }
  .nl-consent__text { margin: 0; max-width: 68ch; font-size: var(--text-sm); line-height: 1.45; color: var(--muted-foreground); }

  /* Accept and Reject: same style, same size. */
  .nl-consent__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); margin-top: var(--space-1); }
  .nl-consent__actions .btn { width: 100%; min-height: 44px; padding-inline: var(--space-2); white-space: normal; text-align: center; line-height: 1.2; }
  @media (min-width: 768px) {
    .nl-consent__actions { grid-template-columns: repeat(2, minmax(0, 13rem)); margin-top: 0; }
    .nl-consent__actions .btn { min-height: 40px; }
  }

  /* ---- Settings panel (disclosure inside the banner) ---------------- */
  .nl-consent__settings:not([hidden]) {
    display: grid; gap: var(--space-3);
    padding-top: var(--space-3); margin-top: var(--space-2); border-top: 1px solid var(--border);
  }
  .nl-consent__settings fieldset { display: grid; gap: var(--space-3); margin: 0; padding: 0; border: 0; min-width: 0; }
  .nl-consent__legend { float: none; width: auto; margin: 0; padding: 0; font-size: var(--text-sm); font-weight: 650; }
  .nl-consent__category { display: flex; align-items: flex-start; gap: var(--space-3); }
  .nl-consent__category .form-check-input { flex: none; width: 1.5rem; height: 1.5rem; margin-top: 0; }
  .nl-consent__category .form-check-input:disabled { opacity: .7; }
  .nl-consent__label { font-size: var(--text-sm); font-weight: 600; cursor: pointer; }
  .nl-consent__label::after { content: none; } /* CKAN appends a colon to every label */
  .nl-consent__category .form-check-input:disabled + div .nl-consent__label { cursor: default; }
  .nl-consent__state { margin-inline-start: var(--space-2); font-weight: 400; color: var(--muted-foreground); }
  .nl-consent__help { margin: .125rem 0 0; font-size: var(--text-xs); color: var(--muted-foreground); max-width: 60ch; }
  .nl-consent__settings > .btn { justify-self: start; }
  @media (max-width: 575.98px) { .nl-consent__settings > .btn { justify-self: stretch; } }

  /* Entry: a short slide-up, only when motion is welcome (reduced motion: none). */
  @media (prefers-reduced-motion: no-preference) {
    .nl-consent:not([hidden]) { animation: nl-consent-in var(--dur-enter) var(--ease-out); }
    @keyframes nl-consent-in { from { opacity: 0; transform: translateY(1rem); } }
  }

  /* While the banner is open leave room under the page so it never covers the footer
     (consent.js sets --nl-consent-h to the banner height). */
  html.nl-consent-visible body { padding-bottom: calc(var(--nl-consent-h, 0px) + var(--space-4)); }

  @media print { .nl-consent { display: none !important; } }

  @media (max-width: 991.98px) { .nl-consent__category { min-height: 44px; } }
}
