/* ==========================================
   ГЛОБАЛЬНЫЙ СБРОС И НАТИВНЫЕ ОПТИМИЗАЦИИ
   ========================================== */
* {
    -webkit-tap-highlight-color: transparent !important; /* Убираем синее мигание при клике */
    -webkit-touch-callout: none !important; /* Отключаем системное меню "Копировать/Сохранить" при долгом тапе */
    user-select: none; /* Запрещаем выделять элементы интерфейса как текст */
    overscroll-behavior-y: none; /* Отключаем "резиновую" прокрутку (Pull-to-refresh) */
    box-sizing: border-box;
}

/* Разрешаем выделять текст ТОЛЬКО внутри сообщений и полей ввода */
.msg, textarea, input {
    user-select: text;
}

/* ==========================================
   БАЗОВЫЙ КАРКАС ПРИЛОЖЕНИЯ (ФИКС СЕРОЙ ПОЛОСЫ)
   ========================================== */
html, body {
    background-color: #f5f7fb; /* Светлый фон всего приложения */
    color: #333333;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0; 
    padding: 0; 
    
    width: 100%;
    height: 100%; 
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0;
    
    display: flex; 
    flex-direction: column; 
    overflow: hidden;
}

/* ==========================================
   ШАПКА И СТАТУС-БАР
   ========================================== */
.header {
    background: #ffffff; 
    padding: max(15px, env(safe-area-inset-top, 15px)) 15px 15px 15px; 
    text-align: center; 
    font-weight: bold; 
    border-bottom: 1px solid #e0e0e0;
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    flex-shrink: 0;
    z-index: 100;
}

.btn-small { 
    background: #e3f2fd; 
    color: #4a90e2; 
    border: none; 
    padding: 5px 10px; 
    border-radius: 10px; 
    font-size: 12px; 
    cursor: pointer; 
    font-weight: 600;
}

#status-bar { 
    background: #e3f2fd; 
    text-align: center; 
    font-size: 11px; 
    padding: 5px; 
    color: #4a90e2; 
    font-weight: bold; 
    flex-shrink: 0; 
    transition: background 0.3s ease; 
}
#status-bar.restoring { background: #ff9800; color: white; }

/* ==========================================
   СПИСКИ И ЧАТ (ПЛАВНЫЙ СКРОЛЛ)
   ========================================== */
#contact-list { 
    display: flex; 
    flex-direction: column; 
    overflow-y: auto; 
    background: #f5f7fb; 
    flex: 1; 
    min-height: 0;
    padding-bottom: 50px; 
    -webkit-overflow-scrolling: touch; /* Нативный скролл */
}

#chat { 
    flex: 1; 
    min-height: 0;
    padding: 15px; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    background: #efece5; 
    -webkit-overflow-scrolling: touch; /* Нативный скролл */
}

/* ==========================================
   КОНТАКТЫ
   ========================================== */
