/* =========================
   IMAGE EDITOR
   ========================= */

.image-editor-section {
    --editor-danger: #b42318;
    --editor-success: #2f7d4a;
    --editor-working: #805019;

    max-width: var(--tc-max-width);
    margin-inline: auto;
}

.image-editor-card [hidden] {
    display: none !important;
}

.image-editor-card {
    margin-top: 2.5rem;
    padding: clamp(1.1rem, 4vw, 2.5rem);

    background: var(--tc-white);
    border: 1px solid var(--tc-border);
    border-radius: 24px;

    box-shadow:
        0 24px 70px rgba(23, 36, 51, 0.1);
}


/* =========================
   UPLOAD AREA
   ========================= */

.edit-drop-zone {
    padding: clamp(2.5rem, 8vw, 5rem) 1.5rem;

    text-align: center;

    background: rgba(166, 106, 36, 0.04);
    border: 2px dashed var(--tc-border);
    border-radius: 20px;

    transition:
        border-color 180ms ease,
        background-color 180ms ease,
        transform 180ms ease;
}

.edit-drop-zone.drag-active {
    background: rgba(166, 106, 36, 0.12);
    border-color: var(--tc-copper);
    transform: scale(1.01);
}

.edit-drop-zone h3 {
    margin: 1rem 0 0.5rem;
    font-size: clamp(1.25rem, 3vw, 1.6rem);
}

.edit-drop-zone>p:not(.status-message) {
    margin: 0 0 1.5rem;
}

.edit-drop-zone .status-message {
    text-align: center;
}


/* =========================
   FILE INFORMATION
   ========================= */

.source-information {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;

    margin-bottom: 1rem;
    padding: 0.9rem 1rem;

    background: var(--tc-cream);
    border: 1px solid var(--tc-border);
    border-radius: 12px;
}

.source-information div {
    display: grid;
    gap: 0.15rem;
}

.source-information strong {
    max-width: 520px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-information span {
    color: var(--tc-text-muted);
    font-size: 0.82rem;
}

#currentDimensions {
    color: var(--tc-heading);
    font-weight: 700;
}


/* =========================
   EDITOR LAYOUT
   ========================= */

.editor-layout {
    display: grid;
    grid-template-columns:
        minmax(0, 1.55fr) minmax(280px, 0.75fr);
    align-items: start;
    gap: 1.25rem;
}

.editor-preview-panel {
    min-width: 0;
    padding: 1rem;

    background: var(--tc-navy-dark);
    border-radius: 16px;
}

.editor-stage-wrapper {
    display: grid;
    place-items: center;

    width: 100%;
    min-height: 360px;
    overflow: auto;
}

