* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    color: #333;
    display: flex;
    min-height: 100vh;
}

/* Сайдбар */
.sidebar {
    width: 250px;
    background: #2c3e50;
    color: white;
    padding: 20px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.logo h2 {
    font-size: 18px;
    margin-bottom: 30px;
    color: #3498db;
}

.nav-section {
    margin-bottom: 30px;
}

.nav-item {
    display: block;
    padding: 12px 15px;
    margin: 5px 0;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    text-decoration: none;
    color: white;
    transition: all 0.3s ease;
}

.nav-item:hover,
.nav-item.active {
    background: #3498db;
    transform: translateX(5px);
}

.user-info {
    margin-top: auto;
    padding: 15px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    margin-bottom: 20px;
}

.level-badge {
    background: linear-gradient(135deg, #9b59b6, #3498db);
    padding: 8px 12px;
    border-radius: 20px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
}

.user-id {
    font-size: 12px;
    opacity: 0.8;
    text-align: center;
}

.logout-btn {
    width: 100%;
    padding: 10px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 6px;
    margin-top: 10px;
    cursor: pointer;
}

.links a {
    display: block;
    color: #95a5a6;
    text-decoration: none;
    padding: 8px 0;
    font-size: 14px;
}

.links a:hover {
    color: white;
}

/* Основной контент */
.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 30px;
}

.content-section {
    display: none;
}

.content-section.active {
    display: block;
}

/* Статистика 🔥 Фикс: 4 колонки на десктопе (2 ряда по 4) */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);  /* 🔥 4 колонки фиксировано */
    gap: 20px;
    margin: 30px 0;
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    text-align: center;
    border-left: 4px solid #3498db;
}

.stat-label {
    font-size: 14px;
    color: #7f8c8d;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: #2c3e50;
}

/* 🔥 Новый: Контролы для графика */
.chart-controls {
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin: 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

#periodSelect {
    padding: 10px 20px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.metrics-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.metrics-checkboxes label {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #2c3e50;
}

.metrics-checkboxes input {
    margin-right: 5px;
}

.chart-container {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-top: 30px;
    height: 400px;
    width: 100%;
}

/* Рефералы */
.referral-link-box {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin: 30px 0;
}

.link-container {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    flex-direction: row;
}

.referral-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #3498db;
    border-radius: 8px;
    font-family: monospace;
}

.copy-btn {
    padding: 12px 25px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.social-share {
    display: flex;
    gap: 10px;
}

.share-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.share-btn:nth-child(1) {
    background: #0088cc;
    color: white;
}

.share-btn:nth-child(2) {
    background: #25D366;
    color: white;
}

.referrals-list {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    max-height: 500px;
    overflow-y: auto;
}

.referral-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.referral-item:last-child {
    border-bottom: none;
}

.vip-badge {
    background: #9b59b6;
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

#userIdInput {
    width: 100%;
    padding: 15px;
    margin: 20px 0;
    border: 2px solid #3498db;
    border-radius: 8px;
    font-size: 16px;
}

.auth-btn {
    width: 100%;
    padding: 15px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    font-weight: bold;
}

.help-text {
    margin-top: 15px;
    font-size: 14px;
    color: #7f8c8d;
}

/* Адаптивность 🔥 Улучшено: на мобильных 2 колонки (4 ряда по 2) */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        padding: 10px;
    }
    
    .main-content {
        margin-left: 0;
        padding: 15px;
    }
    
    .stats-cards {
        grid-template-columns: repeat(2, 1fr);  /* 🔥 2 колонки на мобильных */
        gap: 15px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .chart-container {
        height: 300px;
    }
    
    .link-container {
        flex-direction: column;
    }
    
    .referrals-list, .withdrawals-history, .levels-container, .top-list {
        padding: 15px;
    }
    
    .chart-controls {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .metrics-checkboxes {
        margin-top: 10px;
    }
}

.loading {
    text-align: center;
    padding: 50px;
}

.spinner {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

/* 🔥 Стили для FAQ аккордеона */
.faq-container {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-top: 30px;
}

.faq-item {
    margin-bottom: 10px;
}

.faq-question {
    background: #f5f7fa;
    padding: 15px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    position: relative;
    transition: background 0.3s;
}

.faq-question:hover {
    background: #e0e7ff;
}

.faq-question.active {
    background: #3498db;
    color: white;
}

.faq-question:after {
    content: '+';
    position: absolute;
    right: 15px;
    font-size: 20px;
}

.faq-question.active:after {
    content: '-';
}

.faq-answer {
    display: none;
    padding: 15px;
    border: 1px solid #eee;
    border-top: none;
    border-radius: 0 0 8px 8px;
    background: #fff;
}

.faq-answer.active {
    display: block;
}

/* 🔥 Стили для уровней: flex для side-by-side */
.levels-layout {
    display: flex;
    gap: 20px;
    margin-top: 30px;
}

.levels-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.progress-circle-container {
    flex: 1;
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    height: 400px;  /* 🔥 Фикс высоты для круга */
}

/* Адаптив: на мобильных стек сверху вниз */
@media (max-width: 768px) {
    .levels-layout {
        flex-direction: column;
    }
    
    .progress-circle-container {
        height: 300px;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}