@layer components {
  /* side sheet: the inside of every dock, drawer and modal */
  .sheet { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r); display: flex; flex-direction: column; min-width: 0; }
  .sheet-h { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
  .sheet-tt { display: flex; flex-direction: column; gap: 8px; }
  .sheet-s { color: var(--muted); font-size: 13px; }
  .sheet-k { font-family: var(--f-m); font-weight: 700; font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
  .sheet-t { font-family: var(--f-d); font-weight: 900; font-size: 28px; line-height: 0.95; text-transform: uppercase; color: var(--strong); }
  .sheet-b { padding: 18px 20px; display: flex; flex-direction: column; gap: 20px; }
  .sheet-f { margin-top: auto; padding: 16px 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; background: var(--wash); }
  .sheet-f.acts { flex-direction: row; justify-content: flex-end; }
  .sheet-b .bleed { margin: 0 -20px; border-top: 1px solid var(--line); }
  .sheet-b .bleed > .link { display: flex; padding: 14px 20px 2px; }
  .total { display: flex; justify-content: space-between; align-items: baseline; }
  .total span { font-family: var(--f-m); font-weight: 700; font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
  .total b { font-family: var(--f-d); font-weight: 900; font-size: 30px; color: var(--strong); line-height: 1; }

  dialog { padding: 0; border: 0; color: inherit; max-width: none; max-height: none; }
  dialog.sheet:not([open]), dialog.bsheet:not([open]) { display: none; }
  dialog::backdrop { background: var(--scrim); }

  /* menus and popovers sit in the top layer, placed by script beside what opened them */
  .menu, .pop { position: fixed; inset: auto; margin: 0; background: var(--float); border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: var(--sh-pop); color: var(--ink); font-family: var(--f-ui); letter-spacing: 0; text-transform: none; }
  .menu { min-width: 220px; padding: 6px; display: flex; flex-direction: column; gap: 1px; }
  .pop { width: 300px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
  .menu[popover]:not(:popover-open), .pop[popover]:not(:popover-open) { display: none; }
  .mi { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--dim); font-size: 13.5px; font-weight: 500; text-align: left; white-space: nowrap; }
  .mi svg { width: 15px; height: 15px; color: var(--muted); }
  .mi:hover, .mi:focus-visible { background: var(--hover); color: var(--ink); outline: none; }
  .mi.on, .mi[aria-checked="true"] { color: var(--strong); font-weight: 600; }
  .mi .tick { margin-left: auto; color: var(--accent); visibility: hidden; }
  .mi.bad, .mi.bad svg { color: var(--bad); }
  form.mi-f { display: contents; }
  .mi[aria-checked="true"] .tick { visibility: visible; }
  .mi small { margin-left: auto; font-family: var(--f-m); font-size: 11px; color: var(--muted); }
  .mlab { padding: 8px 10px 4px; font-family: var(--f-m); font-weight: 700; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
  .msep { height: 1px; margin: 5px 2px; background: var(--line); }
  .pop .input { background: var(--well); }
  .pop-f { display: flex; justify-content: flex-end; gap: 8px; padding-top: 2px; }

  /* bottom sheet */
  dialog.bsheet { position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-height: calc(100vh - 56px); max-height: calc(100dvh - 56px); display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line-2); border-radius: var(--r-sheet) var(--r-sheet) 0 0; box-shadow: var(--sh-sheet); }
  dialog.bsheet[open] { animation: sheet-up 0.25s cubic-bezier(0.22, 0.8, 0.28, 1); }
  .bsheet-grab { display: flex; justify-content: center; padding: 8px 0 2px; flex: none; }
  .bsheet-grab span { width: 36px; height: 4px; border-radius: 2px; background: var(--thumb); }
  .bsheet-h { display: flex; align-items: center; gap: 10px; padding: 4px 8px 10px 16px; border-bottom: 1px solid var(--line); flex: none; }
  .bsheet-h b { flex: 1; font-family: var(--f-d); font-weight: 900; font-size: 16px; text-transform: uppercase; color: var(--strong); }
  .bsheet-b { padding: 14px 16px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; overscroll-behavior: contain; }
  .bsheet-f { padding: 12px 16px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex: none; }
  .bsheet-f .btn-p { flex: 1; }
  .opt { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--raised); color: var(--dim); font-size: 14px; font-weight: 500; }
  .opt + .opt { margin-top: 6px; }
  .opt svg { width: 16px; height: 16px; }
  .opt .tick { margin-left: auto; color: var(--accent); visibility: hidden; }
  .opt.bad, .opt.bad svg { color: var(--bad); }
  .opt[aria-checked="true"] { border-color: var(--accent-line); background: var(--accent-soft); color: var(--strong); font-weight: 600; }
  .opt[aria-checked="true"] .tick { visibility: visible; }
  .pills { display: flex; flex-wrap: wrap; gap: 6px; }
  .pill { height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: none; color: var(--dim); font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; position: relative; cursor: pointer; }
  .pill[aria-pressed="true"], .pill[aria-checked="true"], .pill:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .pill input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
  .pill:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

  /* docked panel: beside the list on desktop, a modal on tablet, a sheet on phone */
  .dock { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
  .dock:has(> .dock-slot > .dock-side) { grid-template-columns: minmax(0, 1fr) 400px; }
  .dock:has(> .dock-slot > .dock-side) .tbl .ht { display: none; }
  .dock:has(> .dock-slot > .dock-side) .cols { grid-template-columns: minmax(0, 1fr); }
  .dock-slot:empty { display: none; }
  .dock-scrim { display: none; }
  .dock-side { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto; }
  .dock-k { font-family: var(--f-m); font-weight: 700; font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
  .dock-who { font-family: var(--f-d); font-weight: 900; font-size: 28px; line-height: 0.95; text-transform: uppercase; color: var(--strong); }
  .dock-side .kpis .kpi { padding: 14px 16px; }
  .dock-side .kpis .v { font-size: 24px; }

  /* modals are native dialogs: centred on desktop and tablet, a sheet on a phone */
  dialog.modal { position: fixed; inset: 64px auto auto 50%; transform: translateX(-50%); margin: 0; width: min(720px, calc(100% - 48px)); max-height: calc(100vh - 112px); overflow-y: auto; border: 1px solid var(--line-2); box-shadow: var(--sh-modal); }
  dialog.modal.sm, dialog.modal.md { top: 50%; transform: translate(-50%, -50%); }
  dialog.modal.sm { width: min(440px, calc(100% - 48px)); }
  dialog.modal.md { width: min(520px, calc(100% - 48px)); }
  dialog.modal.drawer { inset: 0 0 0 auto; transform: none; width: 440px; height: 100vh; height: 100dvh; max-height: none; border-radius: 0; border-width: 0 0 0 1px; }
  .sheet-form { display: flex; flex-direction: column; min-height: 100%; }
  .sheet-form .sheet-b { flex: 1; }
  .sheet-f > .end { display: flex; justify-content: flex-end; gap: 8px; }

  /* confirm */
  .cf { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 14px; padding: 22px 22px 18px; }
  .cf.solo { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .cf .ico { width: 40px; height: 40px; }
  .cf .ico svg { width: 19px; height: 19px; }
  .cf h2 { margin: 0 0 6px; font-size: 17px; font-weight: 700; line-height: 1.3; color: var(--strong); }
  .cf p { margin: 0; color: var(--dim); font-size: 13.5px; line-height: 1.55; }
  .cf p + p { margin-top: 10px; }
  .cf ul { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
  .cf li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: var(--r-sm); background: var(--raised); color: var(--dim); font-size: 13px; }
  .cf li b { color: var(--strong); font-variant-numeric: tabular-nums; }
  .cf-warn { margin: 0 22px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--bad-soft); color: var(--bad); font-size: 13px; font-weight: 600; }
  .cf + .sheet-f, .cf-warn + .sheet-f { margin-top: 18px; flex-direction: row; justify-content: flex-end; }
  .sheet-f form { margin: 0; }

  /* toasts: slide in, hold while the line runs down, slide out */
  .toasts { position: fixed; right: 24px; bottom: 24px; z-index: var(--z-toast); width: 360px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
  .toast { position: relative; display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 12px; align-items: start; width: 100%; padding: 12px 10px 14px 14px; background: var(--float); border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: var(--sh-pop); overflow: hidden; color: var(--ink); pointer-events: auto; transition: transform 0.35s cubic-bezier(0.22, 0.8, 0.28, 1), opacity 0.35s; }
  .toast.enter, .toast.out { transform: translateX(calc(100% + 40px)); opacity: 0; }
  .toast .ti { width: 24px; height: 24px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--good-soft); color: var(--good); }
  .toast .ti svg { width: 14px; height: 14px; stroke-width: 2.2; }
  .toast .tt { min-width: 0; padding-top: 2px; }
  .toast .tt b { display: block; color: var(--strong); font-weight: 600; font-size: 13.5px; line-height: 1.35; }
  .toast .tt small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
  .toast .tt small:empty { display: none; }
  .toast .ta { display: flex; align-items: center; gap: 2px; }
  .toast .ta form { margin: 0; }
  .toast .act { height: 26px; padding: 0 8px; border: 0; border-radius: var(--r-sm); background: none; color: var(--accent); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; }
  .toast .act:hover { background: var(--accent-soft); }
  .toast .tx { width: 26px; height: 26px; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--muted); display: grid; place-items: center; }
  .toast .tx:hover { color: var(--ink); background: var(--fill); }
  .toast .tx svg { width: 14px; height: 14px; }
  .toast .bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--good); opacity: 0.7; }
  .toast.run .bar { animation: toast-time 4s linear forwards; }
  .toast:hover .bar, .toast:focus-within .bar { animation-play-state: paused; }
  .toast.err { border-color: var(--bad-line); }
  .toast.err .ti { background: var(--bad-soft); color: var(--bad); }
  .toast.warn .ti { background: var(--warn-soft); color: var(--warn); }
  .toast.warn .bar { background: var(--warn); }
  .toast.info .ti { background: var(--accent-soft); color: var(--accent); }
  .toast.info .bar { background: var(--accent); }
  @keyframes toast-time { from { width: 100%; } to { width: 0; } }

  @media (width < 1100px) {
    .dock:has(> .dock-slot > .dock-side) { grid-template-columns: minmax(0, 1fr); }
    .dock-scrim { display: block; position: fixed; inset: 0; z-index: var(--z-scrim); background: var(--scrim); }
    .dock-side { position: fixed; z-index: var(--z-sheet); }
  }

  @media (700px <= width < 1100px) {
    .dock-scrim { background: var(--scrim-blur); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
    .dock-side { top: 72px; left: 50%; transform: translateX(-50%); width: min(640px, calc(100% - 48px)); max-height: calc(100vh - 120px); box-shadow: var(--sh-modal); }
    dialog.modal::backdrop { background: var(--scrim-blur); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
    dialog.modal:not(.sm):not(.md) { top: 72px; width: min(640px, calc(100% - 48px)); max-height: calc(100vh - 120px); }
    dialog.modal.drawer { inset: 72px auto auto 50%; transform: translateX(-50%); height: auto; border-radius: var(--r); border-width: 1px; }
  }

  @media (width < 700px) {
    .toasts { left: 12px; right: 12px; bottom: 80px; width: auto; }
    .toast.enter, .toast.out { transform: translateY(calc(100% + 24px)); }
    .dock-side { top: auto; left: 0; right: 0; bottom: 0; max-height: calc(100vh - 56px); border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-width: 1px 0 0; box-shadow: var(--sh-sheet); }
    dialog.modal, dialog.modal.sm, dialog.modal.md { inset: auto 0 0 0; transform: none; width: 100%; max-height: calc(100vh - 56px); border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-width: 1px 0 0; box-shadow: var(--sh-sheet); }
    dialog.modal[open] { animation: sheet-up 0.25s cubic-bezier(0.22, 0.8, 0.28, 1); }
    dialog.modal.drawer, dialog.modal.fill { inset: 0; width: 100%; height: 100dvh; max-height: none; border-radius: 0; border-width: 0; }
    dialog.modal.drawer .sheet-f, dialog.modal.fill .sheet-f { position: sticky; bottom: 0; background: var(--bar); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding-bottom: 20px; }
    .cf + .sheet-f > *, .cf-warn + .sheet-f > * { flex: 1; }
    .sheet-f form .btn { width: 100%; }
  }

  @media (prefers-reduced-motion: reduce) {
    .toast { transition: opacity 0.2s; }
    dialog.bsheet[open], dialog.modal[open] { animation: none; }
    .toast.enter, .toast.out { transform: none; }
  }
}
