/* Unified UI. Load tokens first and opt in on body: data-ui="unified".
 * Department/surface/density change semantic aliases only. Old pages remain on their current entry point.
 * Temporary adapters: dashboard, queue, publisher and public form/date hooks share primitives here.
 * Remove adapters as each family adopts canonical classes; do not copy them into page stylesheets.
 * Sublayers: primitives -> patterns -> pages. No normal rules directly in the parent components layer.
 */

@layer components.primitives, components.patterns, components.pages;

@layer reset {
    :where([data-ui="unified"], [data-ui="unified"] *) {
        box-sizing: border-box;
    }
}

@layer base {
    [data-ui="unified"] {
        margin: 0;
        font: var(--font-size-base)/var(--line-height-base) var(--ui-font);
        color: var(--ui-ink);
        background: var(--ui-canvas);
    }

    [data-ui="unified"][data-surface="storefront"] {
        --ui-canvas: var(--store-paper);
        --ui-tint: var(--store-paper-deep);
    }

    [data-ui="unified"][data-department="steve"] {
        --ui-accent: var(--color-steve-dark);
        --ui-accent-hover: var(--color-steve-dark);
        --ui-tint: var(--color-steve-tint);
    }

    [data-ui="unified"][data-department="ruth"] {
        --ui-accent: var(--color-ruth);
        --ui-accent-hover: var(--color-ruth-dark);
        --ui-tint: var(--color-ruth-tint);
    }

    [data-ui="unified"][data-department="bradley"] {
        --ui-accent: var(--color-bradley-dark);
        --ui-accent-hover: var(--color-bradley-dark);
        --ui-tint: var(--color-bradley-tint);
    }

    [data-ui="unified"][data-department="floor"] {
        --ui-accent: var(--color-floor-dark);
        --ui-accent-hover: var(--color-floor-dark);
        --ui-tint: var(--color-floor-tint);
    }

    [data-ui="unified"][data-department="ae"] {
        --ui-accent: var(--color-ae);
        --ui-accent-hover: var(--color-ae-dark);
        --ui-tint: var(--gray-100);
    }

    [data-ui="unified"][data-density="compact"] {
        --ui-panel-space: var(--space-4);
        --ui-row-space: var(--space-2);
    }

    :where([data-ui="unified"]) a {
        color: var(--ui-accent);
        text-underline-offset: 0.18em;
    }

    :where([data-ui="unified"]) :focus-visible {
        outline: 2px solid var(--ui-accent);
        outline-offset: 3px;
    }

    :where([data-ui="unified"]) :is(input, select, textarea, button) {
        font: inherit;
    }

    :where([data-ui="unified"]) :is(h1, h2, h3) {
        line-height: 1.25;
        text-wrap: balance;
    }

    :where([data-ui="unified"]) :is(img, svg) {
        max-width: 100%;
    }

    :where([data-ui="unified"]) :is(p, li, td, label) {
        overflow-wrap: anywhere;
    }

    :where([data-ui="unified"]) :is(section[id], h2[id]) {
        scroll-margin-top: var(--space-8);
    }
}

