.kv-bgremover,
.kv-bgremover * { box-sizing: border-box; }

/* WordPress-темы и оптимизаторы иногда переопределяют display для элементов с hidden.
   Для состояний интерфейса плагина hidden всегда имеет приоритет. */
.kv-bgremover [hidden] {
    display: none !important;
}


.kv-bgremover {
    --kv-primary: #214cff;
    --kv-primary-soft: #edf2ff;
    --kv-text: #172033;
    --kv-muted: #6f7b91;
    --kv-border: #dce3ee;
    --kv-panel: #ffffff;
    --kv-surface: #f8fafc;
    --kv-shadow: 0 10px 30px rgba(34, 53, 86, .08);
    position: relative;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    margin-bottom: 35px;
    color: var(--kv-text);
    font-family: inherit;
}

.kv-bgremover button,
.kv-bgremover input { font: inherit; }

.kv-bgremover button { cursor: pointer; }
.kv-bgremover button:disabled { cursor: default; opacity: .45; }

.kv-bgremover__upload-view {
    display: flex;
    justify-content: center;
    width: 100%;
}

.kv-bgremover__dropzone {
    width: min(760px, 100%);
    min-height: 320px;
    padding: 34px 24px;
    border: 2px dashed #d9dee7;
    border-radius: 26px;
    background: #fff;
    box-shadow: var(--kv-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
    outline: none;
}

.kv-bgremover__dropzone:hover,
.kv-bgremover__dropzone:focus-visible,
.kv-bgremover__dropzone.is-dragover {
    border-color: var(--kv-primary);
    box-shadow: 0 12px 34px rgba(33, 76, 255, .12);
}

.kv-bgremover__upload-icon {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--kv-primary);
    background: var(--kv-primary-soft);
    margin-bottom: 16px;
}

