/* === MOBILE RESPONSIVE MEDIA QUERIES === */

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .logo-icon {
        width: 40px;
        height: 40px;
    }

    .logo-text h1 {
        font-size: 1.8em;
    }

    .logo-text p {
        font-size: 0.65em;
    }

    .videos-layout {
        grid-template-columns: 1fr;
        gap: 15px;
        min-height: 300px;
    }

    .remote-videos-container {
        grid-template-columns: 1fr;
        max-height: 300px;
        overflow-y: auto;
    }

    .input-group {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    input {
        max-width: 100%;
        margin-bottom: 10px;
        padding: 10px 15px;
        font-size: 16px;
    }

    button {
        padding: 10px 20px;
        font-size: 14px;
        min-width: 120px;
    }

    .controls {
        gap: 10px;
        margin: 15px 0;
    }

    .control-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .section {
        padding: 20px 15px;
        margin-bottom: 15px;
    }

    .quality-controls {
        justify-content: center;
        gap: 8px;
        margin-bottom: 10px;
    }

    .quality-btn {
        padding: 6px 12px;
        font-size: 11px;
    }

    .room-info {
        text-align: center;
        font-size: 14px;
    }

    /* Compact info for mobile */
    .room-info-compact {
        font-size: 0.75em;
        gap: 6px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .bottom-panel {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 8px;
        padding: 8px 10px;
    }

    .room-info-compact,
    .controls,
    .copy-room-link-btn {
        justify-self: center;
        text-align: center;
    }

    .copy-room-link-btn {
        grid-row: 3;
    }

    .global-footer {
        font-size: 0.7em;
        padding: 6px;
    }

    .stats-display {
        font-size: 10px;
    }

    /* Keep body normal - only fix when in chat with keyboard */
    body {
        background: var(--gradient-bg);
    }

    /* Fix body only when in call (chat is open) */
    body.in-call {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        overflow: hidden;
    }

    /* Container should not hide background */
    .container {
        background: transparent;
        min-height: 100vh;
    }

    /* Room selection mobile styles */
    #room-selection {
        padding: 30px 15px;
        max-width: 90%;
        margin: 20px auto;
        background: var(--glass-bg);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        border: 1px solid var(--glass-border);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        border-radius: 20px;
    }

    /* Switch to vertical layout on mobile */
    .input-group {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 10px;
    }

    .input-group input {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
    }

    .input-group #join-btn {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
    }

    .input-group #create-room-btn {
        grid-column: 1 / 2;
        grid-row: 3 / 4;
    }

    #room-selection h2 {
        font-size: 1.5em;
        margin-bottom: 25px;
    }

    /* Footer mobile styles */
    .room-footer {
        padding: 15px;
        margin-top: 15px;
        font-size: 0.85em;
    }

    .footer-tagline {
        font-size: 0.9em;
    }

    .footer-brand {
        font-size: 0.8em;
    }

    /* Hide desktop-only elements on mobile */
    .desktop-only {
        display: none !important;
    }

    /* Section styling for mobile */
    .section {
        background: var(--glass-bg);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }

    /* Hide header during call */
    #call-interface:not(.hidden) ~ header,
    body:has(#call-interface:not(.hidden)) header {
        display: none !important;
    }

    /* Hide desktop sections on mobile */
    .main-content .section {
        display: none !important;
    }

    /* Hide main-content grid on mobile */
    .main-content {
        display: none !important;
    }

    /* Hide desktop video containers and chat on mobile */
    #local-video-container,
    #remote-videos,
    #chat-container,
    .local-video-container,
    .remote-videos-container,
    .chat-container {
        display: none !important;
    }

    /* Hide room selection and footer when in call */
    #call-interface:not(.hidden) ~ #room-selection,
    #call-interface:not(.hidden) ~ .room-footer {
        display: none !important;
    }

    /* Show mobile chat layer and video modal */
    .mobile-chat-layer:not(.hidden),
    .mobile-video-modal:not(.hidden) {
        display: flex !important;
    }

    /* Bottom Panel: Floating controls over video */
    .bottom-panel {
        position: fixed;
        bottom: calc(80px + env(safe-area-inset-bottom));
        left: 50%;
        transform: translateX(-50%) translateZ(0);
        width: auto;
        height: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px 20px;
        background: transparent;
        backdrop-filter: none;
        border-radius: 30px;
        border: none;
        box-shadow: none;
        z-index: 10003;
        transition: bottom 0.3s ease;
    }

    /* Hide room info on mobile */
    .room-info,
    .room-link-info {
        display: none !important;
    }

    /* Controls: centered, compact */
    .controls {
        display: flex;
        gap: 15px;
        justify-content: center;
        align-items: center;
        margin: 0;
        padding: 0;
    }

    /* Control buttons: 50px size, floating style */
    .control-btn {
        width: 50px;
        height: 50px;
        min-width: 50px;
        min-height: 50px;
        font-size: 20px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }

    .control-btn:active {
        transform: scale(0.9);
    }

    header h1 {
        font-size: 1.5em;
    }

    header p {
        font-size: 0.8em;
    }

    .section {
        padding: 15px;
    }

    /* Мобильные адаптации для адаптивной сетки */
    .remote-videos-container.participants-2,
    .remote-videos-container.participants-3,
    .remote-videos-container.participants-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .remote-videos-container.participants-5,
    .remote-videos-container.participants-6 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .remote-videos-container.participants-7,
    .remote-videos-container.participants-8,
    .remote-videos-container.participants-9 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* На мобильных 3 участника лучше в 1 столбец */
    .remote-videos-container.participants-3 .remote-video-container:nth-child(3) {
        grid-column: auto !important;
        max-width: none !important;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
    }

    .logo-icon {
        width: 35px;
        height: 35px;
    }

    .logo-container {
        gap: 10px;
    }

    .logo-text h1 {
        font-size: 1.5em;
    }

    .logo-text p {
        font-size: 0.6em;
    }

    .videos-layout {
        min-height: 250px;
        gap: 10px;
    }

    .remote-videos-container {
        grid-template-columns: 1fr;
        max-height: 200px;
        overflow-y: auto;
    }

    .section {
        padding: 15px 10px;
        margin-bottom: 10px;
        border-radius: 10px;
    }

    .controls {
        gap: 8px;
        margin: 10px 0;
    }

    .control-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .quality-controls {
        gap: 5px;
        margin-bottom: 8px;
    }

    .quality-btn {
        padding: 4px 8px;
        font-size: 10px;
    }

    .room-info {
        font-size: 12px;
    }

    .room-link-info p {
        font-size: 12px !important;
    }

    .room-link-info input {
        font-size: 10px !important;
        padding: 6px 8px !important;
    }

    .room-link-info button {
        font-size: 10px !important;
        padding: 6px 8px !important;
        min-width: auto;
    }

    .fullscreen-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
        bottom: 5px;
        right: 5px;
    }

    .video-overlay {
        bottom: 5px;
        left: 5px;
        right: 5px;
        padding: 8px;
    }

    .stats-display {
        font-size: 9px;
    }

    /* Room selection ultra mobile */
    #room-selection {
        padding: 20px 10px;
    }

    #room-selection h2 {
        font-size: 1.3em;
        margin-bottom: 20px;
    }

    /* Footer ultra mobile styles */
    .room-footer {
        padding: 12px;
        margin-top: 12px;
        font-size: 0.75em;
    }

    .footer-tagline {
        font-size: 0.85em;
        margin-bottom: 6px;
    }

    .footer-brand {
        font-size: 0.75em;
    }

    /* Ultra mobile adjustments */
    .mobile-menu-btn {
        top: 15px !important;
        right: 15px !important;
        width: 45px !important;
        height: 45px !important;
    }

    .mobile-slide-panel {
        width: 95% !important;
    }

    .slide-panel-header {
        padding: 15px !important;
    }

    .slide-panel-header h3 {
        font-size: 1.1em !important;
    }

    .mobile-participants-section,
    .mobile-chat-section h4 {
        padding: 15px !important;
    }

    .mobile-chat-messages {
        padding: 0 15px !important;
        min-height: 150px !important;
    }

    .mobile-chat-input-container {
        padding: 12px 15px 15px 15px !important;
    }

    .mobile-chat-input {
        padding: 10px 14px !important;
        font-size: 13px !important;
    }

    .mobile-chat-send {
        width: 40px !important;
        height: 40px !important;
        font-size: 14px !important;
    }

    .mobile-remote-videos {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)) !important;
        gap: 8px !important;
    }

    /* Full screen video on ultra mobile */
    .main-content {
        height: calc(100vh - 8vh - 12vh) !important;
    }

    .section {
        padding: 8px;
    }

    .chat-messages {
        font-size: 11px;
        padding: 6px;
        max-height: 100px;
        overflow-y: auto;
    }

    .chat-message {
        padding: 3px 5px;
        margin-bottom: 4px;
        font-size: 10px;
    }

    .chat-input {
        font-size: 11px;
        padding: 6px 8px;
        height: 32px;
    }

    .chat-send {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    /* Bottom panel stays floating on ultra mobile */
    .bottom-panel {
        padding: 10px 15px;
        bottom: 95px;
    }

    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }

    header h1 {
        font-size: 1.3em;
    }

    header p {
        font-size: 0.7em;
    }

    /* Ensure controls are visible above everything else */
    .controls {
        z-index: 1001;
        display: flex;
        justify-content: center;
        gap: 15px;
        margin-bottom: 8px;
    }

    /* Prevent container overflow */
    .container {
        overflow-y: auto;
        max-height: 100vh;
    }

    /* Improve video container sizing */
    .local-video-container video,
    .remote-videos-container video {
        max-height: 160px;
        object-fit: cover;
    }

    /* Chat container improvements */
    .chat-container {
        height: 130px;
        overflow: hidden;
    }

    /* На маленьких экранах максимум 2 столбца */
    .remote-videos-container.participants-3,
    .remote-videos-container.participants-4,
    .remote-videos-container.participants-5,
    .remote-videos-container.participants-6,
    .remote-videos-container.participants-7,
    .remote-videos-container.participants-8,
    .remote-videos-container.participants-9 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
