/* Menza Hub components — shared vocabulary used by every module.
   Selectors follow the classes the existing JavaScript renders, so no module
   markup has to change to adopt the system. */
@layer components {

  /* ── Buttons ─────────────────────────────────────────────── */
  :where(.button, .ff-button, .icon-button, .dialog-close) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-h);
    padding: 0 var(--space-4);
    border: 1px solid var(--ui-control-border);
    border-radius: var(--radius-control);
    background: var(--ui-surface);
    color: var(--ui-text);
    font-size: var(--type-copy);
    font-weight: var(--weight-medium);
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  }
  :where(.button, .ff-button, .icon-button, .dialog-close):hover:not(:disabled) {
    background: var(--ui-hover);
    border-color: var(--ui-strong-border);
    text-decoration: none;
  }
  :where(.button, .ff-button, .icon-button, .dialog-close):active:not(:disabled) { background: var(--ui-pressed); }
  :where(.button, .ff-button, .icon-button, .dialog-close):disabled,
  :where(.button, .ff-button)[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
  :where(.button, .ff-button)[aria-busy="true"] { cursor: progress; opacity: .75; }
  :where(.button, .ff-button) svg { width: 16px; height: 16px; }

  :where(.button, .ff-button):is(.primary, .ff-primary) {
    background: var(--ui-primary);
    border-color: var(--ui-primary);
    color: var(--ui-on-primary);
  }
  :where(.button, .ff-button):is(.primary, .ff-primary):hover:not(:disabled) {
    background: var(--ui-primary-hover);
    border-color: var(--ui-primary-hover);
  }
  :where(.button, .ff-button):is(.danger, .ff-danger, .destructive) {
    color: var(--ui-danger);
    border-color: var(--ui-danger-border);
    background: var(--ui-danger-bg);
  }
  :where(.button, .ff-button):is(.ghost, .ff-ghost) { border-color: transparent; background: transparent; }
  :where(.button, .ff-button).full-width, .full-width { width: 100%; }

  :where(.icon-button, .dialog-close) {
    width: var(--control-h);
    padding: 0;
    border-color: transparent;
    background: transparent;
    color: var(--ui-muted);
  }
  :where(.icon-button, .dialog-close):hover:not(:disabled) { color: var(--ui-text); border-color: var(--ui-border); }

  /* ── Fields ──────────────────────────────────────────────── */
  :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"], [type="hidden"]), select, textarea) {
    min-height: var(--control-h);
    max-width: 100%;
    padding: 0 var(--space-3);
    border: 1px solid var(--ui-control-border);
    border-radius: var(--radius-control);
    background: var(--ui-input);
    color: var(--ui-text);
    font-size: var(--type-copy);
    line-height: 1.4;
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
  }
  :where(textarea) { padding: var(--space-3); line-height: var(--leading-copy); resize: vertical; }
  :where(input, textarea)::placeholder { color: var(--ui-subtle); opacity: 1; }
  :where(input:not([type="checkbox"], [type="radio"], [type="range"]), select, textarea):hover:not(:disabled, :focus) { border-color: var(--ui-strong-border); }
  :where(input:not([type="checkbox"], [type="radio"], [type="range"]), select, textarea):focus-visible {
    outline: none;
    border-color: var(--ui-focus);
    box-shadow: 0 0 0 3px var(--ui-accent-soft);
  }
  :where(input, select, textarea):disabled { opacity: .55; cursor: not-allowed; }
  :where(input[readonly], textarea[readonly]) { background: var(--ui-raised); color: var(--ui-muted); }
  :where(select) {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--ui-muted) 50%),
      linear-gradient(135deg, var(--ui-muted) 50%, transparent 50%);
    background-position: calc(100% - 19px) 52%, calc(100% - 14px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
  }
  :where(input[type="checkbox"], input[type="radio"]) {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--ui-accent);
    cursor: pointer;
    vertical-align: middle;
  }
  :where(input[type="date"], input[type="time"], input[type="datetime-local"]) { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
  :where(input[type="file"]) { font-size: var(--type-label); color: var(--ui-muted); }
  :where(input[type="file"])::file-selector-button {
    min-height: var(--control-h-sm);
    margin-right: var(--space-3);
    padding: 0 var(--space-3);
    border: 1px solid var(--ui-control-border);
    border-radius: var(--radius-control);
    background: var(--ui-raised);
    color: var(--ui-text);
    font: inherit;
    cursor: pointer;
  }

  :where(.field, .ff-field) {
    display: grid;
    gap: 6px;
    min-width: 0;
    margin: 0 0 var(--space-4);
    color: var(--ui-muted);
    font-size: var(--type-label);
    font-weight: var(--weight-medium);
  }
  :where(.field, .ff-field) :where(input:not([type="checkbox"], [type="radio"]), select, textarea) { width: 100%; font-weight: var(--weight-regular); }
  :where(.field, .ff-field) > :where(small, .form-hint, .ff-help) { font-weight: var(--weight-regular); }
  .ff-field { flex: 1; min-width: 150px; margin: 0; }
  :where(.field-row) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-4); }
  :where(.ff-fields, .ff-filters) { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin: var(--space-4) 0; }
  :where(.ff-filters) > :where(.ff-field:first-child) { flex: 3; min-width: 220px; }
  :where(.ff-dialog) :where(.ff-fields) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  :where(.ff-dialog-header) :where(.ff-inline-actions) { margin-left: auto; }
  @media (max-width: 1024px) {
    :where(.ff-filters) { display: grid; grid-template-columns: minmax(0, 1fr); }
    :where(.ff-filters) > :where(.ff-field:first-child) { min-width: 0; }
    :where(.ff-dialog) :where(.ff-fields) { grid-template-columns: minmax(0, 1fr); }
    :where(.ff-dialog-header) { flex-wrap: wrap; }
  }
  :where(.form-hint, .ff-help) { display: block; margin: var(--space-1) 0 0; color: var(--ui-subtle); font-size: var(--type-meta); line-height: 1.55; font-weight: var(--weight-regular); }
  :where(.form-error) { color: var(--ui-danger); font-size: var(--type-label); line-height: 1.5; }
  :where(.form-error):empty { display: none; }

  :where(.search-field) { position: relative; display: block; min-width: 0; margin: 0; }
  :where(.search-field) > svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--ui-subtle); pointer-events: none; }
  :where(.search-field) input { width: 100%; padding-left: 38px; }

  /* ── Messages and notes ──────────────────────────────────── */
  :where(.ff-message, .integration-banner, .commerce-note) {
    margin: var(--space-4) 0;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-control);
    background: var(--ui-raised);
    color: var(--ui-text);
    font-size: var(--type-label);
    line-height: 1.55;
  }
  :where(.commerce-note) { border-left: 3px solid var(--ui-accent-line); }
  :where(.ff-message-error) { border-color: var(--ui-danger-border); background: var(--ui-danger-bg); color: var(--ui-danger); }
  :where(.ff-message-warning) { border-color: var(--ui-warning-border); background: var(--ui-warning-bg); color: var(--ui-warning); }
  :where(.ff-message-success) { border-color: var(--ui-success-border); background: var(--ui-success-bg); color: var(--ui-success); }
  :where(.ff-message, .integration-banner)[hidden] { display: none; }

  /* ── Surfaces: panels, cards, metrics ────────────────────── */
  :where(.commerce-panel, .ff-card) {
    min-width: 0;
    padding: var(--space-6);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-card);
    background: var(--ui-surface);
    color: var(--ui-text);
  }
  :where(.commerce-panel + .commerce-panel, .ff-card + .ff-card) { margin-top: var(--space-4); }
  :where(.commerce-panel, .ff-card) :where(h3) { margin: 0 0 var(--space-2); font-size: var(--type-section); }
  :where(.commerce-panel, .ff-card) :where(h4) { margin: 0 0 var(--space-2); font-size: var(--type-body); }
  :where(.commerce-panel) :where(p) { color: var(--ui-muted); line-height: var(--leading-copy); }
  :where(.commerce-panel) :where(fieldset) { margin: 0; padding: 0; border: 0; }
  :where(.commerce-section-title, .ff-card-heading) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin: 0 0 var(--space-4);
  }
  :where(.commerce-section-title, .ff-card-heading) :where(h3) { margin: 0; }
  :where(.commerce-section-title) > span, :where(.ff-card-heading) p { color: var(--ui-muted); font-size: var(--type-meta); margin: 0; }
  :where(.detail-section-title) { margin: var(--space-6) 0 var(--space-3); color: var(--ui-text); font-size: var(--type-body); font-weight: var(--weight-strong); }
  :where(.ff-eyebrow) { display: block; color: var(--ui-muted); font-size: var(--type-meta); font-weight: var(--weight-medium); letter-spacing: 0; }

  :where(.commerce-metrics, .stat-grid) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-3);
    margin: 0 0 var(--space-6);
  }
  :where(.commerce-metrics) > div, :where(.stat) {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-card);
    background: var(--ui-surface);
  }
  :where(.commerce-metrics) span, :where(.stat-label) { color: var(--ui-muted); font-size: var(--type-meta); line-height: 1.4; }
  :where(.commerce-metrics) strong, :where(.stat-value) {
    color: var(--ui-text);
    font-family: var(--font-data);
    font-size: var(--type-subtitle);
    font-weight: var(--weight-medium);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    letter-spacing: -.02em;
    overflow-wrap: anywhere;
  }
  :where(.stat-foot) { color: var(--ui-subtle); font-size: var(--type-meta); }
  .stat.lime .stat-value { color: var(--ui-success); }
  .stat.amber .stat-value { color: var(--ui-warning); }

  :where(.commerce-fields) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-4); margin-top: var(--space-4); }
  :where(.commerce-native-grid) { display: grid; grid-template-columns: minmax(240px, .8fr) minmax(0, 1.7fr); gap: var(--space-4); align-items: start; }
  :where(.commerce-records) { display: grid; gap: var(--space-2); margin: var(--space-3) 0; max-height: 420px; overflow: auto; }
  :where(.commerce-record) {
    display: grid;
    gap: var(--space-1);
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-control);
    background: var(--ui-raised);
    color: var(--ui-text);
    text-align: left;
    overflow-wrap: anywhere;
  }
  :where(.commerce-record) span { color: var(--ui-muted); font-size: var(--type-meta); }
  :where(.commerce-record):hover, :where(.commerce-record).selected { border-color: var(--ui-accent-line); background: var(--ui-accent-soft); }
  :where(.commerce-detail) { margin: var(--space-4) 0 0; padding-top: var(--space-3); border-top: 1px solid var(--ui-border); }
  :where(.commerce-detail) > summary {
    display: flex;
    align-items: center;
    min-height: var(--control-h);
    color: var(--ui-text);
    font-weight: var(--weight-medium);
  }
  :where(.commerce-detail) > p { color: var(--ui-muted); line-height: var(--leading-copy); }
  :where(.commerce-actions, .workspace-actions, .ff-inline-actions, .ff-heading-actions, .ff-row-actions) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }
  :where(.ff-row-actions) { flex-wrap: nowrap; }
  :where(.ff-row-actions) :where(.ff-button, .button) { min-height: var(--control-h-sm); padding: 0 var(--space-3); font-size: var(--type-meta); }
  :where(.commerce-report-filter) { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); }
  :where(.commerce-report-filter) :where(.field) { margin: 0; }

  /* ── Tabs (every convention the modules use for "selected") ─ */
  :where(.table-tabs, .ff-tabs) {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    margin: 0 0 var(--space-5);
    padding: 0 0 var(--space-2);
    border-bottom: 1px solid var(--ui-border);
    scrollbar-width: none;
  }
  :where(.table-tabs, .ff-tabs) > button {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0 var(--space-4);
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--ui-muted);
    font-weight: var(--weight-medium);
  }
  :where(.table-tabs, .ff-tabs) > button:hover { background: var(--ui-hover); color: var(--ui-text); }
  :where(.table-tabs, .ff-tabs) > button:is([aria-current="page"], [aria-pressed="true"], .active, .primary, .ff-primary) {
    background: var(--ui-accent-soft);
    color: var(--ui-text);
    box-shadow: inset 0 -2px 0 var(--ui-accent);
  }

  /* ── Tables ─────────────────────────────────────────────── */
  :where(.commerce-table, .ff-table-wrap, .table-wrap) {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-card);
    background: var(--ui-surface);
  }
  :where(#view-content, dialog) :where(table) { width: 100%; border-collapse: collapse; font-size: var(--type-label); text-align: left; }
  :where(#view-content, dialog) :where(th) {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--ui-border);
    text-align: left;
    vertical-align: middle;
  }
  :where(#view-content, dialog) :where(tbody th) { border-bottom-color: var(--ui-divider); color: var(--ui-text); font-weight: var(--weight-regular); }
  :where(#view-content, dialog) :where(thead th) {
    background: var(--ui-raised);
    color: var(--ui-muted);
    font-size: var(--type-meta);
    font-weight: var(--weight-medium);
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
    vertical-align: middle;
  }
  :where(#view-content, dialog) :where(td) {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--ui-divider);
    color: var(--ui-text);
    vertical-align: middle;
  }
  :where(#view-content, dialog) :where(tbody tr:last-child td) { border-bottom: 0; }
  :where(#view-content) :where(tbody tr):hover > td { background: var(--ui-hover); }
  :where(#view-content, dialog) :where(td small) { display: block; margin-top: 2px; color: var(--ui-muted); font-size: var(--type-meta); }
  :where(.ff-table) { min-width: 720px; }

  :where(.num, .numeric, td.mono, th.num) { text-align: right; font-variant-numeric: tabular-nums; }

  /* ── List toolbars and pagination ───────────────────────── */
  :where(.table-toolbar) { display: block; margin: 0 0 var(--space-3); padding: 0; border: 0; }
  :where(.table-tools) { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); width: 100%; }
  :where(.table-tools) :where(.search-field) { flex: 1 1 280px; max-width: 460px; }
  :where(.table-footer, .ff-pagination) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    color: var(--ui-muted);
    font-size: var(--type-meta);
  }
  :where(.page-controls, .ff-pagination > div) { display: flex; align-items: center; gap: var(--space-1); }
  :where(.page-controls) :where(button) { min-width: var(--control-h); }
  :where(#page-info, .page-info) { font-family: var(--font-data); font-variant-numeric: tabular-nums; color: var(--ui-text); }

  /* Page size + "select the visible page" (list-sorting.js#pageToolbar). */
  :where(.page-selection) {
    gap: var(--space-2);
    padding: var(--space-1);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-control);
    background: var(--ui-raised);
  }
  :where(.page-selection) :where(label) { display: inline-flex; align-items: center; gap: var(--space-2); padding-left: var(--space-2); color: var(--ui-muted); font-size: var(--type-meta); }
  :where(.page-selection) :where(select) { min-height: var(--control-h-sm); font-family: var(--font-data); }
  :where(.page-selection) :where(.button, .ff-button) { min-height: var(--control-h-sm); }

  /* ── Badges ─────────────────────────────────────────────── */
  :where(.status-badge, .badge, .ff-badge) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    padding: 0 var(--space-2);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-xs);
    background: var(--ui-raised);
    color: var(--ui-text);
    font-size: var(--type-micro);
    font-weight: var(--weight-medium);
    line-height: 1.2;
    white-space: nowrap;
  }
  :where(.status-badge, .badge, .ff-badge):is(.approve, .ff-success, .success, .ok) { border-color: var(--ui-success-border); background: var(--ui-success-bg); color: var(--ui-success); }
  :where(.status-badge, .badge, .ff-badge):is(.review, .ff-warning, .warning, .pending) { border-color: var(--ui-warning-border); background: var(--ui-warning-bg); color: var(--ui-warning); }
  :where(.status-badge, .badge, .ff-badge):is(.hold, .ff-danger, .danger, .error) { border-color: var(--ui-danger-border); background: var(--ui-danger-bg); color: var(--ui-danger); }
  :where(.status-badge, .badge, .ff-badge).ff-muted { color: var(--ui-muted); }

  /* ── Dialogs (modal) ─────────────────────────────────────── */
  :where(dialog) {
    max-width: min(640px, calc(100vw - 32px));
    max-height: min(86dvh, 900px);
    padding: 0;
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-card);
    background: var(--ui-surface);
    color: var(--ui-text);
    box-shadow: var(--ui-shadow);
    overflow: auto;
    overscroll-behavior: contain;
  }
  :where(dialog)::backdrop { background: var(--ui-scrim); }
  :where(dialog[open]) { animation: menza-dialog-in var(--dur-slow) var(--ease-out); }
  :where(#dialog) { width: min(680px, calc(100vw - 32px)); }
  :where(.ff-dialog) { width: min(1100px, calc(100vw - 40px)); max-width: calc(100vw - 40px); }
  @media (max-width: 767px) {
    :where(dialog:not(.exec-command, .menza-period-dialog)) { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  }
  :where(.dialog-head, .ff-dialog-header) {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6) var(--space-4);
    border-bottom: 1px solid var(--ui-border);
    background: var(--ui-surface);
  }
  :where(.dialog-head, .ff-dialog-header) :where(h2) { margin: 0; font-size: var(--type-section); }
  :where(.dialog-head, .ff-dialog-header) :where(p) { margin: var(--space-1) 0 0; color: var(--ui-muted); font-size: var(--type-label); }
  :where(.dialog-close) { flex-shrink: 0; margin: -6px -10px 0 0; }
  :where(.dialog-body, .ff-dialog-body) { padding: var(--space-5) var(--space-6) var(--space-6); }
  :where(.dialog-actions) {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-6);
  }

  /* ── Side sheet: details open beside the list, keeping context ── */
  :where(dialog.order-drawer, dialog[data-sheet], dialog.exec-filter-dialog) {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(var(--drawer-w), 100vw);
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-width: 0 0 0 1px;
    border-radius: var(--radius-card) 0 0 var(--radius-card);
    animation: menza-sheet-in var(--dur-slow) var(--ease-out);
  }
  @media (max-width: 767px) {
    :where(dialog.order-drawer, dialog[data-sheet], dialog.exec-filter-dialog) { width: 100vw; border-radius: 0; border-width: 0; }
  }
  /* Order drawer: fixed head, scrolling body, decision actions pinned to the footer. */
  :where(#dialog.order-drawer) { overflow: hidden; }
  :where(#dialog.order-drawer) > :where(#dialog-content) { display: flex; flex-direction: column; height: 100%; min-height: 0; }
  :where(#dialog.order-drawer) :where(.dialog-head) { position: static; flex: none; }
  :where(#dialog.order-drawer) :where(.dialog-body) { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  :where(.exec-decision-bar) {
    display: flex;
    flex: none;
    flex-direction: row-reverse;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-4) var(--space-6) calc(var(--space-4) + env(safe-area-inset-bottom));
    border-top: 1px solid var(--ui-border);
    background: var(--ui-surface);
  }
  :where(.exec-decision-bar) > :where(button, .button) { flex: 1; white-space: normal; }

  /* ── Toast ──────────────────────────────────────────────── */
  :where(.toast) {
    position: fixed;
    right: var(--space-6);
    bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
    z-index: var(--z-toast);
    max-width: min(420px, calc(100vw - 32px));
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-control);
    background: var(--ui-primary);
    color: var(--ui-on-primary);
    font-size: var(--type-label);
    font-weight: var(--weight-medium);
    box-shadow: var(--ui-shadow);
    opacity: 0;
    translate: 0 12px;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease-out), translate var(--dur) var(--ease-out);
  }
  :where(.toast.visible) { opacity: 1; translate: 0 0; pointer-events: auto; }
  @media (max-width: 767px) { :where(.toast) { left: var(--space-4); right: var(--space-4); max-width: none; } }

  /* ── Empty, loading and error states ─────────────────────── */
  :where(.empty-state, .ff-empty) {
    display: grid;
    justify-items: center;
    gap: var(--space-2);
    padding: var(--space-10) var(--space-6);
    color: var(--ui-muted);
    text-align: center;
  }
  :where(.empty-state, .ff-empty) :where(strong, h3) { color: var(--ui-text); font-size: var(--type-body); }
  :where(.empty-state, .ff-empty) :where(p) { max-width: 52ch; margin: 0; line-height: var(--leading-copy); }
  :where(.enterprise-loading, .workspace-status) {
    display: grid;
    justify-items: center;
    gap: var(--space-4);
    padding: var(--space-12) var(--space-6);
    color: var(--ui-muted);
    text-align: center;
  }
  :where(.workspace-status) :where(h2) { margin: 0; font-size: var(--type-section); }
  :where(.workspace-status) :where(p) { margin: 0; }
  :where(.enterprise-loading-bars, .enterprise-skeleton) { display: grid; gap: var(--space-2); width: min(320px, 100%); }
  :where(.enterprise-loading-bars, .enterprise-skeleton) > span {
    display: block;
    height: 12px;
    border-radius: var(--radius-xs);
    background: var(--ui-raised);
    animation: menza-pulse 1.4s ease-in-out infinite;
  }
  :where(.enterprise-loading-bars, .enterprise-skeleton) > span:nth-child(2) { width: 82%; animation-delay: .12s; }
  :where(.enterprise-loading-bars, .enterprise-skeleton) > span:nth-child(3) { width: 58%; animation-delay: .24s; }
  :where(.loading-ring) {
    display: block;
    width: 28px;
    height: 28px;
    border: 2px solid var(--ui-border);
    border-top-color: var(--ui-accent);
    border-radius: 50%;
    animation: menza-spin .8s linear infinite;
  }

  /* ── Row overflow menu (app.js MutationObserver) ─────────── */
  :where(.enterprise-row-menu) { position: relative; display: inline-block; flex: none; vertical-align: middle; }
  :where(.enterprise-row-menu) > summary {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--control-h);
    height: var(--control-h);
    list-style: none;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    color: var(--ui-muted);
    font-size: 20px;
  }
  :where(.enterprise-row-menu) > summary::-webkit-details-marker { display: none; }
  :where(.enterprise-row-menu) > summary:hover { background: var(--ui-hover); border-color: var(--ui-border); color: var(--ui-text); }
  :where(.enterprise-row-menu) > div {
    position: fixed;
    z-index: var(--z-overlay);
    min-width: 220px;
    max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: var(--space-1);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-control);
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow);
  }
  :where(.enterprise-row-menu:not([open])) > div { display: none; }
  :where(.enterprise-row-menu) > div > :where(button, a) {
    display: flex;
    justify-content: flex-start;
    width: 100%;
    min-height: var(--control-h);
    margin: 0;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--ui-text);
    text-align: left;
  }
  :where(.enterprise-row-menu) > div > :where(button, a):hover { background: var(--ui-hover); }
  :where(.enterprise-filter-more) { min-width: 0; margin: 0; padding: 0; border: 0; }
  :where(.enterprise-filter-more) > summary { display: flex; align-items: center; gap: var(--space-2); min-height: var(--control-h); color: var(--ui-muted); }
  @media (min-width: 701px) {
    :where(.enterprise-filter-more) { display: block; flex: 1 1 100%; width: 100%; grid-column: 1 / -1; }
    :where(.enterprise-filter-more) > summary { display: none; }
  }

  /* ── Shared period picker (api-client.js#periodPicker) ───── */
  :where(.menza-period-trigger) { font-variant-numeric: tabular-nums; }
  :where(.menza-period-dialog) { width: min(30rem, calc(100vw - 32px)); }
  :where(.menza-period-dialog) { padding: var(--space-5); }
  :where(.menza-period-dialog) > * + * { margin-top: var(--space-4); }
  :where(.menza-period-dialog) :where(header) { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); }
  :where(.menza-period-dialog) :where(header h2) { margin: 0; font-size: var(--type-section); }
  :where(.menza-period-dialog) :where(form) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: var(--space-3); }
  :where(.menza-period-dialog) :where(form label) { display: grid; gap: 6px; color: var(--ui-muted); font-size: var(--type-meta); font-weight: var(--weight-medium); }
  :where(.menza-period-dialog) :where(form input) { width: 100%; min-width: 0; }
  :where(.menza-period-dialog) :where(form button) { grid-column: 1 / -1; }
  :where(.menza-period-presets) { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  :where(.menza-period-presets) :where(button) {
    min-height: var(--control-h-sm);
    padding: 0 var(--space-3);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-pill);
    background: var(--ui-raised);
    color: var(--ui-muted);
    font-size: var(--type-label);
  }
  :where(.menza-period-presets) :where(button):is([aria-pressed="true"], .active, .primary) { border-color: var(--ui-accent-line); background: var(--ui-accent-soft); color: var(--ui-text); }
  :where(.menza-month-nav) { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
  :where(.menza-month-days) { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
  :where(.menza-month-days) :where(button) {
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--ui-text);
    font-family: var(--font-data);
    font-variant-numeric: tabular-nums;
  }
  :where(.menza-month-days) :where(button):hover { background: var(--ui-hover); }
  :where(.menza-month-days) :where(button)[aria-pressed="true"] { border-color: var(--ui-accent-line); background: var(--ui-accent-soft); }

  /* ── Appearance picker ──────────────────────────────────── */
  :where(.appearance-options) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin: 0; padding: 0; border: 0; }
  :where(.appearance-option) {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 64px;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-control);
    background: var(--ui-raised);
    color: var(--ui-text);
    font-weight: var(--weight-medium);
    cursor: pointer;
  }
  :where(.appearance-option):has(input:checked) { border-color: var(--ui-accent-line); background: var(--ui-accent-soft); }

  /* ── Copy affordance ([data-copy], installed by executive-shell.js) ── */
  :where(.menza-copyable) { display: inline-flex; align-items: center; gap: var(--space-1); max-width: 100%; }
  :where(.menza-copy) {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--ui-subtle);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
  }
  :where(.menza-copy) svg { width: 14px; height: 14px; }
  :where(.menza-copyable):hover :where(.menza-copy), :where(.menza-copy):focus-visible, :where(tr:hover) :where(.menza-copy) { opacity: 1; }
  :where(.menza-copy):hover { background: var(--ui-hover); color: var(--ui-text); border-color: var(--ui-border); }
  :where(.menza-copy)[data-copied="true"] { color: var(--ui-success); opacity: 1; }
  @media (hover: none) { :where(.menza-copy) { opacity: 1; width: 36px; height: 36px; } }

  /* ── Text-style actions (legacy .sidebar-link / .text-button) ── */
  :where(.text-button, .sidebar-link) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 40px;
    padding: 0 var(--space-2);
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--ui-muted);
    font-size: var(--type-label);
    font-weight: var(--weight-medium);
  }
  :where(.text-button, .sidebar-link):hover { background: var(--ui-hover); color: var(--ui-text); }
  :where(input[type="range"]) { width: 100%; height: 32px; margin: 0; accent-color: var(--ui-accent); cursor: pointer; }
  :where(input[type="checkbox"].toggle) {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    flex: none;
    width: 48px;
    height: 28px;
    border: 1px solid var(--ui-control-border);
    border-radius: var(--radius-pill);
    background: var(--ui-raised);
    transition: background-color var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
  }
  :where(input[type="checkbox"].toggle)::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--ui-muted);
    transition: transform var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out);
  }
  :where(input[type="checkbox"].toggle):checked { border-color: var(--ui-accent-line); background: var(--ui-accent-soft); }
  :where(input[type="checkbox"].toggle):checked::before { transform: translateX(20px); background: var(--ui-accent); }
  @media (pointer: coarse) { :where(.text-button, .sidebar-link) { min-height: 44px; } }

  /* ── Disclosure basics ──────────────────────────────────── */
  :where(details) > summary { list-style: none; }
  :where(#view-content details) > summary { min-height: 40px; }
  @media (pointer: coarse) { :where(#view-content details) > summary { min-height: 44px; } }
  :where(details) > summary::-webkit-details-marker { display: none; }

  @keyframes menza-dialog-in { from { opacity: 0; transform: translateY(8px) scale(.99); } }
  @keyframes menza-sheet-in { from { opacity: .4; transform: translateX(24px); } }
  @keyframes menza-pulse { 50% { opacity: .45; } }
  @keyframes menza-spin { to { transform: rotate(360deg); } }

  @media (max-width: 700px) {
    :where(.commerce-fields, .field-row, .commerce-native-grid) { grid-template-columns: minmax(0, 1fr); }
    :where(.commerce-metrics, .stat-grid) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
    :where(.commerce-metrics) > div, :where(.stat) { padding: var(--space-3); }
    :where(.commerce-panel, .ff-card) { padding: var(--space-4); }
    :where(.table-tools) :where(.search-field) { flex-basis: 100%; max-width: none; }
    :where(.dialog-head, .ff-dialog-header) { padding: var(--space-4); }
    :where(.dialog-body, .ff-dialog-body) { padding: var(--space-4); }
  }
}

/* Mobile card tables must beat module table widths (min-width on wide tables),
   exactly as the legacy rules did, so they live in the modules layer. */
@layer modules {
  /* Tables become scannable cards on small screens (commerce-hub.js sets the attributes). */
  @media (max-width: 1024px) {
    body.commerce-shell table[data-mobile-cards] { display: block; width: 100%; min-width: 0; max-width: 100%; border: 0; text-align: left; }
    body.commerce-shell table[data-mobile-cards] > thead:not([data-mobile-controls]) {
      position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
    body.commerce-shell table[data-mobile-cards] > thead[data-mobile-controls] { display: block; margin-bottom: var(--space-3); }
    body.commerce-shell table[data-mobile-cards] > thead[data-mobile-controls] > tr { display: flex; flex-wrap: wrap; gap: var(--space-3); }
    body.commerce-shell table[data-mobile-cards] > thead[data-mobile-controls] th { display: none; }
    body.commerce-shell table[data-mobile-cards] > tbody { display: grid; gap: var(--space-3); }
    body.commerce-shell table[data-mobile-cards] > tbody > tr {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      min-width: 0;
      padding: var(--space-1) 0;
      border: 1px solid var(--ui-border);
      border-radius: var(--radius-card);
      background: var(--ui-surface);
    }
    body.commerce-shell table[data-mobile-cards] > tbody > tr > :is(td, th) {
      display: block;
      width: auto;
      min-width: 0;
      max-width: none;
      padding: var(--space-2) var(--space-4);
      border: 0;
      background: transparent;
      text-align: left;
    }
    body.commerce-shell table[data-mobile-cards] > tbody > tr:hover > :is(td, th) { background: transparent; }
    body.commerce-shell table[data-mobile-cards] > tbody > tr > [data-mobile-wide] { grid-column: 1 / -1; }
    body.commerce-shell table[data-mobile-cards] > tbody > tr > :is(td, th)::before {
      content: attr(data-mobile-label);
      display: block;
      margin-bottom: 2px;
      color: var(--ui-muted);
      font-family: var(--font-ui);
      font-size: var(--type-meta);
      font-weight: var(--weight-medium);
    }
    body.commerce-shell table[data-mobile-cards] > tbody > tr > :is([data-mobile-label=""], [data-mobile-actions])::before { display: none; }
    body.commerce-shell table[data-mobile-cards] > tbody > tr > :is(td, th):first-child { margin-bottom: var(--space-1); padding-top: var(--space-3); border-bottom: 1px solid var(--ui-divider); }
    body.commerce-shell table[data-mobile-cards] > tbody > tr > [data-mobile-actions] { padding-top: var(--space-3); text-align: left; }
    body.commerce-shell table[data-mobile-cards] [data-mobile-actions] :is(button, a.button) { width: 100%; justify-content: center; }
  }
  @media (min-width: 600px) and (max-width: 1024px) {
    body.commerce-shell table[data-mobile-cards] > tbody { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  }
}

/* Numărul comenzii ca link spre Shopify Admin (tab nou). */
a.shopify-order-link{color:inherit;text-decoration:underline;text-decoration-color:color-mix(in srgb,currentColor 35%,transparent);text-underline-offset:2px}
a.shopify-order-link:hover,a.shopify-order-link:focus-visible{text-decoration-color:currentColor}
.detail-shopify-link{margin:0 0 12px}

/* Conversația WhatsApp a unei comenzi */
.wa-conversation{list-style:none;margin:8px 0 0;padding:0;display:flex;flex-direction:column;gap:6px;max-width:520px}
.wa-message{padding:6px 10px;border-radius:10px;border:1px solid color-mix(in srgb,currentColor 15%,transparent)}
.wa-message small{display:block;opacity:.7;font-size:.8em}
.wa-message p{margin:2px 0 0;white-space:pre-wrap;overflow-wrap:anywhere}
.wa-message.from-customer{align-self:flex-start;background:color-mix(in srgb,currentColor 4%,transparent)}
.wa-message.from-shop{align-self:flex-end;background:color-mix(in srgb,var(--ui-success) 12%,transparent)}
