/* --- 1. БАЗОВЫЕ НАСТРОЙКИ --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    text-decoration: none;
}

html, body {
    height: 100%; /* Нужно для прижатия футера */
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    background-color: #1a1a1d; /* Темный фон для стабильности */
    color: white;
}

/* --- 2. ШАПКА (Header) --- */
.header {
    width: 100%;
    height: 60px;
    background-color: #111113;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-title { 
    color: white; 
    font-size: 1.1rem; 
    font-weight: bold;
    text-decoration: none;
}

.navigation-buttons {
    display: flex;
    list-style: none;
    gap: 20px;
}

.navigation-buttons a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: 0.3s;
}

.navigation-buttons a:hover { 
    color: oklch(70.7% 0.165 254.624); 
}

/* --- 3. КОНТЕНТ (Макет с боковой панелью) --- */
main {
    flex: 1 0 auto; /* Растягивает блок, толкая футер вниз */
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding-top: 60px; /* Отступ под шапку */
    background: linear-gradient(135deg, #8517eb, #c4abff, #4f74ee);
}

.chat-page {
    width: 100%;
    height: calc(90vh - 60px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-layout {
    display: flex;
    width: 95%;
    max-width: 1200px;
    height: 80vh;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

/* БОКОВАЯ ПАНЕЛЬ */
.chat-sidebar {
    width: 250px;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    font-size: 0.95rem;
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.close-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    font-size: 0.95rem;
}

.close-chat-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
}

.history-header {
    font-size: 0.85rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 5px;
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    padding: 12px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: 0.3s;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.history-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: white;
}

.history-item .delete-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    transition: 0.3s;
}

.history-item .delete-btn:hover {
    color: #ff6b6b;
}

/* ОСНОВНАЯ ОБЛАСТЬ ЧАТА */
.chat-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* ЧАТ-КОНТЕЙНЕР */
.chat-container {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.chat-header {
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.chat-header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.history-toggle-btn {
    display: none;
    border: none;
    padding: 9px 14px;
    border-radius: 14px;
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.history-toggle-btn:hover {
    transform: translateY(-1px);
}

.mobile-history-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 14px;
    z-index: 2000;
}

.mobile-history-modal.hidden {
    display: none;
}

.mobile-history-panel {
    width: 100%;
    max-width: 520px;
    background: rgba(17, 17, 19, 0.98);
    border-radius: 22px 22px 12px 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.mobile-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: white;
    font-weight: 700;
}

.modal-close-btn {
    border: none;
    background: transparent;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
}

.mobile-history-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 18px 0;
}

.mobile-history-panel .chat-history {
    padding: 12px 18px 18px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mobile-history-panel .history-item {
    width: 100%;
    padding: 12px 14px;
}

.status-dot { 
    width: 10px; 
    height: 10px; 
    background: #2ecc71; 
    border-radius: 50%; 
    box-shadow: 0 0 10px #2ecc71;
}

.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.message {
    padding: 12px 16px;
    border-radius: 20px;
    max-width: 80%;
    font-size: 0.95rem;
    line-height: 1.5;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.ai-message { 
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.95) 0%, rgba(118, 75, 162, 0.95) 100%);
    color: white;
    align-self: flex-start; 
    border-bottom-left-radius: 6px;
}

.user-message { 
    background: rgba(255, 255, 255, 0.15);
    color: white; 
    align-self: flex-end; 
    border-bottom-right-radius: 6px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-input-area {
    padding: 20px;
    display: flex;
    gap: 12px;
    background: rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#user-input {
    flex: 1;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    outline: none;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

#user-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#user-input:focus {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

#send-btn {
    border-radius: 14px;
    border: none;
    padding: 10px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#send-btn:hover { 
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

#send-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* --- 4. ФУТЕР (Компактный) --- */
.footer {
    flex-shrink: 0;
    width: 100%;
    background-color: #111113;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.footer-text {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
}

.footer-link {
    color: #00f2ff;
    font-size: 0.85rem;
    text-decoration: none;
    font-weight: 600;
}

.footer-link:hover {
    text-decoration: underline;
}

/* --- 5. АДАПТИВНЫЕ СТИЛИ (Media Queries) --- */

/* ПЛАНШЕТЫ (768px и меньше) */
@media (max-width: 768px) {
    .header {
        padding: 0 3%;
        height: 50px;
    }

    .header-title {
        font-size: 1rem;
    }

    .navigation-buttons {
        gap: 12px;
    }

    .navigation-buttons a {
        font-size: 0.8rem;
    }

    main {
        padding-top: 50px;
    }

    .chat-page {
        height: calc(90vh - 50px);
    }

    .chat-layout {
        width: 98%;
        height: 70vh;
        border-radius: 16px;
    }

    .chat-sidebar {
        width: 200px;
        padding: 15px 10px;
        gap: 10px;
    }

    .new-chat-btn,
    .close-chat-btn {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .history-header {
        font-size: 0.75rem;
        padding: 8px 5px;
    }

    .history-item {
        padding: 10px 10px;
        font-size: 0.85rem;
    }

    .message {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .chat-input-area {
        padding: 15px;
        gap: 8px;
    }

    #user-input {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    #send-btn {
        padding: 0 16px;
        font-size: 0.9rem;
    }
}

/* МОБИЛЬНЫЕ ТЕЛЕФОНЫ (480px и меньше) */
@media (max-width: 480px) {
    /* ГЛОБАЛЬНЫЕ */
    html, body {
        height: 100%;
    }

    body {
        display: flex;
        flex-direction: column;
    }

    /* ХЕДЕР */
    .header {
        height: 50px;
        padding: 0 12px;
        background-color: #111113;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 1000;
    }

    .header-title {
        font-size: 1rem;
        font-weight: 700;
        color: white;
        margin: 0;
        white-space: nowrap;
    }

    .navigation-buttons {
        display: flex;
        gap: 8px;
        list-style: none;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .navigation-buttons a {
        font-size: 0.7rem;
        font-weight: 500;
        padding: 4px 6px;
        color: rgba(255, 255, 255, 0.7);
        white-space: nowrap;
    }

    .navigation-buttons a:active {
        color: #00f2ff;
    }

    /* MAIN */
    main {
        flex: 1;
        padding-top: 50px;
        background: linear-gradient(135deg, #8517eb, #c4abff, #4f74ee);
        display: flex;
        align-items: stretch;
    }

    .chat-page {
        width: 100%;
        height: 100%;
        display: flex;
    }

    .chat-layout {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        background: transparent;
        border: none;
        box-shadow: none;
        border-radius: 0;
        max-width: none;
    }

    .chat-sidebar {
        display: none !important;
    }

    .history-toggle-btn {
        display: inline-flex;
    }

    .chat-main {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 0;
        width: 100%;
        overflow: hidden;
    }

    .chat-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
        overflow: hidden;
    }

    /* ХЕДЕР ЧАТА */
    .chat-header {
        padding: 10px 16px;
        background: #111113;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 0.9rem;
        flex-shrink: 0;
    }

    .status-dot {
        width: 8px;
        height: 8px;
        background: #2ecc71;
        border-radius: 50%;
        box-shadow: 0 0 8px #2ecc71;
        flex-shrink: 0;
    }

    /* СООБЩЕНИЯ */
    .chat-messages {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 16px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .message {
        padding: 10px 14px;
        border-radius: 16px;
        font-size: 0.95rem;
        line-height: 1.5;
        word-wrap: break-word;
        overflow-wrap: break-word;
        width: fit-content;
        max-width: 85%;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
        transition: all 0.2s ease;
    }

    .ai-message {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.9), rgba(118, 75, 162, 0.9));
        color: white;
        align-self: flex-start;
        border-bottom-left-radius: 4px;
    }

    .user-message {
        background: rgba(255, 255, 255, 0.12);
        color: white;
        align-self: flex-end;
        border-bottom-right-radius: 4px;
        backdrop-filter: blur(8px);
        border: 1px solid rgba(255, 255, 255, 0.15);
        text-align: right;
    }

    /* ИНПУТ */
    .chat-input-area {
        padding: 12px 16px;
        display: flex;
        gap: 8px;
        background: rgba(17, 17, 19, 0.8);
        backdrop-filter: blur(10px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        flex-shrink: 0;
        align-items: flex-end;
    }

    #user-input {
        flex: 1;
        padding: 10px 14px;
        font-size: 16px;
        border: 1px solid rgba(255, 255, 255, 0.15);
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.08);
        color: white;
        outline: none;
        resize: none;
        max-height: 80px;
        font-family: 'Segoe UI', Roboto, sans-serif;
        transition: all 0.2s ease;
    }

    #user-input::placeholder {
        color: rgba(255, 255, 255, 0.4);
    }

    #user-input:focus {
        border-color: rgba(255, 255, 255, 0.3);
        background: rgba(255, 255, 255, 0.12);
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
    }

    #send-btn {
        padding: 10px 16px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        border-radius: 10px;
        font-weight: 700;
        cursor: pointer;
        transition: all 0.2s ease;
        flex-shrink: 0;
        font-size: 0.9rem;
        min-height: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 60px;
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.25);
    }

    #send-btn:active {
        transform: scale(0.96);
        box-shadow: 0 1px 4px rgba(102, 126, 234, 0.15);
    }

    /* ФУТЕР */
    .footer {
        display: none;
    }

    /* СКРОЛЛБАР */
    .chat-messages::-webkit-scrollbar {
        width: 4px;
    }

    .chat-messages::-webkit-scrollbar-track {
        background: transparent;
    }

    .chat-messages::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 2px;
    }

    .chat-messages::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    /* ОПТИМИЗАЦИЯ */
    * {
        -webkit-touch-callout: none;
    }

    input, textarea, button {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ОЧЕНЬ УЗКИЕ ЭКРАНЫ (415px и меньше) */
@media (max-width: 415px) {
    .header {
        height: 85px;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
    }

    .header-title {
        font-size: 0.95rem;
        text-align: center;
        order: -1;
    }

    .navigation-buttons {
        gap: 6px;
        justify-content: center;
        width: 100%;
    }

    .navigation-buttons a {
        font-size: 0.65rem;
        padding: 3px 5px;
    }

    main {
        padding-top: 85px;
        background: linear-gradient(135deg, #8517eb, #c4abff, #4f74ee);
    }
}