/*
 * The inline idx editor in CRUD list rows.
 * Flat PAM colors and pill controls, like the rest of the backoffice.
 */

.pam-inline-idx {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    width: 11rem;
}

.pam-inline-idx--static {
    width: auto;
}

/* Each control is its own pill, with the same gap the other button rows use. */
.pam-inline-idx__controls {
    display: inline-flex;
    align-items: stretch;
    gap: .25rem;
}

.pam-inline-idx__input {
    position: relative;
    width: 4rem;
    height: 1.75rem;
    padding: 0 .375rem;
    margin-top: 0;
    margin-bottom: 0;
    margin-right: 0;
    border: 1px solid var(--pam-border, #ebebeb);
    border-radius: 9999px;
    background-color: var(--pam-field, #f7f7f5);
    color: var(--pam-text, #1f1f1f);
    font: inherit;
    font-size: .875rem;
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;
}

.pam-inline-idx__input::-webkit-outer-spin-button,
.pam-inline-idx__input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.pam-inline-idx__input:focus {
    outline: none;
    border-color: var(--pam-green-text, #215732);
    background-color: #fff;
}

.pam-inline-idx__input:focus-visible {
    outline: .125rem solid var(--pam-green-text, #215732);
    outline-offset: .125rem;
    z-index: 1;
}

.pam-inline-idx__input:disabled {
    cursor: progress;
    opacity: .6;
}

.pam-inline-idx__btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 1px solid var(--pam-border, #ebebeb);
    border-radius: 9999px;
    background-color: var(--pam-field, #f7f7f5);
    color: var(--pam-muted, #595959);
    font: inherit;
    font-size: .875rem;
    line-height: 1;
    cursor: pointer;
}

.pam-inline-idx__btn--zero {
    width: 2rem;
    color: var(--pam-green-text, #215732);
}

.pam-inline-idx__btn svg {
    width: 1rem;
    height: 1rem;
}

.pam-inline-idx__btn:hover:not(:disabled) {
    border-color: var(--pam-green-text, #215732);
    color: var(--pam-green-text, #215732);
}

.pam-inline-idx__btn:focus-visible {
    outline: .125rem solid var(--pam-green-text, #215732);
    outline-offset: .125rem;
    z-index: 1;
}

.pam-inline-idx__btn:disabled {
    cursor: progress;
    opacity: .6;
}

.pam-inline-idx.is-busy .pam-inline-idx__btn,
.pam-inline-idx.is-busy .pam-inline-idx__input {
    opacity: .6;
}

.pam-inline-idx__status {
    margin: 0;
    font-size: .75rem;
    line-height: 1.1;
    color: var(--pam-muted, #595959);
    overflow-wrap: anywhere;
}

.pam-inline-idx__status.is-ok {
    color: var(--pam-green-text, #215732);
}

.pam-inline-idx__status.is-error {
    color: var(--pam-red-text, #961731);
}

.pam-inline-idx__status:empty {
    display: none;
}

/* Narrow columns: the zero reset drops its extra width, so the four controls
   stay on one row at any zoom. */

@media (max-width: 640px) {
    .pam-inline-idx {
        width: auto;
    }

    .pam-inline-idx__btn--zero {
        width: 1.75rem;
    }
}

/* ---------- Phones: the key cell carries the editor ---------- */

/* Below 40rem the list hides every low-value column, including the separate
   idx column. The identifying cell renders a second copy of this editor
   (filament.crud.columns.key-with-mobile-idx), so the ordering stays editable
   on the phone. Above that width this copy is not displayed. */
.pam-idx-mobile {
    display: none;
}

@media (max-width: 40rem) {
    /* Filament wraps a cell in a flex row; the value and the editor must stack
       instead of sharing the identifying cell's width. */
    .fi-ta-table .pam-col-mobile-idx .fi-ta-col {
        display: block;
    }

    .pam-idx-mobile {
        display: block;
        margin-top: .5rem;
    }

    /* Two lines inside the key cell: up, value and down, then the zero
       reset, each a comfortable tap target. */
    .pam-idx-mobile .pam-inline-idx {
        width: 100%;
        gap: 0;
    }

    /* Same reading and focus order as the markup: up, value, down, then the
       zero reset across the second line. */
    .pam-idx-mobile .pam-inline-idx__controls {
        display: grid;
        grid-template-areas:
            "up input down"
            "zero zero zero";
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr);
        gap: .25rem;
        width: 100%;
    }

    .pam-idx-mobile .pam-inline-idx__input {
        grid-area: input;
        width: 100%;
        height: 2rem;
        min-width: 0;
        padding-inline: .25rem;
    }

    .pam-idx-mobile .pam-inline-idx__btn--up {
        grid-area: up;
    }

    .pam-idx-mobile .pam-inline-idx__btn--down {
        grid-area: down;
    }

    .pam-idx-mobile .pam-inline-idx__btn--zero {
        grid-area: zero;
    }

    .pam-idx-mobile .pam-inline-idx__btn,
    .pam-idx-mobile .pam-inline-idx__btn--zero {
        width: 100%;
        height: 2rem;
    }

    .pam-idx-mobile .pam-inline-idx__status {
        margin-top: .25rem;
    }
}

/* The 32px drawing keeps the row compact; the hit area grows to 48px tall. */
@media (max-width: 40rem) and (pointer: coarse) {
    .pam-idx-mobile .pam-inline-idx__btn::after {
        content: "";
        position: absolute;
        inset: -.5rem 0;
        border-radius: 9999px;
    }
}
