/* The bin packing problem (/bin-packing): the shelf of item boxes, the bins packed by hand (crates that fill up by
   weight) and the item list in the control panel. The step-by-step view uses css/apps/dp.css. Tiles, buttons, fields
   and the callout come from the app kit. Loaded only on its page (Views/SeoLanding/_BinPackingDemo.cshtml,
   filter-engines/bin-packing.js). */

.bp-app {
    /* The crates are an illustration: the same wood on both themes. */
    --bp-wood: #b7793f;
    --bp-wood-dark: #7c4a1e;
    --bp-inside: #2b1a0e;
    --bp-label: #ffffff;
    --bp-label-text: #0f172a;
}

/* One view at a time (data-bp-current, set by the script). */
.bp-app[data-bp-current="pack"] [data-bp-view="steps"],
.bp-app[data-bp-current="steps"] [data-bp-view="pack"] {
    display: none !important;
}

.bp-app .bp-views { align-self: stretch; }

.bp-app .bp-say {
    min-height: 3.1rem;
    align-items: center;
}

.bp-app .bp-say > .ak-icon { align-self: flex-start; margin-top: 0.1rem; }

.bp-app .bp-say-body {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.6rem;
}

.bp-app .bp-say--success {
    border-color: color-mix(in srgb, var(--ak-success) 45%, var(--ak-border));
    background: color-mix(in srgb, var(--ak-success) 10%, var(--ak-panel));
}

.bp-app .bp-say--success > .ak-icon { color: var(--ak-success); }

.bp-app .bp-see-how {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ak-accent);
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.bp-app .bp-see-how:focus-visible {
    outline: 2px solid var(--ak-accent);
    outline-offset: 2px;
    border-radius: 3px;
}

.bp-app .bp-best-tile.is-found { --ak-stat-color: var(--ak-success) !important; }

.bp-app .bp-scene {
    display: flex;
    flex-direction: column;
    gap: var(--ak-space-5);
}

/* ---- Shelf of item boxes ----------------------------------------------------------------------------------------- */

.bp-app .bp-shelf {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: var(--ak-space-4) var(--ak-space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.bp-app .bp-slot {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    aspect-ratio: 1 / 1;
    padding-bottom: 5px;
    border-bottom: 5px solid color-mix(in srgb, var(--bp-wood-dark) 55%, var(--ak-border));
    border-radius: 0 0 4px 4px;
}

.bp-app .bp-box {
    --bp-s: 1;
    position: relative;
    display: block;
    width: calc(var(--bp-s) * 100%);
    aspect-ratio: 1 / 0.92;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--bp-label-text);
    font: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.2s ease;
}

.bp-app .bp-box:hover { transform: translateY(-3px); }

.bp-app .bp-box:focus-visible {
    outline: 3px solid var(--ak-accent);
    outline-offset: 4px;
    border-radius: 6px;
}

.bp-app .bp-box-top,
.bp-app .bp-box-side,
.bp-app .bp-box-front {
    position: absolute;
    inset: 0;
}

.bp-app .bp-box-top {
    background: color-mix(in srgb, var(--bp-c) 62%, #ffffff);
    clip-path: polygon(0 16%, 14% 0, 100% 0, 86% 16%);
}

.bp-app .bp-box-side {
    background: color-mix(in srgb, var(--bp-c) 68%, #000000);
    clip-path: polygon(86% 16%, 100% 0, 100% 84%, 86% 100%);
}

.bp-app .bp-box-front {
    inset: 16% 14% 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bp-c);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bp-c) 70%, #000000);
}

.bp-app .bp-box-weight {
    padding: 0.05rem 0.35rem;
    border-radius: 5px;
    background: var(--bp-label);
    font-size: 0.82rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bp-app .bp-box-name,
.bp-app .bp-box-check {
    position: absolute;
    top: -0.45rem;
    min-width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    box-shadow: 0 0 0 2px var(--ak-panel);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1.35rem;
    text-align: center;
}

.bp-app .bp-box-name {
    inset-inline-start: -0.45rem;
    padding: 0 0.28rem;
    background: color-mix(in srgb, var(--bp-c) 70%, #000000);
}

.bp-app .bp-box-check {
    inset-inline-end: -0.45rem;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--ak-success);
}

.bp-app .bp-box-check svg { width: 0.9rem; height: 0.9rem; }

/* Picked: lifted, with a ring in the accent colour. */
.bp-app .bp-box.is-picked {
    transform: translateY(-8px);
    filter: drop-shadow(0 6px 6px rgb(0 0 0 / 0.25));
}

.bp-app .bp-box.is-picked .bp-box-front {
    outline: 3px solid var(--ak-accent);
    outline-offset: 2px;
}

/* In a bin: a faded outline stays on the shelf, with a check mark. */
.bp-app .bp-box.is-in .bp-box-top,
.bp-app .bp-box.is-in .bp-box-side,
.bp-app .bp-box.is-in .bp-box-front { opacity: 0.22; }

.bp-app .bp-box.is-in .bp-box-front {
    outline: 2px dashed var(--bp-c);
    outline-offset: -2px;
}

.bp-app .bp-box.is-in .bp-box-check { display: flex; }

/* ---- Bins -------------------------------------------------------------------------------------------------------- */

.bp-app .bp-bins {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: var(--ak-space-4) var(--ak-space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.bp-app .bp-bin {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    width: 5.6rem;
}

.bp-app .bp-bin-head,
.bp-app .bp-bin-foot {
    min-height: 1.1rem;
    color: var(--ak-muted);
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bp-app .bp-bin-head { color: var(--ak-text); }

/* A crate: wooden walls, a dark inside; the items stack from the bottom, each as tall as its share of the bin. */
.bp-app .bp-bin-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    height: 12.5rem;
    margin: 0;
    padding: 4px;
    border: 5px solid var(--bp-wood);
    border-top-width: 3px;
    border-radius: 6px 6px 10px 10px;
    background: var(--bp-inside);
    box-shadow: inset 0 0 0 1px var(--bp-wood-dark), 0 3px 0 var(--bp-wood-dark);
    font: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.bp-app .bp-bin-body:focus-visible {
    outline: 3px solid var(--ak-accent);
    outline-offset: 3px;
}

.bp-app .bp-bin.is-full .bp-bin-body { border-color: color-mix(in srgb, var(--ak-success) 70%, var(--bp-wood)); }

/* While an item is picked: green bins have room for it, red ones do not. */
.bp-app .bp-bin.is-fit .bp-bin-body {
    border-color: var(--ak-success);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ak-success) 35%, transparent), 0 3px 0 var(--bp-wood-dark);
}

.bp-app .bp-bin.is-fit .bp-bin-body:hover { transform: translateY(-2px); }

.bp-app .bp-bin.is-no-fit .bp-bin-body {
    border-color: color-mix(in srgb, var(--ak-danger) 70%, var(--bp-wood));
    opacity: 0.6;
    cursor: not-allowed;
}

.bp-app .bp-bin-body.bp-shake { animation: bp-shake 0.42s ease; }

@keyframes bp-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(3px); }
}

/* The empty spot for a new bin. */
.bp-app .bp-bin--new .bp-bin-body {
    align-items: center;
    justify-content: center;
    border: 3px dashed color-mix(in srgb, var(--bp-wood) 70%, var(--ak-border));
    background: transparent;
    box-shadow: none;
    color: var(--ak-muted);
}

.bp-app .bp-bin--new.is-fit .bp-bin-body {
    border-color: var(--ak-success);
    color: var(--ak-success);
}

.bp-app .bp-new-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
}

