/**
 * 👤 PROFILE PAGE STYLES
 * 
 * Styles for the full-page user profile view
 * Uses existing CSS variables from variables.css
 * Maintains consistent design with the rest of the app
 */

/* ============================================================================
   📄 PROFILE PAGE CONTAINER
   ============================================================================ */

.profile-page {
    min-height: 100vh;
    background: var(--bg-primary);
    padding-bottom: var(--spacing-2xl);
}

.profile-page.loading,
.profile-page.error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

/* ============================================================================
   📋 PAGE HEADER
   ============================================================================ */

.profile-page .page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.profile-header-sticky {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding-top: calc(var(--spacing-md) + env(safe-area-inset-top, 0px));
}

/* Spacer to prevent content from being hidden under sticky header */
.profile-header-spacer {
    height: calc(56px + env(safe-area-inset-top, 0px));
    /* 56px = typical header height with padding */
}

.profile-page .back-button {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    border-radius: var(--radius-round);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-out);
}

.profile-page .back-button:hover {
    background: var(--bg-secondary);
}

.profile-page .back-button svg {
    width: 24px;
    height: 24px;
}

.profile-page .page-title {
    flex: 1;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
    text-align: center;
}

.profile-page .edit-profile-button {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    border-radius: var(--radius-round);
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-out);
}

.profile-page .edit-profile-button:hover {
    background: var(--bg-overlay);
}

.profile-page .edit-profile-button svg {
    width: 20px;
    height: 20px;
}

/* ============================================================================
   👤 PROFILE CARD
   ============================================================================ */

.profile-card {
    background: var(--bg-card);
    padding: var(--spacing-2xl) var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: var(--spacing-lg);
    align-items: flex-start;
}

/* Two-column layout: avatar+info left, action buttons right */
.profile-card.two-col {
    display: flex;
    justif-content: space-between;
    align-items: flex-start;
    gap: var(--spacing-md);
}

/* Grid layout for profile header - NEW */
.profile-header.grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px; /* Reduced gap to bring name/username closer to avatar */
    align-items: start;
}

/* User heading row: name + username in one line */
.user-heading-row {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap; /* allow wrap for line break */
}

/* Scope explicit left alignment where centering might occur */
.profile-header .user-heading-row {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
}

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

.user-heading-row .user-username {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: 0;
    flex-basis: 100%;
    display: block;
    margin-top: 2px;
}

/* Force username to occupy full next line (both class variants and both contexts covered) */
.profile-header .user-heading-row .user-username,
.profile-header .user-heading-row .profile-username,
.profile-modal-content .user-heading-row .user-username,
.profile-modal-content .user-heading-row .profile-username {
    flex-basis: 100%;
    display: block;
    margin-top: 2px; /* subtle spacing below name */
}

.profile-left {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    align-items: flex-start;
}

/* Remove badges placeholder from markup per requirements */

