/* Панель звонка — фиксированная высота, прижата к верху */
.call-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 400px;
    background: var(--bg-dark);
    z-index: 100;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: slideDown 0.3s ease-out;
}

.call-panel.down {
    bottom: 0;
    height: auto;
}

/* Дополнительно: если нужен эффект "воздуха" снизу */
.call-panel:not(.down) .call-controls {
    box-shadow:
        0 -1px 0 rgba(255, 255, 255, 0.05) inset,
        /* Светлая полоска сверху панели */
        0 1px 0 rgba(0, 0, 0, 0.4),
        /* Чёткая граница */
        0 2px 6px rgba(0, 0, 0, 0.3);
    /* Глубина */
}

/* Фиксированная панель 400px — ограничиваем всё внутри */
.call-panel:not(.down):not(.fullscreen) .call-users-grid {
    height: 100%;
    max-height: 100%;
}

.call-panel:not(.down):not(.fullscreen) .call-user {
    max-height: 100%;
}

.call-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.call-users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 1200px;
    max-height: 100%;
    overflow-y: auto;
    padding: 8px;
    border-radius: 8px;
    scrollbar-width: thin;
    scrollbar-color: #5d6269 #36393f;
}

.call-panel:not(.down):not(.fullscreen) .call-users-grid.single {
    display: flex;
    justify-content: center;
}

.call-users-grid::-webkit-scrollbar {
    width: 6px;
}

.call-users-grid::-webkit-scrollbar-track {
    background: #36393f;
}

.call-users-grid::-webkit-scrollbar-thumb {
    background: #5d6269;
    border-radius: 3px;
}

.call-users-grid::-webkit-scrollbar-thumb:hover {
    background: #636871;
}

.call-user {
    background: #202225;
    border-radius: 8px;
    aspect-ratio: 16/9;
    position: relative;
    overflow: hidden;
    border: 2px solid #40444b;
    transition: border-color 0.2s;
    display: flex;
    justify-content: center;
    transition: opacity 0.5s ease-out;
}

.call-user:hover {
    cursor: pointer;
}

.call-user.call {
    border: 2px solid var(--brand);
    animation: scalePulse 2s infinite ease-in-out;
}

/* Подсветка говорящего пользователя */
.call-user.speakOutline {
    border-color: var(--success);
    box-shadow: 0 0 0 2px rgba(59, 165, 93, 0.25);
    transition: border-color 0.1s ease;
}

@keyframes scalePulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.01);
    }

    100% {
        transform: scale(1);
    }
}

.call-user.spotlight {
    grid-column: span 2;
    grid-row: span 2;
}

.user-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-video-screenshare {
    width: 100%;
    object-fit: cover;
}

.fullscreen-screenshare-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s;
    justify-content: center;
    display: flex;
    align-items: center;
    background: transparent;
}

.fullscreen-screenshare-btn:hover {
    background: var(--background-floating);
}

.fullscreen-screenshare-btn:hover img {
    transform: scale(1.05);
}

.user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #202225;
}

.user-avatar img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
}

