/**
 * Ordease Network - Businesses directory
 * Profile cards written for people who are not supply-chain experts: icons and
 * one-line explanations carry the meaning, and the per-company hue (set inline as
 * --biz-hue) gives each business a recognisable identity. That hue is the page's
 * one flourish; everything else stays neutral so the Connect buttons stand out.
 */

/* ── Search and filters ──────────────────────────────────────── */
/* Kept short so the results start high on the page: placeholders ("All sectors")
   name each filter, so the visible labels are dropped (they remain for screen
   readers), and on wide screens search and filters share one line.
   Every control shares one height, border, radius and text style so the bar
   reads as a single row of equals; --biz-control-h follows the theme's select
   height so the Select2 fields need no overriding. */
.biz-filters {
    --biz-control-h: 2.375rem;

    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--on-primary-alpha-3);
}

#bizFilters {
    display: grid;
    gap: 0.625rem;
}

@media (min-width: 1400px) {
    #bizFilters {
        grid-template-columns: minmax(20rem, 2fr) minmax(0, 5fr);
        align-items: start;
    }
}

/* Search field and its button read as a single control */
.biz-search {
    position: relative;
    display: flex;
    align-items: stretch;
    height: var(--biz-control-h);
    padding: 3px;
    border: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    background: var(--bs-paper-bg, var(--bs-body-bg));
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.biz-search:focus-within {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px var(--on-primary-alpha-15);
}

.biz-search-input {
    flex: 1;
    min-width: 0;
    padding: 0 0.5rem 0 calc(0.9375rem - 3px);
    border: 0;
    background: transparent;
    font-size: 0.9375rem;
    color: var(--bs-heading-color);
    text-overflow: ellipsis;
    outline: none;
}

.biz-search-input::placeholder {
    color: var(--bs-secondary-color);
    opacity: 1;
}

/* Native clear button clashes with the theme; the chips below handle clearing */
.biz-search-input::-webkit-search-cancel-button {
    display: none;
}

.biz-search-btn {
    flex-shrink: 0;
    display: inline-grid;
    place-items: center;
    /* Square: control height minus the 3px padding and 1px border on each side */
    width: calc(var(--biz-control-h) - 8px);
    padding: 0;
    border-radius: calc(var(--bs-border-radius) - 2px);
    font-size: 1.125rem;
}

.biz-filter-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.625rem;
}

.biz-field .form-select {
    height: var(--biz-control-h);
    padding-block: 0;
    font-size: 0.9375rem;
    color: var(--bs-heading-color);
    background-color: var(--bs-paper-bg, var(--bs-body-bg));
    text-overflow: ellipsis;
}

.biz-field {
    position: relative;
}

.biz-field .select2-selection {
    background-color: var(--bs-paper-bg, var(--bs-body-bg));
}

/* Multi-selects keep one fixed height: picks show as the summary below, never as
   tags that grow the box (the chips under the bar list them in full) */
.biz-field .select2-container--default .select2-selection--multiple {
    position: relative;
    height: var(--biz-control-h);
    min-block-size: 0;
    overflow: hidden;
}

.biz-field .select2-selection--multiple .select2-selection__choice {
    display: none;
}

.biz-field .select2-selection--multiple .select2-selection__clear {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    z-index: 2;
    margin: 0;
    transform: translateY(-50%);
    color: var(--bs-secondary-color);
}

/* The summary sits over the box; clicks pass through to Select2 underneath */
.biz-ms-summary {
    position: absolute;
    inset: 0 2.25rem 0 0.9375rem;
    z-index: 1;
    display: none;
    align-items: center;
    gap: 0.375rem;
    min-width: 0;
    font-size: 0.9375rem;
    color: var(--bs-heading-color);
    pointer-events: none;
}

.biz-field.has-value .biz-ms-summary {
    display: flex;
}

/* While the list is open the box is for typing a search, so the summary steps aside */
.biz-field.is-open .biz-ms-summary {
    display: none;
}

