/* ============================================================
   Virtual Tailor Studio — Style System
   Premium dark theme · Mobile-first · Glassmorphism
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ── Tokens ─────────────────────────────────────────────── */
:root {
    --bg: #0b0d17;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-glass: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-hl: rgba(168, 130, 255, 0.45);
    --text: #e8e6f0;
    --text-dim: #8b87a0;
    --accent: #a882ff;
    --accent2: #ff6ec7;
    --gradient: linear-gradient(135deg, #a882ff 0%, #ff6ec7 100%);
    --gradient-share: linear-gradient(135deg, #ff6ec7 0%, #a882ff 100%);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, .45);
    --transition: .25s cubic-bezier(.4, 0, .2, 1);
}

/* ── Reset ──────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.5;
    overflow-x: hidden;
}

/* animated gradient orbs background */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: .18;
    pointer-events: none;
    z-index: 0;
}

body::before {
    width: 600px;
    height: 600px;
    background: var(--accent);
    top: -200px;
    left: -100px;
    animation: floatOrb 18s ease-in-out infinite alternate;
}

body::after {
    width: 500px;
    height: 500px;
    background: var(--accent2);
    bottom: -150px;
    right: -80px;
    animation: floatOrb 22s ease-in-out infinite alternate-reverse;
}

@keyframes floatOrb {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(80px, 60px) scale(1.15);
    }
}

/* ── Layout ─────────────────────────────────────────────── */
.app {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 120px;
}

/* ── Header ─────────────────────────────────────────────── */
.header {
    text-align: center;
    padding: 16px 0 20px;
    position: relative;
}

.header__top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding-left: 48px;
    /* Room for back button */
}

.header__close {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    z-index: 10;
}

.header__close svg {
    width: 20px;
    height: 20px;
}

.header__close:hover {
    background: var(--bg-glass);
    border-color: var(--accent);
    color: var(--accent);
}

.header__content {
    flex: 1;
}

.header__logo {
    font-size: 1.45rem;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.header__tagline {
    color: var(--text-dim);
    font-size: .8rem;
    margin-top: 2px;
}

/* ── Gallery ─────────────────────────────────────────── */
.gallery-section {
    margin-bottom: 24px;
}

.gallery-track {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 2px 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.gallery-track::-webkit-scrollbar {
    display: none;
}

.gallery-empty {
    width: 100%;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding: 20px;
    text-align: center;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
}

.gallery-item {
    flex: 0 0 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
}

/* ── Gallery clear button ──────────────────────────────── */
.gallery-clear-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    padding: 0;
    opacity: 0.6;
}

.gallery-clear-btn:hover {
    opacity: 1;
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.12);
}

.gallery-empty {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 8px;
    white-space: nowrap;
}


.gallery-item:hover,
.gallery-item.active {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(168, 130, 255, 0.2);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ── Section titles ─────────────────────────────────────── */
.section-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-start;
}

.section-title .gallery-clear-btn {
    margin-left: auto;
}

.section-title .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gradient);
    display: inline-block;
}

/* timer badge */
.timer-badge {
    margin-left: auto;
    font-family: 'Inter', monospace;
    font-size: 0.8rem;
    color: var(--accent);
    background: rgba(168, 130, 255, 0.12);
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid rgba(168, 130, 255, 0.3);
    font-weight: 600;
    min-width: 50px;
    text-align: center;
}

/* ── Cards / Glass ──────────────────────────────────────── */
.card {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    padding: 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
    border-color: var(--border-hl);
    box-shadow: 0 0 0 1px var(--border-hl), var(--shadow);
}

/* ── Upload zone ────────────────────────────────────────── */
.uploads {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 24px;
}

label.upload-card {
    display: block;
    cursor: pointer;
}
.upload-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 20px;
    min-height: 180px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    text-align: center;
}

.upload-card input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-card__icon {
    margin-top: 0;
    font-size: 2.4rem;
    margin-bottom: 8px;
    transition: transform var(--transition);
}

.upload-card:hover .upload-card__icon {
    margin-top: 0;
    transform: scale(1.15);
}

.upload-card__label {
    font-size: .85rem;
    font-weight: 500;
}

.upload-card__hint {
    font-size: .72rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* preview thumbnails inside upload cards */
.upload-card__preview {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.upload-card__preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius);
}

.upload-card__preview::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(11, 13, 23, .55);
    border-radius: var(--radius);
}

.upload-card.has-image .upload-card__icon,
.upload-card.has-image .upload-card__label,
.upload-card.has-image .upload-card__hint {
    display: none;
}

