/* Public AR product viewer shell */
:root {
    --ar-brand: #059669;
    --ar-brand-dark: #047857;
    --ar-brand-glow: rgba(5, 150, 105, 0.35);
    --ar-sheet-bg: rgba(255, 255, 255, 0.96);
    --ar-sheet-border: rgba(148, 163, 184, 0.35);
    --ar-text: #0f172a;
    --ar-text-muted: #64748b;
    --ar-top-h: calc(56px + env(safe-area-inset-top, 0px));
    --ar-sheet-collapsed: calc(148px + env(safe-area-inset-bottom, 0px));
    --ar-sheet-expanded: calc(220px + env(safe-area-inset-bottom, 0px));
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'IRANYekanX', Tahoma, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

#ar-app {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--ar-scene-bg, #f1f5f9);
}

#ar-scene-backdrop {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 80% 50% at 50% 85%, var(--ar-scene-floor, rgba(15, 23, 42, 0.06)) 0%, transparent 70%),
        linear-gradient(180deg, var(--ar-scene-top, #f8fafc) 0%, var(--ar-scene-bg, #eef2f7) 55%, var(--ar-scene-bottom, #e2e8f0) 100%);
}

model-viewer {
    width: 100%;
    height: 100%;
    background: transparent;
    --progress-bar-color: var(--ar-brand);
}

/* ── Top bar ── */
.ar-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.72) 80%, transparent 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.ar-top-bar__info {
    flex: 1;
    min-width: 0;
}

.ar-top-bar__title {
    font-size: 14px;
    font-weight: 800;
    color: var(--ar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.ar-top-bar__subtitle {
    font-size: 11px;
    color: var(--ar-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.ar-icon-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 1px solid var(--ar-sheet-border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--ar-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.ar-icon-btn:active { transform: scale(0.94); }
.ar-icon-btn svg { width: 18px; height: 18px; }

/* ── Gesture hint ── */
.ar-gesture-hint {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 80;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.78);
    color: #f8fafc;
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.5s ease;
    text-align: center;
    max-width: 240px;
}

.ar-gesture-hint.is-hidden {
    opacity: 0;
    visibility: hidden;
}

.ar-gesture-hint__icon {
    width: 48px;
    height: 48px;
    animation: ar-hint-pulse 2s ease-in-out infinite;
}

@keyframes ar-hint-pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.06); opacity: 1; }
}

/* ── Floating controls ── */
.ar-float-controls {
    position: fixed;
    left: 14px;
    bottom: calc(var(--ar-sheet-collapsed) + 72px);
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: bottom 0.3s ease;
}

body.ar-sheet-expanded .ar-float-controls {
    bottom: calc(var(--ar-sheet-expanded) + 72px);
}

.ar-float-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--ar-sheet-border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ar-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
    transition: transform 0.15s, background 0.15s;
}

.ar-float-btn:active { transform: scale(0.94); }
.ar-float-btn.is-on { background: var(--ar-brand); color: #fff; border-color: var(--ar-brand); }
.ar-float-btn svg { width: 18px; height: 18px; }

/* ── Bottom sheet ── */
.ar-bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    background: var(--ar-sheet-bg);
    border-top: 1px solid var(--ar-sheet-border);
    border-radius: 20px 20px 0 0;
    padding: 0 16px calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.1);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: transform 0.3s ease;
}

.ar-sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 99px;
    background: #cbd5e1;
    margin: 8px auto 12px;
    cursor: pointer;
}

.ar-sheet-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.ar-sheet-variant {
    font-size: 13px;
    font-weight: 700;
    color: var(--ar-text);
}

.ar-sheet-variant-label {
    font-size: 11px;
    color: var(--ar-text-muted);
    font-weight: 600;
}

