/* ==================== TRYON V5 - SEAMLESS STUDIO ==================== */
/* Бесшовный студийный фон из pomelli_image.png */

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

:root {
    /* Точный цвет фона из pomelli_image */
    --studio-bg: #E8E6E3;
    --studio-bg-alt: #EAE8E5;

    /* Пастельная палитра */
    --mint: #b8dcc8;
    --mint-light: #d4ebe0;
    --lavender: #d4c4e0;
    --lavender-light: #e8dff0;
    --text-dark: #2d3436;
    --text-muted: #636e72;
    --text-light: #9b9b9b;
    --white: #ffffff;
    --white-90: rgba(255, 255, 255, 0.9);
    --white-70: rgba(255, 255, 255, 0.7);
    --white-50: rgba(255, 255, 255, 0.5);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.06);
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.08);
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;

    /* Градиент кнопки */
    --btn-gradient: linear-gradient(135deg, #b7f3cb 0%, #c8b8ff 100%);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

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

/* ==================== APP CONTAINER ==================== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--studio-bg);
}

.container {
    max-width: 100%;
    padding: 0 16px;
}

/* ==================== HEADER - Минималистичный ==================== */
.header {
    background: rgba(232, 230, 227, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-dark);
    font-weight: 700;
    font-size: 1rem;
}

.logo-icon {
    font-size: 1.2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.user-name {
    font-weight: 500;
    color: var(--text-dark);
}

.user-credits {
    background: var(--btn-gradient);
    color: var(--text-dark);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.7rem;
}

.btn-header-login {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #229ED9;
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    font-weight: 500;
    font-size: 0.75rem;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-header-login:hover {
    background: #1E8BC3;
}

/* ==================== MAIN ==================== */
.main {
    flex: 1;
    padding: 12px 0 20px;
}

/* ==================== FOOTER ==================== */
.footer {
    display: none;
}

/* ==================== TRYON PAGE ==================== */
.tryon-page-v3 {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tryon-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ==================== PREVIEW AREA - Компактный ==================== */
.preview-column {
    order: 1;
}

.result-preview-area {
    position: relative;
    width: 100%;
    aspect-ratio: 1/1;
    border-radius: var(--radius);
    overflow: hidden;
    background-color: var(--studio-bg);
}

/* Состояние ДО генерации - с пунктиром и blur */
.result-preview-area.awaiting {
    border: 2px dashed rgba(0, 0, 0, 0.2);
}

.result-preview-area.awaiting .preview-bg {
    filter: blur(1px);
    opacity: 0.7;
}

/* Индикатор зоны */
.preview-zone-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 2;
}

.preview-zone-indicator span {
    display: block;
    background: rgba(255,255,255,0.8);
    padding: 6px 12px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
}

/* Фоновое изображение - сливается с фоном */
.preview-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

/* Результат */
.result-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    z-index: 5;
    animation: fadeIn 0.3s ease-out;
    background-color: var(--studio-bg);
}

/* Кнопки управления после генерации */
.result-actions-overlay {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.result-actions-overlay .btn-action {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-action.primary {
    background: var(--btn-gradient);
    color: var(--text-dark);
}

.btn-action.secondary {
    background: var(--white-90);
    color: var(--text-dark);
}

.btn-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Loading state */
.loading-state {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(232, 230, 227, 0.95);
    z-index: 10;
}

.loading-state p {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.spinner-large {
    width: 36px;
    height: 36px;
    border: 3px solid var(--lavender-light);
    border-top-color: var(--lavender);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== CONTROLS COLUMN ==================== */
.controls-column {
    order: 2;
}

.upload-form-v3 {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.upload-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ==================== UPLOAD CARDS - Glassmorphism ==================== */
.upload-card {
    background: var(--white-70);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--white-50);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    transition: all 0.2s ease;
}

.upload-card:hover {
    border-color: var(--mint);
    box-shadow: var(--shadow-soft);
}

.card-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.card-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-dark);
    margin-bottom: 2px;
}

.card-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.count-badge {
    font-weight: 400;
    color: var(--text-light);
    font-size: 0.65rem;
    margin-left: 4px;
}

/* Upload button */
.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    background: var(--white-90);
    color: var(--text-dark);
    font-weight: 500;
    font-size: 0.8rem;
    border-radius: var(--radius-xs);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    transition: all 0.2s;
    border: 1px solid var(--white-50);
    flex-shrink: 0;
}

.upload-btn:hover {
    background: var(--white);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.upload-btn:active {
    transform: scale(0.98);
}

.upload-btn svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

/* ==================== PREVIEW CARDS ==================== */
.preview-card {
    margin-top: 10px;
    position: relative;
    border-radius: var(--radius-xs);
    overflow: hidden;
    background: var(--white-50);
}

.preview-card img {
    width: 100%;
    height: auto;
    max-height: 140px;
    object-fit: cover;
    display: block;
}

.remove-btn-card {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    background: var(--white-90);
    color: #e74c3c;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.remove-btn-card:hover {
    background: #e74c3c;
    color: white;
    transform: scale(1.1);
}

/* ==================== GARMENTS PREVIEW GRID ==================== */
.garments-preview-grid {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.garments-preview-grid .garment-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-xs);
    overflow: hidden;
    background: var(--white-50);
}

.garments-preview-grid .garment-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.garments-preview-grid .remove-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    background: var(--white-90);
    color: #e74c3c;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
    transition: all 0.2s;
}

.garments-preview-grid .remove-btn:hover {
    background: #e74c3c;
    color: white;
    transform: scale(1.1);
}

/* ==================== ERROR MESSAGE ==================== */
.error-msg-v3 {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #c0392b;
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    font-size: 0.8rem;
    text-align: center;
}

/* ==================== SUBMIT BUTTON ==================== */
.btn-submit-v3 {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--btn-gradient);
    color: var(--text-dark);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 6px 20px rgba(183, 243, 203, 0.4);
    text-decoration: none;
}

.btn-submit-v3:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(183, 243, 203, 0.5);
}