.upload-card.has-image .upload-card__label {
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, .6);
}

/* drag active */
.upload-card.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent), inset 0 0 30px rgba(168, 130, 255, .08);
}

/* ── Template gallery ───────────────────────────────────── */
.templates {
    margin-bottom: 24px;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.template-btn {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 6px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text);
}

.template-btn svg {
    width: 38px;
    height: 38px;
    transition: transform var(--transition);
}

.template-btn span {
    font-size: .7rem;
    font-weight: 500;
    white-space: normal;
    text-align: center;
    line-height: 1.3;
    word-break: break-word;
}

.template-btn:hover,
.template-btn:focus-visible {
    border-color: var(--accent);
    background: rgba(168, 130, 255, .08);
}

.template-btn:hover svg {
    transform: scale(1.12);
}

.template-btn.active {
    border-color: var(--accent);
    background: rgba(168, 130, 255, .14);
    box-shadow: 0 0 0 1px var(--accent), 0 4px 20px rgba(168, 130, 255, .15);
}

.template-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    overflow: hidden;
    transition: all var(--transition);
}

.template-btn.active .template-icon {
    border-color: var(--accent);
    background: rgba(168, 130, 255, 0.15);
}

.template-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ── Position / Scale / Style controls ────────────────── */
.controls {
    margin-bottom: 24px;
}

.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.control-grid--single {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0 0 20px 0;
}

.slider-group,
.select-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.slider-group label,
.select-group label {
    font-size: .8rem;
    color: var(--text-dim);
    font-weight: 500;
    text-align: center;
}

.select-group {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin: 0 auto;
}

.slider-group input[type="range"] {
    accent-color: var(--accent);
    height: 6px;
}

.select-group select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .85rem;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
}

.select-group select:focus {
    border-color: var(--accent);
}

.accessories-group {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.accessories-group label {
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 12px;
    display: block;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.checkbox-grid label {
    font-size: .8rem;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    transition: all var(--transition);
}

.checkbox-grid label:hover {
    background: rgba(168, 130, 255, 0.05);
}

.checkbox-grid input[type="checkbox"] {
    accent-color: var(--accent);
}

.checkbox-grid label:has(input:checked) {
    border-color: var(--accent);
    background: rgba(168, 130, 255, 0.1);
    color: #fff;
}

/* ── Canvas preview ─────────────────────────────────────── */
.preview {
    margin-bottom: 24px;
}

.canvas-wrap {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 340px;
}

.canvas-wrap canvas {
    max-width: 100%;
    height: auto;
    display: block;
}

.canvas-placeholder {
    color: var(--text-dim);
    font-size: .85rem;
    text-align: center;
    padding: 40px 20px;
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ── Sticky action bar ──────────────────────────────────── */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 14px 16px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 12px;
    background: rgba(11, 13, 23, .96);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid var(--border);
}

.action-bar button,
.action-bar .action-bar__row {
    width: 100%;
    display: flex;
    justify-content: center;
}

.btn {
    flex: 1;
    padding: 14px 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition);
}

.btn--primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 4px 20px rgba(168, 130, 255, .35);
}

.btn--primary:hover {
    box-shadow: 0 6px 28px rgba(168, 130, 255, .5);
    transform: translateY(-1px);
}

.btn--primary:active {
    transform: translateY(0);
}

.btn--secondary {
    background: var(--gradient-share);
    color: #fff;
    box-shadow: 0 4px 20px rgba(255, 110, 199, .35);
}

.btn--secondary:hover {
    box-shadow: 0 6px 28px rgba(255, 110, 199, .5);
    transform: translateY(-1px);
}

.btn--reset {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-dim);
    border: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: 4px;
    width: 100%;
    min-height: 42px;
    font-size: 0.85rem;
    font-weight: 400;
}

.btn--reset:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.15);
}

.action-bar__row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.action-bar__row .btn {
    flex: 1;
}

.btn:disabled {
    opacity: .35;
    pointer-events: none;
}

.btn__icon {
    font-size: 1.15em;
}