.ar-sheet-colors-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--ar-text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.ar-color-options {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.ar-color-options::-webkit-scrollbar { display: none; }

.ar-color-chip {
    flex: 0 0 auto;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    min-width: 56px;
}

.ar-color-swatch-wrap {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 3px;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.ar-color-chip.is-active .ar-color-swatch-wrap {
    border-color: var(--ar-brand);
    box-shadow: 0 0 0 3px var(--ar-brand-glow);
}

.ar-color-chip:active .ar-color-swatch-wrap { transform: scale(0.94); }

.ar-color-swatch {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.4);
}

.ar-color-chip-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--ar-text-muted);
    max-width: 64px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    transition: color 0.2s;
}

.ar-color-chip.is-active .ar-color-chip-label {
    color: var(--ar-brand-dark);
    font-weight: 800;
}

.ar-sheet-no-colors {
    font-size: 12px;
    color: var(--ar-text-muted);
    padding: 4px 0 8px;
}

/* ── AR CTA (model-viewer slot) ── */
.ar-button {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(var(--ar-sheet-collapsed) + 8px);
    z-index: 160;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 20px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--ar-brand) 0%, var(--ar-brand-dark) 100%);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 28px var(--ar-brand-glow);
    transition: transform 0.15s, bottom 0.3s ease, opacity 0.25s;
}

.ar-button:active { transform: scale(0.98); }

.ar-button.is-pulse {
    animation: ar-cta-pulse 2.4s ease-in-out 2;
}

@keyframes ar-cta-pulse {
    0%, 100% { box-shadow: 0 8px 28px var(--ar-brand-glow); }
    50% { box-shadow: 0 8px 36px rgba(5, 150, 105, 0.55); }
}

.ar-button__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

body.ar-sheet-expanded .ar-button {
    bottom: calc(var(--ar-sheet-expanded) + 8px);
}

body.ar-no-colors {
    --ar-sheet-collapsed: calc(72px + env(safe-area-inset-bottom, 0px));
    --ar-sheet-expanded: calc(72px + env(safe-area-inset-bottom, 0px));
}

body.ar-no-colors .ar-sheet-colors,
body.ar-no-colors .ar-sheet-handle { display: none; }

body.ar-no-colors .ar-sheet-meta { margin-bottom: 0; }

/* ── Color transition on model ── */
model-viewer.ar-color-transition {
    transition: opacity 0.18s ease;
    opacity: 0.72;
}

/* ── Overlays ── */
.ar-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.92);
    color: #e2e8f0;
    text-align: center;
    padding: 1.5rem;
}

.ar-overlay.hidden { display: none; }

.ar-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #334155;
    border-top-color: var(--ar-brand);
    border-radius: 50%;
    animation: ar-spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes ar-spin { to { transform: rotate(360deg); } }

.ar-error {
    color: #fca5a5;
    max-width: 320px;
    line-height: 1.6;
    font-size: 14px;
}

#progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: rgba(148, 163, 184, 0.3);
}

#progress-bar > div {
    height: 100%;
    background: var(--ar-brand);
    width: 0%;
    transition: width 0.2s;
}

/* ── AR session ── */
body.ar-session-active .ar-button { opacity: 0; pointer-events: none; }
body.ar-session-active .ar-bottom-sheet { z-index: 100000; }
body.ar-session-active #loading-overlay,
body.ar-session-active #error-overlay { display: none !important; }
body.ar-session-active .ar-gesture-hint { display: none; }
body.ar-session-active .ar-float-controls { opacity: 0; pointer-events: none; }

.ar-placement-hint {
    position: fixed;
    left: 16px;
    right: 16px;
    top: calc(var(--ar-top-h) + 8px);
    z-index: 100001;
    background: rgba(15, 23, 42, 0.88);
    color: #f8fafc;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 13px;
    text-align: center;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.ar-placement-hint.hidden { display: none; }

/* Legacy bar only used in admin preview — public viewer uses bottom sheet */
body:not(.ar-preview-mode) .ar-color-bar { display: none !important; }
