/* ===== АДАПТИВНОСТЬ (МОБИЛЬНАЯ ВЕРСИЯ) ===== */

/* ---- ПЛАНШЕТЫ И МАЛЕНЬКИЕ ЭКРАНЫ ---- */
@media screen and (max-width: 768px) {
    .messenger {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        flex-direction: column;
        position: relative;
        width: 100%;
        max-width: 100%;
        overflow: visible;
        padding: 0;
        background: #16161c;
    }

    .sidebar {
        width: 100%;
        min-width: unset;
        height: 100%;
        border-right: none;
        display: flex !important;
        flex-direction: column;
        flex: 1;
        border-radius: 0;
        margin: 0;
        background: #16161c;
    }

    /* Чат на мобильных — поверх всей страницы */
    .chat {
        display: none !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        border-radius: 0 !important;
        flex-direction: column;
        margin: 0 !important;
        box-shadow: none !important;
    }

    /* Настройки на мобильных — заменяют сайдбар */
    .settings-page {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        min-width: unset !important;
        height: 100%;
        z-index: 100;
        border-radius: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }
    .settings-layout {
        flex-direction: column;
    }
    .settings-sidebar {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: none;
        max-height: none;
        flex: 1;
        overflow-y: auto;
    }
    .settings-content-panel {
        display: none !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 110;
        background: #16161c;
    }
    .settings-content-panel.visible {
        display: flex !important;
    }
    .settings-list-item.active {
        background: transparent;
    }

    .chat.active {
        display: flex !important;
        flex-direction: column;
    }

    .chat.active ~ .bottom-nav-wrap,
    .chat.active + .bottom-nav-wrap,
    .settings-page.active ~ .bottom-nav-wrap {
        display: none !important;
    }

    .chat-header {
        border-radius: 999px !important;
        margin: 0 10px;
        min-height: 52px;
        padding: 8px 16px;
        background: rgba(30, 30, 35, 0.5) !important;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        border: none !important;
        border-bottom: 1px solid rgba(255,255,255,0.06) !important;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.35);
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        z-index: 10;
    }

    .chat-input {
        position: fixed;
        bottom: 30px;
        left: 10px;
        right: 10px;
        z-index: 100;
        padding: 6px 10px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
        gap: 8px;
        flex-wrap: nowrap;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }
    .chat-input .attach-btn,
    .chat-input .microphone-btn {
        background: rgba(30, 30, 35, 0.5) !important;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: none !important;
        border-top: 1px solid rgba(255,255,255,0.06) !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    }
    .chat-input .input-wrapper {
        background: rgba(30, 30, 35, 0.5) !important;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: none !important;
        border-top: 1px solid rgba(255,255,255,0.06) !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    }

    .chat-messages {
        padding: 12px 16px;
        padding-top: 72px;
        padding-bottom: 120px;
        background: #121217;
    }

    .message {
        max-width: 80%;
        font-size: 14px;
        padding: 8px 14px;
    }

    .chat-header .back-btn-mobile {
        display: flex !important;
        font-size: 28px;
        color: rgb(151, 0, 178);
        background: none;
        border: none;
        padding: 4px 8px;
        cursor: pointer;
        line-height: 1;
    }

    .chat-header .back-btn-mobile:hover {
        color: rgb(130, 0, 155);
    }

    .avatar-crop-box {
        width: 95%;
    }

    .profile-modal {
        padding: 24px;
        width: 95%;
        max-width: 95%;
        margin: 20px;
    }

    .gift-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }

    .gift-image {
        width: 100px;
        height: 100px;
    }

    .gift-emoji {
        font-size: 64px !important;
    }

    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
    }

    .dev-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .profile-gifts-grid {
        grid-template-columns: repeat(5, 44px);
    }

    .side-menu-content {
        width: 260px;
        left: -260px;
    }

    .side-menu.active .side-menu-content {
        left: 0;
    }

    /* ===== МОБИЛЬНАЯ НИЖНЯЯ ПАНЕЛЬ (Telegram-style, во всю ширину) ===== */
    .bottom-nav-wrap {
        display: block;
        position: fixed;
        bottom: 40px;
        left: 15px;
        right: 15px;
        width: auto;
        padding: 0;
        z-index: 200;
        pointer-events: none;
    }
    .bottom-nav-wrap > * {
        pointer-events: auto;
    }
    .bottom-nav-wrap > .bottom-nav {
        position: static;
        width: 100%;
        max-width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-around;
        background: rgba(30, 30, 35, 0.5);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: none;
        border-top: 1px solid rgba(255,255,255,0.06);
        border-radius: 24px;
        padding: 6px 8px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
        z-index: 200;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    }

    .nav-item {
        width: auto;
        min-width: 52px;
        height: 44px;
        border-radius: 14px;
        gap: 1px;
        padding: 2px 6px;
        position: relative;
        z-index: 1;
        outline: none !important;
        -webkit-tap-highlight-color: transparent;
        box-shadow: none !important;
    }
    .nav-item:hover {
        background: transparent !important;
        color: #888 !important;
    }
    .nav-item:focus,
    .nav-item:focus-visible,
    .nav-item:focus-within {
        outline: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }
    .nav-item.active {
        color: #888;
        -webkit-user-select: none;
        user-select: none;
    }
    .nav-item:active {
        background: transparent !important;
        -webkit-tap-highlight-color: transparent;
    }
    .nav-item.active::after,
    .nav-item::after {
        content: none !important;
        display: none !important;
    }
    .nav-active-indicator {
        position: absolute;
        top: 4px;
        bottom: 4px;
        border-radius: 14px;
        background: rgba(151, 0, 178, 0.18);
        transition: left 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s cubic-bezier(0.25, 1, 0.5, 1);
        z-index: 0;
    }
    .nav-item svg {
        width: 22px;
        height: 22px;
    }
    .nav-label {
        display: block;
        font-size: 9px;
        font-weight: 500;
        line-height: 1;
        white-space: nowrap;
    }

    /* Кнопка поиска — внутри плашки, как 5-й элемент */
    .nav-search-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        border-radius: 14px;
        background: transparent;
        border: none;
        color: #888;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    .nav-search-btn:active {
        background: rgba(255,255,255,0.06);
        transform: scale(0.93);
    }

    .settings-content {
        padding: 16px;
    }

    .settings-item {
        font-size: 14px;
        padding: 12px 14px;
    }

    .settings-profile {
        padding: 12px;
        gap: 12px;
    }

    .settings-avatar {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }

    .settings-name #settingsDisplayName {
        font-size: 18px;
    }

    .search-container {
        padding: 8px 12px;
    }

    #searchInput {
        font-size: 13px;
        padding: 6px 12px;
    }

    #searchBtn {
        padding: 6px 12px;
        font-size: 13px;
    }

    .dialog-item {
        padding: 8px 10px;
        gap: 10px;
    }

    .dialog-name {
        font-size: 14px;
    }

    .dialog-last-message {
        font-size: 12px;
    }

    .dialog-avatar .avatar {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }
}

