/* Focused workspace refinements. Kept separate from the core token system. */

/* The app workspace owns page overflow containment; legacy layers must not. */
.app-workspace {
    min-width: 0;
    overflow-x: hidden;
}

/* Shared workspace breadcrumb */
.workspace-context {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 7px;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 12.5px;
}
.workspace-crumb {
    min-width: 0;
    color: var(--text-muted);
    white-space: nowrap;
}
.workspace-crumb-link,
.workspace-product {
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: color var(--transition-fast), background var(--transition-fast);
}
.workspace-crumb-link:hover,
.workspace-product:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, .7);
}
.workspace-crumb-link:focus-visible,
.workspace-product:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 72%, white);
    outline-offset: 3px;
}
.workspace-product { font-weight: 620; }
.workspace-section {
    overflow: hidden;
    color: var(--text-primary);
    text-overflow: ellipsis;
    font-weight: 590;
}
.workspace-separator { flex: 0 0 auto; color: var(--border-strong); }
.workspace-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* Shared page header */
.pm-page-head {
    margin: 0 0 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.pm-page-head-copy { min-width: 0; }
.pm-page-head h1 {
    margin: 0 0 5px;
    font-size: 26px;
    line-height: 1.15;
    letter-spacing: -.025em;
    font-weight: 720;
}
.pm-page-head-copy p {
    max-width: 720px;
    margin: 0;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
}
.pm-page-head-actions {
    margin-left: auto;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.pm-action-row,
.pm-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.pm-form-actions { margin-top: 14px; }
.pm-back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
}
.pm-back-link:hover { color: var(--text-primary); }

/* Shared clickable-row contract. Navigation is handled by ui-primitives.js. */
[data-row-href] { cursor: pointer; }
[data-row-href]:hover { background: var(--surface-hover); }
[data-row-href]:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 68%, white);
    outline-offset: -2px;
}
[data-row-href] a,
[data-row-href] button,
[data-row-href] input,
[data-row-href] select,
[data-row-href] textarea { cursor: auto; }

