:root {
    --primary: #7c4dff;
    --primary-light: #e8eaf6;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --bg-panel: rgba(255, 248, 242, 0.85);
    --text-dark: #2d2d2d;
    --text-gray: #757575;
    --border-radius: 24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    margin: 0;
    color: var(--text-dark);
    background-image: url('../assets/img/bg.png'); 
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

#app-root {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    box-sizing: border-box;
}

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

#loader-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.9);
    z-index: 10000; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 15px;
    backdrop-filter: blur(5px); color: var(--primary);
}
#loader-overlay h3 { margin: 0; font-weight: 600; font-size: 18px; }

/* === ИСПРАВЛЕНИЕ: ЖЕСТКОЕ СКРЫТИЕ ЧЕКБОКСА У УЧЕНИКА === */
body.student .student-bypass { 
    display: none !important; 
}

/* --- ЭКРАН ВХОДА (ЛОГИН) --- */
.login-container {
    display: flex; flex-direction: column; align-items: center;
    padding: 50px 40px; max-width: 450px; width: 100%; text-align: center; gap: 20px;
    transition: opacity 0.4s ease, transform 0.4s ease;
}
.login-container .logo { width: 70px; height: 70px; background: var(--primary); border-radius: 20px; display: flex; align-items: center; justify-content: center; color: white; font-size: 32px; margin-bottom: 10px; flex-shrink: 0;}
.login-container h2 { font-size: 26px; margin: 0; font-weight: 700; }
.login-container p { font-size: 14px; color: var(--text-gray); margin: 0; line-height: 1.5; }

/* Стили для картинки-логотипа внутри фиолетового квадрата */
.logo-img {
    width: 90%; /* Занимает 65% ширины контейнера (оставляет красивые "поля") */
    height: 90%;
    object-fit: contain; /* Пропорции картинки не искажаются */
    /* filter: brightness(0) invert(1); */ /* Раскомментируйте эту строку, если ваш логотип черный, а вы хотите сделать его белым, как иконки */
}

.input-group { width: 100%; display: flex; flex-direction: column; gap: 8px; text-align: left; margin-top: 10px; }
.input-group input {
    width: 100%; padding: 16px; border-radius: 14px;
    border: 2px solid rgba(0,0,0,0.05); font-size: 15px; font-family: 'Inter', sans-serif;
    background: rgba(255,255,255,0.9); outline: none; transition: 0.3s;
}
.input-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(124, 77, 255, 0.15); }
.error-message { color: var(--error); font-size: 12px; display: none; margin-left: 5px; font-weight: 500;}