@layer components.primitives {
    :where([data-ui="unified"]) :is(.btn, .bt-btn, .tas-btn),
    :where([data-ui="unified"]) .page-nav-link,
    :where([data-ui="unified"]) .dash-back-link,
    :where([data-ui="unified"]) .dq-filter,
    :where([data-ui="unified"]) .dq-refresh,
    :where([data-ui="unified"]) .quick-nav-btn,
    :where([data-ui="unified"]) .date-pick-btn,
    :where([data-ui="unified"]) .dash-error-banner-close,
    :where([data-ui="unified"]) .dash-btn,
    :where([data-ui="unified"]) .gp-cell-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-2);
        min-height: var(--ui-control-height);
        padding: var(--space-2) var(--space-4);
        border: 1px solid var(--ui-line-strong);
        border-radius: var(--radius-sm);
        background: var(--ui-surface);
        color: var(--ui-ink);
        font: inherit;
        font-size: var(--font-size-md);
        font-weight: 600;
        line-height: 1.3;
        text-decoration: none;
        cursor: pointer;
        transition:
            background var(--motion-fast) var(--ease-out),
            border-color var(--motion-fast) var(--ease-out);
    }

    :where([data-ui="unified"])
        :is(
            :is(.btn, .bt-btn, .tas-btn),
            .page-nav-link,
            .dash-back-link,
            .dq-filter,
            .dq-refresh,
            .quick-nav-btn,
            .date-pick-btn
        ):hover,
    :where([data-ui="unified"])
        :is(
            .dash-btn,
            .page-nav-link,
            .dash-back-link,
            .dq-filter,
            .dq-refresh,
            .quick-nav-btn,
            .date-pick-btn
        ):hover,
    :where([data-ui="unified"])
        :is(
            .gp-cell-btn,
            .page-nav-link,
            .dash-back-link,
            .dq-filter,
            .dq-refresh,
            .quick-nav-btn,
            .date-pick-btn
        ):hover {
        background: var(--ui-tint);
        border-color: var(--ui-accent);
    }

    :where([data-ui="unified"]) :is(.btn-primary, .bt-btn--primary, .tas-btn--primary),
    :where([data-ui="unified"]) .dq-filter[aria-pressed="true"],
    :where([data-ui="unified"]) .dash-btn--primary {
        background: var(--ui-accent);
        border-color: var(--ui-accent);
        color: var(--color-on-brand);
    }

    :where([data-ui="unified"]) :is(.btn-primary, .bt-btn--primary, .tas-btn--primary):hover,
    :where([data-ui="unified"]) .dash-btn--primary:hover {
        background: var(--ui-accent-hover);
        border-color: var(--ui-accent-hover);
    }

    :where([data-ui="unified"]) .dq-filter[aria-pressed="true"]:hover {
        background: var(--ui-accent-hover);
    }

    :where([data-ui="unified"]) :is(.btn-ghost, .bt-btn--link),
    :where([data-ui="unified"]) .dash-btn--ghost {
        background: transparent;
        border-color: transparent;
        color: var(--ui-accent);
    }

    :where([data-ui="unified"]) :is(.btn-danger, .bt-btn--danger) {
        background: var(--color-danger-ink);
        border-color: var(--color-danger-ink);
        color: var(--color-on-brand);
    }

    :where([data-ui="unified"]) :is(.btn-danger, .bt-btn--danger):hover {
        background: var(--color-danger-ink);
    }

    :where([data-ui="unified"]) :is(:is(.btn, .bt-btn, .tas-btn), .dq-refresh):disabled,
    :where([data-ui="unified"]) :is(.dash-btn, .dq-refresh):disabled,
    :where([data-ui="unified"]) :is(.gp-cell-btn, .dq-refresh):disabled {
        background: var(--gray-100);
        border-color: var(--ui-line-strong);
        color: var(--ui-muted);
        cursor: not-allowed;
    }

    :where([data-ui="unified"]) .field,
    :where([data-ui="unified"]) .gp-field {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        min-width: 0;
    }

    :where([data-ui="unified"]) :is(.field-label, .bt-form-field > label, .tas-form-field > label),
    :where([data-ui="unified"]) .gp-field > span {
        font-size: var(--font-size-md);
        font-weight: 600;
    }

    :where([data-ui="unified"]) .req,
    :where([data-ui="unified"]) .field-msg {
        color: var(--color-danger-ink);
    }

    :where([data-ui="unified"])
        :is(
            .field-input,
            .bt-filter-input,
            .bt-lscm-input,
            .bt-form-field input:not([type="checkbox"], [type="radio"]),
            .bt-form-field select,
            .bt-form-field textarea,
            .tas-input,
            .tas-form-field input:not([type="checkbox"], [type="radio"]),
            .tas-form-field select,
            .tas-form-field textarea
        ),
    :where([data-ui="unified"]) .field-select,
    :where([data-ui="unified"])
        :is(.field-textarea, .bt-form-field textarea, .tas-form-field textarea),
    :where([data-ui="unified"]) .gp-field input[type="text"],
    :where([data-ui="unified"]) .gp-field input[type="file"],
    :where([data-ui="unified"]) .gp-field textarea {
        width: 100%;
        min-width: 0;
        min-height: var(--ui-control-height);
        border: 1px solid var(--ui-line-strong);
        border-radius: var(--radius-sm);
        background: var(--ui-surface);
        color: var(--ui-ink);
        padding: var(--space-2) var(--space-3);
        font: inherit;
        font-size: var(--font-size-base);
    }

    :where([data-ui="unified"])
        :is(.field-textarea, .bt-form-field textarea, .tas-form-field textarea),
    :where([data-ui="unified"]) .gp-field textarea {
        min-height: 112px;
        resize: vertical;
    }

    :where([data-ui="unified"])
        :is(
            :is(
                .field-input,
                .bt-filter-input,
                .bt-lscm-input,
                .bt-form-field input:not([type="checkbox"], [type="radio"]),
                .bt-form-field select,
                .bt-form-field textarea,
                .tas-input,
                .tas-form-field input:not([type="checkbox"], [type="radio"]),
                .tas-form-field select,
                .tas-form-field textarea
            ),
            .field-select,
            :is(.field-textarea, .bt-form-field textarea, .tas-form-field textarea)
        ):focus,
    :where([data-ui="unified"])
        :is(
            .gp-field input[type="text"],
            .field-select,
            :is(.field-textarea, .bt-form-field textarea, .tas-form-field textarea)
        ):focus,
    :where([data-ui="unified"])
        :is(
            .gp-field input[type="file"],
            .field-select,
            :is(.field-textarea, .bt-form-field textarea, .tas-form-field textarea)
        ):focus,
    :where([data-ui="unified"])
        :is(
            :is(
                .field-input,
                .bt-filter-input,
                .bt-lscm-input,
                .bt-form-field input:not([type="checkbox"], [type="radio"]),
                .bt-form-field select,
                .bt-form-field textarea,
                .tas-input,
                .tas-form-field input:not([type="checkbox"], [type="radio"]),
                .tas-form-field select,
                .tas-form-field textarea
            ),
            .field-select,
            .gp-field textarea
        ):focus {
        outline: 2px solid var(--ui-accent);
        outline-offset: 2px;
        border-color: var(--ui-accent);
    }

    :where([data-ui="unified"])
        :is(
            .field-input,
            .bt-filter-input,
            .bt-lscm-input,
            .bt-form-field input:not([type="checkbox"], [type="radio"]),
            .bt-form-field select,
            .bt-form-field textarea,
            .tas-input,
            .tas-form-field input:not([type="checkbox"], [type="radio"]),
            .tas-form-field select,
            .tas-form-field textarea
        )[aria-invalid="true"],
    :where([data-ui="unified"])
        .field.is-error
        :is(
            .field-input,
            .bt-filter-input,
            .bt-lscm-input,
            .bt-form-field input:not([type="checkbox"], [type="radio"]),
            .bt-form-field select,
            .bt-form-field textarea,
            .tas-input,
            .tas-form-field input:not([type="checkbox"], [type="radio"]),
            .tas-form-field select,
            .tas-form-field textarea
        ),
    :where([data-ui="unified"])
        .gp-field.is-error
        :is(
            .field-input,
            .bt-filter-input,
            .bt-lscm-input,
            .bt-form-field input:not([type="checkbox"], [type="radio"]),
            .bt-form-field select,
            .bt-form-field textarea,
            .tas-input,
            .tas-form-field input:not([type="checkbox"], [type="radio"]),
            .tas-form-field select,
            .tas-form-field textarea
        ),
    :where([data-ui="unified"]) .gp-field input[type="text"][aria-invalid="true"],
    :where([data-ui="unified"]) .field.is-error .gp-field input[type="text"],
    :where([data-ui="unified"]) .gp-field input[type="file"][aria-invalid="true"],
    :where([data-ui="unified"]) .field.is-error .gp-field input[type="file"] {
        border-color: var(--color-danger-ink);
    }

    :where([data-ui="unified"]) .field-help,
    :where([data-ui="unified"]) .field-msg {
        font-size: var(--font-size-sm);
        margin: 0;
    }

    :where([data-ui="unified"]) .field-help {
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .choice,
    :where([data-ui="unified"]) .gp-check {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        min-height: var(--ui-control-height);
        padding: var(--space-2) var(--space-3);
        border: 1px solid var(--ui-line-strong);
        border-radius: var(--radius-sm);
        cursor: pointer;
    }

    :where([data-ui="unified"]) .choice:has(input:checked),
    :where([data-ui="unified"]) .gp-check:has(input:checked) {
        background: var(--ui-tint);
        border-color: var(--ui-accent);
    }

    :where([data-ui="unified"]) .choice input,
    :where([data-ui="unified"]) .gp-check input {
        accent-color: var(--ui-accent);
        width: 20px;
        height: 20px;
        flex: 0 0 20px;
        margin: 0;
    }

    :where([data-ui="unified"]) .card,
    :where([data-ui="unified"]) .dash-card,
    :where([data-ui="unified"]) .dash-stat-card {
        background: var(--ui-surface);
        border: 1px solid var(--ui-line);
        border-radius: var(--radius-card);
        padding: var(--ui-panel-space);
        margin-bottom: var(--space-5);
        min-width: 0;
    }

    :where([data-ui="unified"]) .card-title,
    :where([data-ui="unified"]) .dash-card-title {
        margin: 0;
        color: var(--ui-ink);
        font-size: var(--font-size-xl);
        font-weight: 600;
    }

    :where([data-ui="unified"]) .card > .card-title {
        margin-bottom: var(--space-4);
    }

    :where([data-ui="unified"]) .card-sub,
    :where([data-ui="unified"]) .text-muted {
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .alert,
    :where([data-ui="unified"]) .public-form-banner,
    :where([data-ui="unified"]) .dash-error-banner {
        border: 1px solid var(--ui-line);
        border-radius: var(--radius-md);
        padding: var(--space-4);
        margin-bottom: var(--space-4);
        background: var(--ui-surface);
    }

    :where([data-ui="unified"]) .alert-error,
    :where([data-ui="unified"]) .public-form-banner.is-error,
    :where([data-ui="unified"]) .dash-error-banner {
        background: var(--color-danger-bg);
        border-color: var(--color-danger-ink);
        color: var(--color-danger-ink);
    }

    :where([data-ui="unified"]) .alert-success,
    :where([data-ui="unified"]) .public-form-banner.is-ok {
        background: var(--color-success-bg);
        color: var(--color-brand-deep);
    }

    :where([data-ui="unified"]) .alert-warn {
        background: var(--color-warning-bg);
        color: var(--color-warning-ink);
    }

    :where([data-ui="unified"]) .alert-info {
        background: var(--color-info-bg);
        color: var(--color-info-ink);
    }

    :where([data-ui="unified"]) .alert-body {
        margin: var(--space-1) 0 0;
    }

    :where([data-ui="unified"]) :is(.badge, .bt-badge),
    :where([data-ui="unified"]) .dq-chip,
    :where([data-ui="unified"]) .dq-flag,
    :where([data-ui="unified"]) .dq-conf {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        align-self: start;
        gap: var(--space-1);
        border-radius: var(--radius-sm);
        padding: var(--space-1) var(--space-2);
        font-size: var(--font-size-sm);
        font-weight: 600;
        line-height: 1.4;
        background: var(--gray-100);
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .badge-ok,
    :where([data-ui="unified"]) .dq-chip--draw,
    :where([data-ui="unified"]) .dq-conf--confirmed {
        background: var(--color-success-bg);
        color: var(--color-brand-deep);
    }

    :where([data-ui="unified"]) .badge-warn,
    :where([data-ui="unified"]) .dq-chip--research,
    :where([data-ui="unified"]) .dq-flag--warn,
    :where([data-ui="unified"]) .dq-conf--memory {
        background: var(--color-warning-bg);
        color: var(--color-warning-ink);
    }

    :where([data-ui="unified"]) .badge-bad {
        background: var(--color-danger-bg);
        color: var(--color-danger-ink);
    }

    :where([data-ui="unified"]) .table-wrap,
    :where([data-ui="unified"]) .dq-metrics-scroll {
        max-width: 100%;
        overflow: auto;
    }

    :where([data-ui="unified"]) .data-table,
    :where([data-ui="unified"]) .dq-metrics-table,
    :where([data-ui="unified"]) .gp-binding-table {
        width: 100%;
        border-collapse: collapse;
        font-size: var(--font-size-md);
    }

    :where([data-ui="unified"]) :is(.data-table, .dq-metrics-table) :is(th, td),
    :where([data-ui="unified"]) :is(.gp-binding-table, .dq-metrics-table) :is(th, td) {
        text-align: left;
        padding: var(--ui-row-space) var(--space-3);
        border-bottom: 1px solid var(--ui-line);
        vertical-align: top;
    }

    :where([data-ui="unified"]) :is(.data-table, .dq-metrics-table) th,
    :where([data-ui="unified"]) :is(.gp-binding-table, .dq-metrics-table) th {
        font-size: var(--font-size-sm);
        font-weight: 600;
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .data-table .num,
    :where([data-ui="unified"]) .dq-metrics-table td:last-child,
    :where([data-ui="unified"]) .gp-binding-table .num {
        font-variant-numeric: tabular-nums;
    }

    :where([data-ui="unified"]) .data-table .num,
    :where([data-ui="unified"]) .gp-binding-table .num {
        text-align: right;
    }

    :where([data-ui="unified"]) .ui-dialog {
        width: min(560px, calc(100% - 32px));
        max-height: calc(100% - 32px);
        padding: var(--ui-panel-space);
        border: 1px solid var(--ui-line);
        border-radius: var(--radius-lg);
        background: var(--ui-surface);
        color: var(--ui-ink);
        box-shadow: var(--shadow-md);
    }

    :where([data-ui="unified"]) .ui-dialog::backdrop {
        background: rgb(0 0 0 / 45%);
    }

    :where([data-ui="unified"]) .ui-dialog h2 {
        margin-top: 0;
    }

    :where([data-ui="unified"]) .dialog-actions {
        display: flex;
        justify-content: flex-end;
        gap: var(--space-2);
        margin-top: var(--space-5);
    }
}

@layer components.patterns {
    :where([data-ui="unified"]) .dash-shell {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    :where([data-ui="unified"]) .dash-shell > .dash-content {
        flex: 1;
    }

    :where([data-ui="unified"]) .gp-field {
        margin: var(--space-4) 0;
    }

    :where([data-ui="unified"]) .gp-field > span em {
        font-style: normal;
        color: var(--color-danger-ink);
    }

    :where([data-ui="unified"]) .gp-check {
        flex-wrap: wrap;
    }

    :where([data-ui="unified"]) .gp-check input {
        flex: 0 0 20px;
    }

    :where([data-ui="unified"]) .gp-binding {
        max-width: 100%;
        overflow: auto;
    }

    :where([data-ui="unified"]) .nwca-toast-container {
        position: fixed;
        left: 50%;
        bottom: var(--space-5);
        transform: translateX(-50%);
        z-index: var(--z-toast);
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        align-items: center;
        pointer-events: none;
        width: max-content;
        max-width: min(92vw, 640px);
    }

    :where([data-ui="unified"]) .nwca-toast {
        display: flex;
        align-items: flex-start;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-md);
        background: var(--ui-ink);
        color: var(--color-on-brand);
        font: inherit;
        font-size: var(--font-size-md);
        box-shadow: var(--shadow-md);
        opacity: 0;
        transform: translateY(8px);
        transition:
            opacity var(--motion-fast) var(--ease-out),
            transform var(--motion-fast) var(--ease-out);
        pointer-events: auto;
        white-space: pre-line;
        overflow-wrap: anywhere;
    }

    :where([data-ui="unified"]) .nwca-toast.show {
        opacity: 1;
        transform: translateY(0);
    }

    :where([data-ui="unified"]) .nwca-toast-success {
        background: var(--color-brand-deep);
    }

    :where([data-ui="unified"]) .nwca-toast-error {
        background: var(--color-danger-ink);
    }

    :where([data-ui="unified"]) .nwca-toast-warning {
        background: var(--color-warning-ink);
    }

    :where([data-ui="unified"]) .nwca-toast-info {
        background: var(--color-info-ink);
    }

    :where([data-ui="unified"]) .nwca-toast-icon {
        margin-top: 2px;
        flex: none;
    }

    :where([data-ui="unified"]) .skip-link {
        position: absolute;
        top: -100px;
        left: var(--space-3);
        z-index: var(--z-toast);
        padding: var(--space-3);
        background: var(--ui-surface);
    }

    :where([data-ui="unified"]) .skip-link:focus {
        top: var(--space-2);
    }

    :where([data-ui="unified"]) .page-header,
    :where([data-ui="unified"]) .dash-header,
    :where([data-ui="unified"]) .minimal-header,
    :where([data-ui="unified"]) .public-topbar {
        background: var(--ui-surface);
        border-bottom: 1px solid var(--ui-line);
        border-top: 3px solid var(--ui-accent);
    }

    :where([data-ui="unified"]) .page-header-inner,
    :where([data-ui="unified"]) .dash-header,
    :where([data-ui="unified"]) .minimal-header,
    :where([data-ui="unified"]) .public-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--space-4);
        padding: var(--space-4) max(var(--space-4), calc((100% - 1200px) / 2));
    }

    :where([data-ui="unified"]) .page-header-inner {
        max-width: 1248px;
        padding: var(--space-4) var(--space-5);
        margin: auto;
    }

    :where([data-ui="unified"]) .dash-header-left,
    :where([data-ui="unified"]) .dash-header-right,
    :where([data-ui="unified"]) .page-nav,
    :where([data-ui="unified"]) .bt-breadcrumb {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        flex-wrap: wrap;
    }

    :where([data-ui="unified"]) .page-header-logo,
    :where([data-ui="unified"]) .dash-header-logo,
    :where([data-ui="unified"]) .minimal-header .logo {
        display: block;
        width: auto;
        height: 44px;
    }

    :where([data-ui="unified"]) .page-title,
    :where([data-ui="unified"]) .dash-header-title {
        font-size: var(--font-size-2xl);
        margin: 0;
        font-weight: 600;
    }

    :where([data-ui="unified"]) .page-title {
        flex: 1;
    }

    :where([data-ui="unified"]) .page-main,
    :where([data-ui="unified"]) .dash-content {
        max-width: 1248px;
        margin: auto;
        padding: var(--space-6) var(--space-5);
    }

    :where([data-ui="unified"]) .dash-content {
        width: 100%;
    }

    :where([data-ui="unified"]) .page-footer {
        padding: var(--space-5);
        color: var(--ui-muted);
        font-size: var(--font-size-sm);
        text-align: center;
    }

    :where([data-ui="unified"]) .form-row,
    :where([data-ui="unified"]) .card-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-5);
    }

    :where([data-ui="unified"]) .dash-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: var(--space-4);
        margin-bottom: var(--space-4);
    }

    :where([data-ui="unified"]) .dash-stat-grid {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: var(--space-4);
        margin-bottom: var(--space-5);
    }

    :where([data-ui="unified"]) .dash-stat-card {
        margin: 0;
        text-align: left;
    }

    :where([data-ui="unified"]) button.dash-stat-card {
        cursor: pointer;
        color: inherit;
        font: inherit;
    }

    :where([data-ui="unified"]) button.dash-stat-card:hover {
        border-color: var(--ui-accent);
    }

    :where([data-ui="unified"]) .dash-stat-card[aria-pressed="true"] {
        background: var(--ui-tint);
        border-color: var(--ui-accent);
        box-shadow: inset 0 0 0 1px var(--ui-accent);
    }

    :where([data-ui="unified"]) .dash-stat-value {
        font-size: var(--font-size-display);
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        line-height: 1.2;
    }

    :where([data-ui="unified"]) .dash-stat-label {
        margin-top: var(--space-2);
        font-size: var(--font-size-sm);
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .dash-error-banner {
        display: none;
        align-items: center;
        gap: var(--space-3);
    }

    :where([data-ui="unified"]) .dash-error-banner.show {
        display: flex;
    }

    :where([data-ui="unified"]) .dash-error-banner-message {
        flex: 1;
    }

    :where([data-ui="unified"]) .dash-error-banner-close {
        flex: 0 0 var(--ui-control-height);
        padding: var(--space-2);
        background: transparent;
        color: inherit;
        border: 0;
    }

    :where([data-ui="unified"]) .dash-loading,
    :where([data-ui="unified"]) .empty-state {
        padding: var(--space-5);
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .date-anchor {
        position: relative;
        display: flex;
        align-items: stretch;
    }

    :where([data-ui="unified"])
        .date-anchor
        :is(
            .field-input,
            .bt-filter-input,
            .bt-lscm-input,
            .bt-form-field input:not([type="checkbox"], [type="radio"]),
            .bt-form-field select,
            .bt-form-field textarea,
            .tas-input,
            .tas-form-field input:not([type="checkbox"], [type="radio"]),
            .tas-form-field select,
            .tas-form-field textarea
        ),
    :where([data-ui="unified"]) .date-anchor .gp-field input[type="text"],
    :where([data-ui="unified"]) .date-anchor .gp-field input[type="file"] {
        padding-right: 52px;
    }

    :where([data-ui="unified"]) .date-pick-btn {
        position: absolute;
        right: 1px;
        bottom: 1px;
        min-width: var(--ui-control-height);
        padding: var(--space-2);
        border: 0;
        background: transparent;
    }

    :where([data-ui="unified"]) .date-pick-native {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 1px;
        height: 1px;
        opacity: 0;
        pointer-events: none;
    }

    :where([data-ui="unified"]) .hp-wrap {
        display: none;
    }

    @media (width <= 700px) {
        :where([data-ui="unified"]) .page-main,
        :where([data-ui="unified"]) .dash-content {
            padding: var(--space-5) var(--space-4);
        }

        :where([data-ui="unified"]) .page-header-inner {
            padding: var(--space-4);
        }

        :where([data-ui="unified"]) .page-title,
        :where([data-ui="unified"]) .dash-header-title {
            font-size: var(--font-size-xl);
        }

        :where([data-ui="unified"]) .dash-stat-grid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }

        :where([data-ui="unified"]) .form-row,
        :where([data-ui="unified"]) .card-grid {
            grid-template-columns: 1fr;
        }

        :where([data-ui="unified"]) .page-nav {
            width: 100%;
        }
    }

    @media print {
        :where([data-ui="unified"]) .page-header,
        :where([data-ui="unified"]) .dash-header,
        :where([data-ui="unified"]) .minimal-header,
        :where([data-ui="unified"]) .public-topbar,
        :where([data-ui="unified"]) .no-print,
        :where([data-ui="unified"]) .quick-nav,
        :where([data-ui="unified"]) .skip-link {
            display: none;
        }

        :where([data-ui="unified"]) .page-main,
        :where([data-ui="unified"]) .dash-content {
            max-width: none;
            padding: 0;
        }

        :where([data-ui="unified"]) .card {
            box-shadow: none;
            break-inside: avoid;
        }
    }

    :where([data-ui="unified"]) .product-image-unavailable {
        padding: var(--space-4);
        border-radius: var(--radius-sm);
        color: var(--color-warning-ink);
        background: var(--color-warning-bg);
    }

    :where([data-ui="unified"]) :is(.sjd-line-thumb--clickable, .td-live-line-thumb--clickable) {
        padding: 0;
        min-height: var(--ui-control-height);
        min-width: var(--ui-control-height);
    }

    :where([data-ui="unified"])
        :is(.sjd-line-thumb--clickable, .td-live-line-thumb--clickable)
        img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    :where([data-ui="unified"]) .product-image-modal-content {
        max-height: calc(100dvh - 32px);
        overflow: auto;
    }

    :where([data-ui="unified"]) .product-image-modal-close {
        min-width: var(--ui-control-height);
        min-height: var(--ui-control-height);
    }
}