.biz-ms-first {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.biz-ms-more {
    flex-shrink: 0;
    padding: 0 0.4375rem;
    border-radius: var(--on-radius-pill);
    background: var(--on-primary-alpha-12);
    font-size: var(--on-font-size-sm);
    font-weight: 600;
    line-height: 1.6;
    color: var(--bs-primary);
}

/* Option lists get room to breathe even when the field itself is narrow */
.biz-field .select2-dropdown {
    min-width: 16rem;
}

.biz-field .select2-results__group {
    text-transform: none;
    letter-spacing: 0;
}

/* An unchosen native select ("All countries") greys out like the Select2
   placeholders, instead of looking like a picked value */
.biz-field .form-select.is-placeholder {
    color: var(--bs-secondary-color);
}

.biz-field .form-select.is-placeholder option {
    color: var(--bs-body-color);
}

.biz-field .form-select:disabled {
    background-color: color-mix(in srgb, var(--bs-body-color) 4%, var(--bs-paper-bg, var(--bs-body-bg)));
    opacity: 1;
}

@media (max-width: 1199.98px) {
    .biz-filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 767.98px) {
    .biz-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 575.98px) {
    .biz-filters { padding: 0.875rem 1rem; }
    .biz-filter-grid { grid-template-columns: 1fr; }
}

/* Active filters, each removable on its own */
.biz-active {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--bs-border-color);
}

.biz-active-label {
    margin-right: 0.25rem;
    font-size: var(--on-font-size-md);
    color: var(--bs-secondary-color);
}

.biz-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem 0.25rem 0.75rem;
    border-radius: var(--on-radius-pill);
    background: var(--on-primary-alpha-12);
    font-size: var(--on-font-size-md);
    font-weight: 500;
    color: var(--bs-primary);
    text-decoration: none;
}

.biz-chip .ti {
    display: inline-grid;
    place-items: center;
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 50%;
    font-size: 0.75rem;
}

.biz-chip:hover,
.biz-chip:focus-visible {
    background: var(--bs-primary);
    color: #fff;
}

.biz-clear {
    margin-left: 0.25rem;
    font-size: var(--on-font-size-md);
    font-weight: 500;
}

/* ── See more ────────────────────────────────────────────────── */
.biz-more-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.5rem 2rem;
    text-align: center;
}

.biz-more-text {
    margin: 0;
    font-size: var(--on-font-size-md);
    color: var(--bs-secondary-color);
}

.biz-more-text strong {
    color: var(--bs-heading-color);
    font-variant-numeric: tabular-nums;
}

.biz-progress {
    width: min(16rem, 100%);
    height: 0.25rem;
    overflow: hidden;
    border-radius: var(--on-radius-pill);
    background: var(--on-primary-alpha-12);
}

.biz-progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--bs-primary);
    transition: width 0.3s ease;
}

.biz-see-more {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 14rem;
    justify-content: center;
    font-weight: 600;
}

.biz-more-done,
.biz-more-error {
    margin: 0;
    font-size: var(--on-font-size-md);
}

.biz-more-done  { color: var(--bs-secondary-color); }
.biz-more-error { color: var(--bs-danger); }

/* Dims stale results while a changed filter reloads the page */
.biz-grid.is-loading {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

/* Cards added by "See more" fade in so it is clear where the new ones start */
.biz-card.is-new {
    animation: biz-arrive 0.35s ease both;
}

.biz-card.is-new:focus {
    outline: none;
}

@keyframes biz-arrive {
    from { opacity: 0; transform: translateY(0.5rem); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .biz-card.is-new { animation: none; }
    .biz-progress span,
    .biz-search { transition: none; }
}

/* ── Grid ────────────────────────────────────────────────────── */
.biz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
    gap: 1rem;
    padding: 0.75rem 1.25rem 1.25rem;
}

/* ── Results toolbar: count on the left, layout switch on the right ── */
.biz-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.875rem 1.25rem 0;
}

.biz-found {
    margin: 0;
    font-size: var(--on-font-size-md);
    color: var(--bs-secondary-color);
}

