/* ============================================================
   IMAGE CROPPER
   ============================================================ */

.crop-workspace {
    width: 100%;
    max-width: none;
    margin: 0 auto;
}

.is-hidden {
    display: none !important;
}


/* ── Upload zone ─────────────────────────────────────────── */
.crop-upload-zone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: 12px;
    background: var(--surface);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.crop-upload-zone:hover,
.crop-upload-zone.crop-drag-over {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb), 0.06);
}

.crop-upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.crop-upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.crop-upload-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 0.4rem;
}

.crop-upload-sub {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.crop-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    margin-bottom: 0.875rem;
}

.crop-toolbar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.crop-toolbar-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 3.5rem;
    flex-shrink: 0;
}

/* ── Ratio buttons ───────────────────────────────────────── */
.crop-ratio-btns,
.crop-fmt-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.crop-ratio-btn,
.crop-fmt-btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    min-height: 32px;
    line-height: 1;
}

.crop-ratio-btn:hover,
.crop-fmt-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.crop-ratio-btn.crop-ratio-active,
.crop-fmt-btn.crop-fmt-active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

/* ── Quality slider ──────────────────────────────────────── */
.crop-quality-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 0.5rem;
}

.crop-quality-range {
    width: 100px;
    accent-color: var(--primary);
    cursor: pointer;
}

.crop-quality-val {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    min-width: 2.5rem;
}

/* ── Canvas wrap ─────────────────────────────────────────── */
.crop-canvas-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg);
    box-shadow: 0 4px 24px rgba(var(--shadow-color-rgb), 0.18);
}

#cropImg {
    display: block;
    max-width: 100%;
    height: auto;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

#cropCanvas {
    position: absolute;
    inset: 0;
    cursor: crosshair;
    touch-action: none;
}

/* Center the canvas wrap inside the editor */
.crop-editor {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 1060px;
    margin: 0 auto;
}

.crop-editor .crop-toolbar,
.crop-editor .crop-meta,
.crop-editor .crop-actions {
    width: 100%;
    max-width: 100%;
}

/* ── Meta row (dimensions + hint) ────────────────────────── */
.crop-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.625rem;
    flex-wrap: wrap;
}

.crop-dims {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.crop-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ── Action buttons ──────────────────────────────────────── */
.crop-actions {
    display: flex;
    gap: 0.625rem;
    margin-top: 0.875rem;
    flex-wrap: wrap;
}

.crop-btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--on-primary);
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 44px;
    transition: var(--transition);
    flex: 1;
}

.crop-btn-primary:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.crop-btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.crop-btn-secondary {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    min-height: 44px;
    flex-shrink: 0;
}

.crop-btn-remove {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    min-height: 44px;
    flex-shrink: 0;
    margin-left: auto;
}

/* ── Result panel ────────────────────────────────────────── */
.crop-result {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    max-width: 940px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.crop-result-close {
    display: none; /* shown only on mobile via media query */
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(var(--shadow-color-rgb), 0.15);
    z-index: 10;
}

.crop-result-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.crop-result-preview {
    width: 100%;
    text-align: center;
    background: repeating-conic-gradient(rgba(var(--text-muted-rgb), 0.12) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.crop-result-preview img {
    max-width: 100%;
    max-height: 420px;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
}

.crop-result-meta {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.crop-result-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.crop-result-actions .crop-btn-primary {
    width: 100%;
}

.crop-result-actions .crop-btn-secondary {
    width: 100%;
    text-align: center;
}

.crop-btn-new {
    width: 100%;
    text-align: center;
    font-size: 0.875rem;
    min-height: 44px;
}

/* ── Status message ──────────────────────────────────────── */
.crop-status {
    min-height: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}

.crop-status-error {
    color: var(--danger);
    font-weight: 600;
}

/* ── Responsive ──────────────────────────────────────────── */

/* Mobile: result becomes a fullscreen overlay */
@media (max-width: 640px) {
    .crop-upload-zone {
        padding: 2rem 1rem;
    }

    .crop-toolbar {
        padding: 0.75rem;
    }

    .crop-toolbar-row {
        gap: 0.375rem;
    }

    .crop-toolbar-label {
        min-width: 2.8rem;
        font-size: 0.75rem;
    }

    .crop-ratio-btn,
    .crop-fmt-btn {
        padding: 0.3rem 0.55rem;
        font-size: 0.75rem;
    }

    .crop-quality-range {
        width: 70px;
    }

    .crop-actions {
        gap: 0.5rem;
    }

    .crop-btn-primary {
        font-size: 0.95rem;
        padding: 0.7rem 1rem;
    }

    .crop-btn-remove {
        margin-left: 0;
        width: 100%;
        text-align: center;
    }

    .crop-hint {
        display: none;
    }

    /* Fullscreen overlay on mobile */
    .crop-workspace.has-result .crop-result {
        position: fixed;
        inset: 0;
        z-index: 300;
        max-width: none;
        margin: 0;
        border-radius: 0;
        border: none;
        overflow-y: auto;
        padding: 1.25rem 1rem 2rem;
        animation: crop-slide-up 0.22s ease;
    }

    .crop-result-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .crop-workspace.has-result {
        display: block;
    }

    .crop-result-preview img {
        max-height: 55vh;
    }
}

@keyframes crop-slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