.login-btn {
    width: 100%; padding: 16px; background: var(--primary); color: white;
    border: none; border-radius: 14px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: 0.3s; box-shadow: 0 10px 20px rgba(124, 77, 255, 0.2);
    margin-top: 10px;
}
.login-btn:hover { background: #651fff; transform: translateY(-2px); box-shadow: 0 15px 25px rgba(124, 77, 255, 0.3); }

/* --- ГЛАВНОЕ ПРИЛОЖЕНИЕ --- */
.app-container {
    width: 100%; max-width: 1440px;
    display: none; 
    grid-template-columns: 100px 1fr 280px;
    grid-template-areas: "nav main right";
    gap: 24px; margin: 0 auto;
    animation: fadeIn 0.5s ease forwards;
}
.app-container.active { display: grid; }

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* --- ЛЕВОЕ МЕНЮ --- */
.sidebar { grid-area: nav; display: flex; flex-direction: column; align-items: center; padding: 30px 10px; gap: 20px; }
.logo { width: 60px; height: 60px; background: var(--primary); border-radius: 16px; display: flex; align-items: center; justify-content: center; color: white; font-size: 28px; margin-bottom: 10px; flex-shrink: 0;}
.nav-item { display: flex; flex-direction: column; align-items: center; color: var(--text-gray); text-decoration: none; font-size: 12px; gap: 8px; padding: 10px; border-radius: 12px; transition: 0.3s; text-align: center; width: 100%;}
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item i { font-size: 20px; }

/* --- ЦЕНТРАЛЬНЫЙ КОНТЕНТ --- */
.main-content { grid-area: main; display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.header { 
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; padding: 20px 30px; 
    position: relative;
    z-index: 50;
}
.greeting h1 { font-size: clamp(20px, 2vw, 24px); margin-bottom: 4px; font-weight: 700; }
.greeting p { color: var(--text-gray); font-size: 14px; }

.header-stats { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.stat-group { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255, 0.5); padding: 8px 16px; border-radius: 20px; }
.stat-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;}

.level-info { display: flex; flex-direction: column; gap: 4px; min-width: 120px;}
.level-info-top { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }
.progress-bar-bg { width: 100%; height: 6px; background: #e0e0e0; border-radius: 3px; overflow: hidden;}
.progress-bar-fill { width: 65%; height: 100%; background: var(--primary); border-radius: 3px;}
.level-info-bottom { text-align: right; font-size: 10px; color: var(--text-gray); }

.stat-text { display: flex; flex-direction: column; justify-content: center; }
.stat-text strong { font-size: 14px; color: var(--text-dark); }
.stat-text span { font-size: 11px; color: var(--text-gray); }
.avatar { width: 44px; height: 44px; background: #ceb5ff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; border: 2px solid white; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }

/* Трекер */
.tracker-screen {
    flex-grow: 1; min-height: 400px; border-radius: var(--border-radius); position: relative; overflow: hidden;
    background-image: url('../assets/img/tracker-bg.png'); background-size: cover; background-position: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2); display: flex; justify-content: center; align-items: center;
}

.tracker-overlay-top {
    position: absolute; top: 20px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; color: white; z-index: 5; pointer-events: none;
}
.tracker-overlay-top h2 {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100%;
}

/* Убираем жесткий инлайн-отступ, так как теперь мы используем gap */
#current-mode-badge {
margin-left: 0 !important; 
}

.tracker-overlay-top p { font-size: 13px; color: #ddd; text-shadow: 0 1px 2px rgba(0,0,0,0.5);}

.tracker-controls {
    position: absolute; 
    top: 20px; 
    left: 20px; 
    z-index: 20;
    display: flex;
    gap: 10px;
}

.control-toggle {
    background: rgba(0, 0, 0, 0.6); 
    backdrop-filter: blur(5px);
    color: white; 
    padding: 8px 12px; 
    border-radius: 12px;
    font-size: 12px; 
    display: flex; 
    align-items: center; 
    gap: 8px;
    cursor: pointer; 
    border: 1px solid rgba(255,255,255,0.2);
    transition: 0.3s ease;
}
.control-toggle:hover { background: rgba(0, 0, 0, 0.8); }

video { display: none; }
#debug_canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; display: none; z-index: 2; }

#start-btn { padding: 15px 30px; font-size: 16px; font-weight: 600; border-radius: 30px; background: var(--primary); color: white; border: none; cursor: pointer; box-shadow: 0 10px 20px rgba(124, 77, 255, 0.3); transition: 0.3s; z-index: 10; }
#start-btn:hover { transform: translateY(-2px); box-shadow: 0 15px 25px rgba(124, 77, 255, 0.4); }

#stop-btn {
    position: absolute; bottom: 20px; right: 20px; z-index: 10;
    background: rgba(244, 67, 54, 0.85); backdrop-filter: blur(5px);
    color: white; border: 1px solid rgba(255,255,255,0.2); border-radius: 16px;
    padding: 12px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
    display: none; align-items: center; gap: 8px; transition: 0.3s;
}

#download-report-btn {
    position: absolute; bottom: 20px; right: 20px; z-index: 10;
    background: rgba(124, 77, 255, 0.85); backdrop-filter: blur(5px);
    color: white; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 16px;
    padding: 12px 20px; font-size: 14px; font-weight: 600; cursor: pointer; display: none; 
    align-items: center; gap: 8px; transition: 0.3s ease;
}

/* УПРАВЛЕНИЕ МЕДИА */
.media-controls {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 20px; z-index: 150;
}
.media-btn {
    width: 54px; height: 54px; border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1); background: rgba(30, 30, 30, 0.65);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    color: white; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); outline: none;
}
.media-btn.muted { background: rgba(244, 67, 54, 0.9); border-color: rgba(244, 67, 54, 1); }

