/* --- Global & Reset --- */
:root {
    --primary-gradient: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
    --glass-bg: rgba(255, 255, 255, 0.5);
    --glass-border: rgba(255, 255, 255, 0.6);
    --accent: #ff6b81;
    --text-main: #4a4a4a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Montserrat', sans-serif;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(45deg, #ff9a9e, #fad0c4, #a18cd1);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    display: flex; justify-content: center; align-items: center;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.container { width: 100%; height: 100%; padding: 20px; }

/* --- Login --- */
.login-card {
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(20px);
    border-radius: 24px; padding: 60px;
    text-align: center; max-width: 400px; margin: 0 auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.login-card h1 { color: #fff; margin-bottom: 10px; }
.login-card p { color: #fff; margin-bottom: 30px; }
.login-card input { width: 100%; padding: 15px; border-radius: 30px; border:none; margin-bottom: 20px; outline: none; }
.login-card button { width: 100%; padding: 15px; border-radius: 30px; border:none; background: var(--accent); color: white; cursor: pointer; font-weight: bold; transition: 0.3s; }
.login-card button:hover { transform: scale(1.05); }

/* --- GRID SYSTEM --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr; /* 25% - 50% - 25% */
    gap: 20px;
    width: 100%; height: 100%;
    max-width: 1400px; margin: 0 auto;
}

.panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 25px;
    overflow: hidden;
    display: flex; flex-direction: column;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
}

.panel h2 {
    padding: 20px; font-size: 1.2rem; color: var(--accent);
    text-align: center; border-bottom: 1px solid rgba(255,255,255,0.3);
}

/* --- LEFT PANEL: Wish Form --- */
.left-panel { padding: 20px; }
.wish-form-card { display: flex; flex-direction: column; gap: 15px; height: 100%; }
textarea {
    flex: 1; border-radius: 15px; border: none; padding: 15px;
    background: rgba(255,255,255,0.7); resize: none; font-family: inherit; outline: none;
}
.wish-form-card button {
    padding: 15px; border-radius: 15px; border: none;
    background: var(--accent); color: white; font-weight: bold; cursor: pointer;
}
.wish-form-card button:hover { background: #ff4757; }
.decor-image { font-size: 4rem; text-align: center; opacity: 0.3; margin-top: auto; padding-bottom: 20px; }

/* --- CENTER PANEL: Chat (PREMIUM STYLE) --- */
.chat-panel { position: relative; }
.chat-header {
    padding: 15px 20px; background: rgba(255, 255, 255, 0.4);
    display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.3);
}
.my-avatar-top { width: 35px; height: 35px; background: var(--accent); border-radius: 50%; color: white; display: flex; align-items: center; justify-content: center; }

/* Исправленный текст (добавлена тень для читаемости) */
.user-info { 
    display: flex; align-items: center; gap: 10px; font-weight: 600; color: white; 
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.title { 
    flex: 1; text-align: center; color: white; font-weight: bold; 
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Сообщения */
.messages-area {
    flex: 1; padding: 20px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 8px;
}

.msg-row {
    display: flex; align-items: flex-end; margin-bottom: 5px; max-width: 100%;
    animation: popIn 0.3s ease;
}

.avatar {
    width: 36px; height: 36px; min-width: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%);
    color: white; display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 14px; margin-right: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.bubble {
    position: relative; padding: 10px 14px; max-width: 70%;
    word-wrap: break-word; font-size: 0.95rem; line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1); display: flex; flex-direction: column;
}

/* Мои сообщения */
.my-msg { justify-content: flex-end; }
.my-msg .bubble {
    background: linear-gradient(135deg, #ff9a9e 0%, #feacee 100%);
    color: white; border-radius: 18px 18px 0 18px; margin-left: auto;
}
/* Хвостик справа */
.my-msg .bubble::before {
    content: ""; position: absolute; bottom: 0; right: -8px;
    width: 20px; height: 20px; background: inherit;
    clip-path: polygon(0 0, 0% 100%, 100% 100%); z-index: -1;
    border-bottom-left-radius: 10px;
}

/* Чужие сообщения */
.friend-msg { justify-content: flex-start; }
.friend-msg .bubble {
    background: #ffffff; color: #333;
    border-radius: 18px 18px 18px 0;
}
/* Хвостик слева */
.friend-msg .bubble::before {
    content: ""; position: absolute; bottom: 0; left: -8px;
    width: 20px; height: 20px; background: #ffffff;
    clip-path: polygon(100% 0, 100% 100%, 0 100%); z-index: 0;
}

.txt { margin-bottom: 2px; }
.time { font-size: 10px; align-self: flex-end; opacity: 0.7; margin-top: 2px; }
.my-msg .time { color: rgba(255,255,255,0.9); }
.friend-msg .time { color: #999; }

/* Ввод текста */
.input-area { padding: 15px; background: rgba(255,255,255,0.5); display: flex; gap: 10px; }
.input-area input { flex: 1; padding: 12px; border-radius: 20px; border: none; background: rgba(255,255,255,0.9); outline:none; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer; background: var(--accent); color: white; display:flex; align-items:center; justify-content:center;}
.icon-btn { background: transparent; border: none; font-size: 1.5rem; cursor: pointer; }

/* --- RIGHT PANEL: Wishes --- */
.right-panel { display: flex; flex-direction: column; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid rgba(255,255,255,0.3); }
.desktop-logout { font-size: 0.8rem; color: #4a4a4a; text-decoration: none; }
.wishes-list { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }

.wish-card {
    background: #fff9c4; padding: 15px;
    border-radius: 2px 2px 15px 2px;
    box-shadow: 2px 4px 10px rgba(0,0,0,0.1);
    transform: rotate(-1deg); transition: transform 0.3s;
}
.wish-card:nth-child(even) { background: #ffcdd2; transform: rotate(1deg); }
.wish-card:hover { transform: scale(1.02) rotate(0deg); z-index: 10; }
.wish-text { font-size: 1rem; color: #333; margin-bottom: 10px; font-family: 'Comic Sans MS', cursive, sans-serif; }
.wish-meta { font-size: 0.7rem; color: #666; text-align: right; }
.empty-state { text-align: center; opacity: 0.6; margin-top: 50px; }

/* Emoji */
.emoji-picker { position: absolute; bottom: 70px; left: 20px; width: 250px; background: rgba(255,255,255,0.95); border-radius: 15px; padding: 10px; display: none; grid-template-columns: repeat(5, 1fr); gap: 5px; box-shadow: 0 5px 20px rgba(0,0,0,0.1); z-index: 100; }
.emoji-picker.show { display: grid; }
.emoji-picker span { cursor: pointer; font-size: 1.5rem; padding: 5px; transition: 0.2s; }
.emoji-picker span:hover { transform: scale(1.3); }

/* --- MOBILE FIXES (МЕТОД: FIXED POSITION) --- */
/* --- MOBILE FIXES (МЕТОД: FLEXBOX / ЕСТЕСТВЕННЫЙ ПОТОК) --- */
@media (max-width: 900px) {
    .container { padding: 0; }
    
    /* Делаем из страницы гибкую колонку */
    .dashboard-grid { 
        display: flex;
        flex-direction: column;
        height: 100dvh; /* Динамическая высота экрана телефона */
        padding-top: 60px; /* Место под верхнее меню */
        overflow: hidden; /* Запрещаем скролл всей страницы, скроллим только чат */
    }
    
    .panel { display: none !important; }
    
    /* АКТИВНАЯ ВКЛАДКА */
    .chat-panel.active-tab { 
        display: flex !important; 
        flex-direction: column; /* Выстраиваем элементы сверху вниз */
        flex: 1; /* Занимаем всё доступное место */
        height: 100%;
        overflow: hidden;
    }

    .chat-header { display: none; }

    /* ЗОНА СООБЩЕНИЙ */
    .messages-area {
        flex: 1; /* Растягивается на всё свободное пространство */
        overflow-y: auto; /* Прокрутка ТОЛЬКО внутри сообщений */
        width: 100%;
        padding: 15px;
        padding-bottom: 20px;
    }

    /* ПОЛЕ ВВОДА */
    .input-area {
        /* Больше не fixed! Оно теперь просто стоит внизу колонки */
        position: relative; 
        flex-shrink: 0; /* Не сжиматься, если места мало */
        width: 100%;
        
        background: #ffffff;
        border-top: 1px solid #eee;
        padding: 10px 15px;
        /* Учитываем нижнюю полоску iPhone */
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        
        z-index: 50;
    }
    
    /* Смайлики */
    .emoji-picker {
        position: absolute; /* Относительно input-area */
        bottom: 80px;
        left: 10px;
        width: calc(100% - 20px);
    }

    /* --- ВЕРХНЕЕ МЕНЮ --- */
    .mobile-nav {
        display: flex; align-items: center; justify-content: space-between;
        padding: 0 20px; height: 60px;
        background: rgba(255,255,255,0.95);
        border-bottom: 1px solid #eee;
        /* Меню оставляем фиксированным сверху */
        position: fixed; top: 0; left: 0; width: 100%; z-index: 1000;
    }
    
    .mobile-title { font-weight: 800; color: var(--accent); font-size: 1.2rem; text-transform: uppercase; }
    .hamburger span { width: 25px; height: 3px; background: var(--accent); border-radius: 2px; }
    .hamburger { display: flex; flex-direction: column; gap: 5px; }

    .mobile-menu-overlay {
        display: flex; flex-direction: column;
        position: fixed; top: 60px; left: 0; width: 100%; height: 0;
        background: white; overflow: hidden; transition: 0.3s; z-index: 999;
    }
    .mobile-menu-overlay.open { height: calc(100dvh - 60px); padding: 20px; }
    .mobile-menu-overlay a { font-size: 1.2rem; color: #333; text-decoration: none; padding: 20px; border-bottom: 1px solid #eee; text-align: center; }
}

@keyframes popIn { 0% { opacity: 0; transform: scale(0.8); } 100% { opacity: 1; transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.8s ease forwards; }