/* Shared filters */
.pm-filter-shell {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    align-items: end;
    gap: 10px;
}
.pm-filter-field { min-width: 0; }
.pm-filter-field > label {
    display: block;
    margin: 0 0 6px;
}
.pm-filter-field > input,
.pm-filter-field > select { width: 100%; }
.pm-filter-actions {
    grid-column: 1 / -1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 2px;
}
.pm-filter-dirty {
    margin-right: auto;
    color: var(--warning);
    font-size: 11.5px;
    font-weight: 620;
}
.pm-filter-dirty[hidden] { display: none; }
.pm-more-filters {
    grid-column: 1 / -1;
    min-width: 0;
    margin: 2px 0 0;
    padding: 0;
    border: 0;
}
.pm-more-filters > summary {
    width: max-content;
    max-width: 100%;
    padding: 6px 0;
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 630;
    cursor: pointer;
    user-select: none;
}
.pm-more-filter-grid {
    margin-top: 7px;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    align-items: end;
    gap: 10px;
    background: var(--surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
}
.pm-applied-filters {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.pm-applied-filters[hidden] { display: none; }
.pm-applied-filters-label {
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 620;
}
.pm-filter-chip {
    min-height: 28px;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    background: var(--surface-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    font-size: 10.5px;
    text-decoration: none;
}
.pm-filter-chip:hover {
    color: var(--text-primary);
    background: var(--surface-primary);
    border-color: var(--border-default);
}
.pm-filter-chip b {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
}

/* Searchable select keeps the native select as the submitted form control. */
.pm-search-select {
    position: relative;
    width: 100%;
}
.pm-search-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-height: 1px !important;
    padding: 0 !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}
.pm-search-select-trigger {
    width: 100%;
    min-height: 40px;
    padding: 8px 34px 8px 11px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    color: var(--text-primary);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: 10px;
    box-shadow: none;
    font-size: 12.5px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    position: relative;
}
.pm-search-select-trigger::after {
    content: "";
    position: absolute;
    right: 14px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: translateY(-65%) rotate(45deg);
}
.pm-search-select-trigger:hover { border-color: var(--border-strong); }
.pm-search-select-trigger:focus-visible {
    outline: none;
    border-color: color-mix(in srgb, var(--accent) 62%, var(--border-default));
    box-shadow: 0 0 0 3px rgba(56, 103, 232, .1);
}
.pm-search-select-popover {
    position: absolute;
    z-index: 700;
    top: calc(100% + 6px);
    left: 0;
    width: max(100%, 240px);
    max-width: min(360px, calc(100vw - 32px));
    padding: 7px;
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: 11px;
    box-shadow: var(--shadow-md);
}
.pm-search-select.is-up .pm-search-select-popover {
    top: auto;
    bottom: calc(100% + 6px);
}
.pm-search-select-popover[hidden] { display: none; }
.pm-search-select-search {
    width: 100%;
    min-height: 36px !important;
    margin-bottom: 6px;
}
.pm-search-select-options {
    max-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.pm-search-select-option {
    width: 100%;
    min-height: 34px;
    padding: 7px 8px;
    display: block;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: 7px;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}
.pm-search-select-option[hidden],
.pm-search-select-empty[hidden] {
    display: none !important;
}
.pm-search-select-option:hover,
.pm-search-select-option:focus-visible {
    color: var(--text-primary);
    background: var(--surface-hover);
    outline: none;
}
.pm-search-select-option[aria-selected="true"] {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 650;
}
.pm-search-select-empty {
    padding: 14px 8px;
    color: var(--text-muted);
    font-size: 11.5px;
    text-align: center;
}

/* Shared table viewport and sticky header contract. */
.pm-table-viewport {
    position: relative;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-gutter: stable;
}
.pm-table-sticky { min-width: max-content; }
.pm-table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    white-space: nowrap;
    background: var(--surface-secondary);
    background-clip: padding-box;
    box-shadow: inset 0 -1px 0 var(--border-default);
}
/* Intersections of a vertical header with page-specific sticky identity columns. */
.pm-table-sticky thead th.analytics-sticky-code,
.pm-table-sticky thead th.analytics-sticky-product,
.pm-table-sticky thead th.analytics-request-select-cell {
    z-index: 32;
}
.pm-table-sticky td.num,
.pm-table-sticky th.num,
.pm-table-sticky .money-cell {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.pm-table-sticky td { line-height: 1.35; }
.pm-pagination {
    margin-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.pm-pagination-meta {
    color: var(--text-muted);
    font-size: 11px;
}
.pm-pagination-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Shared state blocks */
.pm-empty-state,
.pm-error-state,
.pm-loading-state {
    min-height: 92px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 5px;
    color: var(--text-muted);
    background: var(--surface-secondary);
    border: 1px dashed var(--border-default);
    border-radius: 12px;
    font-size: 12px;
    line-height: 1.45;
}
.pm-empty-state strong,
.pm-error-state strong { color: var(--text-primary); font-size: 13px; }
.pm-error-state { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }

/* Shared local selection presentation. It does not implement cross-page selection. */
.pm-selection-bar {
    margin: 0 0 10px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: 10px;
}
.pm-selection-count { color: var(--text-secondary); font-size: 11.5px; font-weight: 650; }

/* Products: catalog is a normal page table, not a nested scroll workspace. */
.products-filter-panel + .products-table-panel { margin-top: 0; }
.products-table-panel .table-header { margin-bottom: 10px; }
.products-table-panel .table-header p { margin: 3px 0 0; font-size: 10px; }
.products-data-table-scroll {
    max-height: none;
    min-height: 0;
    overflow-y: visible;
}
.product-modal .modal-info-grid { gap: 8px !important; }
.product-modal .modal-info-grid .info-card { min-height: 64px; }
.pagination-bar { padding-top: 3px; }
.pagination-bar > .muted { font-size: 10.5px; }

/* Matching */
.app-content > h1 + p.muted { max-width: 760px; margin-top: -12px; margin-bottom: 18px; font-size: 12.5px; line-height: 1.55; }
.app-content > h1 + p.muted + .panel { padding: 14px 16px; }
.app-content > h1 + p.muted + .panel .inline-form { margin: 0 0 10px; align-items: end; }
.app-content > h1 + p.muted + .panel form:last-child { margin: 0; }
.matching-quality-panel .readiness-badges { display: flex; gap: 5px; flex-wrap: wrap; }
.matching-quality-cards .card { text-decoration: none; transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast); }
.matching-quality-cards a.card:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: var(--border-default); }
.matching-run-counters { display: flex; flex-wrap: wrap; gap: 7px !important; }
.matching-run-counters > span { padding: 6px 8px; color: var(--text-secondary); background: var(--surface-secondary); border: 1px solid var(--border-subtle); border-radius: 8px; font-size: 10px; }
.progress-bar { height: 7px !important; background: var(--surface-tertiary) !important; }
.progress-fill { background: var(--accent) !important; }

/* Empty states in legacy pages */
.products-table-panel > p:only-child,
.panel > p:only-child { color: var(--text-muted); }

@media (max-width: 720px) {
    .workspace-context { gap: 5px; }
    .pm-page-head { align-items: stretch; flex-direction: column; gap: 10px; }
    .pm-page-head-actions,
    .pm-action-row,
    .pm-form-actions { width: 100%; justify-content: flex-end; }
    .pm-filter-shell { grid-template-columns: 1fr; }
    .pm-more-filter-grid { grid-template-columns: 1fr; }
    .pm-filter-actions { align-items: stretch; }
    .pm-filter-actions .btn { flex: 1 1 auto; }
    .pm-filter-dirty { width: 100%; margin-right: 0; }
    .pm-pagination { align-items: stretch; flex-direction: column; }
    .pm-pagination-actions { justify-content: flex-end; }
}
