/* =========================================================
   STORAGE UNIT CALCULATOR MODAL
   Loaded directly INSIDE the Shadow DOM
   ========================================================= */


/* Host */

:host {
    display: block;

    --unit-button-color: #8A0206;
    --unit-button-hover: #680104;
}


/* Reset calculator elements */

*,
*::before,
*::after {
    box-sizing: border-box;
}

button,
input {
    font: inherit;
}


/* =========================================================
   SIDEBAR LAUNCH BUTTON
   ========================================================= */

.launch {
    display: block;

    width: 100%;

    margin: 0;
    padding: 17px 14px;

    border: 0;
    border-radius: 0;

    background: var(--unit-button-color);
    color: #ffffff;

    text-align: center;

    font-family: Arial, Helvetica, sans-serif;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.35;

    cursor: pointer;

    transition:
        background-color 0.2s ease,
        color 0.2s ease;
}

.launch:hover,
.launch:focus {
    background: var(--unit-button-hover);
    color: #ffffff;
}

.launch .icon {
    display: inline-block;

    margin-right: 9px;

    font-size: 18px;
    line-height: 1;
    vertical-align: -1px;
}


/* Keyboard accessibility */

:focus-visible {
    outline: 3px solid #1675c1;
    outline-offset: 3px;
}


/* =========================================================
   MODAL
   ========================================================= */

dialog {
    width: 960px;
    max-width: calc(100vw - 24px);

    height: 850px;

    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);

    margin: auto;
    padding: 0;

    border: 0;
    border-radius: 0;

    background: #ffffff;
    color: #222222;

    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.5;

    box-shadow:
        0 16px 65px rgba(0, 0, 0, 0.4);

    overflow: hidden;
}

dialog[open] {
    display: flex;

    flex-direction: column;
}


/* Native modal backdrop */

dialog::backdrop {
    background: rgba(0, 0, 0, 0.70);
}


/* =========================================================
   MODAL HEADER
   ========================================================= */

header {
    display: flex;

    align-items: center;

    gap: 16px;

    padding: 16px 20px;

    border-bottom: 1px solid #dddddd;

    background: #ffffff;

    flex-shrink: 0;
}

h2 {
    flex: 1;

    margin: 0;

    color: #222222;

    font-family: Arial, Helvetica, sans-serif;
    font-size: 23px;
    font-weight: 700;
    line-height: 1.25;
}


/* Close X */

.close {
    width: 44px;
    height: 44px;

    flex-shrink: 0;

    margin: 0;
    padding: 0;

    border: 1px solid #cccccc;
    border-radius: 0;

    background: #ffffff;
    color: #222222;

    font-size: 28px;
    font-weight: 400;
    line-height: 1;

    cursor: pointer;
}

.close:hover,
.close:focus {
    background: #f1f1f1;
    color: #8A0206;
}


/* =========================================================
   FORM
   ========================================================= */

form {
    display: flex;

    flex: 1;
    flex-direction: column;

    min-height: 0;

    margin: 0;
}


/* Scrollable item portion */

.items {
    flex: 1;

    min-height: 0;

    padding: 18px 20px;

    overflow-x: hidden;
    overflow-y: auto;

    overscroll-behavior: contain;

    background: #ffffff;
}

.items > p {
    margin: 0 0 16px;

    color: #333333;
}


/* =========================================================
   ITEM GROUPS
   ========================================================= */

fieldset {
    min-width: 0;

    margin: 0 0 20px;
    padding: 12px;

    border: 1px solid #d9d9d9;

    background: #ffffff;
}

legend {
    padding: 0 8px;

    color: #222222;

    font-size: 19px;
    font-weight: 700;
}


/* Three-column desktop layout */

.grid {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 12px;
}


/* Individual item */

label {
    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 8px;

    min-width: 0;

    padding: 8px;

    background: #f5f5f5;

    color: #222222;

    font-size: 14px;
}

label span {
    min-width: 0;

    overflow-wrap: anywhere;
}


/* Quantity inputs */

input {
    width: 64px;
    min-width: 64px;
    height: 42px;

    padding: 6px;

    border: 1px solid #999999;
    border-radius: 0;

    background: #ffffff;
    color: #222222;

    text-align: center;
}

input:focus {
    border-color: #8A0206;
}


/* Remove WebKit number appearance where possible */

input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    margin: 0;

    -webkit-appearance: none;
}


/* =========================================================
   CALCULATOR FOOTER
   ========================================================= */

footer {
    flex-shrink: 0;

    padding: 14px 20px;

    border-top: 1px solid #dddddd;

    background: #fafafa;
}


/* Result */

output {
    display: block;

    margin: 0 0 12px;

    color: #222222;

    font-size: 16px;
    font-weight: 700;
}


/* Buttons */

.actions {
    display: flex;

    gap: 10px;

    flex-wrap: wrap;
}

.calculate,
.reset {
    margin: 0;
    padding: 12px 18px;

    border-radius: 0;

    font-weight: 700;

    cursor: pointer;
}

.calculate {
    border: 1px solid var(--unit-button-color);

    background: var(--unit-button-color);
    color: #ffffff;
}

.calculate:hover,
.calculate:focus {
    border-color: var(--unit-button-hover);

    background: var(--unit-button-hover);
    color: #ffffff;
}

.reset {
    border: 1px solid #aaaaaa;

    background: #ffffff;
    color: #333333;
}

.reset:hover,
.reset:focus {
    background: #eeeeee;
}


/* Disclaimer */

.note {
    margin: 10px 0 0;

    color: #555555;

    font-size: 12px;
    line-height: 1.45;
}


/* =========================================================
   TABLET
   ========================================================= */

@media screen and (max-width: 700px) {

    .grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

}


/* =========================================================
   MOBILE
   ========================================================= */

@media screen and (max-width: 480px) {

    dialog {
        width: calc(100vw - 12px);
        max-width: calc(100vw - 12px);

        height: calc(100dvh - 12px);
        max-height: calc(100dvh - 12px);
    }

    .grid {
        grid-template-columns: 1fr;

        gap: 8px;
    }

    header {
        padding: 12px;
    }

    h2 {
        font-size: 19px;
    }

    .items {
        padding: 12px;
    }

    footer {
        padding: 12px;
    }

    .launch {
        padding: 15px 12px;

        font-size: 16px;
    }

}