/* RRB-SHARED v0.1.0 — do not edit project copy; sync from /opt/stacks/ops/shared */
/* RRB-SHARED — source of truth (sync writes per-version header in project copies) */
/* RRB UX Patterns — composite behavioral patterns
 * Owner: shared (do not edit project copies)
 * Sync: /opt/stacks/ops/shared/sync-shared-assets.sh
 */

/* === Toast === */
:root {
  --rrb-z-toast: 2147483000;
}
.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: var(--rrb-z-toast) !important;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
  pointer-events: none;
  isolation: isolate;
}
.toast-container {
  z-index: var(--rrb-z-toast) !important;
  isolation: isolate;
}
.toast {
  pointer-events: auto;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  display: flex;
  gap: 8px;
  align-items: flex-start;
  z-index: var(--rrb-z-toast);
  animation: toast-in 160ms ease-out;
}
.toast-stack > .toast,
.toast-container > .toast {
  position: relative;
  top: auto;
  right: auto;
  z-index: 1;
}
.toast[data-type="success"] { border-left: 4px solid var(--color-accent); }
.toast[data-type="error"]   { border-left: 4px solid var(--color-danger); }
.toast[data-type="warn"]    { border-left: 4px solid var(--color-warning); }
.toast[data-type="info"]    { border-left: 4px solid var(--color-primary); }
.toast--leaving { animation: toast-out 140ms ease-in forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(-6px); } }
@media (max-width: 480px) {
  .toast-stack { left: 8px; right: 8px; max-width: none; top: 8px; }
}

/* === Modal shell === */
.rrb-modal {
  border: none;
  border-radius: 8px;
  background: var(--color-card);
  padding: 0;
  display: flex;
  flex-direction: column;
  /* Re-assert the UA modal centering: a project-level `* { margin: 0 }` reset
     beats the UA `dialog:modal { margin: auto }`, collapsing the dialog to
     inset:0 (top-left). This class selector wins over `*` and recentres it. */
  margin: auto;
  max-width: 480px;
  width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(28,42,68,0.18);
}
.rrb-modal::backdrop { background: rgba(0,0,0,0.4); }
/* Entrance: a <dialog> flips display on showModal(), so a CSS *transition* on
   [open] never fires — a keyframe *animation* on [open] does. Entrance only;
   close stays instant (native dialog limitation). 240ms = overlay tier. */
.rrb-modal[open] { animation: rrb-modal-in 240ms var(--ease); }
.rrb-modal[open]::backdrop { animation: rrb-modal-backdrop-in 160ms ease-out; }
@keyframes rrb-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes rrb-modal-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .rrb-modal[open], .rrb-modal[open]::backdrop { animation: none; }
}
.rrb-modal__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 12px;
  align-items: center;
  flex: 0 0 auto;
}
.rrb-modal__title {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}
.rrb-modal__close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
}
.rrb-modal__close:hover { color: var(--color-text); background: var(--surface-muted); }
.rrb-modal__close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.rrb-modal__body {
  padding: 20px;
  font-size: 14px;
  line-height: 1.5;
  overflow: auto;
  min-height: 0;
}
.rrb-modal__footer {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex: 0 0 auto;
}
@media (max-width: 480px) {
  .rrb-modal { width: 100vw; max-width: 100vw; border-radius: 0; max-height: 100dvh; }
  .rrb-modal__footer { flex-direction: column-reverse; }
  .rrb-modal__footer .btn { width: 100%; min-height: 44px; }
}

/* === Confirm modal danger variant === */
.rrb-modal[data-danger="true"] .rrb-modal__header { color: var(--color-danger); }

/* === Action menu === */
.rrb-menu {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 180px;
  padding: 4px 0;
  z-index: 900;
}
.rrb-menu__item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  min-height: 36px;
}
.rrb-menu__item:hover:not([disabled]) { background: var(--surface-muted); }
.rrb-menu__item[disabled] { color: var(--text-muted); cursor: not-allowed; }
.rrb-menu__item[data-danger="true"] { color: var(--danger); }
@media (hover: none) {
  .rrb-menu__item { min-height: 44px; }
}