@layer utilities {
    @media (prefers-reduced-motion: reduce) {
        :where([data-ui="unified"]) *,
        :where([data-ui="unified"]) *::before,
        :where([data-ui="unified"]) *::after {
            transition: none;
            scroll-behavior: auto;
            animation: none;
        }
    }

    :where([data-ui="unified"]) [hidden] {
        display: none;
    }
}

@layer components.patterns {
    :where([data-ui="unified"]) .tab-container {
        max-width: 1248px;
        margin: auto;
        padding: var(--space-6) var(--space-5);
    }

    :where([data-ui="unified"]) .tab-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        padding-bottom: var(--space-5);
    }

    :where([data-ui="unified"]) .tab-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: var(--ui-control-height);
        padding: var(--space-2) var(--space-4);
        border: 1px solid var(--ui-line);
        border-radius: var(--radius-sm);
        background: var(--ui-surface);
        color: var(--ui-ink);
        font: inherit;
        font-size: var(--font-size-md);
        text-decoration: none;
        cursor: pointer;
    }

    :where([data-ui="unified"]) .tab-button.active {
        color: var(--color-on-brand);
        background: var(--ui-accent);
        border-color: var(--ui-accent);
    }

    :where([data-ui="unified"]) .tab-button:not(.active):hover {
        background: var(--ui-tint);
        border-color: var(--ui-accent);
    }

    :where([data-ui="unified"]) .tab-title {
        margin: 0 0 var(--space-2);
        font-size: var(--font-size-2xl);
        color: var(--ui-ink);
    }

    :where([data-ui="unified"]) :is(.bt-modal, .tas-modal, .bt-lscm-overlay) {
        position: fixed;
        inset: 0;
        z-index: var(--z-modal);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-4);
    }

    :where([data-ui="unified"]) :is(.bt-modal, .bt-lscm-overlay) {
        background: rgb(0 0 0 / 45%);
    }

    :where([data-ui="unified"]) :is(.bt-modal-content, .tas-modal-content) {
        position: relative;
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 640px;
        max-height: calc(100dvh - 32px);
        min-width: 0;
        overflow: hidden;
        border: 1px solid var(--ui-line);
        border-radius: var(--radius-lg);
        background: var(--ui-surface);
        color: var(--ui-ink);
        box-shadow: var(--shadow-md);
    }

    :where([data-ui="unified"]) :is(.bt-modal-header, .tas-modal-header) {
        display: flex;
        flex-shrink: 0;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        padding: var(--space-4) var(--space-5);
        border-bottom: 1px solid var(--ui-line);
        color: var(--ui-ink);
        background: var(--ui-surface);
    }

    :where([data-ui="unified"]) :is(.bt-modal-header, .tas-modal-header) h3 {
        margin: 0;
        font-size: var(--font-size-xl);
    }

    :where([data-ui="unified"]) :is(.bt-modal-body, .tas-modal-body) {
        padding: var(--space-5);
        overflow: auto;
        min-height: 0;
    }

    :where([data-ui="unified"]) :is(.bt-modal-close, .tas-modal-close, .bt-lscm-close) {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: var(--ui-control-height);
        min-height: var(--ui-control-height);
        border: 0;
        border-radius: var(--radius-sm);
        background: transparent;
        color: var(--ui-ink);
        font-size: var(--font-size-2xl);
        cursor: pointer;
    }

    :where([data-ui="unified"]) :is(.bt-modal-close, .tas-modal-close):hover {
        background: var(--ui-tint);
    }

    :where([data-ui="unified"]) .bt-modal-content--identity {
        max-width: 400px;
    }

    :where([data-ui="unified"]) .bt-modal-content--form {
        max-width: 500px;
    }

    :where([data-ui="unified"]) .bt-modal-content--status {
        max-width: 440px;
    }

    :where([data-ui="unified"]) .bt-form-row--thirds {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    :where([data-ui="unified"]) .bt-modal-intro--warning {
        background: var(--color-warning-bg);
        border-left: 4px solid var(--color-warning-ink);
        color: var(--color-warning-ink);
    }

    :where([data-ui="unified"]) .bt-label-note {
        display: block;
        margin-top: var(--space-2);
    }

    :where([data-ui="unified"]) .bt-label-note--normal {
        font-weight: 400;
    }

    :where([data-ui="unified"]) .bt-checkline-input {
        margin-top: 3px;
    }

    :where([data-ui="unified"]) .text-danger {
        color: var(--color-danger-ink);
    }

    @media (width <= 600px) {
        :where([data-ui="unified"]) .tab-container {
            padding: var(--space-5) var(--space-4);
        }

        :where([data-ui="unified"]) .tab-button {
            flex: 1 1 45%;
        }

        :where([data-ui="unified"]) .bt-form-row--thirds {
            grid-template-columns: 1fr;
        }
    }
}

