/* ============================================
   PROFILE MODAL — User Profile Popup
   ============================================
   
   Модальное окно профиля пользователя в стиле SmartMap.
   Показывает информацию о пользователе, подписки, промокоды.
   
   ============================================ */

/* ==========================================
   OVERLAY (reuses auth-modal pattern)
   ========================================== */

.profile-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-scrim);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--z-max);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-normal) var(--ease-out),
                visibility var(--duration-normal) var(--ease-out);
}

.profile-modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* ==========================================
   MODAL CONTAINER
   ========================================== */

.profile-modal {
    background: var(--surface-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    transition: transform var(--duration-slow) var(--ease-bounce),
                opacity var(--duration-normal) var(--ease-out);
}

.profile-modal-overlay.open .profile-modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Custom scrollbar */
.profile-modal::-webkit-scrollbar {
    width: 6px;
}

.profile-modal::-webkit-scrollbar-track {
    background: transparent;
}

.profile-modal::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: var(--radius-pill);
}

/* ==========================================
   MODAL HEADER
   ========================================== */

.profile-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
}

.profile-modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0;
}

.profile-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--surface-3);
    color: var(--text-secondary);
    font-size: 18px;
    transition: background var(--transition-fast),
                color var(--transition-fast);
    cursor: pointer;
}

.profile-modal-close:hover {
    background: var(--surface-elevated);
    color: var(--text-primary);
}

/* ==========================================
   MODAL CONTENT
   ========================================== */

.profile-modal-content {
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

/* ==========================================
   LOADING STATE
   ========================================== */

.profile-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    gap: var(--space-4);
    color: var(--text-muted);
}

.profile-modal-loading .spinner {
    width: 32px;
    height: 32px;
}

/* ==========================================
   USER INFO SECTION
   ========================================== */

.profile-modal-section {
    padding: var(--space-4);
    background: var(--surface-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
}

.profile-modal-section-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--space-3) 0;
}

/* User section specific styles */
.profile-modal-section:not(.profile-favorites-section) .profile-modal-section-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.profile-modal-section:not(.profile-favorites-section) .profile-modal-section-title::before {
    content: '👤';
    font-size: 14px;
}

.profile-user-email {
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    word-break: break-all;
    padding-left: 22px; /* Align with title after icon */
}

/* ==========================================
   SUBSCRIPTION SECTION
   ========================================== */

.profile-subscription-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.profile-subscription-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-pill);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: fit-content;
}

.profile-subscription-badge.active {
    background: var(--color-success-muted);
    color: var(--color-success);
}

.profile-subscription-badge.inactive {
    background: var(--surface-elevated);
    color: var(--text-muted);
}

.profile-subscription-name {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0;
}

.profile-subscription-details {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}

/* Progress bar for request-based subscriptions */
.profile-progress {
    margin-top: var(--space-2);
}

.profile-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--surface-1);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin-bottom: var(--space-2);
}

.profile-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-success) 0%, #34d399 100%);
    border-radius: var(--radius-pill);
    transition: width 0.4s ease;
}

.profile-progress-text {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: var(--font-medium);
}

/* No subscription CTA */
.profile-subscription-cta {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--space-2);
}

.profile-subscription-cta a {
    padding: var(--space-2) var(--space-4);
    background: var(--accent);
    border-radius: var(--radius-md);
    color: var(--accent-contrast);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    text-decoration: none;
    transition: background var(--transition-fast);
}

.profile-subscription-cta a:hover {
    background: var(--accent-hover);
}

/* ==========================================
   PROMO CODE SECTION
   ========================================== */

.profile-promo-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.profile-promo-input-group {
    display: flex;
    gap: var(--space-2);
}

.profile-promo-input {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    transition: border-color var(--transition-fast),
                background var(--transition-fast);
}

.profile-promo-input:focus {
    background: var(--surface-elevated);
    border-color: var(--accent);
    outline: none;
}

.profile-promo-input::placeholder {
    text-transform: none;
    letter-spacing: normal;
    font-family: var(--font-family);
    color: var(--text-muted);
}

.profile-promo-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.profile-promo-submit {
    padding: var(--space-3) var(--space-4);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--accent-contrast);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast);
}

.profile-promo-submit:hover:not(:disabled) {
    background: var(--accent-hover);
}

.profile-promo-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Promo message */
.profile-promo-message {
    padding: var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    display: none;
}

.profile-promo-message.visible {
    display: block;
}

.profile-promo-message.success {
    background: var(--color-success-muted);
    color: var(--color-success);
}

.profile-promo-message.error {
    background: var(--color-danger-muted);
    color: var(--color-danger);
}

/* ==========================================
   SUBSCRIPTION HISTORY
   ========================================== */

.profile-history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 200px;
    overflow-y: auto;
}

.profile-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3);
    background: var(--surface-1);
    border-radius: var(--radius-md);
    gap: var(--space-3);
}

.profile-history-info {
    flex: 1;
    min-width: 0;
}