/* === Upload dropzone === */
.rrb-upload {
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
.rrb-upload:hover, .rrb-upload[data-dragover="true"] {
  border-color: var(--color-primary);
  background: var(--color-bg);
}
.rrb-upload__input { display: none; }
.rrb-upload__hint { color: var(--color-text-muted); font-size: 13px; margin-top: 4px; }

/* === Photo grid with delete-X === */
.rrb-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.rrb-photo-grid__item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  background: var(--color-bg);
}
.rrb-photo-grid__item img,
.rrb-photo-grid__item video { width: 100%; height: 100%; object-fit: cover; }
.rrb-photo-grid__delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  border: 0;
  background: rgba(0,0,0,0.6);
  color: white;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rrb-photo-grid__delete:hover { background: var(--color-danger); }
@media (hover: none) {
  .rrb-photo-grid__delete { width: 32px; height: 32px; border-radius: 16px; font-size: 16px; }
}

/* === Save bar === */
.rrb-savebar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  display: none;
  gap: 8px;
  justify-content: flex-end;
  z-index: 50;
}
.rrb-savebar[data-dirty="true"] { display: flex; }
@media (max-width: 480px) {
  .rrb-savebar { flex-direction: column-reverse; padding: 12px; }
  .rrb-savebar .btn { width: 100%; min-height: 44px; }
}

/* === Search & filter facet === */
.rrb-search-facet {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}
.rrb-search-facet .search-bar {
  width: 100%;
}
.rrb-search-facet[data-loading="true"] .search-bar {
  border-color: var(--color-primary);
}
.rrb-search-results[aria-busy="true"] {
  opacity: 0.72;
}
.rrb-search-status {
  min-height: 18px;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}
/* On initial render / cleared search the status node is empty; without this it
   still reserves its 18px row and shows a blank grey strip under the picker. */
.rrb-search-status:empty { min-height: 0; display: none; }
/* contactPicker dropdown items (rendered by ux/contact-picker.js) */
.cp-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: var(--sp-sm) var(--sp-md);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.cp-item:last-child {
  border-bottom: 0;
}
.cp-item:hover,
.cp-item:focus {
  background: var(--surface-muted);
}
.cp-name {
  font-weight: 600;
}
.cp-meta {
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}
.cp-empty,
.cp-stale {
  padding: var(--sp-sm) var(--sp-md);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}
/* productPicker dropdown (rendered by ux/product-picker.js) — sibling of cp-*,
   plus a self-contained floating panel so the dropdown can be lifted onto <body>
   (float mode) and escape an overflow:auto / transformed table ancestor.
   Item-level rules are scoped under .pp-results so they never collide with an
   unrelated project-local `.pp-*` component (e.g. inventory's legacy
   components/product-picker.js, which uses .pp-item/.pp-name on the same page). */
.pp-results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1100;
}
.pp-results[hidden] {
  display: none;
}
.pp-results .pp-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: var(--sp-sm) var(--sp-md);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.pp-results .pp-item:last-child {
  border-bottom: 0;
}
.pp-results .pp-item:hover,
.pp-results .pp-item:focus,
.pp-results .pp-item.pp-active {
  background: var(--surface-muted);
}
.pp-results .pp-name {
  font-weight: 600;
}
.pp-results .pp-meta {
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}
.pp-results .pp-empty,
.pp-results .pp-stale {
  padding: var(--sp-sm) var(--sp-md);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}
@media (max-width: 768px) {
  .rrb-search-facet {
    gap: var(--sp-md);
  }
  .rrb-search-facet .search-bar,
  .rrb-search-facet .search-input {
    min-height: 44px;
  }
  .rrb-search-facet .filter-row {
    width: 100%;
  }
}

/* =====================================================================
   RRB UI Defaults — Batch 1 (additive; spec 2026-06-24-rrb-ui-defaults-batch-1)
   ===================================================================== */

/* --- Modal size variants (default .rrb-modal stays 480; md/omitted = no-op).
   Desktop-only so the mobile full-bleed rule (@max-width:480px) always wins on
   phones — otherwise .rrb-modal--sm would cap a 361-480px modal at 360px. --- */
@media (min-width: 481px) {
  .rrb-modal--sm   { max-width: 360px; }
  .rrb-modal--lg   { max-width: 680px; }
  .rrb-modal--wide { max-width: 860px; }
}

/* --- Action-menu entrance (was instant; now matches modal/toast polish) --- */
.rrb-menu {
  transform-origin: top;
  animation: rrb-menu-in 140ms var(--ease);
}
@keyframes rrb-menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* --- Save bar entrance (display:none -> flex still toggles; slide-up on appear) --- */
.rrb-savebar[data-dirty="true"] { animation: rrb-savebar-in 180ms var(--ease); }
@keyframes rrb-savebar-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rrb-menu, .rrb-savebar[data-dirty="true"] { animation: none; }
}