.btn-submit-v3:active:not(:disabled) {
    transform: translateY(0);
}

.btn-submit-v3:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-submit-v3 svg {
    flex-shrink: 0;
}

/* Button loader */
.btn-loader {
    display: flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--white-50);
    border-top-color: var(--text-dark);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    width: 12px;
    height: 12px;
    border: 2px solid var(--lavender-light);
    border-top-color: var(--lavender);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
}

/* ==================== HELP TEXT ==================== */
.help-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
    line-height: 1.4;
}

/* ==================== AUTH WAITING ==================== */
#auth-waiting {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

/* ==================== HISTORY SECTION ==================== */
.history-v3 {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(0,0,0,0.06);
}

.history-title-v3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.history-scroll-v3 {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 8px;
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
}

.history-scroll-v3::-webkit-scrollbar {
    display: none;
}

.history-scroll-v3 .history-item {
    flex: 0 0 80px;
    aspect-ratio: 3/4;
    border-radius: var(--radius-xs);
    overflow: hidden;
    border: 2px solid rgba(0,0,0,0.06);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: var(--white);
}

.history-scroll-v3 .history-item:hover {
    transform: scale(1.03);
    border-color: var(--mint);
    box-shadow: var(--shadow-soft);
}

.history-scroll-v3 .history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-scroll-v3 .history-date {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    padding: 16px 4px 4px;
    font-size: 0.6rem;
    text-align: center;
    color: white;
    font-weight: 500;
}

.history-scroll-v3 .history-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.history-scroll-v3 .history-item:hover .history-delete {
    opacity: 1;
}

.history-scroll-v3 .history-delete:hover {
    background: rgba(220, 53, 69, 0.9);
}

/* ==================== IMAGE MODAL ==================== */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.modal-content {
    position: relative;
    max-width: 95vw;
    max-height: 90vh;
    z-index: 1001;
    animation: zoomIn 0.2s ease-out;
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-sm);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    background: var(--white-90);
    color: var(--text-dark);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #e74c3c;
    color: white;
    transform: rotate(90deg);
}

/* ==================== TABLET+ RESPONSIVE ==================== */
@media (min-width: 480px) {
    .container {
        max-width: 440px;
        margin: 0 auto;
    }

    .history-scroll-v3 .history-item {
        flex: 0 0 100px;
    }
}

/* ==================== DESKTOP RESPONSIVE ==================== */
@media (min-width: 900px) {
    .container {
        max-width: 600px;
        padding: 0 32px;
    }

    .main {
        padding: 24px 0;
    }

    /* Один столбик как на мобильных */
    .tryon-container {
        display: flex;
        flex-direction: column;
        gap: 24px;
    }

    .preview-column {
        order: 1;
    }

    .controls-column {
        order: 2;
    }

    /* Увеличенный блок результата */
    .result-preview-area {
        max-width: 600px;
        margin: 0 auto;
    }

    .upload-cards {
        gap: 14px;
    }

    .upload-card {
        padding: 16px 18px;
    }

    .btn-submit-v3 {
        padding: 16px 28px;
        font-size: 1rem;
    }

    .history-v3 {
        margin-top: 28px;
    }

    .history-scroll-v3 {
        margin: 0;
        padding-left: 0;
        padding-right: 0;
    }

    .history-scroll-v3 .history-item {
        flex: 0 0 120px;
    }

    .footer {
        display: block;
        background: rgba(232, 230, 227, 0.8);
        padding: 14px 0;
        text-align: center;
        color: var(--text-muted);
        font-size: 0.75rem;
    }
}

/* ==================== LEGACY SUPPORT ==================== */
.error-message {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #c0392b;
    padding: 10px;
    border-radius: var(--radius-xs);
    text-align: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius-xs);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--btn-gradient);
    color: var(--text-dark);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(183, 243, 203, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--white-70);
    color: var(--text-dark);
    border: 1px solid var(--white-50);
}

.btn-secondary:hover {
    background: var(--white-90);
}

.btn-telegram {
    background: #229ED9;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.btn-telegram:hover {
    background: #1E8BC3;
}

.result-page {
    text-align: center;
}

.result-container {
    background: var(--white-70);
    backdrop-filter: blur(20px);
    border-radius: var(--radius);
    padding: 20px;
}

.result-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.result-image-wrapper {
    max-width: 100%;
}

.result-image-wrapper img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
}

.result-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.auth-required {
    text-align: center;
    padding: 20px;
}

.auth-required p {
    color: var(--text-muted);
    margin-bottom: 14px;
}