.profile-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Status card within profile */
.user-status-card {
    background: var(--surface, #FFFFFF);
    border: 1px solid var(--border, #E6E0D6);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 8px;
}

.user-status-card-text {
    font-size: var(--font-size-sm, 14px);
    line-height: 1.4;
    color: var(--text-primary, #2D2D2D);
    font-style: italic;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.profile-actions-top {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

/* Left column: avatar, name, username, status */
.profile-card-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Right column: action buttons in row */
.profile-card-right.profile-actions-right {
    flex: 0 0 auto;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 6px; /* Reduced from default for compact layout */
    padding-top: var(--spacing-md);
}

.profile-badges-placeholder {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-align: center;
    padding: var(--spacing-md);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-avatar-container {
    width: 120px;
    height: 120px;
    margin: 0 auto var(--spacing-lg);
    position: relative;
    border-radius: var(--radius-round);
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(210, 69, 44, 0.2);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

.profile-avatar-fallback {
    font-size: 48px;
    font-weight: var(--font-weight-bold);
    color: var(--text-inverse);
    text-transform: uppercase;
    z-index: 1;
}

.profile-avatar-container.fallback .profile-avatar-img {
    display: none;
}

.profile-name {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin: 0 0 var(--spacing-2xs);
}

.profile-username {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin: 0 0 var(--spacing-sm);
}

.profile-status {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: 0 0 var(--spacing-md);
    line-height: var(--line-height-normal);
}

/* User status - smaller than username, secondary color, multi-line wrapping */
.user-status {
    font-size: calc(var(--font-size-sm) - 1px);
    color: var(--text-secondary);
    margin: 0 0 var(--spacing-md);
    line-height: 1.25;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-style: italic;
}

.profile-bio {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    line-height: var(--line-height-normal);
    margin: 0 0 var(--spacing-lg);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.follow-btn-large {
    width: 100%;
    max-width: 300px;
    height: var(--button-height);
    background: var(--primary-color);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: var(--spacing-md);
}

.follow-btn-large:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-primary);
}

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

.follow-btn-large.following {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.follow-btn-large.following:hover {
    background: var(--bg-primary);
    border-color: var(--primary-color);
}

.follow-btn-large:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================================================================
   📊 STATISTICS SECTION
   ============================================================================ */

.profile-statistics {
    display: flex;
    justify-content: space-around;
    padding: var(--spacing-lg);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.stat-item {
    text-align: center;
    flex: 1;
    cursor: pointer;
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    transition: all var(--duration-fast) var(--ease-out);
    position: relative;
}

.stat-item:hover {
    background: var(--bg-overlay);
}

.stat-item.active {
    background: var(--bg-overlay);
}

.stat-item.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--primary-color);
    margin-bottom: var(--spacing-xs);
}

.stat-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================================
   📚 RECENT QUOTES SECTION
   ============================================================================ */

.recent-quotes-section {
    padding: var(--spacing-lg);
}

.recent-quotes-section .section-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--spacing-lg);
}

/* ============================================================================
   📑 TAB CONTENT SECTION
   ============================================================================ */

/* ============================================================================
   📑 TAB CONTENT
   ============================================================================ */

.profile-tab-content {
    padding: var(--spacing-lg);
    min-height: 300px;
    position: relative;
}

/* Loading overlay for tab content - ANTI-FLICKER DESIGN
   Uses overlay spinner instead of rebuilding DOM to prevent visual blinks
   pointer-events: none allows interaction to be disabled during loading */
.profile-tab-content.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* Allow clicks to pass through to prevent stray interactions */
}

.profile-tab-content.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: var(--radius-round);
    animation: spin 1s linear infinite;
    z-index: 11;
    pointer-events: none; /* Prevent interaction with spinner */
}

.quotes-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.quotes-list .quote-card {
    background: var(--bg-card);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--duration-normal) var(--ease-out);
}

.quotes-list .quote-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* ============================================================================
   👥 USERS LIST (Followers/Following)
   ============================================================================ */

/* ANTI-FLICKER: No transitions on container to prevent blinks during innerHTML updates */
.users-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    /* Explicitly disable transitions to prevent flicker during targeted updates */
    transition: none !important;
}

.user-card {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    background: var(--bg-card);
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
}

.user-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    background: var(--bg-overlay);
}

.user-avatar-container {
    width: 48px;
    height: 48px;
    position: relative;
    border-radius: var(--radius-round);
    overflow: hidden;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

.user-avatar-fallback {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-inverse);
    text-transform: uppercase;
    z-index: 1;
}

.user-avatar-container.fallback .user-avatar-img {
    display: none;
}

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

.user-name {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin-bottom: var(--spacing-2xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-username {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-2xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-bio {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quote-text {
    font-family: var(--font-family-secondary);
    font-size: var(--font-size-lg);
    font-style: italic;
    color: var(--text-primary);
    line-height: var(--line-height-loose);
    margin: 0 0 var(--spacing-md);
}

.quote-author {
    display: block;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.quote-source {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* ============================================================================
   🌟 EMPTY STATE
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: var(--spacing-2xl);
    color: var(--text-muted);
}

.empty-state p {
    font-size: var(--font-size-base);
    margin: 0;
}

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

.loading-spinner-container {
    text-align: center;
    padding: var(--spacing-2xl);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: var(--radius-round);
    animation: spin 1s linear infinite;
    margin: 0 auto var(--spacing-md);
}

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

.loading-spinner-container p {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin: 0;
}

/* ============================================================================
   ♾️ INFINITE SCROLL
   ============================================================================ */

/* Infinite scroll loader - centered spinner with terracotta animation */
.infinite-loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin: var(--spacing-lg) auto;
}

/* Sentinel element - invisible trigger for IntersectionObserver */
.infinite-sentinel {
    height: 1px;
    width: 100%;
    visibility: hidden;
    pointer-events: none;
}

/* ============================================================================
   ❌ ERROR STATE
   ============================================================================ */

.error-container {
    text-align: center;
    padding: var(--spacing-2xl);
    max-width: 400px;
}

.error-container h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--error-color);
    margin: 0 0 var(--spacing-md);
}

.error-container p {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin: 0 0 var(--spacing-lg);
    line-height: var(--line-height-normal);
}

.error-container .btn-primary {
    width: 100%;
    height: var(--button-height);
    background: var(--primary-color);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
}

.error-container .btn-primary:hover {
    background: var(--primary-dark);
}

/* ============================================================================
   🔘 PROFILE ACTION BUTTONS
   ============================================================================ */

/* Profile: action buttons container on the right */
.profile-actions-right {
    display: inline-flex;
    gap: 6px; /* Reduced from 8px for more compact layout */
}

/* Action buttons - square, compact: 32×32, gap 6px, radius 6px, font-size 16px */
.profile-action-btn {
    width: 32px;   /* Reduced from 36px */
    height: 32px;  /* Reduced from 36px */
    border-radius: 6px; /* Reduced from 8px */
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px; /* For emoji icons to fit properly in 32px buttons */
    transition: all var(--duration-fast) var(--ease-out);
}

.profile-action-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--bg-overlay);
}

