/* ============================================================
 * RESET & BASE
 * ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Jost:wght@300;400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================================
 * CSS VARIABLES
 * ============================================================ */

:root {
    /* Геометрия */
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-glow: 0 0 0 3px rgba(17, 65, 133, 0.15);

    /* Брендовые цвета */
    --primary: #114185;
    --primary-light: #3366A9;
    --primary-lighter: #82B7DC;
    --accent: #3366A9;
    
    /* Семантические цвета */
    --success: #059669;
    --warning: #F59E0B;
    --error: #DC2626;
    
    /* Нейтральные цвета */
    --grey: #808080;
    --grey-light: #D1D5DB;
    --white: #FFFFFF;
    --black: #1C1C1C;
    
    /* Фоны */
    --bg-base: #FFFFFF;
    --bg-sidebar: #F8FAFB;
    --bg-main: #FFFFFF;
    --bg-card: #F3F4F6;
    --bg-input: #FFFFFF;
    --bg-hover: #F0F4FF;
    --bg-primary-light: #F0F4FF;
    
    /* Границы */
    --border: #E5E7EB;
    --border-dark: #D1D5DB;
    --border-active: #114185;
    
    /* Текст */
    --text: #1C1C1C;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --text-light: #D1D5DB;
    --text-white: #FFFFFF;
    
    /* Пузырьки сообщений */
    --user-bubble: linear-gradient(135deg, #114185 0%, #3366A9 100%);
    --ai-bubble: #F3F4F6;
}

/* ============================================================
 * BASE STYLES
 * ============================================================ */

body {
    font-family: 'Cormorant Garamond', serif;
    background: var(--bg-base);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

/* ============================================================
 * SCROLLBAR
 * ============================================================ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
    transition: background 0.2s;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-dark);
}

* {
    scrollbar-color: var(--border) transparent;
    scrollbar-width: thin;
}

/* ============================================================
 * LAYOUT - APP CONTAINER
 * ============================================================ */

.app-container {
    display: flex;
    height: 100vh;
    position: relative;
    background: var(--bg-base);
    overflow: hidden;
}

/* ============================================================
 * LAYOUT - SIDEBAR
 * ============================================================ */

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    flex-shrink: 0;
    height: 100vh;
    box-shadow: 1px 0 0 var(--border);
}

.sidebar-header {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-logo {
    position: relative;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.sidebar-logo .logo-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: contain;
}

.sidebar-header h1 {
    font-size: 30px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    margin: 0;
    flex: 1;
    text-align: left;
    font-family: 'Cormorant Garamond', serif;
}

.sidebar-close-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    color: var(--text-secondary);
    transform: rotate(180deg);
}

.sidebar-close-btn:hover {
    color: var(--primary);
    transform: scale(1.1);
}

.sidebar-close-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@media (min-width: 769px) {
    .sidebar-close-btn {
        display: none;
    }
}

/* ============================================================
 * LAYOUT - NAVIGATION
 * ============================================================ */

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.nav-item-wrapper {
    position: relative;
    width: 100%;
}

.nav-item {
    padding: 11px 14px;
    background: #F8F9FE;
    border: none;
    color: #121212;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 15px;
    font-weight: 400;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    width: 100%;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

.nav-item.active {
    background: var(--bg-primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    width: 15px;
    height: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-icon img {
    width: 15px;
    height: 15px;
}

.nav-label {
    flex: 1;
    text-align: left;
}

.nav-dropdown-icon,
.nav-vector-icon {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.3s;
}

.nav-item.active .nav-dropdown-icon {
    transform: rotate(180deg);
}

.nav-chats-dropdown {
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    overflow: hidden;
    max-height: 400px;
    overflow-y: auto;
    animation: slideDown 0.3s ease;
    padding: 8px 0;
}

.nav-chats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.nav-chats-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 4px 0;
    font-family: 'Jost', sans-serif;
}

.nav-chat-item {
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-chat-item:hover {
    background: var(--bg-primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    padding-left: 16px;
}

.nav-chat-item.active {
    background: var(--bg-primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-spacer {
    flex: 1;
    min-height: 20px;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.theme-buttons {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    margin-top: 8px;
}

.btn-theme-option {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-theme-option:hover {
    background: var(--bg-hover);
}

.btn-theme-option.active {
    background: var(--bg-primary-light);
}

.theme-option-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.theme-option-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        box-shadow: none;
        background: var(--bg-base);
        z-index: 999;
        width: 260px;
        padding-top: 20px;
    }
    
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
    }
}

/* ============================================================
 * LAYOUT - BURGER BUTTON
 * ============================================================ */

.burger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    padding: 0;
    z-index: 1000;
    transition: all 0.2s;
    flex-shrink: 0;
    min-width: 16px;
    min-height: 16px;
    background: transparent;
    border: none;
}

.burger-btn:hover {
    opacity: 0.7;
}

.burger-btn img {
    width: 16px;
    height: 16px;
}

@media (max-width: 768px) {
    .burger-btn {
        display: flex !important;
        position: fixed;
        top: 27px;
        left: 24px;
    }

    .sidebar.active ~ .main-content .burger-btn,
    .sidebar.active .burger-btn {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .burger-btn {
        display: none !important;
    }
}

/* ============================================================
 * LAYOUT - MAIN CONTENT
 * ============================================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    overflow: hidden;
    position: relative;
    min-width: 0;
    height: 100vh;
    min-height: 0;
}

.section {
    display: none !important;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.section.active {
    display: flex !important;
    position: relative;
}

/* ============================================================
 * LAYOUT - HEADER
 * ============================================================ */

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 30px 0px 30px;
    background: var(--bg-main);
    border-bottom: none;
    flex-shrink: 0;
    height: 60px;
    gap: 5px;
}

@media (max-width: 768px) {
    .app-header {
        border-bottom: none;
    }
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    justify-content: flex-start;
    background: #F8F9FE;
    border-radius: 10px;
    padding: 6px 8px 6px 6px;
    margin-left: 20px;
    margin-right: auto;
}

@media (max-width: 768px) {
    .header-logo {
        margin-left: 20px;
        margin-right: auto;
    }
}

.logo-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .logo-icon {
        width: 28px;
        height: 28px;
        flex-shrink: 0;
    }
}

.logo-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
    color: #1C1C1C;
    font-family: 'Cormorant Garamond', serif;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .logo-text {
        font-size: 16px;
        color: #1C1C1C;
        gap: 2px;
    }
}

.btn-back-to-chat,
.btn-settings {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s;
    padding: 0;
    border-radius: 0;
    color: #3366A9;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

@media (max-width: 768px) {
    .btn-settings {
        min-width: 16px;
        min-height: 16px;
    }
}

.btn-settings img {
    width: 16px;
    height: 16px;
}

.btn-settings:hover {
    opacity: 0.7;
}

@media (max-width: 768px) {
    .btn-settings:hover {
        opacity: 0.7;
    }
}

.deviding-line {
    text-align: center;
}

.btn-new-chat {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 2px solid var(--primary);
    border-radius: 8px;
    cursor: pointer;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-new-chat:hover {
    background: var(--bg-primary-light);
    border-color: var(--primary-light);
}

.btn-new-chat:active {
    transform: scale(0.95);
}

/* ============================================================
 * ANIMATIONS
 * ============================================================ */

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUpAuth {
    from {
        opacity: 0;
        transform: translateY(60px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

@keyframes modern-pulse {
    0% {
        box-shadow: 
            0 0 0 0 rgba(74, 123, 204, 0.8),
            0 0 0 0 rgba(74, 123, 204, 0.6);
        transform: scale(1);
    }
    50% {
        box-shadow: 
            0 0 0 8px rgba(74, 123, 204, 0),
            0 0 0 12px rgba(74, 123, 204, 0);
        transform: scale(1.02);
    }
    100% {
        box-shadow: 
            0 0 0 0 rgba(74, 123, 204, 0),
            0 0 0 0 rgba(74, 123, 204, 0);
        transform: scale(1);
    }
}