.editor-stage {
    position: relative;

    display: block;
    flex: none;

    overflow: hidden;

    background-color: #1b2633;

    background-image:
        linear-gradient(45deg,
            #263545 25%,
            transparent 25%),
        linear-gradient(-45deg,
            #263545 25%,
            transparent 25%),
        linear-gradient(45deg,
            transparent 75%,
            #263545 75%),
        linear-gradient(-45deg,
            transparent 75%,
            #263545 75%);

    background-position:
        0 0,
        0 10px,
        10px -10px,
        -10px 0;

    background-size: 20px 20px;

    user-select: none;
}

.editor-canvas {
    display: block;

    width: 100%;
    height: 100%;
}

.editor-help {
    margin: 0.9rem 0 0;

    color: rgba(255, 255, 255, 0.72);
    font-size: 0.78rem;
    text-align: center;
}


/* =========================
   CROP SELECTION
   ========================= */

.crop-box {
    position: absolute;

    box-sizing: border-box;

    border: 2px solid var(--tc-copper-light);

    box-shadow:
        0 0 0 9999px rgba(6, 12, 18, 0.58),
        inset 0 0 0 1px rgba(255, 255, 255, 0.55);

    cursor: move;
    outline: none;
    touch-action: none;

    background-image:
        linear-gradient(to right,
            transparent 33.1%,
            rgba(255, 255, 255, 0.5) 33.1%,
            rgba(255, 255, 255, 0.5) 33.6%,
            transparent 33.6%,
            transparent 66.2%,
            rgba(255, 255, 255, 0.5) 66.2%,
            rgba(255, 255, 255, 0.5) 66.7%,
            transparent 66.7%),
        linear-gradient(to bottom,
            transparent 33.1%,
            rgba(255, 255, 255, 0.5) 33.1%,
            rgba(255, 255, 255, 0.5) 33.6%,
            transparent 33.6%,
            transparent 66.2%,
            rgba(255, 255, 255, 0.5) 66.2%,
            rgba(255, 255, 255, 0.5) 66.7%,
            transparent 66.7%);
}

.crop-box:focus-visible {
    box-shadow:
        0 0 0 9999px rgba(6, 12, 18, 0.58),
        0 0 0 4px rgba(193, 138, 71, 0.35);
}

.crop-handle {
    position: absolute;

    width: 18px;
    height: 18px;

    background: var(--tc-copper-light);
    border: 2px solid var(--tc-white);
    border-radius: 50%;

    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.35);
}

.handle-nw {
    top: 0;
    left: 0;
    cursor: nwse-resize;
    transform: translate(-50%, -50%);
}

.handle-ne {
    top: 0;
    right: 0;
    cursor: nesw-resize;
    transform: translate(50%, -50%);
}

.handle-sw {
    bottom: 0;
    left: 0;
    cursor: nesw-resize;
    transform: translate(-50%, 50%);
}

.handle-se {
    right: 0;
    bottom: 0;
    cursor: nwse-resize;
    transform: translate(50%, 50%);
}


/* =========================
   EDITOR CONTROLS
   ========================= */

.editor-controls {
    display: grid;
    gap: 1rem;
}

.control-group {
    display: grid;
    gap: 0.85rem;

    padding: 1rem;

    background: var(--tc-cream);
    border: 1px solid var(--tc-border);
    border-radius: 14px;
}

.control-group h3 {
    margin: 0;

    color: var(--tc-heading);
    font-size: 1rem;
}

.image-editor-section .setting-field {
    display: grid;
    gap: 0.5rem;
}

.image-editor-section .setting-field>span {
    color: var(--tc-heading);
    font-size: 0.85rem;
    font-weight: 700;
}

.image-editor-section .setting-field select {
    width: 100%;
    min-height: 48px;
    padding: 0.7rem 0.85rem;

    color: var(--tc-heading);

    background: var(--tc-white);
    border: 1px solid var(--tc-border);
    border-radius: 9px;

    outline: none;
}

.image-editor-section .setting-field select:focus {
    border-color: var(--tc-copper);

    box-shadow:
        0 0 0 3px rgba(166, 106, 36, 0.16);
}

.transform-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.editor-controls .btn-secondary {
    color: var(--tc-copper-dark);

    background: var(--tc-white);
    border: 1px solid var(--tc-border);
}

.editor-controls .btn-secondary:hover {
    color: var(--tc-white);

    background: var(--tc-copper);
    border-color: var(--tc-copper);
}

.control-button {
    width: 100%;
    justify-content: center;
}


/* Quality */

.quality-setting {
    display: grid;
    gap: 0.65rem;
}

.setting-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.setting-label-row label {
    color: var(--tc-heading);
    font-size: 0.85rem;
    font-weight: 700;
}

.setting-label-row output {
    min-width: 62px;
    padding: 0.25rem 0.55rem;

    color: var(--tc-copper-dark);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;

    background: rgba(166, 106, 36, 0.1);
    border-radius: 999px;
}

.quality-setting input[type="range"] {
    width: 100%;

    accent-color: var(--tc-copper);
    cursor: pointer;
}

.quality-setting input[type="range"]:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.quality-setting.is-disabled {
    opacity: 0.55;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    gap: 1rem;

    color: var(--tc-text-muted);
    font-size: 0.7rem;
}


/* Actions */

.editor-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.7rem;
}

.editor-actions .btn {
    width: 100%;
    justify-content: center;
}

.editor-controls .btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.image-editor-section .status-message {
    min-height: 1.5rem;
    margin-top: 0;

    text-align: center;
}

.image-editor-section .status-message.status-working {
    color: var(--editor-working);
}

.image-editor-section .status-message.status-success {
    color: var(--editor-success);
}

.image-editor-section .status-message.status-error {
    color: var(--editor-danger);
}


/* =========================
   RESPONSIVE
   ========================= */

@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .editor-stage-wrapper {
        min-height: 300px;
    }

    .editor-controls {
        grid-template-columns: 1fr 1fr;
    }

    .editor-actions,
    .editor-controls>.status-message {
        grid-column: 1 / -1;
    }
}

@media (max-width: 650px) {
    .image-editor-card {
        padding: 1rem;
        border-radius: 18px;
    }

    .editor-preview-panel {
        padding: 0.75rem;
    }

    .editor-stage-wrapper {
        min-height: 220px;
    }

    .editor-controls {
        grid-template-columns: 1fr;
    }

    .editor-actions,
    .editor-controls>.status-message {
        grid-column: auto;
    }

    .source-information {
        align-items: flex-start;
        flex-direction: column;
    }

    .source-information strong {
        max-width: 260px;
    }
}

@media (max-width: 430px) {
    .transform-buttons {
        grid-template-columns: 1fr;
    }

    .crop-handle {
        width: 22px;
        height: 22px;
    }
}