:root {
    --live-bg: #f4f7f5;
    --live-surface: rgba(255, 255, 255, 0.88);
    --live-ink: #12201e;
    --live-muted: #5f706c;
    --live-line: #d9e5e1;
    --live-brand: #0f766e;
    --live-accent: #b7791f;
    --live-radius: 14px;
}

.live-shell {
    display: grid;
    gap: 18px;
}

.live-hero {
    display: grid;
    gap: 14px;
    align-items: end;
    padding: 8px 0 0;
}

.live-hero h1 {
    margin: 0;
    font-size: clamp(28px, 6vw, 52px);
    line-height: 0.98;
}

.live-hero p {
    margin: 10px 0 0;
    max-width: 68ch;
    color: var(--live-muted);
    line-height: 1.6;
}

.live-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.live-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 46px;
    padding: 0 14px;
    border-radius: var(--live-radius);
    background: #edf8f5;
    border: 1px solid #cfe6e1;
    color: var(--live-brand);
    font-weight: 700;
}

.live-stage-card {
    display: grid;
    gap: 12px;
    border: 1px solid var(--live-line);
    border-radius: var(--live-radius);
    background: var(--live-surface);
    padding: 12px;
    backdrop-filter: blur(16px);
}

.live-stage {
    position: relative;
    overflow: hidden;
    width: 100%;
    border-radius: calc(var(--live-radius) - 4px);
    background: #0b1110;
    aspect-ratio: 4 / 3;
    min-height: 260px;
    max-height: min(62svh, 620px);
    touch-action: none;
    isolation: isolate;
}

.live-stage[data-point-edit="true"] {
    cursor: move;
}

.live-video,
.live-overlay,
.live-occlusion-layer,
.live-grid-layer,
.live-marker-layer,
.live-empty-state {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.live-video {
    display: block;
    object-fit: contain !important;
    background: #050806;
    z-index: 1;
}

.live-overlay {
    display: block;
    pointer-events: none;
    z-index: 2;
}

.live-occlusion-layer {
    display: block;
    pointer-events: none;
    z-index: 3;
}

.live-grid-layer {
    display: block;
    pointer-events: none;
    z-index: 4;
    mix-blend-mode: screen;
    opacity: 0.9;
}

.live-marker-layer {
    pointer-events: none;
    z-index: 5;
}

.point-chip {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: rgba(15, 118, 110, 0.92);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    border: 2px solid #fff;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
}

.point-chip.editable {
    width: 40px;
    height: 40px;
    cursor: move;
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14), 0 12px 24px rgba(0, 0, 0, 0.2);
}

.live-empty-state {
    display: grid;
    place-items: center;
    padding: 20px;
    text-align: center;
    color: #fff;
    font-weight: 700;
    background: linear-gradient(180deg, rgba(5, 8, 6, 0.18), rgba(5, 8, 6, 0.45));
    pointer-events: none;
    z-index: 6;
}

.live-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.live-toolbar .ghost-button[data-active="true"] {
    background: #e7f7f4;
    border-color: #8dcfc8;
    color: #0f766e;
}

.live-toolbar .ghost-button[data-on="true"] {
    background: #ecf4ff;
    border-color: #a8c9ff;
    color: #1d4ed8;
}