.biz-found strong {
    font-size: 1rem;
    color: var(--bs-heading-color);
    font-variant-numeric: tabular-nums;
}

/* Segmented control: the pressed option reads as a raised tab */
.biz-view {
    display: inline-flex;
    padding: 0.1875rem;
    border-radius: var(--on-radius-md);
    background: color-mix(in srgb, var(--bs-body-color) 7%, transparent);
}

.biz-view-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.875rem;
    border: 0;
    border-radius: calc(var(--on-radius-md) - 2px);
    background: transparent;
    font-size: var(--on-font-size-md);
    font-weight: 500;
    color: var(--bs-secondary-color);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.biz-view-btn .ti {
    font-size: 1.0625rem;
}

.biz-view-btn:hover {
    color: var(--bs-heading-color);
}

.biz-view-btn[aria-pressed="true"] {
    background: var(--bs-paper-bg, var(--bs-body-bg));
    box-shadow: var(--on-shadow-sm);
    color: var(--bs-primary);
}

.biz-view-btn:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 1px;
}

/* ── List view ───────────────────────────────────────────────────
   Built for density: one compact row per business, column titles said once in
   .biz-list-head rather than in every row. Same card markup as the grid; below
   768px both views are the same stacked card, so the switch is hidden there. */
.biz-list-head {
    display: none;
}

@media (min-width: 768px) {
    .biz-grid.is-list {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.5rem;
    }

    .biz-grid.is-list .biz-card {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        border-radius: var(--on-radius-md);
    }

    .biz-grid.is-list .biz-card-top {
        grid-column: 1;
        grid-row: 1;
        padding: 0.5rem 0.875rem;
    }

    .biz-grid.is-list .biz-mark {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 0.875rem;
    }

    /* Facts become three columns: label row, then values */
    .biz-grid.is-list .biz-facts {
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr) minmax(0, 1.2fr);
        grid-template-rows: auto auto;
        grid-auto-flow: column;
        gap: 0.125rem 1.25rem;
        padding: 0.5rem 0.875rem 0.625rem;
    }

    .biz-grid.is-list .biz-facts dt {
        padding-top: 0;
    }

    .biz-grid.is-list .biz-card-foot {
        grid-column: 2;
        grid-row: 1;
        min-height: 0;
        margin: 0;
        padding: 0.5rem 0.875rem;
        border-top: 0;
        background: var(--biz-tint);
    }
}

/* Wide: a single line per business - identity | industry | role | sells | action */
@media (min-width: 1200px) {
    .biz-grid.is-list {
        /* Name column grows with the window: a fixed 18rem starved Industry/Role at
           1200-1230px and pushed "Pharmaceuticals & Healthcare Products" into the
           next column. Names wrap, so the narrower end is fine */
        --biz-cols: clamp(15.5rem, 20vw, 18rem) minmax(0, 1fr) 10.5rem;
        --biz-fact-cols: minmax(0, 1fr) minmax(0, 0.85fr) minmax(0, 1.2fr);
        gap: 0.375rem;
    }

    .biz-grid.is-list .biz-list-head {
        display: grid;
        grid-template-columns: var(--biz-cols);
        padding: 0 1px;
        font-size: var(--on-font-size-sm);
        font-weight: 500;
        color: var(--bs-secondary-color);
    }

    .biz-grid.is-list .biz-list-head > span:first-child {
        padding-left: 0.875rem;
    }

    .biz-grid.is-list .biz-list-head > div {
        display: grid;
        grid-template-columns: var(--biz-fact-cols);
        column-gap: 1.25rem;
        padding-inline: 1rem;
    }

    .biz-grid.is-list .biz-card {
        grid-template-columns: var(--biz-cols);
    }

    .biz-grid.is-list .biz-card-top {
        height: 100%;
    }

    .biz-grid.is-list .biz-facts {
        grid-column: 2;
        grid-row: 1;
        grid-template-columns: var(--biz-fact-cols);
        grid-template-rows: auto;
        grid-auto-flow: row;
        align-items: center;
        padding: 0.5rem 1rem;
    }

    .biz-grid.is-list .biz-facts dt {
        display: none;
    }

    .biz-grid.is-list .biz-brands {
        margin-bottom: 0.125rem;
    }

    .biz-grid.is-list .biz-card-foot {
        grid-column: 3;
        grid-row: 1;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;
        gap: 0.375rem;
        padding: 0.5rem 0.75rem;
        border-left: 1px solid var(--bs-border-color);
        background: transparent;
    }

    /* A connection button already says where you stand (Connect / Respond / View
       connection), and the row edge is coloured, so the status text only stays when
       no connection button carries it (Products alone says nothing about that) */
    .biz-grid.is-list .biz-card-foot:has(.btn:not(.biz-products-btn)) .biz-state {
        display: none;
    }

    /* Stacked in the narrow action column: natural height, connection action on top */
    .biz-grid.is-list .biz-card-foot .btn {
        flex: none;
        width: 100%;
    }

    .biz-grid.is-list .biz-products-btn {
        order: 1;
    }
}

