/* Photo Editor (tools/partials/photo-editor-layout.blade.php) - loaded only on that page. */

.pe {
    display: flex;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    min-height: 34rem;
}

.pe[hidden] {
    display: none;
}

.pe__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.pe-icon {
    width: 1.5rem;
    height: 1.5rem;
    flex: none;
}

/* Toolbar */
.pe-toolbar {
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: thin;
}

.pe-toolbar__group {
    display: flex;
    gap: 0.15rem;
    padding: 0 0.6rem;
    border-right: 1px solid var(--line);
}

.pe-toolbar__group:last-child {
    border-right: 0;
}

/* Centred when it fits; when it doesn't, auto margins (unlike
   justify-content: center) still let it scroll back to the first tool. */
.pe-toolbar__group:first-child {
    margin-left: auto;
}

.pe-toolbar__group:last-child {
    margin-right: auto;
}

.pe-tool {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    min-width: 4.1rem;
    padding: 0.55rem 0.4rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink-2);
    cursor: pointer;
    font: inherit;
}

.pe-tool:hover {
    background: var(--brand-light);
    color: var(--brand);
}

.pe-tool[aria-pressed="true"] {
    background: var(--brand-light);
    color: var(--brand);
}

.pe-tool__label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Tool panels */
.pe-panels {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.pe-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pe-panel[hidden] {
    display: none;
}

.pe-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1.25rem;
}

.pe-row--tight {
    gap: 0.75rem;
}

.pe-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.pe-chip,
.pe-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-2);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.pe-btn {
    border-radius: var(--radius-sm);
}

.pe-btn .pe-icon {
    width: 1.1rem;
    height: 1.1rem;
}

.pe-chip:hover,
.pe-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.pe-chip[aria-pressed="true"] {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.pe-btn--primary {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.pe-btn--primary:hover {
    background: var(--brand-dark);
    color: #fff;
}

.pe-btn--outline {
    justify-content: center;
    border-color: var(--brand);
    color: var(--brand);
    font-weight: 600;
}

.pe-actions {
    display: flex;
    gap: 0.5rem;
}

.pe-hint {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--ink-3);
}

.pe-sliders {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 0.5rem 1.5rem;
}

.pe-slider {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: var(--text-sm);
    color: var(--ink-2);
}

.pe-slider--wide {
    max-width: 32rem;
}

.pe-slider__label {
    flex: none;
    min-width: 5.5rem;
}

.pe-slider input[type="range"] {
    flex: 1;
    min-width: 6rem;
    accent-color: var(--brand);
}

.pe-slider__value {
    min-width: 2.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--ink-3);
}

.pe-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: var(--text-sm);
    color: var(--ink-2);
}

.pe-input {
    min-width: 7rem;
    padding: 0.4rem 0.6rem;
}

.pe-field--narrow .pe-input {
    min-width: 0;
    width: 5.5rem;
}

.pe-check {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: var(--text-sm);
    color: var(--ink-2);
    cursor: pointer;
}

.pe-check input {
    accent-color: var(--brand);
}

.pe-toggles {
    display: inline-flex;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.pe-toggle {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.1rem;
    border: 0;
    border-right: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
    font: inherit;
    cursor: pointer;
}

.pe-toggle:last-child {
    border-right: 0;
}

.pe-toggle .pe-icon {
    width: 1.1rem;
    height: 1.1rem;
}

.pe-toggle[aria-pressed="true"] {
    background: var(--brand-light);
    color: var(--brand);
}

.pe-toggle--bold {
    font-weight: 800;
}

.pe-toggle--italic {
    font-style: italic;
    font-family: Georgia, serif;
}

.pe-toggle--underline {
    text-decoration: underline;
}

/* Color control */
.pe-color {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--text-sm);
    color: var(--ink-2);
}

.pe-color__input {
    width: 2.1rem;
    height: 2.1rem;
    padding: 0.1rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
}

