/* Final shared density adapters for authenticated desktop workspaces.
   Large desktops, mobile and print keep their existing styles. Use layout
   dimensions rather than device pixels; never change root font size or zoom. */
@media screen and (min-width: 901px) and (max-width: 1600px),
       screen and (min-width: 901px) and (max-height: 850px) {
    body.workspace-shell-active {
        --bridge-density-body: .875rem;
        --bridge-density-control-text: .8125rem;
        --bridge-density-lead: .875rem;
        --bridge-density-title: clamp(1.875rem, 2.65vw, 2.5rem);
        --bridge-density-section-title: 1.1875rem;
        --bridge-density-card-title: .9375rem;
        --bridge-density-gap: 1rem;
        --bridge-density-pad: .875rem;
        --bridge-density-page-pad: 1.25rem;
        --bridge-density-control-height: 2.375rem;
        --bridge-density-control-pad: .75rem;
        --bridge-density-icon: 2.375rem;
        --bridge-density-card-height: 10.75rem;
        --bridge-density-cell-pad: .5rem;
        --bridge-density-supplier-width: clamp(12.5rem, 17vw, 16rem);
        --bridge-density-supplier-min: 12.5rem;
        --bridge-density-ai-chat-width: clamp(18rem, 23vw, 23rem);
        --bridge-density-workspace-min: 28rem;
        --bridge-density-checklist-min: 26rem;
        --bridge-density-details-min: 17rem;
        --bridge-ui-control-h: var(--bridge-density-control-height);
        --workspace-topbar-height: 4.125rem;
        --workspace-topbar-step-font: var(--bridge-density-control-text);
        --workspace-topbar-pad-inline: var(--bridge-density-pad);
        --workspace-topbar-shell-gap: .75rem;
        --workspace-topbar-nav-gap: .375rem;
        --workspace-topbar-button-pad: .625rem;
        --workspace-topbar-logo-width: 6.5rem;
        --workspace-topbar-logo-height: 2rem;
        --space-3: .625rem;
        --space-4: .875rem;
        --space-5: 1.125rem;
        --space-6: 1.5rem;
        font-size: var(--bridge-density-body);
    }

    /* Header height and content offsets share the existing topbar token. */
    body.workspace-shell-active #dashboard-sidebar :is(#btn-dash-main, .sidebar-btn) {
        height: var(--bridge-density-control-height) !important;
        min-height: var(--bridge-density-control-height) !important;
    }
    body.workspace-shell-active #dashboard-sidebar.dashboard-topbar .sidebar-footer {
        --topbar-utility-height: var(--bridge-density-control-height);
        gap: .375rem;
    }
    body.workspace-shell-active #dashboard-sidebar.dashboard-topbar .sidebar-footer .sidebar-group {
        gap: .375rem;
    }

    /* Page rhythm, independently of which workflow is selected. */
    body.workspace-shell-active .dashboard-main-panel {
        padding: var(--bridge-density-page-pad) !important;
    }
    body.workspace-shell-active :is(.workspace-dashboard-shell, .workspace-dashboard-grid,
        .workspace-home-shell, .workspace-metrics, .order-execution-shell,
        .order-execution-overview-grid, .order-detail-shell, .order-detail-bottom-grid,
        .qc-dashboard-shell, .logistics-board-shell, .logistics-detail-shell) {
        gap: var(--bridge-density-gap) !important;
    }
    body.workspace-shell-active :is(.workspace-dashboard-header h1, .workspace-hero h1,
        .sourcing-overview-copy h2, .sourcing-project-board-header h1,
        .order-execution-hero h2, .qc-dashboard-shell > .section-header h2,
        .logistics-detail-title-row h2) {
        font-size: var(--bridge-density-title) !important;
        line-height: 1.15;
    }
    body.workspace-shell-active :is(.workspace-dashboard-hero-title,
        .workspace-dashboard-section-head h2, .order-execution-section-title,
        .order-detail-card h3, .logistics-detail-hero-main h2) {
        font-size: var(--bridge-density-section-title) !important;
    }
    body.workspace-shell-active :is(.workspace-hero p, .sourcing-overview-copy p,
        .sourcing-project-board-header p, .order-execution-hero p,
        .logistics-detail-hero-main p) {
        font-size: var(--bridge-density-lead);
    }
    body.workspace-shell-active :is(.workspace-card, .workspace-metric-card,
        .workspace-dashboard-task-card, .order-execution-overview-card,
        .order-execution-commercial-section, .order-detail-card, .qc-filter-shell,
        .qc-dashboard-toolbar, .qc-dashboard-shell > .section-header,
        .workspace-hero, .sourcing-overview-hero, .order-execution-hero,
        .logistics-detail-hero, .logistics-shipment-card) {
        padding: var(--bridge-density-pad) !important;
    }
    body.workspace-shell-active .workspace-dashboard-hero-cta {
        min-height: 9rem !important;
        padding: var(--bridge-density-pad) !important;
    }
    body.workspace-shell-active :is(.workspace-dashboard-hero-icon,
        .workspace-dashboard-task-icon-wrap) {
        width: var(--bridge-density-icon) !important;
        height: var(--bridge-density-icon) !important;
    }

    /* Shared text controls; icon-only and per-row actions keep their own sizing. */
    body.workspace-shell-active :is(.btn-primary, .btn-secondary, .btn-outline,
        .dashboard-main-btn, .workspace-start-btn, .submit-btn,
        .order-detail-action-btn, .order-execution-create-invoice-btn,
        .logistics-board-cta, .qc-folder-btn) {
        min-height: var(--bridge-density-control-height) !important;
        padding: .5rem var(--bridge-density-control-pad) !important;
        font-size: var(--bridge-density-control-text) !important;
        line-height: 1.4;
    }
    body.workspace-shell-active :is(.qc-filter-shell, .qc-dashboard-toolbar,
        .order-execution-commercial-section, .logistics-board-filters,
        .logistics-detail-shell, .price-payment-layout, .modal-content) :is(
        input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]):not([type="color"]),
        select, textarea) {
        font-size: var(--bridge-density-control-text);
    }

    /* Sourcing index: match the shared scale despite its fixed-pixel skin. */
    body.workspace-shell-active .sourcing-project-board-shell {
        padding-top: .75rem;
        padding-bottom: var(--bridge-density-page-pad);
    }
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-board-header {
        gap: var(--bridge-density-gap);
        margin-bottom: var(--bridge-density-gap);
    }
    body.workspace-shell-active .sourcing-project-board-header-actions,
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-board-filters {
        gap: var(--bridge-density-gap);
    }
    body.workspace-shell-active .sourcing-project-board-shell :is(
        .sourcing-project-board-cta, .sourcing-daily-digest-label,
        .sourcing-project-board-search, .sourcing-project-board-sort) {
        height: var(--bridge-density-control-height) !important;
        min-height: var(--bridge-density-control-height) !important;
        padding-inline: var(--bridge-density-control-pad) !important;
        font-size: var(--bridge-density-control-text) !important;
    }
    body.workspace-shell-active .sourcing-daily-digest-control {
        height: var(--bridge-density-control-height);
    }
    body.workspace-shell-active .sourcing-project-board-shell :is(
        .sourcing-project-board-search input, .sourcing-project-board-sort select) {
        height: calc(var(--bridge-density-control-height) - 2px);
        min-height: 0 !important;
        font-size: var(--bridge-density-body) !important;
    }
    body.workspace-shell-active .sourcing-project-board-count {
        margin: var(--bridge-density-gap) 0 .625rem;
    }
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-board-list {
        gap: var(--bridge-density-gap) !important;
    }
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-row {
        grid-template-rows: var(--bridge-density-icon) 1fr auto;
        min-height: var(--bridge-density-card-height) !important;
        padding: var(--bridge-density-pad) !important;
        gap: .625rem !important;
    }
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-row-title {
        font-size: var(--bridge-density-card-title) !important;
    }
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-row-icon {
        width: var(--bridge-density-icon) !important;
        min-width: var(--bridge-density-icon) !important;
        height: var(--bridge-density-icon) !important;
        font-size: 1.25rem !important;
    }

    /* Reduce table whitespace; preserve existing compact checklist/status text. */
    body.workspace-shell-active :is(.workspace-dashboard-table, .workspace-table,
        .qc-table, .logistics-table, .order-detail-table, .price-payment-table) :is(th, td) {
        padding-block: var(--bridge-density-cell-pad) !important;
        padding-inline: .625rem !important;
    }
    body.workspace-shell-active :is(.qc-table, .logistics-table) > tbody > tr > td {
        font-size: var(--bridge-density-control-text);
    }

    /* Project modes and Messaging keep their editors, tab heights and scroll roots. */
    body.workspace-shell-active :is(.contact-panel-item, .conversation-row) {
        padding: .75rem !important;
    }
    body.workspace-shell-active :is(.supplier-state-inspector-body,
        .project-workspace-ai-thread, .friends-column, .chat-header) {
        padding: var(--bridge-density-pad);
    }
    body.workspace-shell-active :is(.supplier-state-sidebar-content,
        .sourcing-chat-assistant-note, .sourcing-chat-bubble) {
        font-size: var(--bridge-density-control-text);
    }

    /* Settings uses the same typography and spacing scale as the workflows. */
    body.workspace-shell-active #settings-view .settings-section {
        padding: var(--bridge-density-page-pad) var(--bridge-density-page-pad) 3rem;
    }
    body.workspace-shell-active #settings-view .section-title {
        font-size: var(--bridge-density-title);
    }
    body.workspace-shell-active #settings-view .section-description {
        font-size: var(--bridge-density-lead);
    }
    body.workspace-shell-active #settings-view .settings-grid {
        margin-top: var(--bridge-density-page-pad);
    }
    body.workspace-shell-active #settings-view .settings-card {
        padding-block: var(--bridge-density-page-pad);
        column-gap: var(--bridge-density-page-pad);
    }
    body.workspace-shell-active #settings-view .settings-card > h3 {
        font-size: var(--bridge-density-section-title);
    }
    body.workspace-shell-active #settings-view :is(
        input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]):not([type="color"]), select) {
        min-height: var(--bridge-density-control-height);
        padding: .5rem .625rem;
        font-size: var(--bridge-density-control-text);
    }
}