@media (max-width: 767.98px) {
    .biz-view {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .biz-view-btn { transition: none; }
}

/* ── Card ────────────────────────────────────────────────────── */
.biz-card {
    --biz-tint: hsl(var(--biz-hue, 248) 75% 55% / 0.09);
    --biz-ink: hsl(var(--biz-hue, 248) 55% 40%);

    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--on-radius-lg);
    background: var(--bs-paper-bg, var(--bs-body-bg));
}

[data-bs-theme="dark"] .biz-card {
    --biz-tint: hsl(var(--biz-hue, 248) 60% 60% / 0.12);
    --biz-ink: hsl(var(--biz-hue, 248) 80% 74%);
}

/* The relationship is also told by the card edge, so connected and pending
   businesses stand out while scrolling */
.biz-card.is-connected { border-color: rgba(var(--bs-success-rgb), 0.45); }
.biz-card.is-received  { border-color: rgba(var(--bs-warning-rgb), 0.6); }
.biz-card.is-blocked   { opacity: 0.65; }

.biz-card:focus-within {
    box-shadow: 0 0 0 3px var(--on-primary-alpha-20);
}

/* ── Identity band ───────────────────────────────────────────── */
.biz-card-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--biz-tint);
}

.biz-mark {
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: 2.625rem;
    height: 2.625rem;
    border-radius: var(--on-radius-md);
    background: var(--bs-paper-bg, var(--bs-body-bg));
    box-shadow: 0 1px 2px hsl(var(--biz-hue, 248) 40% 30% / 0.12),
                inset 0 0 0 1px hsl(var(--biz-hue, 248) 60% 50% / 0.2);
    color: var(--biz-ink);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* The company name is the one thing a business is recognised by, so it is never
   cut off - it wraps as many lines as it needs, breaking even a name typed
   without spaces rather than letting it overflow its column */
.biz-name {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--bs-heading-color);
    overflow-wrap: anywhere;
}

/* Location and NTN share one line */
.biz-sub {
    display: flex;
    flex-wrap: wrap;
    column-gap: 0.75rem;
    font-size: var(--on-font-size-sm);
    line-height: 1.5;
    color: var(--bs-secondary-color);
}

.biz-place {
    font-weight: 500;
    color: var(--bs-body-color);
}

.biz-place .ti {
    margin-right: 0.1875rem;
    color: var(--biz-ink);
    vertical-align: -0.0625rem;
}

.biz-meta {
    font-size: var(--on-font-size-md);
    line-height: 1.5;
    color: var(--bs-secondary-color);
}

.biz-ntn {
    font-variant-numeric: tabular-nums;
}

/* ── Fact rows ───────────────────────────────────────────────── */
.biz-facts {
    display: grid;
    grid-template-columns: 4rem minmax(0, 1fr);
    gap: 0.625rem 0.75rem;
    margin: 0;
    padding: 0.875rem 1rem;
}

.biz-facts dt {
    padding-top: 0.1875rem;
    font-size: var(--on-font-size-sm);
    font-weight: 500;
    color: var(--bs-secondary-color);
}

