/* public/css/responsive.css */

/*
 * Twarde zabezpieczenie widoku desktopowego. Dolny pasek nie może stać się
 * dodatkową kolumną, nawet jeśli inny arkusz CSS zostanie wczytany z cache.
 * Reguła mobilna poniżej nadpisuje to ustawienie wyłącznie do 768 px.
 */
#nav-rail {
    display: none !important;
}

/* ========================================
   RESPONSYWNOŚĆ (Średnie laptopy i okna iframe)
========================================= */
@media (max-width: 1280px) {
    #right-widgets-sidebar {
        width: 270px;
        padding: 1rem;
    }
    #chat-list-panel {
        width: 250px;
    }
    .main-content-view {
        padding: 1.5rem 1.25rem;
    }
}

/* ========================================
   RESPONSYWNOŚĆ (Tablety i mniejsze ekrany)
========================================= */
@media (max-width: 1024px) {
    /* Zwijany prawy panel widgetów aktywacji na tabletach i w Multi-Noduś */
    #right-widgets-sidebar {
        display: none;
    }
    #right-widgets-sidebar.open {
        display: flex;
        position: fixed;
        top: 0; right: 0;
        width: 320px;
        max-width: 85%;
        height: 100%;
        z-index: var(--z-sidebar);
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.4);
    }

    /* Pokaż dzwonek aktywności/powiadomień w pasek nawigacji gdy prawy panel jest zwinięty */
    #mobile-notification-btn {
        display: inline-flex !important;
    }

    /* Panel Szczegółów Czatu */
    #chat-details-panel {
        display: none;
    }
    #chat-details-panel.open {
        display: flex;
        position: fixed;
        top: 0; right: 0;
        width: 320px;
        max-width: 85%;
        height: 100%;
        z-index: var(--z-sidebar);
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.4);
    }

    /* Zmniejsz paddingi sceny głównej */
    .main-content-view { padding: 1.25rem 1rem; }
    #chat-messages { padding: 1rem; }
    #message-input-area { padding: 0.75rem 1rem; }

    .topic-tiles-grid {
        gap: 0.75rem;
    }

    /* Kompaktowe 2-kolumnowe przyciski nawigacyjne na mniejszych ekranach / Multi-Noduś */
    .sidebar-nav-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
        padding: 0 0.85rem;
    }

    .sidebar-nav-grid .sidebar-action-btn {
        padding: 0.45rem 0.5rem;
        font-size: 0.82rem;
        font-weight: 600;
        justify-content: center;
        border-radius: 10px;
        white-space: nowrap;
    }
}

