/* Friends Management System - Modern iPhone-First Design */
:root {
    --friends-primary: #00d4ff;
    --friends-secondary: #ff6b35;
    --friends-success: #4ecdc4;
    --friends-danger: #ff4757;
    --friends-bg-dark: #0a0511;
    --friends-bg-card: rgba(0, 20, 40, 0.6);
    --friends-text-primary: #ffffff;
    --friends-text-secondary: #a8b2d1;
}

.friends-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.friends-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.friends-container {
    width: 90%;
    max-width: 600px;
    height: 85vh;
    background: #0a0511;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
    position: relative;
}

/* Space theme background effect */
.friends-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(0, 212, 255, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 107, 53, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(155, 89, 182, 0.04) 0%, transparent 70%);
    pointer-events: none;
}

/* Header with gradient accent */
.friends-header {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.08) 0%, rgba(255, 107, 53, 0.05) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 10;
}

.friends-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--friends-primary);
    margin: 0;
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
    letter-spacing: -0.5px;
}

.friends-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--friends-text-secondary);
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.friends-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--friends-text-primary);
    transform: scale(1.1);
}

/* Tab System */
.friends-tabs {
    display: flex;
    padding: 0.5rem;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.friends-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex-shrink: 0;
    min-width: 100px;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--friends-text-secondary);
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
}

.tab-btn.active {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.2) 0%, rgba(255, 107, 53, 0.15) 100%);
    color: var(--friends-primary);
    border-color: rgba(0, 212, 255, 0.3);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.2);
}

/* Badge for request count */
.badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--friends-danger);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    display: none;
}

.badge.has-count {
    display: block;
}

/* Content area with scrolling */
.friends-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
}

.view-content {
    display: none;
}

.view-content.active {
    display: block;
}

/* Friend Cards Grid */
.friends-grid, .requests-grid {
    display: grid;
    gap: 1rem;
    animation: fadeIn 0.3s ease;
}

.friend-card {
    background: var(--friends-bg-card);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.friend-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(0, 212, 255, 0.2) 50%, 
        transparent 100%);
    transition: left 0.5s ease;
}

.friend-card:hover::before {
    left: 100%;
}

.friend-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border-color: rgba(0, 212, 255, 0.2);
    background: rgba(0, 20, 40, 0.8);
}

/* Avatar styling */
.friend-avatar {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.2) 0%, rgba(255, 107, 53, 0.1) 100%);
    padding: 2px;
    flex-shrink: 0;
}

.friend-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 14px;
    object-fit: cover;
}

/* Friend info */
.friend-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.friend-info:hover {
    transform: translateX(2px);
}

.friend-name {
    font-weight: 700;
    color: var(--friends-text-primary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.friend-base {
    font-size: 0.875rem;
    color: var(--friends-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.friend-level {
    font-size: 0.75rem;
    color: var(--friends-primary);
    margin-top: 0.25rem;
}

/* Online status indicator */
.online-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 0.5rem;
}

.online-indicator.online {
    background: var(--friends-success);
    box-shadow: 0 0 6px var(--friends-success);
}

.online-indicator.recently {
    background: #ffd93d;
    box-shadow: 0 0 6px #ffd93d;
}

.online-indicator.offline {
    background: #6c757d;
}

/* Action buttons */
.friend-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.delete-btn {
    background: rgba(255, 71, 87, 0.2);
    color: var(--friends-danger);
}

.delete-btn:hover {
    background: var(--friends-danger);
    color: white;
    transform: scale(1.1);
}

.accept-btn {
    background: rgba(78, 205, 196, 0.2);
    color: var(--friends-success);
}

.accept-btn:hover {
    background: var(--friends-success);
    color: white;
    transform: scale(1.1);
}

.decline-btn {
    background: rgba(255, 71, 87, 0.2);
    color: var(--friends-danger);
}

.decline-btn:hover {
    background: var(--friends-danger);
    color: white;
    transform: scale(1.1);
}

/* Invite View Styling */
.invite-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    max-width: 400px;
    margin: 0 auto;
}

.my-code-section, .add-friend-section {
    background: var(--friends-bg-card);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.my-code-section h3, .add-friend-section h3 {
    color: var(--friends-text-primary);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 1rem 0;
    padding: 1rem;
    background: rgba(0, 212, 255, 0.1);
    border-radius: 12px;
    border: 2px dashed var(--friends-primary);
}

.code-text {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.2rem;
    color: var(--friends-primary);
    font-family: 'Courier New', monospace;
}

.copy-btn {
    background: rgba(0, 212, 255, 0.2);
    color: var(--friends-primary);
    border: 1px solid rgba(0, 212, 255, 0.3);
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

.copy-btn:hover {
    transform: scale(1.1);
    background: rgba(0, 212, 255, 0.3);
    box-shadow: 0 4px 16px rgba(0, 212, 255, 0.3);
}

.copy-btn.copied {
    background: var(--friends-success);
}

.code-hint {
    font-size: 0.875rem;
    color: var(--friends-text-secondary);
    margin-top: 0.5rem;
}

#friendCodeInput {
    width: 100%;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    text-align: center;
    letter-spacing: 0.1rem;
    margin: 1rem 0;
    font-family: 'Courier New', monospace;
}

#friendCodeInput:focus {
    outline: none;
    border-color: var(--friends-primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.2);
}

.send-request-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.2) 0%, rgba(255, 107, 53, 0.15) 100%);
    color: var(--friends-primary);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.send-request-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.3) 0%, rgba(255, 107, 53, 0.2) 100%);
    box-shadow: 0 6px 30px rgba(0, 212, 255, 0.3);
    border-color: var(--friends-primary);
}