.live-toolbar .ghost-button[data-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.live-control {
    display: grid;
    gap: 8px;
    grid-column: 1 / -1;
}

.live-control span {
    font-size: 13px;
    font-weight: 800;
    color: var(--live-muted);
}

.live-control input {
    width: 100%;
}

.live-hint {
    color: var(--live-muted);
    font-size: 14px;
    line-height: 1.5;
}

.live-selected,
.live-catalog {
    border: 1px solid var(--live-line);
    border-radius: var(--live-radius);
    background: #fff;
    padding: 14px;
}

.selected-card {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

.selected-card img {
    width: 84px;
    height: 84px;
    border-radius: 12px;
    object-fit: cover;
    background: #eef6f4;
}

.selected-card p {
    margin: 4px 0 0;
    color: var(--live-muted);
}

.catalog-grid {
    display: grid;
    gap: 12px;
}

.rug-compact {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--live-line);
    border-radius: 12px;
    background: #fbfdfc;
}

.rug-compact img {
    width: 88px;
    height: 88px;
    border-radius: 10px;
    object-fit: cover;
}

.rug-compact h3 {
    margin: 0 0 4px;
    font-size: 17px;
}

.rug-compact p {
    margin: 0;
    color: var(--live-muted);
    font-size: 14px;
}

.rug-compact .actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.rug-compact .actions button {
    width: auto;
    min-height: 40px;
    padding: 0 12px;
}

.rug-compact.selected {
    border-color: var(--live-brand);
    box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.12), 0 0 0 3px rgba(15, 118, 110, 0.08);
    background: #f3fffd;
}

.rug-compact[data-selected="true"] h3 {
    color: var(--live-brand);
}

.rug-compact[data-selected="true"] .primary-button {
    background: var(--live-brand);
    border-color: var(--live-brand);
    color: #fff;
    cursor: default;
    pointer-events: none;
}

.catalog-loading {
    padding: 16px;
    border: 1px dashed var(--live-line);
    border-radius: 12px;
    color: var(--live-muted);
}

@media (min-width: 900px) {
    .live-hero {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .live-stage {
        aspect-ratio: 16 / 9;
    }
}

@media (max-width: 520px) {
    .live-stage {
        aspect-ratio: 3 / 4;
        min-height: 360px;
    }

    .live-toolbar {
        grid-template-columns: 1fr;
    }
}


/* v3: data-attribute fallback. HTML class аты басқа болса да камера/canvas дәл stage ішінде тұрады */
[data-live-shell] [data-stage] {
    position: relative !important;
    overflow: hidden !important;
    width: 100% !important;
    aspect-ratio: 4 / 3;
    min-height: 260px;
    max-height: min(62svh, 620px);
    border-radius: calc(var(--live-radius, 14px) - 4px);
    background: #0b1110;
    touch-action: none;
    isolation: isolate;
}

[data-live-shell] [data-video],
[data-live-shell] [data-overlay],
[data-live-shell] [data-marker-layer],
[data-live-shell] [data-empty-state] {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

[data-live-shell] [data-video] {
    display: block !important;
    object-fit: contain !important;
    background: #050806;
    z-index: 1;
}

[data-live-shell] [data-overlay] {
    pointer-events: none !important;
    z-index: 2;
}

[data-live-shell] [data-marker-layer] {
    pointer-events: none !important;
    z-index: 3;
}

[data-live-shell] [data-empty-state] {
    z-index: 4;
}

@media (min-width: 900px) {
    [data-live-shell] [data-stage] {
        aspect-ratio: 16 / 9;
    }
}

/* v4 fixes: selected rug photo must not become a giant overlay and controls must stay clickable */
[data-live-shell] {
    position: relative;
}

[data-live-shell] button,
[data-live-shell] input,
[data-live-shell] select,
[data-live-shell] a {
    position: relative;
    z-index: 20;
    pointer-events: auto !important;
}

[data-live-shell] [data-stage] {
    display: block !important;
    margin: 12px 0 !important;
    z-index: 1;
}

[data-live-shell] [data-video],
[data-live-shell] [data-overlay],
[data-live-shell] [data-marker-layer],
[data-live-shell] [data-empty-state] {
    max-width: 100% !important;
}

[data-live-shell] [data-selected-image] {
    width: 84px !important;
    height: 84px !important;
    max-width: 84px !important;
    max-height: 84px !important;
    object-fit: cover !important;
    border-radius: 12px !important;
    display: block !important;
}

[data-live-shell] [data-selected-wrap] {
    overflow: hidden !important;
}