/* ========================================
   RESPONSYWNOŚĆ (Telefony i smartfony)
========================================= */
@media (max-width: 768px) {
    #app-container {
        flex-direction: column;
    }

    #issue-report-modal {
        top: calc(50% - (env(safe-area-inset-bottom) / 2));
        width: calc(100% - 1rem);
        max-height: calc(100dvh - 1rem - env(safe-area-inset-bottom));
        border-radius: 18px;
    }

    .issue-report-dialog {
        padding: 1.1rem;
    }

    .issue-report-row,
    .issue-report-row:first-child {
        grid-template-columns: 1fr;
    }

    .issue-report-header p {
        font-size: 0.82rem;
    }

    .issue-report-actions {
        position: sticky;
        bottom: -1.1rem;
        margin: 0 -1.1rem -1.1rem;
        padding: 0.85rem 1.1rem calc(0.85rem + env(safe-area-inset-bottom));
        background: var(--secondary-bg);
        border-top: 1px solid var(--border-color);
    }

    /* --- BOTTOM NAVIGATION (dawny Nav Rail) --- */
    #nav-rail {
        display: flex !important;
        width: 100%;
        height: calc(65px + env(safe-area-inset-bottom));
        min-height: calc(65px + env(safe-area-inset-bottom));
        flex-shrink: 0;
        flex-direction: row;
        align-items: center;
        padding: 0 1rem env(safe-area-inset-bottom);
        gap: 0;
        justify-content: space-around;
        order: 2; /* Przenieś na dół w kontenerze flex */
        background-color: var(--secondary-bg);
        border-top: 1px solid var(--border-color);
        overflow-y: hidden;
        z-index: var(--z-drawer);
        pointer-events: auto;
    }

    .nav-rail-btn {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
        background: transparent;
        color: var(--secondary-text);
        border: 0;
        border-radius: 14px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        cursor: pointer;
        touch-action: manipulation;
        pointer-events: auto;
        transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
    }

    .nav-rail-btn:hover,
    .nav-rail-btn.active {
        color: var(--accent-color);
        background-color: rgba(0, 242, 254, 0.12);
    }

    .nav-rail-btn:active {
        transform: scale(0.94);
    }

    .mobile-stranger-status-btn {
        width: auto;
        min-width: 72px;
        padding: 4px 10px;
        gap: 3px;
        flex-direction: column;
        color: var(--accent-color);
        background-color: rgba(0, 242, 254, 0.1);
        border: 1px solid rgba(0, 242, 254, 0.3);
    }

    .mobile-stranger-status-btn.connected {
        color: var(--green-online);
        background-color: rgba(46, 213, 115, 0.12);
        border-color: rgba(46, 213, 115, 0.38);
    }

    .mobile-stranger-status-btn span {
        max-width: 76px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.62rem;
        font-weight: 700;
        line-height: 1;
    }

    .mobile-stranger-status-btn .fa-circle {
        font-size: 0.58rem;
    }

    .nav-rail-spacer { display: none; }

    /* Funkcje przeniesione do dolnej nawigacji nie są dublowane na mobilce. */
    #menu-toggle-btn,
    #mobile-notification-btn,
    #chat-list-panel .my-profile-mini-card,
    #chat-list-panel .sidebar-nav-grid,
    #chat-list-panel .my-profile-mini-card + .sidebar-section-divider,
    #chat-list-panel .sidebar-nav-grid + .sidebar-section-divider {
        display: none !important;
    }

    #my-profile-avatar-nav {
        width: 36px;
        height: 36px;
    }

    /* --- LISTA CZATÓW (Panel 2 - Wysuwana Szuflada) --- */
    #chat-list-panel {
        position: fixed;
        left: 0;
        top: 0;
        height: calc(100dvh - 65px - env(safe-area-inset-bottom));
        z-index: var(--z-drawer);
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 5px 0 20px rgba(0,0,0,0.35);
        width: 85%;
        max-width: 320px;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }
    
    #chat-list-panel.open {
        transform: translateX(0);
    }

    /* --- GŁÓWNY OBSZAR SCENY (Panel 3) --- */
    #main-chat-area {
        height: calc(100dvh - 65px - env(safe-area-inset-bottom));
        order: 1;
    }

    /* Widok Powitalny & Kafelki na mobilce */
    #welcome-view {
        padding: 1rem 0.5rem 2rem 0.5rem;
    }
    #welcome-view h1 {
        font-size: 1.5rem;
    }

    .hero-search-card {
        padding: 1.25rem 1rem;
    }
    .hero-search-btn {
        width: 100%;
        padding: 0.8rem 1rem;
        font-size: 1rem;
    }

    .topic-tiles-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.6rem;
    }
    .topic-tile {
        padding: 0.85rem 0.65rem;
    }
    .topic-tile-icon {
        font-size: 1.2rem;
    }
    .topic-tile-title {
        font-size: 0.88rem;
    }
    .topic-tile-subtitle {
        font-size: 0.72rem;
    }

    .recent-strangers-section {
        max-height: 240px;
        padding: 0.85rem;
        display: flex;
        flex-direction: column;
        flex: 0 0 auto;
        overflow: hidden;
    }

    .recent-strangers-header {
        flex: 0 0 auto;
    }

    .recent-strangers-grid {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        scrollbar-width: none;
    }

    .recent-strangers-grid::-webkit-scrollbar {
        display: none;
    }

    .recent-stranger-card {
        flex: 0 0 auto;
        gap: 0.5rem;
        padding: 0.7rem 0.75rem;
    }

    .recent-stranger-info,
    .recent-stranger-details {
        min-width: 0;
    }

    .recent-stranger-info {
        flex: 1 1 auto;
    }

    .recent-stranger-actions {
        margin-left: 0.35rem;
    }

    /* Przycisk hamburgera */
    #menu-toggle-btn { display: inline-flex; }

    /* Powiadomienia mobilne */
    #nav-notifications-btn { display: none; }
    #mobile-notification-btn { display: inline-flex; }
    #right-widgets-sidebar > .notification-panel {
        position: static;
        inset: auto;
        width: 100%;
        max-height: none;
        flex: 0 0 auto;
        z-index: auto;
        border-radius: 18px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
        animation: none;
    }

    #right-widgets-sidebar.open > .notification-panel.hidden {
        display: block !important;
    }

    #right-widgets-sidebar > .notification-panel #notification-list {
        max-height: min(32dvh, 280px);
        overscroll-behavior: contain;
    }

    /* --- NAVBAR --- */
    .navbar { 
        padding: 0.5rem 0.75rem; 
        min-height: 56px; 
    }

    /* Kompaktowy licznik online */
    .global-online-count {
        padding: 3px 8px;
        font-size: 0.78rem;
        margin-right: 0.25rem;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .global-online-count .online-label {
        display: none;
    }

    #chat-partner-info { gap: 0.4rem; }
    .chat-partner-avatar { width: 32px; height: 32px; }
    .chat-partner-name { 
        font-size: 0.95rem; 
        max-width: 120px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* --- CZAT I INPUT --- */
    .main-content-view { padding: 0.5rem; }
    #chat-messages { padding: 0.5rem; }
    
    #message-input-area { 
        padding: 0.4rem 0.5rem; 
        background-color: var(--secondary-bg);
    }
    .input-controls-wrapper { 
        padding: 0.3rem 0.5rem; 
        gap: 0.25rem;
        align-items: center;
        width: 100%;
    }
    .input-controls-wrapper .icon-btn { 
        width: 34px; 
        height: 34px; 
        font-size: 1rem;
        flex-shrink: 0;
        padding: 0;
    }
    .input-controls-wrapper .emoji-container #emojiBtn img {
        width: 22px;
        height: 22px;
    }
    #msgInput { 
        flex: 1 1 auto;
        min-width: 60px;
        padding: 0.5rem 0.6rem; 
        font-size: 1rem; /* Zapobiega automatycznemu zoomowaniu na iOS */
    }
    #sendBtn { 
        padding: 0; 
        width: 38px;
        height: 34px; 
        font-size: 0;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        background: linear-gradient(135deg, #00f2fe, #00c6ff);
        color: #06101e;
        border: none;
    }
    #sendBtn::after {
        content: '\f1d8'; /* Font Awesome paper plane icon */
        font-family: 'Font Awesome 6 Free';
        font-weight: 900;
        font-size: 0.95rem;
    }

    /* Dymki wiadomości */
    .message { max-width: 92%; }
    .message-content { font-size: 0.95rem; padding: 0.5rem 0.8rem; }
    .message-avatar { width: 30px; height: 30px; }

    /* Panel szczegółów na mobilce */
    #right-widgets-sidebar.open,
    #chat-details-panel.open {
        width: 85%;
        max-width: 320px;
        height: calc(100dvh - 65px - env(safe-area-inset-bottom));
    }

    /*
     * Tryb pisania wiadomości. Klasa jest ustawiana wyłącznie wtedy, gdy
     * klawiatura ekranowa faktycznie zmniejszy viewport pola #msgInput.
     */
    body.mobile-chat-keyboard-open #nav-rail {
        display: none !important;
    }

    body.mobile-chat-keyboard-open #app-container {
        position: fixed;
        top: var(--chat-visual-viewport-offset-top, 0px);
        right: 0;
        bottom: auto;
        left: 0;
        width: 100%;
        height: var(--chat-visual-viewport-height, 100dvh);
        min-height: 0;
    }

    body.mobile-chat-keyboard-open #main-chat-area {
        order: 1;
        height: 100%;
        min-height: 0;
    }

    body.mobile-chat-keyboard-open #main-content-wrapper,
    body.mobile-chat-keyboard-open #chat-view,
    body.mobile-chat-keyboard-open #chat-messages {
        min-height: 0;
    }

    body.mobile-chat-keyboard-open #message-input-area {
        padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
    }
}

/* ========================================
   RESPONSYWNOŚĆ (BARDZO MAŁE TELEFONY <= 480px)
========================================= */
@media (max-width: 480px) {
    .topic-tiles-grid {
        grid-template-columns: 1fr; /* Pionowy stos kafelków na miniaturowych ekranach */
    }
    .chat-filter-pills {
        gap: 0.25rem;
    }
    .filter-pill {
        padding: 0.3rem 0.25rem;
        font-size: 0.72rem;
    }
    .hero-search-card {
        padding: 1rem 0.75rem;
    }
    .hero-title {
        font-size: 1.15rem;
    }
}

/* Fix dla ekranów <= 360px */
@media (max-width: 360px) {
    .nav-rail-btn { width: 38px; height: 38px; font-size: 1.1rem; }
    .mobile-stranger-status-btn { width: auto; min-width: 62px; padding-inline: 7px; }
    .chat-partner-name { max-width: 80px; }
    .global-online-count { font-size: 0.72rem; padding: 2px 6px; }
}