.send-request-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Custom Confirm Dialog */
.confirm-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--friends-bg-dark);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10002;
    animation: confirmSlideIn 0.3s ease;
    min-width: 300px;
}

.confirm-message {
    margin-bottom: 1rem;
    color: var(--friends-text-primary);
    text-align: center;
}

.confirm-buttons {
    display: flex;
    gap: 0.5rem;
}

.confirm-btn, .cancel-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.confirm-btn {
    background: var(--friends-danger);
    color: white;
}

.cancel-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--friends-text-secondary);
}

.confirm-btn:hover {
    background: #ff3838;
    transform: translateY(-1px);
}

.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Loading States */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--friends-primary);
    animation: spin 0.8s linear infinite;
}

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--friends-text-secondary);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--friends-text-secondary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-message {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--friends-text-primary);
}

.empty-hint {
    font-size: 0.9rem;
    opacity: 0.7;
}

/* Responsive Design */
/* Portrait Mode */
@media (orientation: portrait) and (max-width: 768px) {
    .friends-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
        max-width: none;
    }
    
    .friends-tabs {
        justify-content: flex-start;
    }
    
    .tab-btn {
        flex: 0 0 auto;
    }
    
    .friends-header {
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    
    .friends-content {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    .friends-grid, .requests-grid {
        grid-template-columns: 1fr;
    }
    
    .friend-card {
        padding: 0.75rem;
    }
    
    .friend-avatar {
        width: 50px;
        height: 50px;
    }
    
    .friends-tabs {
        padding: 0.5rem;
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    .friends-container {
        max-height: 95vh;
        height: 95vh;
    }
    
    .friends-header {
        padding: 0.75rem 1rem;
    }
    
    .friends-title {
        font-size: 1.2rem;
    }
    
    .friends-tabs {
        padding: 0.25rem;
    }
    
    .tab-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    .friends-grid, .requests-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .friend-card {
        padding: 0.5rem;
    }
    
    .friend-avatar {
        width: 40px;
        height: 40px;
    }
    
    .friend-name {
        font-size: 0.9rem;
    }
    
    .friend-base {
        font-size: 0.8rem;
    }
    
    .action-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

/* Large screens */
@media (min-width: 768px) {
    .friends-grid, .requests-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Animations */
@keyframes modalSlideIn {
    from {
        transform: scale(0.9) translateY(20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes confirmSlideIn {
    from {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Toast notifications */
.friends-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 36, 81, 0.95);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10003;
    animation: toastSlideIn 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.friends-toast.success {
    border-color: var(--friends-success);
    background: rgba(78, 205, 196, 0.2);
}

.friends-toast.error {
    border-color: var(--friends-danger);
    background: rgba(255, 71, 87, 0.2);
}

@keyframes toastSlideIn {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Feed View Styling */
.feed-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.feed-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--friends-bg-card);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    animation: cardSlideIn 0.5s ease backwards;
    cursor: default;
}

.feed-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.3);
}

.feed-avatar {
    flex-shrink: 0;
}

.feed-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 255, 0.3);
}

.feed-content {
    flex: 1;
    min-width: 0;
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.feed-username {
    font-weight: 600;
    color: var(--friends-primary);
    cursor: pointer;
    transition: color 0.2s ease;
}

.feed-username:hover {
    color: var(--friends-primary-hover);
    text-decoration: underline;
}

.feed-time {
    font-size: 0.85rem;
    color: var(--friends-text-secondary);
}

.feed-achievement {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(0, 212, 255, 0.1);
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

.achievement-icon {
    font-size: 2rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.achievement-details {
    flex: 1;
    min-width: 0;
}

.achievement-name {
    font-weight: 600;
    color: var(--friends-text-primary);
    margin-bottom: 0.25rem;
}

.achievement-description {
    font-size: 0.9rem;
    color: var(--friends-text-secondary);
    line-height: 1.4;
}

/* Achievement tier colors */
.feed-achievement.bronze {
    background: rgba(205, 127, 50, 0.1);
    border-color: rgba(205, 127, 50, 0.3);
}

.feed-achievement.silver {
    background: rgba(192, 192, 192, 0.1);
    border-color: rgba(192, 192, 192, 0.3);
}

.feed-achievement.gold {
    background: rgba(255, 215, 0, 0.1);
    border-color: rgba(255, 215, 0, 0.3);
}

.feed-achievement.platinum {
    background: rgba(229, 228, 226, 0.1);
    border-color: rgba(229, 228, 226, 0.3);
}

.feed-achievement.master {
    background: rgba(138, 43, 226, 0.1);
    border-color: rgba(138, 43, 226, 0.3);
}

/* Load More Button */
.load-more-container {
    display: flex;
    justify-content: center;
    padding: 1rem;
    margin-top: 1rem;
}

.load-more-btn {
    background: linear-gradient(135deg, var(--friends-primary) 0%, var(--friends-secondary) 100%);
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.load-more-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.4);
}

.load-more-btn:active {
    transform: translateY(0);
}

.loading-more {
    display: flex;
    justify-content: center;
    padding: 1rem;
}

.loading-more .loading-spinner {
    width: 30px;
    height: 30px;
    border-width: 3px;
}