.accuracy-widget {
    position: absolute; bottom: 20px; left: 20px; background: rgba(30, 30, 30, 0.85); backdrop-filter: blur(10px);
    padding: 12px 20px; border-radius: 20px; display: flex; align-items: center; gap: 15px; color: white; border: 1px solid rgba(255,255,255,0.1); opacity: 0; transition: opacity 0.5s; z-index: 5;
}
.circular-progress { width: 44px; height: 44px; border-radius: 50%; background: conic-gradient(var(--success) 100%, #444 0); display: flex; align-items: center; justify-content: center; }
.circular-progress::before { content: ""; position: absolute; width: 34px; height: 34px; background: #2a2a2a; border-radius: 50%; }
.circular-progress i { position: relative; color: var(--success); font-size: 16px; }
.accuracy-info h3 { font-size: 20px; margin: 0; font-family: monospace; }
.accuracy-info p { font-size: 12px; color: #aaa; margin: 0; }

.status-panel { display: flex; align-items: center; justify-content: space-between; padding: 20px 30px; flex-wrap: wrap; gap: 15px; }
.status-left { display: flex; align-items: center; gap: 15px; flex: 1; min-width: 250px;}
.status-icon { width: 50px; height: 50px; background: #e8f5e9; color: var(--success); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0;}
.status-text h3 { margin-bottom: 4px; font-size: clamp(16px, 1.5vw, 18px); font-weight: 600;}
.status-text p { color: var(--text-gray); font-size: 13px; line-height: 1.4;}
.status-metrics { display: flex; gap: 30px; flex-wrap: wrap;}
.metric { display: flex; flex-direction: column; gap: 5px; }
.metric span { font-size: 12px; color: var(--text-gray); }
.metric strong { font-size: 16px; color: var(--success); transition: color 0.3s;}

.right-sidebar { grid-area: right; display: flex; flex-direction: column; gap: 20px; align-self: start; }
.tip-card { padding: 24px; display: flex; flex-direction: column; gap: 15px; }
.tip-header { display: flex; flex-direction: column; gap: 10px; }
.tip-header .icon { color: #ffca28; font-size: 24px; }
.tip-header h3 { font-size: 16px; margin: 0; }
.tip-text { font-size: 13px; line-height: 1.5; color: var(--text-gray); margin: 0;}
.tip-visual { display: flex; flex-direction: column; align-items: center; gap: 15px; margin-top: 10px;}
.tip-image-placeholder { width: 110px; height: 110px; background: rgba(0,0,0,0.03); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 45px; }
.pagination { display: flex; gap: 6px; }
.dot { width: 6px; height: 6px; background: #ddd; border-radius: 50%; }
.dot.active { background: var(--primary); }

/* --- СТИЛИ ДЛЯ ВЛАДКИ СТАТИСТИКИ И НАСТРОЕК --- */
.stats-top-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 20px; margin-top: 20px; }
.stat-card { display: flex; align-items: center; gap: 15px; padding: 20px; }
.stat-card i { font-size: 30px; background: rgba(0,0,0,0.05); padding: 15px; border-radius: 12px; }
.stat-card p { margin: 0; color: #757575; font-size: 13px; }
.stat-card h3 { margin: 5px 0 0 0; font-size: 24px; color: #333; }

.stats-middle-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.chart-box, .weak-points-box, .history-box { padding: 20px; }
.chart-box h3, .weak-points-box h3, .history-box h3 { margin-top: 0; margin-bottom: 20px; color: #333; font-size: 18px;}

.weak-point { margin-bottom: 15px; }
.wp-header { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; color: #555; font-weight: 500;}
.error-fill { background: var(--error) !important; }
.warning-fill { background: var(--warning) !important; }
.primary-fill { background: var(--primary) !important; }

.history-table { width: 100%; border-collapse: collapse; text-align: left; }
.history-table th { padding: 12px 10px; border-bottom: 2px solid #eee; color: #888; font-weight: 500; font-size: 14px; }
.history-table td { padding: 15px 10px; border-bottom: 1px solid #eee; color: #444; font-size: 14px; }

.exercises-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.achievements-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* === ПАНЕЛЬ ПРЕПОДАВАТЕЛЯ (Убираем лишнее) === */

/* 1. Скрываем кнопку "Статистика" и правую панель "Советы" */
body.teacher a[href="#/stats"],
body.teacher .right-sidebar {
    display: none !important;
}

/* 2. Растягиваем центральную зону на место пропавшей панели советов */
body.teacher #app-screen {
    grid-template-columns: 100px 1fr !important;
    grid-template-areas: "nav main" !important;
}

/* ==========================================================================
   АДАПТИВНОСТЬ (МОБИЛЬНЫЕ УСТРОЙСТВА)
   ========================================================================== */
@media (max-width: 1150px) {
    .app-container.active { display: grid; grid-template-columns: 90px 1fr; grid-template-areas: "nav main" "nav right"; }
    .right-sidebar { align-self: stretch; }
}

@media (max-width: 768px) {
    .login-container {
        padding: 30px 20px;
        width: 95%;
        max-width: 400px;
    }

    .app-container.active { 
        display: flex !important; 
        flex-direction: column !important; 
        padding: 10px !important; 
        gap: 15px !important; 
    }

    /* Меню */
    .sidebar { 
        flex-direction: row !important; 
        width: 100% !important; 
        padding: 10px !important; 
        gap: 10px !important; 
        overflow-x: auto !important; 
        justify-content: flex-start !important;
        border-radius: 16px !important;
        white-space: nowrap;
    }
    .sidebar::-webkit-scrollbar { display: none; }
    .sidebar .logo { display: none !important; } 
    
    .nav-item { 
        flex-direction: row !important; 
        width: auto !important; 
        padding: 10px 15px !important; 
        font-size: 13px !important;
        gap: 8px !important;
        background: rgba(255,255,255,0.5);
    }
    .nav-item.active { background: var(--primary) !important; color: white !important; }

    /* === ИСПРАВЛЕНИЕ: ШАПКА СО СТАТИСТИКОЙ === */
    .header { 
        flex-direction: column !important; 
        align-items: flex-start !important; 
        padding: 15px !important; 
        gap: 15px !important;
    }
    .greeting { padding-right: 50px; } 
    
    /* Заставляем 3 плашки статистики строиться друг под другом */
    .header-stats { 
        flex-direction: column !important; 
        align-items: stretch !important;
        width: 100% !important; 
        gap: 10px !important;
    }
    .stat-group { 
        width: 100% !important; 
        justify-content: flex-start !important;
        padding: 12px 15px !important;
    }
    
    .avatar-wrapper {
        position: static !important;
    }
    
    .avatar {
        position: absolute !important;
        top: 15px !important;
        right: 15px !important;
        z-index: 100 !important; /* Держим поверх других элементов шапки */
    }

    /* === ИСПРАВЛЕНИЕ: НАСЛОЕНИЯ В ТРЕКЕРЕ === */
    .tracker-screen { 
        min-height: 400px !important; 
        height: auto !important;
    }
    
    .tracker-overlay-top {
        display: flex !important;
        top: 15px !important;
        /* Увеличиваем боковые отступы, чтобы текст не залезал под круглую кнопку */
        padding: 0 65px !important; 
        text-align: center !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Опускаем панель с бейджиками ниже, чтобы не пересекались */
    .tracker-controls {
        top: auto !important;
        bottom: 85px !important; 
        left: 10px !important;
        right: 10px !important;
        justify-content: center !important;
    }

    .accuracy-widget {
        bottom: 10px !important;
        left: 10px !important;
        padding: 8px 12px !important;
    }

    #webcam:not([style*="width: 100%"]),
    #remote-video:not([style*="width: 100%"]) {
        width: 110px !important;
        height: 80px !important;
        bottom: 85px !important; 
        right: 10px !important;
        border-radius: 8px !important;
    }

    .media-controls {
        bottom: 15px !important;
        gap: 10px !important;
    }

    /* === ИСПРАВЛЕНИЕ: НАСЛОЕНИЯ СТАТУСОВ ВНИЗУ === */
    .status-panel { 
        flex-direction: column !important; 
        align-items: flex-start !important; 
        padding: 15px !important; 
        gap: 15px !important;
    }
    .status-metrics { 
        width: 100% !important; 
        justify-content: space-between !important; 
        border-top: 1px solid rgba(0,0,0,0.05); 
        padding-top: 15px !important;
    }

    /* === ИСПРАВЛЕНИЕ: КАРТОЧКА С СОВЕТОМ === */
    .tip-card { 
        flex-direction: column !important; 
        align-items: flex-start !important; 
        gap: 10px !important; 
    }
    .tip-header { 
        flex-direction: row !important; 
        align-items: center !important; 
        gap: 10px !important;
        width: 100% !important;
    }
    .tip-visual { display: none !important; }
    .tip-card .pagination {
        position: static !important;
        display: flex !important;
        margin-top: 15px !important;
        width: 100% !important;
        justify-content: center !important;
    }
    
    .stats-top-grid, .stats-middle-grid, .settings-grid { 
        grid-template-columns: 1fr !important; 
    }

    /* === ИСПРАВЛЕНИЕ: ПАНЕЛЬ ПРЕПОДАВАТЕЛЯ (МОБИЛЬНАЯ ВЕРСИЯ) === */
    
    /* 1. Делаем шапку вертикальной и растягиваем на всю ширину */
    #main-area > .app-container > .glass-panel:first-child {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 15px !important;
    }

    /* 2. Защищаем заголовок от наложения аватарки (аватарка висит абсолютно справа) */
    #main-area > .app-container > .glass-panel:first-child > div:first-child {
        padding-right: 50px !important;
    }

    /* 3. Блок с полем ввода и кнопкой вызова - элементы друг под другом */
    #main-area > .app-container > .glass-panel:first-child > div:nth-child(2) {
        flex-direction: column !important;
        width: 100% !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    /* 4. Растягиваем инпут на 100% */
    #main-area #room-input {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 5. Растягиваем кнопку "Позвонить" и центрируем текст */
    #main-area #call-btn {
        width: 100% !important;
        justify-content: center !important;
        margin-left: 0 !important;
    }

    /* 6. Адаптация всплывающей панели "Настройка зоны ИИ", чтобы она не вылезала за края */
    #teacher-zone-panel {
        width: calc(100% - 30px) !important;
        max-width: 320px !important;
        right: 15px !important;
        top: 15px !important;
        box-sizing: border-box !important;
    }
}