.profile-action-btn:active {
    transform: scale(0.95);
}

/* Stat buttons with counters - adapted for horizontal row */
.profile-action-btn.stat-btn {
    width: auto;
    min-width: 60px;
    height: auto;
    padding: 6px 8px;
    flex-direction: column;
    gap: 2px;
}

.stat-btn-value {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--primary-color);
    line-height: 1;
}

.stat-btn-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1;
    white-space: nowrap;
}

.profile-action-btn.stat-btn.active {
    background: var(--bg-overlay);
    border-color: var(--primary-color);
}

.profile-action-btn.stat-btn.active .stat-btn-value {
    color: var(--primary-color);
}

.profile-action-btn.stat-btn:hover .stat-btn-value {
    color: var(--primary-color);
}

/* Profile modal: apply same compact styling to action buttons */
.profile-modal-actions {
    display: inline-flex;
    gap: 6px; /* Reduced from 8px for more compact layout */
}

.profile-modal-actions .profile-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 16px;
}

/* ============================================================================
   🎭 PROFILE MODAL STYLES (IDENTICAL TO PROFILE PAGE)
   ============================================================================ */

.profile-modal-header.grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px; /* Match profile page gap for consistency */
    align-items: start;
    padding: var(--spacing-lg);
}

.profile-modal-left {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    align-items: flex-start;
}

.profile-modal-avatar-container {
    width: 72px; /* Reduced from 120px */
    height: 72px; /* Reduced from 120px */
    position: relative;
    border-radius: var(--radius-round);
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(210, 69, 44, 0.2);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-modal-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

.profile-modal-avatar-fallback {
    font-size: 28px; /* Reduced from 48px to match smaller avatar */
    font-weight: var(--font-weight-bold);
    color: var(--text-inverse);
    text-transform: uppercase;
    z-index: 1;
}

/* Profile modal heading row: name + username in one line */
.profile-modal-heading-row {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap; /* allow wrap for line break */
}

/* Scope explicit left alignment where centering might occur */
.profile-modal-content .profile-modal-heading-row {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
}

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

.profile-modal-heading-row .profile-modal-username {
    color: var(--text-secondary);
    margin: 0;
    font-size: var(--font-size-sm);
    flex-basis: 100%;
    display: block;
    margin-top: 2px; /* subtle spacing below name */
}

/* Force username to occupy full next line (both class variants and both contexts covered) */
.profile-header .profile-modal-heading-row .user-username,
.profile-header .profile-modal-heading-row .profile-username,
.profile-modal-content .profile-modal-heading-row .user-username,
.profile-modal-content .profile-modal-heading-row .profile-username,
.profile-modal-content .profile-modal-heading-row .profile-modal-username {
    flex-basis: 100%;
    display: block;
    margin-top: 2px; /* subtle spacing below name */
}

.profile-modal-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Status card within modal */
.profile-modal-status-card {
    background: var(--surface, #FFFFFF);
    border: 1px solid var(--border, #E6E0D6);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 8px;
}

.profile-modal-status-card-text {
    font-size: var(--font-size-sm, 14px);
    line-height: 1.4;
    color: var(--text-primary, #2D2D2D);
    font-style: italic;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.profile-modal-actions-top {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

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

@media (max-width: 480px) {
    .profile-card {
        padding: var(--spacing-xl) var(--spacing-md);
    }
    
    .profile-avatar-container {
        width: 100px;
        height: 100px;
    }
    
    .profile-avatar-fallback {
        font-size: 40px;
    }
    
    .profile-name {
        font-size: var(--font-size-xl);
    }
    
    .profile-statistics {
        padding: var(--spacing-md);
    }
    
    .stat-item {
        padding: var(--spacing-xs);
    }
    
    .stat-value {
        font-size: var(--font-size-xl);
    }
    
    .profile-tab-content {
        padding: var(--spacing-md);
    }
    
    .recent-quotes-section {
        padding: var(--spacing-md);
    }
    
    .quote-text {
        font-size: var(--font-size-base);
    }
    
    .user-avatar-container {
        width: 40px;
        height: 40px;
    }
    
    .user-avatar-fallback {
        font-size: var(--font-size-base);
    }
}