/* A second bounded preset for especially short/narrow desktop windows. */
@media screen and (min-width: 901px) and (max-width: 1280px),
       screen and (min-width: 901px) and (max-height: 760px) {
    body.workspace-shell-active {
        --bridge-density-body: .8125rem;
        --bridge-density-title: clamp(1.75rem, 2.5vw, 2.125rem);
        --bridge-density-card-title: .875rem;
        --bridge-density-gap: .75rem;
        --bridge-density-pad: .75rem;
        --bridge-density-page-pad: 1rem;
        --bridge-density-control-height: 2.125rem;
        --bridge-density-control-pad: .625rem;
        --bridge-density-icon: 2.125rem;
        --bridge-density-card-height: 10rem;
        --bridge-density-cell-pad: .4375rem;
        --workspace-topbar-height: 3.875rem;
        --workspace-topbar-shell-gap: .5rem;
        --workspace-topbar-step-font: .75rem;
        --space-4: .75rem;
        --space-5: 1rem;
        --space-6: 1.25rem;
    }
}

/* Reflow before titles become cramped; preserve the existing mobile grids. */
@media screen and (min-width: 1101px) and (max-width: 1400px) {
    body.workspace-shell-active .sourcing-project-board-shell .sourcing-project-board-list {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* Pointer targets remain comfortable on touch-capable desktop layouts. */
@media screen and (min-width: 901px) and (any-pointer: coarse) {
    body.workspace-shell-active {
        --bridge-density-control-height: 2.75rem;
    }
}