.biz-facts dd {
    min-width: 0;
    margin: 0;
}

.biz-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3125rem;
}

/* Icon chips: tinted for sectors, outlined for roles */
.biz-chip-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    /* Last resort for a column narrower than one word: break the word inside the
       chip rather than let the chip cross into the next column */
    max-width: 100%;
    overflow-wrap: anywhere;
    padding: 0.125rem 0.5rem 0.125rem 0.375rem;
    border-radius: var(--on-radius-sm);
    background: var(--biz-tint);
    font-size: var(--on-font-size-md);
    font-weight: 500;
    line-height: 1.5;
    color: var(--bs-heading-color);
}

.biz-chip-icon .ti {
    flex-shrink: 0;
    font-size: 1rem;
    color: var(--biz-ink);
}

.biz-chip-plain {
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--bs-border-color);
}

.biz-chip-plain[title]:not([title=""]) {
    cursor: help;
}

.biz-clamp {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.biz-facts .biz-industries {
    margin-top: 0.25rem;
    font-size: var(--on-font-size-sm);
    line-height: 1.45;
}

.biz-more-hint {
    font-weight: 600;
    color: var(--bs-primary);
    white-space: nowrap;
    cursor: help;
}

.biz-brands {
    margin-bottom: 0.25rem;
    font-size: var(--on-font-size-md);
    font-weight: 600;
    line-height: 1.5;
    color: var(--bs-heading-color);
}

.biz-product {
    max-width: 100%;
    overflow: hidden;
    padding: 0.0625rem 0.5rem;
    border-radius: var(--on-radius-pill);
    background: color-mix(in srgb, var(--bs-body-color) 7%, transparent);
    font-size: var(--on-font-size-sm);
    line-height: 1.6;
    color: var(--bs-body-color);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* "+N more" sits inline with the pills; once opened it takes the full row */
.biz-more summary {
    display: inline-block;
    padding: 0.0625rem 0.5rem;
    border-radius: var(--on-radius-pill);
    font-size: var(--on-font-size-sm);
    font-weight: 600;
    line-height: 1.6;
    color: var(--bs-primary);
    cursor: pointer;
    list-style: none;
}

.biz-more summary::-webkit-details-marker {
    display: none;
}

.biz-more summary:hover {
    background: var(--on-primary-alpha-10);
}

.biz-more summary:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 1px;
}

.biz-more[open] {
    flex-basis: 100%;
}

.biz-product-all {
    max-height: 9rem;
    overflow-y: auto;
    margin-top: 0.375rem;
}

/* ── Footer: where you stand + next step, one row ────────────── */
.biz-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 3.25rem;
    margin-top: auto;
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--bs-border-color);
}

.biz-state {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    min-width: 0;
    font-size: var(--on-font-size-md);
    font-weight: 500;
    color: var(--bs-secondary-color);
}

.biz-state .ti {
    font-size: 1.0625rem;
}

.biz-card-foot .btn {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Connection button and Products together: the connection button already tells the
   relationship, so the status text gives way and the two buttons share the row */
.biz-card-foot:has(.btn:not(.biz-products-btn)):has(.biz-products-btn) .biz-state {
    display: none;
}

/* :where() keeps this light so the list view can stack the same buttons instead */
.biz-card-foot:where(:has(.btn:not(.biz-products-btn)):has(.biz-products-btn)) .btn {
    flex: 1 1 0;
}

/* Products sits before the connection button, which stays the end-of-row action */
.biz-products-btn {
    order: -1;
}

.biz-state {
    order: -2;
}

/* Empty state */
.biz-empty {
    max-width: 28rem;
    margin: 0 auto;
    padding: 4rem 1.5rem;
    text-align: center;
}

.biz-empty-icon {
    display: inline-block;
    margin-bottom: 1rem;
    font-size: 2.75rem;
    color: var(--bs-secondary-color);
}

@media (max-width: 575.98px) {
    .biz-grid {
        padding: 1rem;
        gap: 1rem;
    }
}