.profile-history-name {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.profile-history-date {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.profile-history-badge {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.profile-history-badge.active {
    background: var(--color-success-muted);
    color: var(--color-success);
}

.profile-history-badge.expired {
    background: var(--surface-elevated);
    color: var(--text-muted);
}

.profile-history-badge.cancelled {
    background: var(--color-danger-muted);
    color: var(--color-danger);
}

.profile-history-empty {
    text-align: center;
    padding: var(--space-4);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* ==========================================
   FOOTER ACTIONS
   ========================================== */

.profile-modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.profile-logout-btn {
    padding: var(--space-2) var(--space-4);
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast),
                color var(--transition-fast),
                border-color var(--transition-fast);
}

.profile-logout-btn:hover {
    background: var(--color-danger-muted);
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.profile-close-btn {
    padding: var(--space-2) var(--space-4);
    background: var(--surface-3);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.profile-close-btn:hover {
    background: var(--surface-elevated);
}

/* ==========================================
   FAVORITES SECTION
   ========================================== */

.profile-favorites-section {
    padding: 0;
    background: transparent;
    border: none;
}

/* Main section title "Избранное" */
.profile-favorites-section > .profile-modal-section-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    text-transform: none;
    letter-spacing: 0;
    padding: var(--space-4) var(--space-5) var(--space-3);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Heart icon before title */
.profile-favorites-section > .profile-modal-section-title::before {
    content: '❤️';
    font-size: 16px;
}

.profile-favorites-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-8);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.profile-favorites-loading .spinner.small {
    width: 20px;
    height: 20px;
}

.profile-favorites-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-8);
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-align: center;
    background: var(--surface-3);
    border-radius: var(--radius-lg);
    margin: 0 var(--space-5) var(--space-4);
}

.profile-favorites-empty-icon {
    font-size: 32px;
    opacity: 0.6;
}

/* Category groups container */
.profile-favorites-categories {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Individual category within favorites */
.profile-favorites-category {
    padding: var(--space-3) 0 var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

.profile-favorites-category:first-child {
    border-top: none;
    padding-top: 0;
}

/* Category subtitle "Вторичка", "Аренда" etc */
.profile-favorites-category-title {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0.02em;
    padding: 0 var(--space-5);
    margin-bottom: var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Category count badge */
.profile-favorites-category-count {
    font-size: 10px;
    font-weight: var(--font-semibold);
    color: var(--text-muted);
    background: var(--surface-3);
    padding: 2px 6px;
    border-radius: var(--radius-pill);
}

/* Horizontal scroll container */
.profile-favorites-scroll {
    display: flex;
    gap: var(--space-3);
    overflow-x: auto;
    padding: var(--space-1) var(--space-5);
    padding-bottom: var(--space-2);
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.profile-favorites-scroll::-webkit-scrollbar {
    display: none;
}

/* Favorite card — compact listing card style */
.profile-favorite-card {
    flex: 0 0 160px;
    scroll-snap-align: start;
    cursor: pointer;
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform var(--transition-fast), 
                border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

.profile-favorite-card:hover {
    transform: translateY(-3px);
    border-color: var(--border-default);
    box-shadow: var(--shadow-md);
}

.profile-favorite-card:active {
    transform: translateY(-1px) scale(0.99);
}

/* Card image — taller for better visuals */
.profile-favorite-image {
    position: relative;
    width: 100%;
    height: 110px;
    background-size: cover;
    background-position: center;
    background-color: var(--surface-3);
    overflow: hidden;
}

/* Gradient overlay for price readability */
.profile-favorite-image::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.6) 0%,
        rgba(0, 0, 0, 0.2) 40%,
        transparent 70%
    );
    pointer-events: none;
}

/* Heart icon on image */
.profile-favorite-heart {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    width: 18px;
    height: 18px;
    color: var(--color-danger);
    z-index: 1;
}

.profile-favorite-heart svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

/* Price badge on image */
.profile-favorite-price-badge {
    position: absolute;
    bottom: var(--space-2);
    left: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    color: #fff;
    z-index: 1;
    white-space: nowrap;
}

/* Card info — clean typography */
.profile-favorite-info {
    padding: var(--space-2) var(--space-3);
    min-height: 52px;
}

.profile-favorite-title {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.profile-favorite-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
    line-height: 1.3;
}

/* Metro indicator */
.profile-favorite-metro {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.profile-favorite-metro-icon {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-danger);
    flex-shrink: 0;
}

.profile-favorite-metro-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* No image placeholder */
.profile-favorite-image.no-image {
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-favorite-image.no-image::before {
    content: '🏠';
    font-size: 28px;
    opacity: 0.4;
    z-index: 1;
}

/* ==========================================
   MOBILE RESPONSIVE
   ========================================== */

@media (max-width: 767px) {
    .profile-modal-overlay {
        padding: var(--space-3);
        align-items: flex-end;
    }
    
    .profile-modal {
        max-width: 100%;
        max-height: 90vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        transform: translateY(100%);
    }
    
    .profile-modal-overlay.open .profile-modal {
        transform: translateY(0);
    }
    
    .profile-modal-header {
        padding: var(--space-3) var(--space-4);
    }
    
    .profile-modal-content {
        padding: var(--space-4);
        gap: var(--space-4);
    }
    
    .profile-modal-footer {
        padding: var(--space-3) var(--space-4);
    }
    
    .profile-promo-input-group {
        flex-direction: column;
    }
}

/* Very small screens */
@media (max-width: 320px) {
    .profile-modal-content {
        padding: var(--space-3);
    }
    
    .profile-modal-section {
        padding: var(--space-3);
    }
}
