:root {
    --bg-color: #f5f5f7;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --card-bg: rgba(255, 255, 255, 0.75);
    --card-border: rgba(255, 255, 255, 0.6);
    --primary-color: #0071e3;
    --primary-hover: #0077ed;
    --success-color: #34c759;
    --success-bg: #e5f9e7;
    --warning-color: #ff9f0a;
    --warning-bg: #fff5e5;
    --danger-color: #ff3b30;
    --border-radius: 20px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --shadow-sm: 0 4px 15px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 40px rgba(0, 0, 0, 0.08);
}

/* ==========================================
   ФУНДАМЕНТАЛЬНЫЙ СБРОС (БРОНЕБОЙНОСТЬ)
   ========================================== */
html {
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 10% 20%, #e6f0fa 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, #f0fdf4 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, #fdf4f6 0%, transparent 60%);
    background-attachment: fixed;
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    
    min-height: 100vh; 
    min-height: 100dvh; 
    
    padding: 20px 0;
    -webkit-font-smoothing: antialiased;
}

/* Общие стили контейнеров */
.screen { display: none; width: 100%; max-width: 1400px; padding: 0 20px; box-sizing: border-box; opacity: 0; transition: opacity 0.4s ease-in-out; }
.screen.active { display: block; opacity: 1; }

.glass, .card {
    background: var(--card-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--shadow-md);
    
    /* Защита от разрыва сетки (Grid Blowout) */
    min-width: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.card { margin-bottom: 20px; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.text-primary { color: var(--primary-color); }
.text-success { color: var(--success-color); }

/* Резиновая типографика (Fluid Typography) */
h1 { font-size: clamp(24px, 3vw, 32px); font-weight: 700; margin: 0 0 8px; letter-spacing: -0.5px; }
h2 { font-size: clamp(22px, 2.5vw, 28px); font-weight: 600; margin: 0 0 10px; }
h3 { font-size: clamp(18px, 2vw, 20px); font-weight: 600; margin: 0 0 10px; color: var(--text-primary); }
h4 { font-size: 16px; font-weight: 600; margin: 0 0 12px; color: #333; }
p { margin: 0 0 10px; line-height: 1.5; }
.subtitle { color: var(--text-secondary); margin-bottom: 24px; font-size: 15px; }

/* Отступы */
.mt-5 { margin-top: 5px; }
.mt-10 { margin-top: 10px; }
.mt-15 { margin-top: 15px; }
.mt-20 { margin-top: 20px; }
.mb-15 { margin-bottom: 15px; }
.mb-20 { margin-bottom: 20px; }

/* Авторизация */
.auth-card { max-width: 440px; margin: 10vh auto 0; padding: 40px; }
.auth-header { text-align: center; margin-bottom: 30px; }
.input-group { margin-bottom: 15px; }
input[type="text"], input[type="password"], select {
    width: 100%; padding: 15px 20px; border: 1px solid #d2d2d7;
    border-radius: 14px; font-size: 15px; box-sizing: border-box; font-family: inherit;
    background-color: rgba(255,255,255,0.9); transition: all 0.2s ease;
}
input:focus, select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15); }
.error-text { color: var(--danger-color); font-size: 14px; text-align: center; margin-top: 15px; font-weight: 500; }

/* Кнопки и доступность */
button { font-family: inherit; transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1); cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 3px; }