/* Bradley workflow: scoped shared UI, department semantics and existing business hooks.
 */

@layer components.patterns {
    /* Product Thumbnail Modal — standalone extract from quote-builder-common.css
 *
 * Rules copied from quote-builder-common.css lines 2995-3116 (2026-01-29 original).
 * Extracted 2026-04-24 so non-quote-builder pages (supacolor-job-detail) can use
 * the modal without pulling in all quote-builder-specific CSS.
 *
 * NEW in 2026-04-24: .product-image-modal-actions, .product-image-modal-download,
 * .product-image-modal-details .meta-label — for the download button + generic
 * meta-line layout added alongside openGeneric() in product-thumbnail-modal.js.
 *
 * Quote builders continue to load quote-builder-common.css which has the ORIGINAL
 * rules — CSS cascade resolves identical rules to the same values, so loading
 * both files is harmless (just a byte duplicate).
 */

    /* ============================================
   PRODUCT IMAGE MODAL (click thumbnail to see larger)
   ============================================ */

    :where([data-ui="unified"]) .product-image-modal {
        position: fixed;
        inset: 0;
        z-index: var(--z-modal, 1000);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    :where([data-ui="unified"]) .product-image-modal.hidden {
        display: none;
    }

    :where([data-ui="unified"]) .product-image-modal-backdrop {
        position: absolute;
        inset: 0;
        background: rgb(0 0 0 / 60%);
        backdrop-filter: blur(2px);
    }

    :where([data-ui="unified"]) .product-image-modal-content {
        position: relative;
        background: var(--ui-surface);
        border-radius: var(--radius-lg);
        max-width: 480px;
        width: 90%;
        padding: 20px;
        box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
        animation: productModalSlideIn 0.2s ease;
    }

    @keyframes productModalSlideIn {
        from {
            transform: scale(0.95) translateY(10px);
        }

        to {
            transform: scale(1) translateY(0);
        }
    }

    :where([data-ui="unified"]) .product-image-modal-close {
        position: absolute;
        top: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        border: none;
        background: var(--slate-100);
        border-radius: 50%;
        cursor: pointer;
        font-size: var(--font-size-xl);
        color: var(--ui-muted);
        display: flex;
        align-items: center;
        justify-content: center;
        transition:
            background-color 0.15s ease,
            color 0.15s ease;
        z-index: 2;
    }

    :where([data-ui="unified"]) .product-image-modal-close:hover {
        background: var(--slate-200);
        color: var(--gray-700);
    }

    :where([data-ui="unified"]) .product-image-modal-image {
        width: 100%;
        max-height: 360px;
        object-fit: contain;
        border-radius: var(--radius-md);
        margin-bottom: 16px;
        background: var(--gray-50);
    }

    :where([data-ui="unified"]) .product-image-modal-details {
        text-align: center;
    }

    :where([data-ui="unified"]) .product-image-modal-details h3 {
        margin: 0 0 12px;
        font-size: var(--font-size-lg);
        font-weight: 600;
        color: var(--gray-800);
    }

    :where([data-ui="unified"]) .product-image-modal-details p {
        margin: 6px 0;
        font-size: var(--font-size-md);
        color: var(--ui-muted);
    }

    :where([data-ui="unified"]) .product-image-modal-details p span {
        color: var(--gray-700);
        font-weight: 500;
    }

    /* ============================================
   NEW (2026-04-24): Generic meta-line layout + Download button
   Used by openGeneric() — supacolor-job-detail and future consumers.
   ============================================ */

    :where([data-ui="unified"]) .product-image-modal-details .meta-label {
        color: var(--ui-muted);
        font-weight: 600;
        margin-right: 4px;
    }

    :where([data-ui="unified"]) .product-image-modal-actions {
        display: flex;
        justify-content: center;
        gap: 10px;
        padding-top: 14px;
        margin-top: 14px;
        border-top: 1px solid var(--gray-200);
    }

    :where([data-ui="unified"]) .product-image-modal-download {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 9px 18px;
        background: var(--ui-accent);
        color: var(--color-on-brand);
        border-radius: var(--radius-sm);
        text-decoration: none;
        font-size: var(--font-size-md);
        font-weight: 500;
        transition: background-color 0.15s ease;
        cursor: pointer;
        border: none;
    }

    :where([data-ui="unified"]) .product-image-modal-download:hover {
        background: var(--ui-accent-hover);
        color: var(--color-on-brand);
        text-decoration: none;
    }

    :where([data-ui="unified"]) .product-image-modal-download i {
        font-size: var(--font-size-md);
    }

    /* Mobile responsive */
    @media (width <= 768px) {
        :where([data-ui="unified"]) .product-image-modal-content {
            max-width: 95%;
            margin: 10px;
            padding: 16px;
        }

        :where([data-ui="unified"]) .product-image-modal-image {
            max-height: 280px;
        }
    }
}