.kv-bgremover__drop-title { font-size: 21px; font-weight: 800; }
.kv-bgremover__drop-subtitle { margin-top: 6px; font-size: 14px; color: #9aa4b3; }

.kv-bgremover__choose-btn,
.kv-bgremover__download-btn {
    border: 0;
    color: #fff;
    font-weight: 800;
    border-radius: 14px;
    background: linear-gradient(100deg, #ae91e7 0%, #81cdf5 100%);
    box-shadow: 0 6px 16px rgba(123, 159, 234, .22);
}

.kv-bgremover__choose-btn {
    min-width: 150px;
    min-height: 42px;
    padding: 9px 22px;
    margin-top: 20px;
}

.kv-bgremover__editor {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(330px, .75fr);
    gap: 16px;
    align-items: stretch;
}

.kv-bgremover__preview-card,
.kv-bgremover__controls-card {
    background: var(--kv-panel);
    border: 1px solid var(--kv-border);
    border-radius: 22px;
    box-shadow: var(--kv-shadow);
}

.kv-bgremover__preview-card {
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.kv-bgremover__preview-head {
    min-height: 54px;
    padding: 10px 14px;
    display: flex;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid #edf0f5;
}

.kv-bgremover__mini-btn,
.kv-bgremover__reset-btn,
.kv-bgremover__tab,
.kv-bgremover__mode-btn,
.kv-bgremover__icon-btn {
    border: 1px solid #d6deeb;
    background: #fff;
    color: var(--kv-text);
    border-radius: 12px;
    font-weight: 700;
}

.kv-bgremover__mini-btn { min-height: 30px; padding: 4px 10px; color: var(--kv-primary); border-color: #bfcaff; }
.kv-bgremover__filename { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--kv-muted); }

.kv-bgremover__stage-wrap {
    min-height: 520px;
    flex: 1;
    display: grid;
    place-items: center;
    overflow: auto;
    padding: 18px;
    background: #f7f8fa;
}

.kv-bgremover__stage {
    position: relative;
    display: inline-block;
    line-height: 0;
    border-radius: 16px;
    overflow: visible;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
        linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
        linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    box-shadow: 0 8px 26px rgba(28, 40, 65, .12);
}

.kv-bgremover__canvas {
    display: block;
    max-width: none;
    height: auto;
    border-radius: 16px;
    touch-action: none;
    user-select: none;
}

.kv-bgremover__brush-cursor {
    position: fixed;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,.95);
    box-shadow: 0 0 0 1px rgba(0,0,0,.75);
    pointer-events: none;
    z-index: 999999;
    transform: translate(-50%, -50%);
}

.kv-bgremover__preview-toolbar {
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #edf0f5;
}

.kv-bgremover__icon-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 20px;
}

.kv-bgremover__icon-btn:hover:not(:disabled),
.kv-bgremover__mini-btn:hover,
.kv-bgremover__reset-btn:hover,
.kv-bgremover__mode-btn:hover,
.kv-bgremover__tab:hover { border-color: var(--kv-primary); color: var(--kv-primary); }

.kv-bgremover__toolbar-sep { width: 1px; height: 28px; background: #dfe4ec; margin: 0 3px; }
.kv-bgremover__toolbar-spacer { flex: 1; }
.kv-bgremover__zoom-label { min-width: 45px; text-align: center; font-size: 12px; color: var(--kv-muted); }

.kv-bgremover__controls-card {
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.kv-bgremover__tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid #edf0f5;
}

.kv-bgremover__tab { min-height: 38px; padding: 7px 8px; font-size: 14px !important; }
.kv-bgremover__tab.is-active { border-color: var(--kv-primary); color: var(--kv-primary); background: var(--kv-primary-soft); }

.kv-bgremover__panel { display: none; padding: 16px; }
.kv-bgremover__panel.is-active { display: block; }
.kv-bgremover__section-title { font-size: 14px; font-weight: 800; margin-bottom: 13px; }

.kv-bgremover__bg-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 18px;
    font-size: 14px !important; 
}

.kv-bgremover__bg-tile {
    min-width: 0;
    border: 1px solid #d9e0eb;
    background: #fff;
    border-radius: 14px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: center;
    color: #4c5669;
    font-size: 11px;
    font-weight: 700;
}

.kv-bgremover__bg-tile.is-active { border: 2px solid var(--kv-primary); padding: 7px; color: var(--kv-primary); }
.kv-bgremover__checker,
.kv-bgremover__white-tile,
.kv-bgremover__photo-icon {
    width: 54px;
    height: 46px;
    border-radius: 10px;
    border: 1px solid #dfe4ec;
}

.kv-bgremover__checker {
    background-color: #fff;
    background-image: linear-gradient(45deg,#e7e7e7 25%,transparent 25%),linear-gradient(-45deg,#e7e7e7 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#e7e7e7 75%),linear-gradient(-45deg,transparent 75%,#e7e7e7 75%);
    background-size: 14px 14px;
    background-position: 0 0,0 7px,7px -7px,-7px 0;
}
.kv-bgremover__white-tile { background: #fff; }
.kv-bgremover__photo-icon { display: grid; place-items: center; font-size: 25px; background: #f8fafc; color: var(--kv-primary); }

.kv-bgremover__field-label,
.kv-bgremover__range-label { display: block; font-size: 13px; font-weight: 700; }
.kv-bgremover__field-label { margin-bottom: 8px; }
.kv-bgremover__colors { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.kv-bgremover__swatch,
.kv-bgremover__color-input {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid #d5dce7;
    padding: 0;
}
.kv-bgremover__swatch { background: var(--swatch); }
.kv-bgremover__color-input { overflow: hidden; background: none; }
.kv-bgremover__color-input::-webkit-color-swatch-wrapper { padding: 0; }
.kv-bgremover__color-input::-webkit-color-swatch { border: 0; }

.kv-bgremover__segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.kv-bgremover__mode-btn { min-height: 38px; padding: 7px 10px; }
.kv-bgremover__mode-btn.is-active { border-color: var(--kv-primary); color: var(--kv-primary); background: var(--kv-primary-soft); }

.kv-bgremover__range-label { margin-top: 16px; }
.kv-bgremover__range-label > span { float: left; }
.kv-bgremover__range-label > output { float: right; color: var(--kv-primary); font-weight: 800; }
.kv-bgremover__range-label input[type="range"] { width: 100%; margin-top: 10px; accent-color: var(--kv-primary); }
.kv-bgremover__hint { margin: 18px 0 0; color: var(--kv-muted); font-size: 12px; line-height: 1.55; }

.kv-bgremover__quality-box {
    padding: 13px;
    border: 1px solid #dce3ee;
    border-radius: 14px;
    background: #f8fafc;
    margin-bottom: 18px;
}
.kv-bgremover__quality-title { font-size: 13px; font-weight: 800; margin-bottom: 5px; }
.kv-bgremover__quality-status { font-size: 12px; line-height: 1.45; color: var(--kv-muted); }
.kv-bgremover__quality-btn {
    width: 100%;
    min-height: 38px;
    margin-top: 10px;
    padding: 7px 10px;
    border: 1px solid #bfcaff;
    border-radius: 12px;
    background: #fff;
    color: var(--kv-primary);
    font-weight: 800;
}
.kv-bgremover__quality-btn:hover:not(:disabled) { border-color: var(--kv-primary); background: var(--kv-primary-soft); }
.kv-bgremover__quality-btn:disabled { color: #5f6b7f; background: #f2f4f7; border-color: #d9e0eb; }
.kv-bgremover__quality-note { margin-top: 8px; font-size: 11px; line-height: 1.45; color: #8a95a6; }

.kv-bgremover__controls-footer {
    margin-top: auto;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid #edf0f5;
}
.kv-bgremover__reset-btn { min-height: 44px; padding: 8px 14px; }
.kv-bgremover__download-btn { min-height: 44px; padding: 9px 18px; }
.kv-bgremover__download-btn:hover,
.kv-bgremover__choose-btn:hover { filter: brightness(.98); transform: translateY(-1px); }

.kv-bgremover__loading {
    position: absolute;
    inset: 0;
    z-index: 20;
    border-radius: 22px;
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    justify-content: center;
    min-height: 220px;
}
.kv-bgremover__spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #e2e8f3;
    border-top-color: var(--kv-primary);
    border-radius: 50%;
    animation: kv-bg-spin .85s linear infinite;
}
.kv-bgremover__loading-text { font-size: 14px; font-weight: 700; }

.kv-bgremover__progress {
    width: min(300px, calc(100vw - 48px));
    display: grid;
    grid-template-columns: 1fr 48px;
    align-items: center;
    gap: 10px;
}
.kv-bgremover__progress-track {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e7ebf3;
}
.kv-bgremover__progress-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--kv-primary);
    transition: width .28s ease;
}
.kv-bgremover__progress-value {
    font-size: 13px;
    font-weight: 800;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
@keyframes kv-bg-spin { to { transform: rotate(360deg); } }

.kv-bgremover__error {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fff1f1;
    border: 1px solid #ffd0d0;
    color: #a32121;
    font-size: 13px;
}

@media (max-width: 900px) {
    .kv-bgremover__editor { grid-template-columns: 1fr; }
    .kv-bgremover__controls-card { min-height: 420px; }
    .kv-bgremover__stage-wrap { min-height: 430px; }
}

@media (max-width: 560px) {
    .kv-bgremover {
        width: calc(100% - 24px);
        margin-left: auto;
        margin-right: auto;
    }
    .kv-bgremover__dropzone { min-height: 270px; border-radius: 20px; padding: 26px 16px; }
    .kv-bgremover__drop-title { font-size: 18px; }
    .kv-bgremover__preview-card,
    .kv-bgremover__controls-card { border-radius: 18px; }
    .kv-bgremover__stage-wrap { min-height: 360px; padding: 10px; }
    .kv-bgremover__preview-head {
        align-items: center;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .kv-bgremover__new-image { flex: 0 0 auto; }
    .kv-bgremover__filename {
        flex: 1 1 140px;
        min-width: 0;
        white-space: normal;
        overflow-wrap: anywhere;
        line-height: 1.25;
    }
    .kv-bgremover__tabs { gap: 5px; padding: 10px; }
    .kv-bgremover__tab { font-size: 11px; padding: 6px 4px; }
    .kv-bgremover__controls-footer { grid-template-columns: 1fr; }
    .kv-bgremover__reset-btn,
    .kv-bgremover__download-btn { width: 100%; }
}


/* Mobile processing UX:
   - keep the loader compact even if the previous photo was very tall;
   - animate the progress bar independently of JS/main-thread timers.
   The bar slowly advances to 96% and waits there until processing actually completes. */
@media (max-width: 560px) {
    .kv-bgremover.is-mobile-processing {
        min-height: 300px;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__upload-view,
    .kv-bgremover.is-mobile-processing .kv-bgremover__editor {
        display: none !important;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__loading {
        position: relative;
        inset: auto;
        width: 100%;
        min-height: 300px;
        max-height: 360px;
        border: 1px solid var(--kv-border);
        box-shadow: var(--kv-shadow);
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__progress {
        grid-template-columns: 1fr;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__progress-value {
        display: none;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__progress-fill {
        width: 100% !important;
        transform-origin: left center;
        transform: scaleX(.03);
        transition: none;
        will-change: transform;
        animation: kv-bg-mobile-fake-progress 48s cubic-bezier(.16,.78,.22,1) forwards;
    }
}

@keyframes kv-bg-mobile-fake-progress {
    0%   { transform: scaleX(.03); }
    12%  { transform: scaleX(.18); }
    28%  { transform: scaleX(.38); }
    48%  { transform: scaleX(.61); }
    68%  { transform: scaleX(.78); }
    84%  { transform: scaleX(.89); }
    100% { transform: scaleX(.96); }
}



/* v0.8.16: keep a visible numeric percentage on mobile too.
   Because heavy mobile inference can block JS updates, we animate a fake percentage reel
   with three rotating preset sequences (e.g. 3, 15, 22, ...) while the real processing runs.
   The bar still waits for actual completion before disappearing. */
@media (max-width: 560px) {
    .kv-bgremover.is-mobile-processing .kv-bgremover__progress {
        grid-template-columns: 1fr 56px !important;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__progress-value {
        display: block !important;
        position: relative;
        height: 1.25em;
        overflow: hidden;
        text-align: right;
        font-size: 13px;
        font-weight: 800;
        font-variant-numeric: tabular-nums;
        line-height: 1.25;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__progress-value-reel {
        position: absolute;
        inset: 0;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        animation-duration: 48s;
        animation-timing-function: steps(12, end);
        animation-fill-mode: forwards;
        will-change: transform;
    }

    .kv-bgremover.is-mobile-processing .kv-bgremover__progress-value-reel > span {
        display: block;
        height: 1.25em;
        line-height: 1.25;
    }

    .kv-bgremover.is-mobile-processing.progress-seq-1 .kv-bgremover__progress-value-reel {
        animation-name: kv-bg-mobile-value-reel-1;
    }

    .kv-bgremover.is-mobile-processing.progress-seq-2 .kv-bgremover__progress-value-reel {
        animation-name: kv-bg-mobile-value-reel-2;
    }

    .kv-bgremover.is-mobile-processing.progress-seq-3 .kv-bgremover__progress-value-reel {
        animation-name: kv-bg-mobile-value-reel-3;
    }
}

@keyframes kv-bg-mobile-value-reel-1 {
    from { transform: translateY(0); }
    to   { transform: translateY(-15em); }
}
@keyframes kv-bg-mobile-value-reel-2 {
    from { transform: translateY(0); }
    to   { transform: translateY(-15em); }
}
@keyframes kv-bg-mobile-value-reel-3 {
    from { transform: translateY(0); }
    to   { transform: translateY(-15em); }
}