.btn-primary { background-color: var(--primary-color); color: white; border: none; padding: 15px 24px; border-radius: 14px; font-size: 16px; font-weight: 600; width: 100%; }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 113, 227, 0.3); }
.btn-secondary { background-color: transparent; color: var(--danger-color); border: 1px solid rgba(255, 59, 48, 0.3); padding: 12px 20px; border-radius: 12px; font-size: 15px; font-weight: 500; width: 100%; }
.btn-secondary:hover { background-color: #fff0f0; border-color: var(--danger-color); }

.demo-users { display: flex; flex-direction: column; gap: 10px; margin-bottom: 25px; }
.demo-btn { background: rgba(255,255,255,0.6); border: 1px solid #d2d2d7; text-align: left; padding: 12px 16px; border-radius: 14px; display: flex; align-items: center; gap: 15px; }
.demo-btn:hover { background: white; border-color: var(--primary-color); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.demo-icon { font-size: 24px; }
.demo-text strong { display: block; font-size: 15px; color: var(--text-primary); margin-bottom: 2px; }
.demo-text span { display: block; font-size: 12px; color: var(--text-secondary); }

.divider { text-align: center; margin: 25px 0; color: var(--text-secondary); font-size: 13px; font-weight: 500; position: relative; text-transform: uppercase; letter-spacing: 1px; }
.divider::before, .divider::after { content: ''; position: absolute; top: 50%; width: 25%; height: 1px; background: #d2d2d7; }
.divider::before { left: 0; } .divider::after { right: 0; }

/* Основной Layout */
.dashboard-layout { display: grid; grid-template-columns: 300px 1fr; gap: 30px; align-items: start; }

/* Сайдбар */
.sidebar { position: sticky; top: 20px; padding: 25px; }
.profile-widget { text-align: center; padding-bottom: 25px; border-bottom: 1px solid rgba(0,0,0,0.08); margin-bottom: 20px; }
.avatar { font-size: 54px; background: linear-gradient(135deg, #e6f0fa, #ffffff); width: 90px; height: 90px; line-height: 90px; border-radius: 50%; margin: 0 auto 15px; box-shadow: inset 0 2px 4px rgba(0,0,0,0.05); display: flex; align-items: center; justify-content: center;}
.profile-org { color: var(--text-secondary); font-size: 13px; margin-bottom: 15px; line-height: 1.4; }
.badge-container { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-block; background: #f0f4f8; color: #555; padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 600; border: 1px solid #e2e8f0; }
.badge-grade { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }

.sidebar-controls { margin-bottom: 25px; background: rgba(0,0,0,0.02); padding: 15px; border-radius: 14px; }
.sidebar-label { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar-select { padding: 10px 15px; font-size: 14px; border-radius: 10px; margin-bottom: 15px; }
.sidebar-btn { padding: 12px 15px; font-size: 14px; border-radius: 10px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 8px; margin-bottom: 30px;}
.nav-header { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin: 0 0 10px 10px; }
.nav-item { background: transparent; border: none; text-align: left; padding: 12px 15px; border-radius: 12px; color: #555; font-size: 15px; font-weight: 500; transition: all 0.2s; display: flex; align-items: center; gap: 12px; }
.nav-item:hover { background: rgba(0,0,0,0.04); color: var(--text-primary); transform: none; box-shadow: none; }
.nav-item.active { background: white; color: var(--primary-color); box-shadow: var(--shadow-sm); font-weight: 600; }
.nav-icon { font-size: 18px; }

.spinner { width: 48px; height: 48px; margin: 0 auto 20px; border: 4px solid rgba(0, 113, 227, 0.1); border-top-color: var(--primary-color); border-radius: 50%; animation: spin 1s infinite linear; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Вкладки */
.trs-view { display: none; animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.trs-view.active { display: block; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Сетка Summary */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; min-width: 0; }
.stat-card { background: white; padding: 24px; border-radius: 18px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; justify-content: center; min-width: 0; overflow-wrap: break-word; word-wrap: break-word; }
.hero-stat { grid-column: span 4; background: linear-gradient(135deg, #0071e3, #4facfe); color: white; padding: 35px 30px; }
.hero-stat .stat-label { color: rgba(255,255,255,0.8); }
.hero-stat h2 { color: white; font-size: 42px; margin: 10px 0 5px; }
.hero-stat .stat-context { color: rgba(255,255,255,0.9); font-size: 15px; margin: 0; }

.stat-card.outline { background: transparent; border: 1px solid rgba(0,0,0,0.08); box-shadow: none; }
.stat-card.highlight { background: var(--success-bg); border-color: #bbf7d0; }
.stat-card.highlight h3 { color: #166534; }
.lti-card { background: #faf5ff; border-color: #e9d5ff; }
.lti-card h3 { color: #6b21a8; }

.stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card h3 { font-size: 26px; margin: 12px 0 6px; color: var(--text-primary); }
.stat-context { font-size: 13px; color: var(--text-secondary); margin: 0; }
.chart-container { position: relative; height: 380px; width: 100%; margin-top: 20px; }

/* Таблицы (Десктоп) */
.table-container { background: white; border-radius: 14px; border: 1px solid #f0f0f0; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th, .data-table td { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.data-table th { font-size: 13px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; background: #fafafa; }
.data-table td { font-size: 14px; color: var(--text-primary); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fdfdfd; }

.status-badge { padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; display: inline-block; white-space: nowrap; }
.status-overachieved { background: var(--success-bg); color: #166534; }
.status-achieved { background: #e0f2fe; color: #0369a1; }
.status-underachieved { background: var(--warning-bg); color: #9a3412; }

/* KPI Section */
.kpi-header-card { display: flex; align-items: center; justify-content: space-between; padding: 30px; }
.kpi-score { display: flex; align-items: center; gap: 25px; }
.score-circle { min-width: 90px; height: 90px; border-radius: 50%; background: white; border: 6px solid var(--success-color); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; color: var(--text-primary); box-shadow: var(--shadow-sm); }
.score-text h3 { margin-bottom: 5px; font-size: 22px; }

/* Benefits Section */
.benefits-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; min-width: 0; }
.benefit-col { background: white; padding: 25px; border-radius: 16px; border: 1px solid #f0f0f0; box-shadow: var(--shadow-sm); min-width: 0; overflow-wrap: break-word; word-wrap: break-word; }
.benefit-col-header { font-size: 16px; font-weight: 600; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; padding-bottom: 15px; border-bottom: 1px solid #f0f0f0; }
.icon-health::before { content: '🏥'; font-size: 20px; }
.icon-lifestyle::before { content: '🧘‍♂️'; font-size: 20px; }
.icon-financial::before { content: '💳'; font-size: 20px; }

.benefit-cost-list { list-style: none; padding: 0; margin: 0; }
.benefit-cost-list li { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px dashed #e8e8ed; font-size: 14px; gap: 15px;}
.benefit-cost-list li:last-child { border-bottom: none; padding-bottom: 0; }
.benefit-info { display: flex; align-items: center; gap: 10px; }
.benefit-val { font-weight: 600; color: var(--text-primary); white-space: nowrap; }

/* Grade & Compa-Ratio */
.grade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; min-width: 0; }
.compa-ratio-box { background: #f8fafc; padding: 15px 20px; border-radius: 12px; border: 1px solid #e2e8f0; display: flex; align-items: center; gap: 10px; font-size: 15px; margin-top: 15px; flex-wrap: wrap;}
.compa-ratio-box strong { font-size: 18px; color: var(--primary-color); }
.fork-info { margin-left: auto; font-size: 13px; color: var(--text-secondary); background: white; padding: 4px 10px; border-radius: 6px; border: 1px solid #e2e8f0; }

.simple-list { padding-left: 0; margin: 0; font-size: 14px; color: #444; list-style: none; }
.simple-list li { position: relative; padding-left: 20px; margin-bottom: 8px; line-height: 1.4; }
.simple-list li::before { content: '•'; position: absolute; left: 0; color: var(--primary-color); font-weight: bold; font-size: 18px; top: -2px; }

.next-grade-card { background: linear-gradient(135deg, #f0f9ff, #ffffff); border: 1px solid #bae6fd; }
.next-grade-perks { display: flex; flex-wrap: wrap; gap: 10px; }
.perk-pill { background: white; border: 1px solid #bae6fd; color: #0369a1; padding: 8px 14px; border-radius: 20px; font-size: 13px; font-weight: 500; box-shadow: 0 2px 4px rgba(0,0,0,0.02); display: flex; align-items: center; gap: 6px; }

/* Training */
.total-training-card { display: flex; align-items: center; gap: 25px; background: linear-gradient(to right, #ffffff, #faf5ff); border-color: #f3e8ff; }
.training-icon { font-size: 48px; background: white; min-width: 80px; height: 80px; border-radius: 20px; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm); border: 1px solid #f3e8ff; }

/* ==========================================
   ФУТЕР И ДОПОЛНИТЕЛЬНЫЕ КНОПКИ (ПОРТФОЛИО)
   ========================================== */
.site-footer {
    width: 100%;
    margin-top: 40px;
    padding-bottom: 20px;
    box-sizing: border-box; /* Защита от выхода за края */
}

.footer-card {
    padding: 20px;
    background: linear-gradient(135deg, rgba(255,255,255,0.8), rgba(255,255,255,0.4));
}

.footer-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

.btn-footer {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    flex: 1 1 auto; /* Гибкая ширина вместо жесткой */
    white-space: nowrap; /* Не даем тексту ломаться на несколько строк, если есть место */
}

.btn-footer:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 113, 227, 0.15);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-footer-icon {
    font-size: 20px;
}

.highlight-resume {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-color: #bae6fd;
    color: #0369a1;
}

.highlight-resume:hover {
    background: linear-gradient(135deg, #e0f2fe, #bae6fd);
    color: #0284c7;
    border-color: #7dd3fc;
    box-shadow: 0 8px 25px rgba(3, 105, 161, 0.2);
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.header-titles {
    flex: 1;
}

.header-titles .subtitle {
    margin-bottom: 0; /* Убираем лишний отступ снизу у подзаголовка */
}

.header-logout-btn {
    width: auto;
    padding: 10px 24px;
    white-space: nowrap; /* Чтобы текст кнопки не переносился */
}

/* ==========================================
   АДАПТИВНОСТЬ / MOBILE UI
   ========================================== */

@media (max-width: 1100px) {
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .hero-stat { grid-column: span 2; }
    .benefits-columns { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    body { 
        padding: 10px 0 0 0; 
    }
    
    .main-content {
        /* Увеличенная безопасная зона снизу, чтобы подвал не перекрывался меню */
        padding-bottom: calc(120px + env(safe-area-inset-bottom, 20px)); 
    }
    
    .dashboard-layout { grid-template-columns: 1fr; gap: 15px; }
    
    .sidebar { 
        position: static; margin-bottom: 0; padding: 15px; 
        background: transparent; border: none; box-shadow: none; 
        backdrop-filter: none !important; 
        -webkit-backdrop-filter: none !important;
    }
    
    .profile-widget { display: flex; align-items: center; text-align: left; gap: 15px; padding-bottom: 0; border-bottom: none; margin-bottom: 15px; }
    .avatar { width: 50px; height: 50px; line-height: 50px; font-size: 24px; margin: 0; flex-shrink: 0; }
    
    .profile-info { flex: 1; }
    h3#profile-name { margin-bottom: 2px; font-size: 18px; }
    .profile-org { margin-bottom: 5px; }
    .badge-container { justify-content: flex-start; }
    
    .sidebar-controls { background: white; box-shadow: var(--shadow-sm); }
    
    .sidebar-footer { display: block; margin-top: 15px; }
    .sidebar-footer .btn-secondary { background: white; padding: 10px; font-size: 14px; }

    /* Плавающее нижнее меню с аппаратным ускорением */
    .sidebar-nav { 
        position: fixed; 
        bottom: 0; left: 0; right: 0; 
        background: rgba(255, 255, 255, 0.95); 
        backdrop-filter: blur(20px); 
        -webkit-backdrop-filter: blur(20px);
        display: flex;
        flex-direction: row; 
        justify-content: space-around; 
        align-items: stretch;
        
        padding: 10px 5px calc(20px + env(safe-area-inset-bottom)); 
        margin: 0; 
        box-shadow: 0 -5px 20px rgba(0,0,0,0.06); 
        z-index: 9999; 
        border-top: 1px solid rgba(0,0,0,0.05); 
        border-radius: 20px 20px 0 0;
        
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        will-change: transform;
    }
    
    .nav-header { display: none; }
    
    .nav-item { 
        display: flex;
        flex-direction: column; 
        justify-content: center; 
        align-items: center;
        padding: 8px 4px; 
        font-size: 11px; 
        line-height: 1.2;
        gap: 4px; 
        color: var(--text-secondary); 
        flex: 1; 
        text-align: center; 
        min-height: 50px; 
    }
    
    .nav-icon { font-size: 22px; margin-bottom: 2px;}
    .nav-item.active { background: transparent; color: var(--primary-color); box-shadow: none; font-weight: 600; }
    .nav-item.active .nav-icon { background: var(--primary-color); color: white; border-radius: 12px; padding: 4px 14px; }

    /* Card View для таблиц (защита от слома flexbox) */
    .table-container { background: transparent; border: none; overflow: visible; padding: 0; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; box-sizing: border-box; }
    
    .data-table tr { 
        margin-bottom: 15px; background: white; border-radius: 16px; 
        padding: 15px; border: 1px solid #f0f0f0; box-shadow: var(--shadow-sm); 
    }
    
    .data-table td { 
        display: flex; 
        justify-content: space-between; 
        align-items: flex-start; 
        padding: 10px 0; 
        border-bottom: 1px dashed #f0f0f0; 
        text-align: right; 
        gap: 15px;
        word-break: break-word; 
    }
    
    .data-table td:last-child { border-bottom: none; padding-bottom: 0; }
    .data-table td:first-child { padding-top: 0; font-size: 15px; border-bottom: 1px solid #f0f0f0; padding-bottom: 10px; margin-bottom: 5px;}
    
    .data-table td::before { 
        content: attr(data-label); 
        font-weight: 500; 
        color: var(--text-secondary); 
        text-transform: uppercase; 
        font-size: 11px; 
        text-align: left; 
        flex-shrink: 0; 
        max-width: 40%; 
    }

    .grade-grid { grid-template-columns: 1fr; }
    .kpi-score { flex-direction: row; text-align: left; }
    .chart-container { height: 300px; }
    .glass, .card { padding: 20px; border-radius: 18px; }
}

@media (max-width: 768px) {
    /* Исправление проблемы с кнопками футера на мобильных */
    .footer-actions {
        flex-direction: column;
        gap: 12px;
    }
    .btn-footer {
        width: 100%;
        min-height: 52px;
        white-space: normal; /* Разрешаем перенос текста, если экран совсем узкий */
    }
}

@media (max-width: 600px) {
    .auth-card { padding: 30px 20px; margin: 5vh auto 0; }
    
    .summary-grid { grid-template-columns: 1fr; gap: 15px; }
    .hero-stat { grid-column: span 1; padding: 25px 20px; }
    
    .kpi-score { flex-direction: column; text-align: center; gap: 15px; }
    .total-training-card { flex-direction: column; text-align: center; }
    .compa-ratio-box { flex-direction: column; align-items: flex-start; }
    .fork-info { margin-left: 0; margin-top: 10px; }
    .action-row { flex-direction: column; align-items: stretch; }
    .action-row select { width: 100%; margin-bottom: 10px; }
    .sidebar-controls { display: flex; flex-direction: column; }
    .sidebar-select, .sidebar-btn { width: 100%; box-sizing: border-box; }
    .content-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .header-logout-btn {
        width: 100%; /* Кнопка будет на всю ширину, как и планировалось */
    }
}

@media (max-width: 400px) {
    .nav-item {
        font-size: 10px;
        padding: 8px 2px;
    }
    .nav-icon {
        font-size: 20px;
    }
}