/* ---- МАЛЕНЬКИЕ ТЕЛЕФОНЫ (до 480px) ---- */
@media screen and (max-width: 480px) {
    .auth-container {
        padding: 24px;
        width: 95%;
    }

    .auth-logo h1 {
        font-size: 24px;
    }

    .logo-image {
        width: 60px;
        height: 60px;
    }

    .settings-content {
        padding: 12px;
    }

    .settings-profile {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .settings-avatar {
        width: 72px;
        height: 72px;
        font-size: 28px;
    }

    .settings-name #settingsDisplayName {
        font-size: 17px;
    }

    .chat-messages {
        padding: 10px 12px;
        padding-top: 72px;
        padding-bottom: 120px;
        background: #121217;
    }

    .message {
        max-width: 85%;
        font-size: 13px;
        padding: 7px 12px;
    }

    .chat-input {
        padding: 8px 10px;
        gap: 6px;
    }

    .attach-btn,
    .emoji-btn,
    .microphone-btn {
        width: 36px;
        height: 36px;
        font-size: 17px;
    }

    #messageInput {
        font-size: 14px;
        padding: 8px 12px;
    }

    .send-btn {
        padding: 6px 14px;
        font-size: 13px;
        min-width: 60px;
    }

    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
        max-height: 180px;
    }

    .emoji-panel {
        max-width: 100%;
        left: 0;
        right: 0;
        bottom: 60px;
        border-radius: 16px 16px 0 0;
        max-height: 280px;
    }

    .dev-stats {
        grid-template-columns: 1fr;
    }

    .gift-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .gift-image {
        width: 70px;
        height: 70px;
    }

    .gift-emoji {
        font-size: 40px !important;
    }

    .gift-card {
        padding: 12px 8px;
    }

    .gift-name {
        font-size: 12px;
    }

    .gift-price {
        font-size: 12px;
    }

    .gift-buy-btn {
        font-size: 12px;
        padding: 4px 10px;
    }

    .profile-gifts-grid {
        grid-template-columns: repeat(4, 40px);
    }

    .profile-gift-emoji {
        width: 40px;
        height: 40px;
        font-size: 40px;
    }

    .profile-modal {
        padding: 20px;
        width: 95%;
        max-width: 95%;
        margin: 10px;
    }

    .profile-modal .profile-avatar {
        width: 64px;
        height: 64px;
        font-size: 26px;
    }

    .profile-modal .profile-fullname {
        font-size: 18px;
    }

    .profile-modal .profile-username {
        font-size: 13px;
    }

    .profile-modal .profile-bio {
        font-size: 13px;
        padding: 10px 12px;
    }

    .profile-modal .profile-info-row {
        font-size: 13px;
        padding: 6px 0;
    }

    .dialog-item {
        padding: 6px 8px;
        gap: 8px;
    }

    .dialog-name {
        font-size: 13px;
    }

    .dialog-last-message {
        font-size: 11px;
    }

    .dialog-avatar .avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .unread-badge {
        font-size: 10px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
    }

    .dialog-time {
        font-size: 10px;
    }

    .side-menu-content {
        width: 240px;
        left: -240px;
    }

    .side-menu-item {
        font-size: 14px;
        padding: 10px 16px;
    }

    .menu-avatar {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }

    .menu-display-name {
        font-size: 14px;
    }

    .menu-username {
        font-size: 12px;
    }

    .currency-icon-wrap {
        width: 32px;
        height: 32px;
    }

    .currency-icon {
        width: 20px;
        height: 20px;
    }

    .currency-balance {
        font-size: 13px;
    }

    .ticket-item {
        padding: 10px 12px;
    }

    .ticket-message {
        font-size: 13px;
    }

    .ticket-user {
        font-size: 13px;
    }

    .ticket-status {
        font-size: 11px;
        padding: 1px 8px;
    }
}

