/* ============================================================================
   BOTTOM SHEET — shared compound (single source of truth).
   A bottom-docked, scrim-backed panel for small screens: drag handle, snap
   points (half / full), drag-to-dismiss, sticky footer. Entrance + exit motion
   driven by --sh-* tokens on the scrim. Self-contained on the CSS architecture
   (own @layer tokens / theme / components); import AFTER colors_and_type.css.
   Behaviour lives in _sheet.js (focus trap, drag, snap, restart-safe motion);
   schema in _sheet.config.js (window.FP_COMPOUNDS.sheet).

   Used as an OVERLAY (Sheet.open) — a fixed .sheet-layer holds one .sheet-scrim
   per open sheet — OR INLINE (.sheet-scrim--inline) for showcases (the DS card
   thumbnail uses this).
   ============================================================================ */

@layer tokens {
  :root {
    /* Motion (read at play time on the scrim; governor-scaled, Inspector-tunable). */
    --sh-dur: 340ms;        /* @kind other */
    --sh-ease: cubic-bezier(0.16, 1, 0.3, 1);   /* @kind other */
    --sh-scrim-dur: 200ms;  /* @kind other */
    --sh-snap-dur: 260ms;   /* @kind other */

    /* Snap-point heights (plain lengths — _sheet.js parses vh/px for drag math). */
    --sh-half: 56vh;
    --sh-full: 92vh;

    /* Surface (literals that differ by theme → token + theme override). */
    --sheet-scrim-bg: rgba(12, 24, 56, 0.44);
    --sheet-shadow: 0 -18px 50px -12px rgba(12, 24, 56, 0.28), 0 -6px 18px -6px rgba(12, 24, 56, 0.16);
    --sheet-bd: var(--color-border-default);
    --sheet-handle: var(--gov-color-neutral-300);
  }
}

