.image-workbench {
    padding-bottom: 24px;
}

.workbench-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 20px;
    margin-bottom: 20px;
}

.workbench-head h2 {
    margin-bottom: 6px;
}

.workbench-status {
    margin: 0;
    text-align: right;
    max-width: 360px;
}

.workbench-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 18px;
    align-items: start;
}

.workbench-stage {
    min-width: 0;
}

.crop-workspace {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: #060912;
    min-height: min(58vh, 600px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.crop-workspace.empty {
    min-height: min(62vh, 640px);
}

.crop-workspace:not(.empty) {
    overflow: auto;
    padding: 0;
    overscroll-behavior: contain;
}

.upload-dropzone {
    position: absolute;
    inset: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    z-index: 2;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
    border-color: rgba(91, 124, 250, 0.55);
    background: rgba(91, 124, 250, 0.06);
}

.upload-dropzone input {
    display: none;
}

.upload-dropzone-inner {
    text-align: center;
    padding: 20px;
}

.upload-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 14px;
    border-radius: 16px;
    font-size: 24px;
    font-weight: 700;
    color: #c9d4f5;
    background: rgba(91, 124, 250, 0.12);
    border: 1px solid rgba(91, 124, 250, 0.25);
}

.image-workbench.workbench-ready .upload-dropzone {
    display: none;
}

#cropCanvas {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
    touch-action: none;
}

#cropCanvas.cursor-move {
    cursor: move;
}

#cropCanvas.cursor-grabbing {
    cursor: grabbing;
}

#cropCanvas.cursor-nwse {
    cursor: nwse-resize;
}

#cropCanvas.cursor-nesw {
    cursor: nesw-resize;
}

#cropCanvas.cursor-ns {
    cursor: ns-resize;
}

#cropCanvas.cursor-ew {
    cursor: ew-resize;
}

.canvas-toolbar {
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}

.image-workbench.workbench-ready .canvas-toolbar {
    display: block;
}

.canvas-toolbar[hidden] {
    display: none !important;
}

.toolbar-section {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
}

.toolbar-section + .toolbar-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.toolbar-section-actions {
    justify-content: space-between;
}

.toolbar-label {
    font-size: 13px;
    color: var(--muted);
    min-width: 56px;
}

.toolbar-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.toolbar-btns button {
    height: 38px;
    padding: 0 14px;
    font-size: 13px;
}

.zoom-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.zoom-row label {
    font-size: 13px;
    color: var(--muted);
}

.zoom-row input[type="range"] {
    width: 120px;
    min-width: 80px;
}

.zoom-row #zoomValue {
    font-size: 13px;
    color: #c9d4f5;
    min-width: 38px;
}

.zoom-hint {
    font-size: 11px;
    color: var(--muted);
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
}

.zoom-fit-btn {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
}

.ratio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ratio-btn {
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
}

.ratio-btn.active {
    color: var(--text);
    border-color: rgba(91, 124, 250, 0.5);
    background: rgba(91, 124, 250, 0.12);
}

.ratio-custom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.ratio-custom-inline input {
    width: 120px;
    height: 34px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 13px;
}

.ratio-apply-btn {
    height: 34px;
    padding: 0 12px;
    font-size: 12px;
}

.workbench-sidebar {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.sidebar-card {
    padding: 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    min-width: 0;
    overflow: hidden;
}

.sidebar-card h3 {
    font-size: 15px;
    margin: 0 0 10px;
}

.sidebar-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.sidebar-card-head h3 {
    margin: 0;
}

.sidebar-link-btn {
    height: 32px;
    padding: 0 12px;
    font-size: 12px;
}

.sidebar-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    width: 100%;
}

.form-field-full {
    grid-column: 1 / -1;
}

.sidebar-form .form-field {
    min-width: 0;
}

.sidebar-form .form-field label {
    font-size: 12px;
    margin-bottom: 6px;
}

.sidebar-form .form-field input[type="number"] {
    width: 100%;
    max-width: 100%;
    height: 40px;
    flex: none;
    padding: 0 10px;
    font-size: 13px;
    box-sizing: border-box;
}

.sidebar-form .form-field input[type="range"] {
    width: 100%;
    max-width: 100%;
    height: auto;
    flex: none;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.sidebar-form .form-field .tool-select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.tool-select {
    width: 100%;
    max-width: 100%;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    padding: 0 10px;
    cursor: pointer;
    color-scheme: light;
    font-size: 13px;
    box-sizing: border-box;
}

.tool-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tool-select option {
    color: #1a2233;
    background: #eef2fb;
}

.output-preview-wrap {
    text-align: center;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
}

.preview-placeholder {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.image-workbench.workbench-ready .preview-placeholder {
    display: none;
}

#outputPreview {
    max-width: 100%;
    max-height: 180px;
    border-radius: 10px;
    display: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.file-meta {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.7;
}

.file-meta strong {
    color: #c9d4f5;
}

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.sidebar-actions button {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.status-msg.success {
    color: #7dcea0;
}

.status-msg.error {
    color: #f08a8a;
}

@media (max-width: 960px) {
    .workbench-body {
        grid-template-columns: 1fr;
    }

    .workbench-sidebar {
        position: static;
    }

    .workbench-status {
        text-align: left;
        max-width: none;
    }

    .toolbar-section-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-btns {
        justify-content: flex-end;
    }
}

@media (max-width: 560px) {
    .sidebar-form {
        grid-template-columns: 1fr;
    }

    .ratio-custom-inline input {
        flex: 1;
        width: auto;
        min-width: 0;
    }
}