.bp-app .bp-new-plus {
    font-size: 1.8rem;
    font-weight: 400;
    line-height: 1;
}

.bp-app .bp-free {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: color-mix(in srgb, #ffffff 70%, transparent);
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.bp-app .bp-layer {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    overflow: hidden;
    border-radius: 4px;
    background: var(--bp-c);
    box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--bp-c) 65%, #000000);
    color: var(--bp-label-text);
    cursor: pointer;
}

.bp-app .bp-layer:hover { filter: brightness(1.08); }

.bp-app .bp-layer-name {
    flex: none;
    min-width: 1.1rem;
    height: 1.1rem;
    border-radius: 999px;
    background: color-mix(in srgb, #000000 28%, transparent);
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 800;
    line-height: 1.1rem;
    text-align: center;
}

.bp-app .bp-layer-text {
    padding: 0 0.25rem;
    border-radius: 3px;
    background: var(--bp-label);
    font-size: 0.68rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bp-app .bp-layer.is-thin .bp-layer-text { display: none; }
.bp-app .bp-layer.is-tiny .bp-layer-name { display: none; }

.bp-app .bp-layer--new { animation: bp-drop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2); }

@keyframes bp-drop {
    from { transform: translateY(-120%); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.bp-app .bp-problem { margin: 0; }

.bp-app.bp-is-solving .bp-box,
.bp-app.bp-is-solving .bp-bin-body { pointer-events: none; }

@media (max-width: 560px) {
    .bp-app .bp-bin { width: 4.4rem; }
    .bp-app .bp-bin-body { height: 10rem; }
    .bp-app .bp-shelf { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
    .bp-app .bp-box-weight { font-size: 0.72rem; }
}

@media (prefers-reduced-motion: reduce) {
    .bp-app .bp-box,
    .bp-app .bp-bin-body,
    .bp-app .bp-layer--new,
    .bp-app .bp-bin-body.bp-shake { transition: none; animation: none; }
}

/* ---- Item list in the control panel ------------------------------------------------------------------------------ */

.bp-app .bp-item-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem 0.6rem;
    margin: 0.15rem 0 0.5rem;
    padding: 0;
    list-style: none;
}

.bp-app .bp-item {
    display: grid;
    grid-template-columns: 1.5rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.3rem;
}

.bp-app .bp-item-swatch {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.4rem;
    background: var(--bp-c);
    box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--bp-c) 65%, #000000);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1.5rem;
    text-align: center;
}

.bp-app .bp-item-affix .bp-unit {
    position: absolute;
    inset-inline-end: 0.5rem;
    color: var(--ak-muted);
    font-size: var(--ak-fs-sm);
    pointer-events: none;
}

.bp-app .bp-item-affix > input.ak-field.bp-item-field:not([type="range"]) {
    width: 100%;
    min-width: 0;
    padding-inline-end: 1.9rem;
}

.bp-app .bp-item-remove { flex: none; }

.bp-app .bp-add {
    justify-self: start;
    align-self: flex-start;
}