.user-call-info {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-name {
    font-weight: 500;
}

/* Панель управления звонком */
.call-controls {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s, transform 0.3s;
    border-top: 2px solid #0f0e0e14;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.call-controls.hidden {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

.call-controls-left {
    flex: 1;
}

.call-controls-right {
    flex: 1;
    display: flex;
    justify-content: right;
}

.call-controls-center {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--background-tertiary);
    border-radius: 8px;
    padding: 6px 12px 6px 12px;
    box-shadow: 1px 1px 5px black;
}

/* === ИСПРАВЛЕНО: call-control-group (было control-group) === */
.call-control-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* === ИСПРАВЛЕНО: call-control-btn (было control-btn) === */
.call-control-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.call-control-btn:hover {
    background: #5d6269;
    transform: scale(1.05);
}

/* Настройки (стрелка вниз) */
.call-control-btn.settings-control {
    width: 32px;
    height: 32px;
    background: transparent;
}

.call-control-btn.settings-control:hover {
    background: rgba(79, 84, 92, 0.8);
}

/* Кнопка завершения звонка */
.call-control-btn.end-call {
    display: none;
    background: #ed4245;
    border-radius: 8px;
    width: 60px;
    height: 42px;
    box-shadow: 1px 1px 3px #ed4245;
    position: relative;
    left: 15px;
}

.call-control-btn.end-call:hover {
    background: #ff474a;
    transform: scale(1.05);
}

.call-control-btn.end-call.active {
    display: block;
    background: #ed4245;
}

/* Кнопка присоединения к звонку */
.call-control-btn.connect-to-call {
    display: none;
    background: #43b581;
    border-radius: 8px;
    width: 60px;
    height: 42px;
    box-shadow: 1px 1px 3px #43b581;
    position: relative;
    left: 15px;
}

.call-control-btn.connect-to-call.active {
    display: block;
    background: #43b581;
}

/* === ИСПРАВЛЕНО: call-control-icon (было control-icon) === */
.call-control-icon {
    width: 22px;
    height: 22px;
    filter: brightness(0.8);
}

.call-control-icon.small {
    width: 16px;
    height: 16px;
}

/* === Индикаторы состояния === */
.call-control-btn.active {
    background: #43b581;
}

.call-control-btn.inactive {
    background: #ed4245;
}

.call-control-btn.screenshare-active {
    background: #43b581;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== */
/* АДАПТИВНОСТЬ ДЛЯ МОБИЛЬНЫХ УСТРОЙСТВ */
/* ==================== */

/* Планшеты и маленькие ноутбуки */
@media (max-width: 1024px) {
    .call-panel {
        height: 350px;
    }

    .call-users-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 10px;
        padding: 6px;
    }

    .user-avatar img {
        width: 60px;
        height: 60px;
    }

    .user-call-info {
        font-size: 13px;
        padding: 5px 10px;
        bottom: 8px;
        left: 8px;
    }

    .call-control-btn {
        width: 36px;
        height: 36px;
    }

    .call-control-icon {
        width: 20px;
        height: 20px;
    }

    .call-control-icon.small {
        width: 14px;
        height: 14px;
    }
}

/* Большие смартфоны и маленькие планшеты */
@media (max-width: 768px) {
    .call-panel {
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
    }

    .call-main {
        flex: 0.95;
        padding: 5px;
        justify-content: center;
        align-items: flex-start;
    }

    .call-users-grid {
        gap: 8px;
        padding: 4px;
        justify-items: center;
        width: 100%;
        height: 90%;
        justify-content: center;
    }

    .call-user {
        aspect-ratio: 16/9;
        width: 100%;
        height: 100%;
    }

    .call-user.spotlight {
        grid-column: 1;
        grid-row: 1;
        max-height: 250px;
        max-width: 95%;
    }

    .user-avatar img {
        width: 50px;
        height: 50px;
    }

    .user-call-info {
        font-size: 12px;
        padding: 4px 8px;
        bottom: 6px;
        left: 6px;
    }

    .call-controls {
        padding: 10px 15px;
        background: rgba(47, 49, 54, 0.95);
        backdrop-filter: blur(10px);
        bottom: 25px;
        left: 0;
        right: 0;
        z-index: 1001;
        position: relative;
    }

    .call-controls-left,
    .call-controls-right {
        display: none;
    }

    .call-controls-center {
        gap: 2px;
        padding: 4px 8px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .call-control-group {
        gap: 2px;
    }

    .call-control-btn {
        width: 44px;
        height: 44px;
        margin: 2px;
    }

    .call-control-btn.settings-control {
        width: 36px;
        height: 36px;
    }

    .call-control-btn.end-call,
    .call-control-btn.connect-to-call {
        width: 50px;
        height: 44px;
        left: 10px;
    }

    .call-control-icon {
        width: 20px;
        height: 20px;
    }

    .call-control-icon.small {
        width: 14px;
        height: 14px;
    }
}

/* Смартфоны среднего размера */
@media (max-width: 480px) {
    .call-users-grid {
        grid-template-columns: auto;
        gap: 6px;
        padding: 3px;
        justify-items: center;
    }

    .call-user {
        border-width: 1px;
        max-width: 95%;
    }

    .call-user.spotlight {
        max-height: 220px;
        max-width: 95%;
    }

    .user-avatar img {
        width: 40px;
        height: 40px;
    }

    .user-call-info {
        font-size: 11px;
        padding: 3px 6px;
        bottom: 4px;
        left: 4px;
    }

    .call-controls {
        padding: 8px 12px;
    }

    .call-controls-center {
        justify-content: space-between;
        gap: 0;
        padding: 6px 10px;
    }

    .call-control-btn {
        width: 42px;
        height: 42px;
        margin: 1px;
    }

    .call-control-btn.settings-control {
        width: 34px;
        height: 34px;
    }

    .call-control-btn.end-call,
    .call-control-btn.connect-to-call {
        width: 48px;
        height: 42px;
    }

    .call-control-group {
        gap: 1px;
    }
}

/* Очень маленькие смартфоны */
@media (max-width: 360px) {
    .call-user {
        max-width: 92%;
    }

    .call-user.spotlight {
        max-height: 180px;
        max-width: 92%;
    }

    .user-avatar img {
        width: 35px;
        height: 35px;
    }

    .call-controls-center {
        padding: 4px 6px;
    }

    .call-control-btn {
        width: 38px;
        height: 38px;
    }

    .call-control-btn.settings-control {
        width: 30px;
        height: 30px;
    }

    .call-control-btn.end-call,
    .call-control-btn.connect-to-call {
        width: 44px;
        height: 38px;
    }

    .call-control-icon {
        width: 18px;
        height: 18px;
    }

    .call-control-icon.small {
        width: 12px;
        height: 12px;
    }
}

/* Портретная ориентация */
@media (max-height: 600px) and (orientation: portrait) {
    .call-panel {
        height: 100vh;
    }

    .call-users-grid {
        max-height: calc(100vh - 100px);
        justify-items: center;
    }

    .call-user {
        max-width: 95%;
    }

    .call-user.spotlight {
        max-height: 160px;
        max-width: 95%;
    }
}

/* Ландшафтная ориентация для мобильных */
@media (max-width: 900px) and (orientation: landscape) {
    .call-panel {
        height: 100vh;
    }

    .call-users-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        max-height: calc(100vh - 80px);
        justify-items: center;
    }

    .call-user {
        max-width: 95%;
    }

    .call-user.spotlight {
        max-height: 140px;
        max-width: 95%;
    }

    .call-controls {
        padding: 6px 10px;
    }

    .call-control-btn {
        width: 36px;
        height: 36px;
    }

    .call-control-btn.settings-control {
        width: 28px;
        height: 28px;
    }
}

/* Поддержка устройств с вырезом (notch) */
@supports (padding: max(0px)) {
    .call-panel {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .call-controls {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

/* Улучшения для touch-устройств */
@media (hover: none) and (pointer: coarse) {
    .call-control-btn:hover {
        background: transparent;
        transform: none;
    }

    .call-control-btn:active {
        background: #5d6269;
        transform: scale(0.95);
    }

    .call-controls.hidden {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }
}