.contact-card { background: #ffffff; padding: 12px 15px; display: flex; align-items: center; gap: 15px; border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background 0.2s; }
.contact-card:active { background: #f0f4f8; }
.contact-avatar { width: 50px; height: 50px; border-radius: 50%; background: linear-gradient(135deg, #85c4f2, #4a90e2); color: white; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; flex-shrink: 0; }
.contact-info { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.contact-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.contact-name { font-weight: bold; color: #333333; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { color: #888888; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge { background: #ff4d4d; color: white; font-size: 11px; padding: 2px 7px; border-radius: 10px; font-weight: bold; flex-shrink: 0; }
.contact-actions { display: flex; gap: 12px; font-size: 16px; flex-shrink: 0; }
.contact-actions span { cursor: pointer; padding: 5px; background: #f0f4f8; border-radius: 8px; color: #4a90e2;}

/* ==========================================
   СООБЩЕНИЯ
   ========================================== */
.msg { max-width: 80%; padding: 10px 15px; border-radius: 15px; margin-bottom: 10px; font-size: 15px; line-height: 1.4; word-wrap: break-word; box-shadow: 0 1px 2px rgba(0,0,0,0.1); color: #333333;}
.msg.in { background: #ffffff; align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.out { background: #e3f2fd; align-self: flex-end; border-bottom-right-radius: 5px; }
.msg small { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 10px; color: #888888; margin-top: 5px; }

.circle-video { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; border: 3px solid #4a90e2; }
#video-preview-container { display: none; position: absolute; bottom: 130px; right: 20px; width: 150px; height: 150px; border-radius: 50%; overflow: hidden; border: 3px solid #ff4d4d; box-shadow: 0 5px 15px rgba(0,0,0,0.2); z-index: 100; }
#video-preview { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

/* ==========================================
   ПАНЕЛЬ ВВОДА (ИДЕАЛЬНАЯ ПРИВЯЗКА К НИЗУ)
   ========================================== */
.controls { 
    display: flex; 
    align-items: flex-end; 
    padding: 8px 10px;
    padding-bottom: max(45px, calc(30px + env(safe-area-inset-bottom, 0px)));
    background: #ffffff; 
    border-top: 1px solid #e0e0e0; 
    gap: 8px; 
    flex-shrink: 0; 
    z-index: 10;
    flex-wrap: nowrap;
    min-width: 0;
    overflow: visible;
    position: relative;
}


.input-area {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    background: #f0f4f8;
    border-radius: 20px;
    align-items: flex-end;
    padding: 0 4px;
    min-height: 40px;
    overflow: hidden;
}
textarea#content {
    flex: 1 1 0;
    min-width: 0;
    background: transparent;
    border: none;
    color: #333333;
    font-size: max(14px, 0.875rem);
    padding: 8px 6px;
    outline: none;
    resize: none;
    height: 40px;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.25;
    font-family: inherit;
    overflow-y: auto;
}
.input-area button {
    background: none;
    border: none;
    color: #888888;
    font-size: clamp(16px, 4.5vw, 20px);
    padding: 6px 4px;
    cursor: pointer;
    min-height: 40px;
    min-width: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.controls > button {
    background: #4a90e2;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: clamp(16px, 5vw, 20px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.recording-active { color: #ff4d4d !important; animation: pulse 1s infinite; }
@keyframes pulse { 0% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.1); } 100% { opacity: 1; transform: scale(1); } }

/* ==========================================
   МОДАЛЬНЫЕ ОКНА И ИНПУТЫ
   ========================================== */
.modal {
    display: none;
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: #ffffff !important;
    padding: 25px !important;
    border-radius: 20px !important;
    z-index: 10000 !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15) !important;
    width: 85% !important;
    max-width: 340px !important;
    border: 1px solid #e0e0e0 !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: auto !important;
}
.modal h3 { margin-top: 0; color: #4a90e2; text-align: center; font-size: 18px; }
.modal input { width: 100%; padding: 12px; margin-bottom: 15px; background: #f5f7fb; border: 1px solid #e0e0e0; color: #333333; border-radius: 12px; box-sizing: border-box; }
/* Клавиатура + трёхкнопочная навигация: прокрутка вместо «белой полосы», единый фон */
#web3-auth-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    background: #ffffff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    text-align: center;
    padding: max(20px, env(safe-area-inset-top, 0px)) 20px calc(24px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.auth-input { width: 100%; padding: 15px; margin-bottom: 15px; background: #f5f7fb; border: 1px solid #4a90e2; color: #333333; border-radius: 15px; text-align: center; font-size: 16px; }
.btn-primary { background: #4a90e2; color: white; padding: 15px; width: 100%; border-radius: 15px; border: none; font-weight: bold; font-size: 16px; cursor: pointer; }

/* ==========================================
   ГАЛЕРЕЯ, МЕДИА И ИНВАЙТЫ
   ========================================== */
#chat-media-list { max-height: 350px !important; padding: 8px !important; background: #f0f4f8; border-radius: 12px; border: 1px solid #e0e0e0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior-y: auto; }
.media-gallery-item { display: flex; align-items: center; padding: 12px 10px !important; margin-bottom: 6px !important; background: #ffffff; border: 1px solid #e0e0e0; border-radius: 8px; cursor: pointer; transition: background 0.2s ease; }
.media-gallery-item:active { background: #f5f7fb; }
.media-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-right: 12px; flex-shrink: 0; background: #e3f2fd; color: #4a90e2;}
.media-info { flex: 1; display: flex; flex-direction: column; }
.media-title { color: #333333; font-size: 14px; font-weight: bold; }
.media-sender { color: #4a90e2; font-size: 12px; font-weight: bold; margin: 3px 0; display: block; }
.media-date { color: #888888; font-size: 11px; display: block; }

.highlight-msg { animation: flashMessage 2s ease-out; }
@keyframes flashMessage { 0% { transform: scale(1); box-shadow: 0 0 0px rgba(74, 144, 226, 0); } 15% { transform: scale(1.02); box-shadow: 0 0 20px rgba(74, 144, 226, 0.4); background: #e3f2fd; } 100% { transform: scale(1); box-shadow: 0 0 0px rgba(74, 144, 226, 0); } }

.invite-card { background: #ffffff; border: 1px solid #4a90e2; border-radius: 12px; padding: 12px; margin-top: 5px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.invite-header { color: #ff9800; font-weight: bold; font-size: 13px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.invite-body { color: #333333; font-size: 14px; margin-bottom: 12px; line-height: 1.4; }
.invite-room-name { color: #4a90e2; font-size: 16px; font-weight: bold; display: inline-block; margin-top: 5px; }
.invite-btn { flex: 1; padding: 10px; border: none; border-radius: 8px; font-size: 13px; font-weight: bold; cursor: pointer; color: white; transition: opacity 0.2s; }
.invite-btn:active { opacity: 0.7; }
.invite-btn.accept { background: #4CAF50; }
.invite-btn.decline { background: #ff4d4d; }

.media-tabs-container { display: flex; justify-content: space-around; background: #ffffff; padding: 10px 5px; border-radius: 12px 12px 0 0; margin-bottom: 5px; }
.media-tab { color: #888888; font-size: 14px; font-weight: bold; padding: 6px 16px; border-radius: 20px; cursor: pointer; transition: all 0.2s ease; }
.media-tab.active { background: #e3f2fd; color: #4a90e2; }

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding-bottom: 10px; }
.media-grid-item { aspect-ratio: 1 / 1; background: #f0f4f8; position: relative; cursor: pointer; overflow: hidden; touch-action: pan-y; }
.media-grid-item img, .media-grid-item video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.video-grid-overlay { position: absolute; bottom: 5px; left: 5px; background: rgba(0, 0, 0, 0.6); color: white; font-size: 10px; padding: 3px 6px; border-radius: 5px; display: flex; align-items: center; gap: 4px; font-weight: bold; pointer-events: none; }

/* ==========================================
   БОМБОЧКИ
   ========================================== */
.bomb-timer-badge { background: #ff4d4d; color: white; font-size: 10px; font-weight: bold; padding: 2px 6px; border-radius: 6px; margin-left: 8px; display: inline-flex; align-items: center; gap: 3px; box-shadow: 0 0 5px rgba(255, 77, 77, 0.3); animation: pulse-bomb 1.5s infinite; }
@keyframes pulse-bomb { 0% { opacity: 1; } 50% { opacity: 0.6; } 100% { opacity: 1; } }

.msg-exploding { animation: explode-fade 1s forwards; }
@keyframes explode-fade { 0% { transform: scale(1); opacity: 1; filter: blur(0); } 50% { transform: scale(1.05); opacity: 0.5; filter: blur(2px); background: #ff4d4d; } 100% { transform: scale(0.8); opacity: 0; filter: blur(5px); display: none; } }

/* Скроллбары для модалок */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 3px; }

/* ==========================================
   📢 РЕКЛАМНЫЙ БАННЕР (Ad Banner)
   ========================================== */
#ad-banner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: adBannerFadeIn 0.3s ease-out;
}
#ad-banner-overlay.ad-banner-hiding {
    animation: adBannerFadeOut 0.4s ease-in forwards;
}
@keyframes adBannerFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes adBannerFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
#ad-banner-box {
    background: #ffffff;
    border: 2px solid #ff9800;
    border-radius: 20px;
    padding: 30px 25px;
    max-width: 380px;
    width: 85%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(255, 152, 0, 0.15), 0 0 0 1px rgba(255, 152, 0, 0.05);
    animation: adBannerPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes adBannerPop {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
#ad-banner-box .ad-badge {
    display: inline-block;
    background: #ff9800;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 20px;
    margin-bottom: 15px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
#ad-banner-box .ad-text {
    color: #333333;
    font-size: 18px;
    font-weight: bold;
    line-height: 1.4;
    margin-bottom: 12px;
}
#ad-banner-box .ad-subtext {
    color: #888888;
    font-size: 13px;
    margin-bottom: 18px;
}
#ad-banner-box .ad-image {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
}
#ad-banner-box .ad-link-btn {
    display: inline-block;
    background: #ff9800;
    color: #fff;
    padding: 12px 30px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 15px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}
#ad-banner-box .ad-link-btn:active {
    background: #e68900;
}
#ad-banner-timer {
    color: #888888;
    font-size: 12px;
    margin-top: 15px;
}
#ad-banner-close {
    position: absolute;
    top: 12px;
    right: 18px;
    background: rgba(0,0,0,0.05);
    border: none;
    color: #888888;
    font-size: 22px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
#ad-banner-close:hover {
    background: rgba(0,0,0,0.1);
    color: #333;
}