/*
 * Visual box-model editor for tt_content.tx_t3b_spacing.
 *
 * Keeps interactive controls on TYPO3 backend Bootstrap defaults
 * (btn, form-check, dropdown-menu, input-group). Only the structural
 * pieces — the margin/padding frames with striped backgrounds, the
 * 3-by-3 grid that places eight steppers around the content box —
 * are styled here.
 */

.t3b-box-model {
    --bm-margin-color: #5a4fcf;
    --bm-padding-color: #1a936f;
    --bm-content-bg: #ffffff;
    --bm-stripe-opacity: 0.14;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.t3b-box-model[data-disabled="1"] {
    opacity: 0.6;
    pointer-events: none;
}

/* ---- Sync bar -------------------------------------------------- */

.t3b-box-model .bm-trbar {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.t3b-box-model .bm-trbar .form-check-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    margin: 0;
}

.t3b-box-model .bm-tricn {
    display: inline-flex;
    align-items: center;
    color: var(--bm-margin-color);
}

.t3b-box-model .bm-trtxt {
    font-size: 12px;
}

/* ---- Position badge ------------------------------------------- */
/*
 * Surfaces the column-position context (first / last / first+last) that
 * the BE editor detects from the DB. Colour-codes per state so editors
 * spot at a glance why the inherited defaults look the way they do.
 */
.t3b-box-model .bm-position {
    --bm-pos-color: var(--token-color-text-secondary, #6c757d);
    --bm-pos-bg: var(--typo3-component-bg-secondary, #f1f3f5);
    --bm-pos-border: var(--token-color-stroke-default, #d7d7d7);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bm-pos-bg);
    border: 1px solid var(--bm-pos-border);
    border-left-width: 4px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.3;
}

.t3b-box-model .bm-position--first {
    --bm-pos-color: var(--bm-margin-color);
    --bm-pos-border: var(--bm-margin-color);
    --bm-pos-bg: rgba(90, 79, 207, 0.08);
}

.t3b-box-model .bm-position--last {
    --bm-pos-color: var(--bm-padding-color);
    --bm-pos-border: var(--bm-padding-color);
    --bm-pos-bg: rgba(26, 147, 111, 0.08);
}

.t3b-box-model .bm-position--first_and_last {
    /* Single-CE column: visually distinct from either "first" or "last" alone */
    --bm-pos-color: #b25400;
    --bm-pos-border: #b25400;
    --bm-pos-bg: rgba(178, 84, 0, 0.08);
}

.t3b-box-model .bm-position-pin {
    color: var(--bm-pos-color);
    display: inline-flex;
    align-items: center;
}

.t3b-box-model .bm-position-label {
    font-weight: 700;
    color: var(--bm-pos-color);
    letter-spacing: 0.2px;
}

.t3b-box-model .bm-position-hint {
    color: var(--token-color-text-secondary, #6c757d);
}

/* ---- Breakpoint bar -------------------------------------------- */

.t3b-box-model .bm-bp-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--typo3-component-bg-secondary, #f8f9fa);
    border: 1px solid var(--token-color-stroke-default, #d7d7d7);
    border-radius: 4px;
    flex-wrap: wrap;
}

.t3b-box-model .bm-bp-head {
    display: flex;
    flex-direction: column;
}

.t3b-box-model .bm-bp-eyebrow {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--token-color-text-secondary, #6c757d);
}

.t3b-box-model .bm-bp-hint {
    font-size: 12px;
    color: var(--token-color-text-secondary, #6c757d);
}

/* ---- Box frames ------------------------------------------------ */

.t3b-box-model .bm-box {
    position: relative;
    border: 1px dashed var(--bm-margin-color);
    border-radius: 4px;
    padding: 12px 18px 18px;
    background-image: repeating-linear-gradient(
            -45deg,
            rgba(90, 79, 207, var(--bm-stripe-opacity)) 0,
            rgba(90, 79, 207, var(--bm-stripe-opacity)) 1px,
            transparent 1px,
            transparent 8px
    );
}

.t3b-box-model .bm-box--padding {
    border-color: var(--bm-padding-color);
    background-image: repeating-linear-gradient(
            -45deg,
            rgba(26, 147, 111, var(--bm-stripe-opacity)) 0,
            rgba(26, 147, 111, var(--bm-stripe-opacity)) 1px,
            transparent 1px,
            transparent 8px
    );
    padding: 14px;
    margin: 0;
}

.t3b-box-model .bm-box-tag {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    background: var(--typo3-component-bg, #ffffff);
    color: var(--bm-margin-color);
    padding: 2px 8px;
    border-radius: 2px;
    border: 1px solid currentColor;
}

.t3b-box-model .bm-box--padding > .bm-box-tag {
    color: var(--bm-padding-color);
}

/* The grid is 3 columns: corner / center cell / corner.
   Top + bottom rows hold the horizontal stepper. Middle row holds
   left stepper / content (or padding-box) / right stepper. */
.t3b-box-model .bm-box-grid {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(220px, 2fr) minmax(140px, 1fr);
    grid-template-rows: auto auto auto;
    gap: 8px;
    align-items: center;
    justify-items: center;
}

.t3b-box-model .bm-corner {
    width: 12px;
    height: 12px;
}

/* ---- Stepper (one per side) ------------------------------------ */

.t3b-box-model .bm-stepper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.t3b-box-model .bm-stepper .input-group {
    flex-wrap: nowrap;
    justify-content: center;
}

.t3b-box-model .bm-stepper .input-group button {
    max-width: 100px;
}

.t3b-box-model .bm-stepper--top,
.t3b-box-model .bm-stepper--bottom {
    grid-column: 2;
}

.t3b-box-model .bm-stepper--left {
    grid-column: 1;
    grid-row: 2;
}

.t3b-box-model .bm-stepper--right {
    grid-column: 3;
    grid-row: 2;
}

.t3b-box-model .bm-stepper-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    margin: 0;
    color: var(--bm-margin-color);
    background: var(--typo3-component-bg, #ffffff);
    padding: 1px 6px;
    border-radius: 2px;
}

.t3b-box-model .bm-stepper--padding .bm-stepper-label {
    color: var(--bm-padding-color);
}

.t3b-box-model .bm-stepper-input {
    position: relative;
    width: 100%;
}

.t3b-box-model .bm-stepper-value {
    width: 100%;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.t3b-box-model .bm-stepper--source-cascade .bm-stepper-value {
    font-style: italic;
    opacity: 0.85;
}

.t3b-box-model .bm-stepper--source-override .bm-stepper-value {
    border-color: var(--typo3-component-primary-color, #0a7cb9);
}

.t3b-box-model .bm-stepper-inherit {
    font-size: 9px;
    font-style: italic;
}

/* Content placeholder in the middle */
.t3b-box-model .bm-content {
    grid-column: 2;
    grid-row: 2;
    background: var(--bm-content-bg);
    border: 1px solid var(--token-color-stroke-default, #d7d7d7);
    border-radius: 3px;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    min-height: 80px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.t3b-box-model .bm-content-title {
    font-weight: 600;
    color: var(--token-color-text-primary, #212529);
}

.t3b-box-model .bm-content-ctype {
    font-size: 11px;
    color: var(--token-color-text-secondary, #6c757d);
    margin-top: 4px;
    font-family: var(--bs-font-monospace, ui-monospace, SFMono-Regular, monospace);
}

/* ---- Popover (step picker) ------------------------------------- */

.t3b-box-model .bm-pop {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 260px;
    padding: 6px;
    z-index: 1080;
    background: var(--typo3-component-bg, #ffffff);
    border: 1px solid var(--token-color-stroke-default, #d7d7d7);
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.t3b-box-model .bm-pop::before {
    content: "";
    position: absolute;
    top: -5px;
    left: 50%;
    width: 8px;
    height: 8px;
    background: inherit;
    border-top: 1px solid var(--token-color-stroke-default, #d7d7d7);
    border-left: 1px solid var(--token-color-stroke-default, #d7d7d7);
    transform: translateX(-50%) rotate(45deg);
}

.t3b-box-model .bm-pop-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
}

.t3b-box-model .bm-pop-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
    padding: 6px 4px;
    min-height: 56px;
    line-height: 1.1;
}

.t3b-box-model .bm-pop-chip-bar {
    display: inline-block;
    width: 18px;
    background: currentColor;
    border-radius: 1px;
    opacity: 0.4;
}

.t3b-box-model .bm-pop-chip.active .bm-pop-chip-bar {
    opacity: 1;
}

.t3b-box-model .bm-pop-chip.is-default::after {
    content: "★";
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 9px;
    color: var(--typo3-component-primary-color, #0a7cb9);
}

.t3b-box-model .bm-pop-chip {
    position: relative;
}

.t3b-box-model .bm-pop-chip-label {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.t3b-box-model .bm-pop-chip-px {
    font-size: 10px;
}

/* ---- Legend ---------------------------------------------------- */

.t3b-box-model .bm-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 11px;
    color: var(--token-color-text-secondary, #6c757d);
}

.t3b-box-model .bm-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.t3b-box-model .bm-legend-item::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 1px dashed currentColor;
}

.t3b-box-model .bm-legend-margin {
    color: var(--bm-margin-color);
}

.t3b-box-model .bm-legend-padding {
    color: var(--bm-padding-color);
}

.t3b-box-model .bm-legend-hint {
    margin-left: auto;
}

/* ---- Compact mode for narrow palettes -------------------------- */

@media (max-width: 720px) {
    .t3b-box-model .bm-box-grid {
        grid-template-columns: minmax(110px, 1fr) minmax(160px, 2fr) minmax(110px, 1fr);
    }
}