.pe-color__swatches {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.pe-swatch {
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 50%;
    cursor: pointer;
}

.pe-swatch:hover {
    transform: scale(1.12);
}

.pe-swatch--ffffff { background: #ffffff; }
.pe-swatch--000000 { background: #000000; }
.pe-swatch--e53935 { background: #e53935; }
.pe-swatch--fb8c00 { background: #fb8c00; }
.pe-swatch--fdd835 { background: #fdd835; }
.pe-swatch--43a047 { background: #43a047; }
.pe-swatch--1e88e5 { background: #1e88e5; }
.pe-swatch--8e24aa { background: #8e24aa; }
.pe-swatch--ec407a { background: #ec407a; }
.pe-swatch--6d4c41 { background: #6d4c41; }
.pe-swatch--9e9e9e { background: #9e9e9e; }

/* Stickers */
.pe-stickers {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr));
    gap: 0.25rem;
    max-height: 7.5rem;
    overflow-y: auto;
}

.pe-sticker {
    height: 2.75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.pe-sticker:hover {
    background: var(--brand-light);
}

/* Canvas stage - a checkerboard so transparency is visible */
.pe-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 26rem;
    padding: 1rem;
    overflow: auto;
    background-color: #eef0f3;
    background-image:
        linear-gradient(45deg, #e2e5ea 25%, transparent 25%),
        linear-gradient(-45deg, #e2e5ea 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e5ea 75%),
        linear-gradient(-45deg, transparent 75%, #e2e5ea 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.pe-stage__canvas {
    flex: none;
    margin: auto;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15), 0 8px 24px rgba(15, 23, 42, 0.12);
    line-height: 0;
}

/* Sidebar */
.pe-side {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 19rem;
    flex: none;
    border-left: 1px solid var(--line);
    padding: 1.25rem;
}

.pe-side__open {
    width: 100%;
    padding: 0.7rem;
    margin-bottom: 1rem;
    cursor: pointer;
}

.pe-side__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
}

.pe-round {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: #f1f3f6;
    color: var(--ink-2);
    cursor: pointer;
}

.pe-round .pe-icon {
    width: 1.2rem;
    height: 1.2rem;
}

.pe-round:hover:not(:disabled),
.pe-round[aria-pressed="true"] {
    background: var(--brand-light);
    color: var(--brand);
}

.pe-round:disabled {
    opacity: 0.4;
    cursor: default;
}

.pe-round--sm {
    width: 2.1rem;
    height: 2.1rem;
}

.pe-round--danger:hover:not(:disabled) {
    background: #fdecea;
    color: #d32f2f;
}

.pe-zoom__value {
    border: 0;
    background: none;
    font: inherit;
    font-size: var(--text-sm);
    color: var(--ink-2);
    cursor: pointer;
}

.pe-selection {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
}

.pe-selection[hidden] {
    display: none;
}

.pe-selection__name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pe-selection__actions {
    display: flex;
    gap: 0.4rem;
}

.pe-layers {
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
}

.pe-layers__title {
    margin: 0 0 0.5rem;
    font-size: var(--text-sm);
    font-weight: 600;
}

.pe-layers__list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 14rem;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.pe-layer {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.35rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.pe-layer.is-active {
    border-color: var(--brand);
    background: var(--brand-light);
}

.pe-layer.is-hidden .pe-layer__name {
    opacity: 0.45;
}

.pe-layer__name {
    flex: 1;
    min-width: 0;
    padding: 0.3rem;
    border: 0;
    background: none;
    font: inherit;
    font-size: var(--text-sm);
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.pe-layer__name:disabled {
    color: var(--ink-3);
    cursor: default;
}

.pe-layer__btn {
    padding: 0.2rem 0.45rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink-3);
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

.pe-layer__btn:hover {
    background: #f1f3f6;
    color: var(--ink-2);
}

.pe-layer__btn--danger:hover {
    background: #fdecea;
    color: #d32f2f;
}

.pe-side__save {
    margin-top: auto;
    padding-top: 0.85rem;
    border-top: 1px solid var(--line);
}

.pe-side__save .pe-field {
    flex: 1;
}

.pe-side__save .pe-input {
    width: 100%;
    min-width: 0;
}

.pe-side__size {
    margin: 0.6rem 0;
    font-size: var(--text-sm);
    color: var(--ink-3);
    text-align: center;
}

.pe-side__save-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.9rem;
    font-size: 1.05rem;
}

.pe-side__save-btn .pe-icon {
    width: 1.2rem;
    height: 1.2rem;
}

@media (max-width: 64rem) {
    .pe {
        flex-direction: column;
    }

    .pe-side {
        width: auto;
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .pe-toolbar {
        padding: 0.5rem;
    }

    .pe-tool {
        min-width: 4rem;
    }

    .pe-stage {
        order: -1;
        min-height: 16rem;
        padding: 0.5rem;
        border-bottom: 1px solid var(--line);
    }
}

@media (max-width: 40rem) {
    .pe-panels {
        padding: 0.75rem;
    }

    .pe-sliders {
        grid-template-columns: 1fr;
    }

    .pe-slider__label {
        min-width: 4.5rem;
    }

    /* The native picker is enough on a phone - the swatch rows double the panel's height. */
    .pe-color__swatches {
        display: none;
    }
}
