/* ============================================================
   BACKGROUND REMOVER
   ============================================================ */

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

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

/* ── Upload zone ─────────────────────────────────────────── */
.br-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;
}

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

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

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

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

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

/* ── Editor layout ───────────────────────────────────────── */
.br-editor {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    max-width: 1060px;
    margin: 0 auto;
}

.br-sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.br-sidebar-disabled .br-panel {
    opacity: 0.55;
    pointer-events: none;
}

.br-panel {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    transition: opacity 0.2s ease;
}

.br-panel-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Background swatches ─────────────────────────────────── */
.br-bg-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.br-bg-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: var(--transition);
    position: relative;
}

.br-bg-btn:hover {
    border-color: var(--primary);
}

.br-bg-btn.br-bg-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.35);
}

.br-bg-transparent {
    background: repeating-conic-gradient(rgba(var(--text-muted-rgb), 0.25) 0% 25%, transparent 0% 50%) 0 0 / 12px 12px;
}

.br-bg-white { background: #ffffff; }
.br-bg-black { background: #000000; }

.br-bg-custom {
    overflow: hidden;
    background: conic-gradient(#f43f5e, #f59e0b, #22c55e, #3b82f6, #a855f7, #f43f5e);
}

.br-bg-custom input[type="color"] {
    position: absolute;
    inset: -25%;
    width: 150%;
    height: 150%;
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}

/* ── Format buttons ──────────────────────────────────────── */
.br-fmt-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.br-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;
}

.br-fmt-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.br-quality-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

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

.br-jpg-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

/* ── Viewer ──────────────────────────────────────────────── */
.br-viewer-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.br-zoom-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
}

.br-zoom-btn {
    min-width: 34px;
    min-height: 34px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
    padding: 0 0.5rem;
}

.br-zoom-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.br-zoom-val {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 3rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.br-viewport {
    overflow: auto;
    max-height: 620px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    box-shadow: 0 4px 24px rgba(var(--shadow-color-rgb), 0.18);
}

.br-stage {
    position: relative;
    width: 100%;
    min-width: 220px;
    margin: 0 auto;
    background: repeating-conic-gradient(rgba(var(--text-muted-rgb), 0.16) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px;
    user-select: none;
}

/* Once a result exists, the whole image scrubs the compare divider */
.br-stage.br-has-result {
    cursor: ew-resize;
    touch-action: pan-y pinch-zoom;
}

/* Touch-up (brush) mode */
.br-stage.br-touchup {
    cursor: none;
    touch-action: none;
}

/* Restore needs a faint ghost of the original to show what can be brought
   back. Erase hides it entirely so the transparent areas show the exact same
   checkerboard as Compare and leftovers stay easy to spot. */
.br-stage.br-touchup .br-original-wrap {
    background: transparent;
    clip-path: none !important;
}

.br-stage.br-touchup-restore .br-original-wrap { opacity: 0.35; }
.br-stage.br-touchup-erase   .br-original-wrap { opacity: 0; }

.br-brush-cursor {
    position: absolute;
    left: 0;
    top: 0;
    /* Moved via transform only: keeps the cursor on the compositor thread, so
       it never lags behind the pointer while the canvas repaints */
    transform: translate(-50%, -50%);
    will-change: transform;
    border: 1.5px solid #ffffff;
    outline: 1px solid rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    pointer-events: none;
    z-index: 6;
}

#brResultCanvas {
    display: block;
    width: 100%;
    height: auto;
}

.br-original-wrap {
    position: absolute;
    inset: 0;
    background: var(--bg);
}

.br-original-wrap img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
}

/* ── Compare divider ─────────────────────────────────────── */
.br-divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 0;
    pointer-events: none;   /* dragging is handled by the stage */
    z-index: 5;
}

.br-divider::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -1.5px;
    width: 3px;
    background: var(--primary);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.45);
}

.br-divider-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.br-divider-handle svg {
    width: 20px;
    height: 20px;
}

.br-compare-labels span {
    position: absolute;
    top: 0.6rem;
    z-index: 4;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    pointer-events: none;
}

.br-label-original { left: 0.6rem; }
.br-label-result   { right: 0.6rem; }

/* ── Progress ────────────────────────────────────────────── */
.br-progress {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
}

.br-progress-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: rgba(var(--text-muted-rgb), 0.18);
    overflow: hidden;
}

.br-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    transition: width 0.35s ease;
}

.br-progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.br-progress-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.br-cancel-btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
    min-height: 34px;
    flex-shrink: 0;
}

/* ── Actions ─────────────────────────────────────────────── */
.br-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.br-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);
    width: 100%;
}

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

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

.br-btn-secondary {
    width: 100%;
    text-align: center;
    padding: 0.7rem 1.25rem;
    font-size: 0.9rem;
    min-height: 44px;
}

.br-result-meta {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    text-align: center;
    min-height: 1.2rem;
    margin: 0;
}

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

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

/* ── Desktop layout ──────────────────────────────────────── */
@media (min-width: 768px) {
    .br-editor {
        display: grid;
        grid-template-columns: 250px 1fr;
        grid-template-areas: "sidebar viewer";
        column-gap: 1.25rem;
        align-items: start;
    }

    .br-sidebar     { grid-area: sidebar; }
    .br-viewer-area { grid-area: viewer; }
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 767px) {
    .br-upload-zone {
        padding: 2rem 1rem;
    }

    /* Viewer first, controls below */
    .br-editor      { flex-direction: column; }
    .br-viewer-area { order: 1; }
    .br-sidebar     { order: 2; }

    .br-viewport {
        max-height: 60vh;
    }

    .br-zoom-bar {
        justify-content: center;
    }
}
