/* =========================================================
   YAZME - ЭТАЛОННАЯ ГЛАВНАЯ СТРАНИЦА (GEMINI / CHATGPT STYLE)
   ========================================================= */

html, body {
    /* ЖЕСТКАЯ ФИКСАЦИЯ: страница становится монолитной и не проваливается под адресную строку */
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0;
    width: 100%; 
    height: 100%;
    margin: 0; 
    padding: 0;
    overflow: hidden; 
    background-color: var(--bg-main, #131314);
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    flex-direction: column;
    /* Прибиваем контейнер строго к краям вьюпорта */
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 0; 
    right: 0;
    width: 100%; 
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
    background: var(--bg-main, #131314);
}

/* === ОБЕРТКА КОНТЕНТА === */
.chat-wrapper {
    flex: 1 1 auto; /* Занимает всё доступное пространство между шапкой и вводом */
    height: 0; /* Обязательно для правильного скролла внутри flex-контейнера */
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    position: relative;
    padding-top: calc(75px + env(safe-area-inset-top, 0px)); 
    padding-bottom: 20px; 
    box-sizing: border-box;
    scroll-behavior: smooth;
}

.chat-wrapper::-webkit-scrollbar { width: 6px; }
.chat-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

/* === СТАРТОВЫЙ ЭКРАН === */
.welcome-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex: 1; 
    padding: 20px;
    box-sizing: border-box;
    transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1), transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
.welcome-screen.hidden-smooth { 
    opacity: 0 !important; 
    transform: translateY(-20px) !important; 
    pointer-events: none; 
    position: absolute;
}

.critter-top-zone { width: 120px; height: 140px; margin: 0 auto 30px auto; position: relative; z-index: 50; display: flex; align-items: center; justify-content: center; }
.critter-chalk-outline { width: 100%; height: 100%; animation: floatOutline 4s ease-in-out infinite; }
@keyframes floatOutline { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.welcome-screen h2 {
    color: var(--text-primary, #ffffff);
    font-size: 22px;
    margin-bottom: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    text-align: center;
}

/* === ГОРИЗОНТАЛЬНАЯ ЛЕНТА БОТОВ === */
.main-bots-row {
    display: flex; gap: 16px; overflow-x: auto; padding: 10px 20px 20px; margin: 0 -20px; width: calc(100% + 40px);
    scrollbar-width: none; -ms-overflow-style: none; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; scroll-padding-left: 20px;
}
.main-bots-row::-webkit-scrollbar { display: none; }

.bot-card-v2 {
    flex: 0 0 auto; width: 130px; background: var(--bg-panel, #1c1c1e); border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
    border-radius: 24px; padding: 20px 16px; text-align: center; cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s, box-shadow 0.2s; scroll-snap-align: start;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12); position: relative; overflow: hidden;
}
.bot-card-v2::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%); opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.bot-card-v2:hover::before { opacity: 1; }
.bot-card-v2:active { transform: scale(0.92); }
.bot-card-v2:hover { background: rgba(255,255,255,0.08); box-shadow: 0 12px 32px rgba(0,0,0,0.18); }

.bot-avatar-v2 { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 32px; box-shadow: inset 0 -4px 0 rgba(0,0,0,0.15), 0 8px 16px rgba(0,0,0,0.2); }
.bot-name-v2 { margin: 0 0 6px 0; font-size: 15px; font-weight: 700; color: var(--text-primary, #fff); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.3px; }
.bot-desc-v2 { margin: 0; font-size: 12px; color: var(--text-secondary, #8e8e9e); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.4; }

.swipe-hint-area { margin-top: auto; padding: 40px 0 20px; text-align: center; color: var(--text-secondary, #8e8e9e); font-size: 13px; font-weight: 500; opacity: 0.6; display: flex; flex-direction: column; align-items: center; gap: 8px; animation: pulse-hint 2s infinite cubic-bezier(0.4, 0, 0.6, 1); pointer-events: none; }
@keyframes pulse-hint { 0% { transform: translateY(0); opacity: 0.4; } 50% { transform: translateY(-6px); opacity: 0.8; } 100% { transform: translateY(0); opacity: 0.4; } }

/* =========================================================
   === ИСТОРИЯ ЧАТА (ЭТАЛОННЫЙ ДИЗАЙН YAZME) ===
   ========================================================= */
.chat-history { 
    display: flex; 
    flex-direction: column; 
    gap: 32px; 
    width: 100%; 
    padding: 20px 24px; 
    box-sizing: border-box; 
    opacity: 0; 
    transition: opacity 0.4s ease; 
}
.chat-history.visible { opacity: 1; }
body:has(.chat-history:not(.hidden)) #critter-container { display: none !important; }

/* Общий контейнер сообщения */
.msg-container {
    display: flex;
    width: 100%;
    animation: fadeInMsg 0.3s ease forwards;
}
@keyframes fadeInMsg { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Сообщение пользователя */
.msg-container.user {
    justify-content: flex-end;
}
.msg-container.user .msg-content {
    background: var(--accent-primary, #6b48ff);
    color: #ffffff; 
    padding: 12px 18px;
    border-radius: 24px 24px 4px 24px;
    font-size: 16px;
    line-height: 1.5;
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

/* Сообщение ИИ */
.msg-container.assistant {
    justify-content: flex-start;
    align-items: flex-start;
    gap: 16px;
}
.msg-container.assistant .msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}
.msg-container.assistant .msg-body {
    flex: 1;
    min-width: 0;
}
.msg-container.assistant .msg-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
    margin-bottom: 6px;
}
.msg-container.assistant .msg-content {
    color: var(--text-primary, #e3e3e3);
    font-size: 16px;
    line-height: 1.6;
    word-wrap: break-word;
}

/* Стилизация Markdown */
.msg-content p { margin: 0 0 12px 0; }
.msg-content p:last-child { margin: 0; }
.msg-content pre { background: var(--bg-panel, #000); padding: 12px; border-radius: 12px; overflow-x: auto; margin: 12px 0; border: 1px solid var(--glass-border, rgba(255,255,255,0.1)); font-family: monospace; font-size: 14px; }
.msg-content code { background: var(--glass-bg, rgba(255,255,255,0.1)); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 14px; color: var(--accent-primary, #a8c7fa); }
.msg-content pre code { background: transparent; padding: 0; color: inherit; }
.msg-content ul, .msg-content ol { margin: 0 0 12px 0; padding-left: 20px; }
.msg-content strong { color: inherit; font-weight: 700; }

/* Эффект курсора */
.typing-cursor::after {
    content: '▋';
    display: inline-block;
    vertical-align: text-bottom;
    animation: blink 1s step-start infinite;
    color: var(--text-primary, #ffffff);
    margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Индикатор печатания */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 8px 0;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary, #8e8e9e);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce { 0%, 80%, 100% { transform: scale(0); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* =========================================================
   === ПАНЕЛЬ ВВОДА (СТРОГО ЗАКРЕПЛЕНА ВНИЗУ ПОТОКА) === 
   ========================================================= */
.app-container #input-panel {
    position: relative;
    width: 100%;
    flex-shrink: 0; /* Не дает панели сжаться */
    padding: 12px 24px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-main, #131314);
    z-index: 1000;
    box-sizing: border-box;
    border-top: 1px solid var(--glass-border, rgba(255,255,255,0.05)); /* Легкий разделитель */
}

.app-container #input-panel .input-wrapper {
    display: flex;
    align-items: flex-end;
    width: 100%;
    background: var(--bg-panel, #1e1f20);
    border: 1px solid var(--glass-border, rgba(255,255,255,0.1));
    border-radius: 32px;
    padding: 8px 12px;
    min-height: 56px;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.app-container #input-panel .input-wrapper:focus-within {
    border-color: var(--accent-primary, rgba(255,255,255,0.2));
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.app-container #input-panel textarea#message-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary, #ffffff);
    font-family: inherit;
    font-size: 16px;
    font-weight: 400;
    resize: none;
    padding: 12px 8px;
    max-height: 150px;
    overflow-y: auto;
    outline: none;
    margin: 0;
    line-height: 20px;
}
.app-container #input-panel textarea#message-input::placeholder { color: var(--text-secondary, #8e8e9e); }

.app-container #input-panel .attach-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary, #8e8e9e);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    transition: color 0.2s, background 0.2s;
}
.app-container #input-panel .attach-btn:hover { color: var(--text-primary, #fff); background: rgba(255,255,255,0.05); }

.app-container #input-panel .media-record-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    margin-left: 4px;
    align-self: flex-end;
    position: relative;
}

.app-container #input-panel .record-btn,
.app-container #input-panel .send-btn {
    width: 100%;
    height: 100%;
    background: var(--text-primary, #ffffff);
    border: none;
    border-radius: 50%;
    color: var(--bg-main, #131314);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    transition: transform 0.2s, opacity 0.2s;
}
.app-container #input-panel .record-btn:active,
.app-container #input-panel .send-btn:active { transform: scale(0.9); }

.app-container .hidden { display: none !important; }

/* === Анимация свечения === */
@keyframes glowPulse { 0% { box-shadow: 0 4px 20px rgba(0,0,0,0.3); border-color: var(--glass-border, rgba(255, 255, 255, 0.1)); } 50% { box-shadow: 0 0 20px 2px var(--accent-primary, rgba(255, 255, 255, 0.15)); border-color: var(--accent-primary, rgba(255, 255, 255, 0.3)); } 100% { box-shadow: 0 4px 20px rgba(0,0,0,0.3); border-color: var(--glass-border, rgba(255, 255, 255, 0.1)); } }
.app-container .input-wrapper.trigger-glow { animation: glowPulse 2s ease-in-out !important; }

/* === МЕНЮ ВЛОЖЕНИЙ === */
.attachment-menu {
    position: absolute; 
    bottom: 90px;
    left: 24px;
    background: var(--bg-panel, #1e1f20);
    border: 1px solid var(--glass-border, rgba(255,255,255,0.1));
    border-radius: 16px;
    padding: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.attach-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-primary, #fff);
    font-size: 15px;
}

/* === АДАПТИВНОСТЬ (MOBILE) === */
@media (max-width: 600px) {
    .bot-card-v2 { width: 120px; padding: 16px 12px; }
    .bot-avatar-v2 { width: 56px; height: 56px; font-size: 28px; }
    .welcome-screen h2 { font-size: 20px; }
    /* Меньший отступ панели ввода на мобилках */
    .app-container #input-panel { padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
    .chat-history { padding: 16px; gap: 24px; }
    .msg-container.user .msg-content { max-width: 90%; font-size: 15px; }
    .msg-container.assistant .msg-content { font-size: 15px; }
}