@layer theme {
  [data-theme="dark"] {
    --sheet-scrim-bg: rgba(2, 6, 18, 0.62);
    --sheet-shadow: 0 -18px 54px -12px rgba(0, 0, 0, 0.6), 0 -6px 20px -6px rgba(0, 0, 0, 0.45);
    --sheet-bd: var(--color-border-strong, var(--color-border-default));
    --sheet-handle: var(--gov-color-neutral-500, #5b6572);
  }
}

@layer components {
  /* The fixed stack the controller appends overlay scrims into. */
  .sheet-layer {
    position: fixed;
    inset: 0;
    z-index: 1200;
    pointer-events: none;
  }
  .sheet-layer:empty { display: none; }

  /* ── Scrim ───────────────────────────────────────────────────────────── */
  .sheet-scrim {
    position: absolute;
    inset: 0;
    background: var(--sheet-scrim-bg);
    -webkit-backdrop-filter: saturate(1) blur(1.5px);
    backdrop-filter: saturate(1) blur(1.5px);
    pointer-events: auto;
    opacity: 0;
    transition: opacity var(--sh-scrim-dur) ease-out;
  }
  .sheet-scrim.is-open { opacity: 1; }

  /* Inline showcase variant — sits in normal flow, no fixed positioning. */
  .sheet-scrim--inline {
    position: relative;
    inset: auto;
    opacity: 1;
    background: transparent;            /* the host frames the dim; don't double it */
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  /* ── Panel ───────────────────────────────────────────────────────────── */
  .sheet {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    margin: 0 auto;
    max-width: 720px;                    /* tablets: docked strip, not full-bleed */
    height: min(var(--sh-half), calc(100% - 24px));
    display: flex;
    flex-direction: column;
    background: var(--color-bg-surface);
    color: var(--color-fg-default);
    border: 1px solid var(--sheet-bd);
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--sheet-shadow);
    /* Entrance resting state (visible) — the controller animates FROM offscreen
       so reduced-motion / print / no-JS show the panel, not a blank strip. */
    opacity: 1;
    transform: none;
    overflow: hidden;
    transition: transform var(--sh-dur) var(--sh-ease),
                height var(--sh-snap-dur) var(--sh-ease);
  }
  .sheet[data-snap="full"] { height: min(var(--sh-full), calc(100% - 12px)); }
  /* Mid-drag: the pointer owns the height — no transition fighting the hand. */
  .sheet.is-dragging { transition: opacity var(--sh-scrim-dur) ease-out; }

  /* The controller stamps these while the scrim is mid-open / mid-close. The
     :not(.sheet-scrim--inline) guard keeps the inline showcase surface visible
     (it never gets .is-open). */
  .sheet-scrim:not(.is-open):not(.sheet-scrim--inline) .sheet {
    transform: translateY(105%);
  }
  .sheet-scrim--inline .sheet {
    position: relative;
    height: auto;
    max-height: none;
    transition: none;
    transform: none;
    border-bottom: 1px solid var(--sheet-bd);
  }

  /* ── Drag handle ─────────────────────────────────────────────────────── */
  .sheet__grip {
    all: unset;
    box-sizing: border-box;
    flex: none;
    width: 100%;
    padding: 12px 0 8px;
    display: grid;
    place-items: center;
    cursor: grab;
    touch-action: none;                  /* pointer drag owns the gesture (pitfalls) */
    user-select: none; -webkit-user-select: none;
  }
  .sheet__grip:active { cursor: grabbing; }
  .sheet__grip::before {
    content: "";
    width: 44px; height: 5px;
    border-radius: 999px;
    background: var(--sheet-handle);
    transition: background 120ms ease-out, box-shadow 220ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sheet__grip:hover::before,
  .sheet__grip[data-state~="hover"]::before { background: var(--gov-color-primary-500); }
  .sheet__grip:focus-visible { outline: none; }
  .sheet__grip:focus-visible::before,
  .sheet__grip[data-state~="focus"]::before {
    background: var(--gov-color-primary-500);
    box-shadow: var(--shadow-focus);
  }

  /* ── Head ────────────────────────────────────────────────────────────── */
  .sheet__head {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 0 20px 10px;
    touch-action: none;                  /* head is draggable chrome too */
    user-select: none; -webkit-user-select: none;
  }
  .sheet__titles { flex: 1; min-width: 0; }
  .sheet__eyebrow {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-fg-tertiary);
    margin-bottom: 3px;
  }
  .sheet__title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-fg-default);
    letter-spacing: -0.01em;
  }
  .sheet__sub {
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-fg-secondary);
  }

  /* Close button — same vocabulary as the modal / toast close. */
  .sheet__close {
    all: unset;
    cursor: pointer;
    user-select: none; -webkit-user-select: none;
    flex: none;
    position: relative;
    width: 30px; height: 30px;
    border-radius: 999px;
    display: inline-grid; place-items: center;
    color: var(--color-fg-tertiary);
    transition: background-color 120ms ease, color 120ms ease,
                box-shadow 220ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sheet__close i { font-size: 20px; line-height: 1; display: block; margin-top: -1px; }
  .sheet__close:hover,
  .sheet__close[data-state~="hover"] { background: var(--gov-color-neutral-100); color: var(--color-fg-default); }
  .sheet__close:active,
  .sheet__close[data-state~="pressed"] { background: var(--gov-color-neutral-200); }
  .sheet__close:focus-visible,
  .sheet__close[data-state~="focus"] { outline: none; box-shadow: var(--shadow-focus); }
  @media (pointer: coarse) {
    .sheet__close::after { content: ""; position: absolute; top: 50%; left: 50%;
      transform: translate(-50%, -50%); width: 100%; height: 100%;
      min-width: 44px; min-height: 44px; }
  }

  /* ── Body ────────────────────────────────────────────────────────────── */
  .sheet__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;                  /* filter motion can overflow sideways for a beat — never show a bar */
    overscroll-behavior: contain;        /* body scroll never chains to the page */
    scrollbar-width: none;               /* touch-first surface — hide the bars, keep the scroll */
    padding: 4px 20px 16px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--color-fg-default);
  }
  .sheet__body::-webkit-scrollbar { display: none; }
  .sheet__body > :first-child { margin-top: 0; }
  .sheet__body > :last-child { margin-bottom: 0; }

  /* ── Footer (sticky confirm row) ─────────────────────────────────────── */
  .sheet__foot {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--color-border-subtle, var(--color-border-default));
    background: var(--color-bg-surface);
  }
  .sheet__foot .btn { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
  .sheet__foot-note { font-size: 12px; color: var(--color-fg-tertiary); flex: none; }
}