/* ── Toast ──────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(168, 130, 255, .92);
    color: #fff;
    padding: 10px 22px;
    border-radius: 30px;
    font-size: .82rem;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: all .35s ease;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(168, 130, 255, .4);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 480px) {
    .header__logo {
        font-size: 1.55rem;
    }

    .template-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .template-btn {
        padding: 10px 4px 8px;
    }

    .template-btn svg {
        width: 30px;
        height: 30px;
    }

    .template-btn span {
        font-size: .62rem;
    }

    .uploads {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .upload-card {
        min-height: 150px;
    }
}

@media (min-width: 768px) {
    .app {
        padding: 30px 24px 120px;
    }

    .header__logo {
        font-size: 2.5rem;
    }

    .template-grid {
        grid-template-columns: repeat(8, 1fr);
    }

    .uploads {
        grid-template-columns: 1fr 1fr;
        gap: 18px;
    }

    .upload-card {
        min-height: 220px;
    }

    .action-bar {
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: var(--radius) var(--radius) 0 0;
        border: 1px solid var(--border);
        border-bottom: none;
    }
}

@media (min-width: 1024px) {
    .canvas-wrap {
        min-height: 500px;
    }
}

/* ── Scale slider extra ─────────────────────────────────── */
.slider-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.slider-row .slider-group {
    flex: 1;
    min-width: 200px;
}

/* ── Generate button ────────────────────────────────────── */
.generate-section {
    margin-bottom: 20px;
    text-align: center;
}

.btn--generate {
    padding: 10px 32px;
    font-size: 0.95rem;
    border-radius: 16px;
    background: var(--gradient);
    color: #fff;
    border: 1.5px solid rgba(168, 130, 255, 0.5);
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 24px rgba(168, 130, 255, .4);
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn--generate:hover {
    box-shadow: 0 6px 32px rgba(168, 130, 255, .55);
    transform: translateY(-2px);
}

.btn--generate:active {
    transform: translateY(0);
}

.btn--generate:disabled {
    opacity: .35;
    pointer-events: none;
}

/* spinner */
.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

.spinner.active {
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
/* ── Upload buttons (camera / gallery) ─────────────────── */
.upload-card__buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    width: 100%;
}

.upload-btn {
    flex: 1;
    padding: 8px 4px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.upload-btn:hover,
.upload-btn:active {
    border-color: var(--accent);
    background: rgba(168, 130, 255, 0.12);
    color: var(--accent);
}

.upload-card__hint { display: none; }

/* ── Bottom Sheet ───────────────────────────────────────── */
.bottom-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    backdrop-filter: blur(4px);
}

.bottom-sheet-overlay.active {
    display: block;
}

.bottom-sheet {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: #1e2235;
    border-radius: 20px 20px 0 0;
    padding: 12px 16px 32px;
    z-index: 101;
    transition: bottom 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bottom-sheet.active {
    bottom: 0;
}

.bottom-sheet__handle {
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 0 auto 12px;
}

.bottom-sheet__title {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 4px;
    font-weight: 500;
}

.bottom-sheet__btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1.5px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    width: 100%;
}

.bottom-sheet__btn:hover,
.bottom-sheet__btn:active {
    border-color: var(--accent);
    background: rgba(168, 130, 255, 0.1);
}

.bottom-sheet__btn-icon {
    font-size: 1.4rem;
    width: 32px;
    text-align: center;
}

.bottom-sheet__btn--cancel {
    justify-content: center;
    border-color: transparent;
    background: transparent;
    color: var(--text-muted);
    margin-top: 4px;
}

.bottom-sheet__btn--cancel:hover {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.08);
    border-color: transparent;
}

/* Скрыть hint т.к. теперь bottom sheet */
.upload-card__hint { display: none; }
.upload-btn { display: none; }
.upload-card__buttons { display: none; }

/* ── Bottom Sheet ── */
.bs-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,0.5);z-index:100;backdrop-filter:blur(4px)}
.bs-overlay.active{display:block}
.bs{position:fixed;bottom:-100%;left:0;right:0;background:#1e2235;border-radius:20px 20px 0 0;padding:12px 16px 32px;z-index:101;transition:bottom 0.3s ease;display:flex;flex-direction:column;gap:8px}
.bs.active{bottom:0}
.bs__handle{width:40px;height:4px;background:rgba(255,255,255,0.2);border-radius:2px;margin:0 auto 12px}
.bs__title{font-size:0.85rem;color:var(--text-muted);text-align:center;margin-bottom:4px}
.bs__btn{display:flex;align-items:center;gap:14px;padding:16px 18px;border-radius:14px;border:1.5px solid var(--border);background:rgba(255,255,255,0.04);color:var(--text);font-size:1rem;font-weight:500;cursor:pointer;transition:all 0.2s;width:100%}
.bs__btn:active{border-color:var(--accent);background:rgba(168,130,255,0.1)}
.bs__btn--cancel{justify-content:center;border-color:transparent;background:transparent;color:var(--text-muted)}