/* ---- ОЧЕНЬ МАЛЕНЬКИЕ ЭКРАНЫ (до 360px) ---- */
@media screen and (max-width: 360px) {
    .chat-messages {
        padding: 8px 10px;
        padding-top: 72px;
        padding-bottom: 120px;
        background: #121217;
    }

    .message {
        max-width: 90%;
        font-size: 12px;
        padding: 6px 10px;
    }

    .chat-input {
        padding: 6px 8px;
        gap: 4px;
    }

    .attach-btn,
    .emoji-btn,
    .microphone-btn {
        width: 32px;
        height: 32px;
        font-size: 15px;
    }

    #messageInput {
        font-size: 13px;
        padding: 6px 10px;
    }

    .send-btn {
        padding: 4px 10px;
        font-size: 12px;
        min-width: 50px;
    }

    .chat-header {
        padding: 8px 12px;
        min-height: 50px;
    }

    .chat-user-name {
        font-size: 14px;
    }

    .chat-user-status {
        font-size: 11px;
    }

    .chat-avatar-wrapper .avatar-chat {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .gift-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .gift-image {
        width: 60px;
        height: 60px;
    }

    .gift-emoji {
        font-size: 32px !important;
    }

    .gift-card {
        padding: 10px 6px;
    }

    .gift-name {
        font-size: 11px;
    }

    .gift-price {
        font-size: 11px;
    }

    .gift-buy-btn {
        font-size: 11px;
        padding: 3px 8px;
    }

    .profile-gifts-grid {
        grid-template-columns: repeat(3, 36px);
    }

    .profile-gift-emoji {
        width: 36px;
        height: 36px;
        font-size: 36px;
    }

    .emoji-grid {
        grid-template-columns: repeat(5, 1fr);
        max-height: 150px;
    }

    .emoji-item {
        font-size: 20px;
        padding: 4px 2px;
    }

    .side-menu-content {
        width: 200px;
        left: -200px;
    }

    .side-menu-item {
        font-size: 13px;
        padding: 8px 14px;
    }

    .menu-avatar {
        width: 36px;
        height: 36px;
        font-size: 15px;
    }

    .menu-display-name {
        font-size: 13px;
    }

    .menu-username {
        font-size: 11px;
    }

    .auth-container {
        padding: 16px;
        width: 98%;
    }

    .auth-logo h1 {
        font-size: 20px;
    }

    .auth-form input {
        padding: 10px 12px;
        font-size: 13px;
    }

    .auth-form button {
        padding: 10px;
        font-size: 14px;
    }

    .settings-item {
        font-size: 13px;
        padding: 10px 12px;
    }

    .settings-arrow {
        font-size: 17px;
    }

    .settings-header h2 {
        font-size: 16px;
    }

    .settings-header {
        padding: 12px 16px;
    }
}
