/* Custom styles for KeepAI */

/* ========== Кнопки навигации в шапке (единый стиль на всех страницах) ========== */
header .header-nav-link,
.header-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: rgb(229 231 235);
    background: transparent;
    border-radius: 0.5rem;
    transition: color 0.15s, background-color 0.15s;
}
header .header-nav-link:hover,
.header-nav-link:hover {
    color: #fff;
    background: rgba(38 38 38 / 0.8);
}
header .header-nav-link svg,
.header-nav-link svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}
header .header-nav-link-accent,
.header-nav-link-accent {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #22d3ee;
    background: rgba(34 211 238 / 0.15);
    border-radius: 0.5rem;
    transition: color 0.15s, background-color 0.15s;
}
header .header-nav-link-accent:hover,
.header-nav-link-accent:hover {
    color: #67e8f9;
    background: rgba(34 211 238 / 0.25);
}
header .header-nav-link-accent svg,
.header-nav-link-accent svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

/* ========== Кастомные выпадающие списки (select) ========== */
select.select-custom,
select.image-gen-select,
#image-gen-modal select {
    width: 100%;
    max-width: 100%;
    background-color: rgb(31 31 30);
    border: 1px solid rgb(75 85 99);
    border-radius: 0.5rem;
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    color: #fff;
    font-size: 0.875rem;
    line-height: 1.25rem;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.25rem 1.25rem;
}
select.select-custom:hover,
select.image-gen-select:hover,
#image-gen-modal select:hover {
    border-color: rgb(107 114 128);
}
select.select-custom:focus,
select.image-gen-select:focus,
#image-gen-modal select:focus {
    outline: none;
    border-color: #a855f7;
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}
select.select-custom option,
select.image-gen-select option,
#image-gen-modal select option {
    background: #1f1f1e;
    color: #fff;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a19;
}

::-webkit-scrollbar-thumb {
    background: #252524;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #0e7490;
}

/* Text selection */
::selection {
    background: #0e7490;
    color: white;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Typing indicator animation */
@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.typing-dot {
    animation: typingBounce 1.4s ease-in-out infinite;
}

/* Loading spinner */
.spinner {
    border: 2px solid #1a1a19;
    border-top: 2px solid #6366f1;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast notifications - современный дизайн */
.toast-notification {
    position: fixed;
    top: 24px;
    right: 24px;
    min-width: 380px;
    max-width: 520px;
    background: linear-gradient(135deg, rgba(20, 20, 19, 0.98) 0%, rgba(26, 26, 25, 0.98) 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset,
        0 1px 2px 0 rgba(0, 0, 0, 0.3);
    z-index: 10000;
    backdrop-filter: blur(24px) saturate(180%);
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-notification::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    opacity: 0.6;
}

.toast-success::before {
    background: linear-gradient(90deg, transparent, rgba(34, 197, 94, 0.3), transparent);
}

.toast-error::before {
    background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.3), transparent);
}

.toast-warning::before {
    background: linear-gradient(90deg, transparent, rgba(234, 179, 8, 0.3), transparent);
}

.toast-info::before {
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

.toast-content {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 22px;
    position: relative;
    z-index: 1;
}

.toast-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px) saturate(180%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.toast-notification:hover .toast-icon {
    transform: scale(1.05);
}

.toast-success .toast-icon {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.25) 0%, rgba(22, 163, 74, 0.25) 100%);
    color: #4ade80;
    border: 1.5px solid rgba(34, 197, 94, 0.4);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.toast-error .toast-icon {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.25) 0%, rgba(220, 38, 38, 0.25) 100%);
    color: #f87171;
    border: 1.5px solid rgba(239, 68, 68, 0.4);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.toast-warning .toast-icon {
    background: linear-gradient(135deg, rgba(234, 179, 8, 0.25) 0%, rgba(202, 138, 4, 0.25) 100%);
    color: #fbbf24;
    border: 1.5px solid rgba(234, 179, 8, 0.4);
    box-shadow: 0 0 20px rgba(234, 179, 8, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.toast-info .toast-icon {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.25) 0%, rgba(37, 99, 235, 0.25) 100%);
    color: #60a5fa;
    border: 1.5px solid rgba(59, 130, 246, 0.4);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.toast-message {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}

.toast-title {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.6;
    color: #f9fafb;
    word-wrap: break-word;
    letter-spacing: -0.01em;
}

.toast-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: -2px;
    margin-right: -6px;
    background: rgba(255, 255, 255, 0.03);
}

.toast-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #f3f4f6;
    transform: scale(1.1) rotate(90deg);
}

.toast-close:active {
    transform: scale(0.95);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, #0e7490, #14b8a6);
    transform-origin: left;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
}

.toast-success .toast-progress {
    background: linear-gradient(90deg, #22c55e 0%, #16a34a 50%, #15803d 100%);
    box-shadow: 0 -2px 12px rgba(34, 197, 94, 0.3);
}

.toast-error .toast-progress {
    background: linear-gradient(90deg, #ef4444 0%, #dc2626 50%, #b91c1c 100%);
    box-shadow: 0 -2px 12px rgba(239, 68, 68, 0.3);
}

.toast-warning .toast-progress {
    background: linear-gradient(90deg, #eab308 0%, #ca8a04 50%, #a16207 100%);
    box-shadow: 0 -2px 12px rgba(234, 179, 8, 0.3);
}

.toast-info .toast-progress {
    background: linear-gradient(90deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
    box-shadow: 0 -2px 12px rgba(59, 130, 246, 0.3);
}

@keyframes toastProgress {
    from {
        transform: scaleX(1);
    }
    to {
        transform: scaleX(0);
    }
}

/* Анимация появления */
@keyframes slideInToast {
    from {
        transform: translateX(calc(100% + 24px));
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Дополнительные эффекты для toast */
.toast-notification:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 30px 60px -12px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.08) inset,
        0 1px 2px 0 rgba(0, 0, 0, 0.4);
}

/* Responsive для мобильных */
@media (max-width: 640px) {
    .toast-notification {
        top: 16px;
        right: 16px;
        left: 16px;
        min-width: auto;
        max-width: none;
    }
    
    .toast-notification:hover {
        transform: none;
    }
    
    .toast-content {
        padding: 18px;
        gap: 14px;
    }
    
    .toast-icon {
        width: 44px;
        height: 44px;
    }
    
    .toast-title {
        font-size: 14px;
    }
    
    .toast-close {
        width: 30px;
        height: 30px;
    }
}

/* ========== Chat message bubble & layout ========== */
.message {
    animation: fadeIn 0.3s ease-out;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Обёртка контента — по ширине текста, без растягивания на всю строку */
.message .message-content {
    width: fit-content;
    max-width: 100%;
}

/* Пузырь сообщения: тень, скругление, отступы */
.message .message-bubble {
    border-radius: 1rem 1rem 1rem 0.25rem;
    padding: 0.875rem 1.125rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    line-height: 1.55;
    letter-spacing: 0.01em;
}

/* Сообщения пользователя — скругление с другой стороны */
.message.justify-end .message-bubble {
    border-radius: 1rem 1rem 0.25rem 1rem;
}

.message .message-bubble p,
.message .message-bubble .markdown-content {
    margin: 0;
    color: #f1f5f9;
    font-size: 0.9375rem;
}

/* Строка под сообщением: время, копировать, звёзды */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.375rem;
    padding-left: 0.125rem;
    padding-right: 0.125rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.message-meta .message-time {
    font-size: 0.6875rem;
    color: #6b7280;
    font-variant-numeric: tabular-nums;
}

.message-meta .copy-btn {
    font-size: 0.75rem;
    color: #9ca3af;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    transition: color 0.15s, background 0.15s;
}

.message-meta .copy-btn:hover {
    color: #0e7490;
    background: rgba(14, 116, 144, 0.08);
}

.message-meta .message-stars {
    font-size: 0.6875rem;
    color: #6b7280;
    display: inline-flex;
    align-items: center;
    gap: 0.125rem;
}

/* Аватарки в сообщениях */
.message .message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.message .message-avatar-user {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Расстояние между аватаркой и текстом */
.message .flex.items-start.space-x-3 {
    gap: 0.75rem;
}

/* File upload drag & drop */
.drag-over {
    border-color: #6366f1 !important;
    background: rgba(99, 102, 241, 0.1) !important;
}

/* Input container with centered items */
.input-container.items-end {
    justify-content: center !important;
    align-items: center !important;
}

/* Message textarea - выравнивание текста слева */
.message-textarea {
    text-align: left;
}.message-textarea::placeholder {
    text-align: left;
}

/* Send button padding */
.send-button {
    padding: 0.4rem !important;
}

/* Model Selectors - Claude, Gemini, ChatGPT */
#claude-model-selector, #gemini-model-selector, #gpt-model-selector {
    position: relative;
}

#claude-model-selector-btn, #gemini-model-selector-btn, #gpt-model-selector-btn {
    cursor: pointer;
    user-select: none;
}

#claude-model-dropdown, #gemini-model-dropdown, #gpt-model-dropdown {
    animation: fadeIn 0.2s ease-out;
}

.claude-model-option, .gemini-model-option, .gpt-model-option {
    border: 1px solid transparent;
    transition: all 0.2s;
}

.claude-model-option:hover, .gemini-model-option:hover, .gpt-model-option:hover {
    background-color: rgba(14, 116, 144, 0.1) !important;
}

.claude-model-option.bg-primary\/20, .gemini-model-option.bg-primary\/20, .gpt-model-option.bg-primary\/20 {
    background-color: rgba(12, 100, 124, 0.267) !important;
    border-color: rgba(14, 116, 144, 0.3) !important;
}

/* Code block: header with language + copy button */
.code-block-wrapper {
    border: 1px solid #2f2f2e;
    border-radius: 8px;
    overflow: hidden;
    margin: 0.75rem 0;
    max-width: 100%;
    box-sizing: border-box;
}
.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #1a1a19;
    border-bottom: 1px solid #2f2f2e;
}
.code-block-lang {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
}
.code-block-copy {
    font-size: 0.75rem;
    padding: 4px 10px;
    background: rgba(14, 116, 144, 0.2);
    border: 1px solid rgba(14, 116, 144, 0.4);
    border-radius: 6px;
    color: #0e7490;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}
.code-block-copy:hover {
    background: rgba(14, 116, 144, 0.3);
    border-color: rgba(14, 116, 144, 0.6);
}
.code-block-wrapper pre {
    margin: 0;
    padding: 12px 16px;
    overflow-x: auto;
    overflow-y: hidden;
    background: #141413;
    max-width: 100%;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}
.code-block-wrapper pre code {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Markdown content styles */
.markdown-content {
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

.markdown-content p {
    margin: 0.5rem 0;
    line-height: 1.6;
}

.markdown-content strong {
    font-weight: 600;
    color: #e5e7eb;
}

.markdown-content em {
    font-style: italic;
}

.markdown-content code {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

/* Inline code (не в pre) - перенос текста */
.markdown-content code:not(pre code) {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-all;
}

.markdown-content pre {
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

.markdown-content pre code {
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
}

.markdown-content ul, .markdown-content ol {
    padding-left: 1.5rem;
}

.markdown-content li {
    padding-left: 0;
}

.markdown-content h1, .markdown-content h2, .markdown-content h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Ссылки-источники (Perplexity citations): серый фон, тускло-синяя окантовка в стиле сайта */
.markdown-content .citation-link,
.citation-link {
    display: inline-block;
    background-color: #374151;
    color: #e5e7eb;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    border: 1px solid rgba(14, 116, 144, 0.6);
    text-decoration: none;
    margin-left: 0.25rem;
    white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.markdown-content .citation-link:hover,
.citation-link:hover {
    background-color: #4b5563;
    border-color: #0e7490;
    color: #f3f4f6;
}

.items-end{
    align-items: center;
    justify-content: center;
}
.items-end div  {
    align-items: start;
    justify-content: center;
}

.flex-1.relative {
display: flex;
justify-content: center;
}

/* Enhanced background with gradient instead of solid black */
body {
    background: linear-gradient(135deg, #141413 0%, #1a1a19 50%, #141413 100%);
    background-attachment: fixed;
    min-height: 100vh;
}

/* Subtle gradient overlays for depth */
.bg-dark {
    background: linear-gradient(135deg, #141413 0%, #1a1a19 100%) !important;
}

.bg-dark-light {
    background: linear-gradient(135deg, #1a1a19 0%, #252524 100%) !important;
}

/* Sidebar profile section - different shade to break up the solid color */
.sidebar-profile-section {
    background: linear-gradient(135deg, #1f1f1e 0%, #252524 100%) !important;
    border-top: 1px solid #2f2f2e !important;
}



div#chat-avatar {
    background-color: rgba(0,0,0,0);
}

/* New Chat Button */
#new-chat-btn {
    background-color: rgba(12, 100, 124, 0.267) !important;
}

#new-chat-btn:hover {
    background-color: rgba(12, 100, 124, 0.4) !important;
}

/* ============================================
   RESPONSIVE / ADAPTIVE STYLES
   ============================================ */

/* Sidebar mobile styles */
.sidebar-mobile {
    transform: translateX(-100%);
}

.sidebar-mobile.sidebar-open {
    transform: translateX(0);
}

/* Desktop: sidebar always visible */
@media (min-width: 1024px) {
    .sidebar-mobile {
        position: relative !important;
        transform: translateX(0) !important;
    }
    
    #sidebar-overlay {
        display: none !important;
    }
}

/* Mobile-first adjustments */
@media (max-width: 1023px) {
    /* Sidebar overlay z-index */
    #sidebar-overlay {
        backdrop-filter: blur(4px);
        z-index: 90 !important;
    }
    
    /* Сайдбар должен быть выше всего на мобильных */
    #sidebar {
        z-index: 100 !important;
    }
    .bg-dark-light\/50 {
        background-color: rgb(26 26 25) !important;
    }
    /* Header и панель ввода должны быть ниже сайдбара (исключая чат страницу) */
    header.bg-dark-light\/50:not(.chat-header) {
        z-index: 10 !important;
        position: relative !important;
    }
    
    .bg-dark-light\/30.p-4:not(.chat-input-bar) {
        z-index: 10 !important;
        position: relative !important;
    }
    
    /* Main content takes full width when sidebar is hidden */
    .flex-1.flex.flex-col {
        width: 100% !important;
    }
}

/* Страница чата: скроллится только область сообщений, не вся страница (убирает появление меню браузера при свайпе) */
body.chat-page-no-scroll {
    overflow: hidden !important;
    position: fixed !important;
    width: 100%;
    height: 100%;
    height: 100dvh; /* динамическая высота viewport на мобильных */
}
body.chat-page-no-scroll .chat-page {
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
}

/* Чтобы скролл был только в .chat-messages */
.chat-page .chat-main {
    min-height: 0;
}

/* Chat layout: lock header/input on mobile */
@media (max-width: 768px) {
    .chat-page {
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .chat-page .chat-main {
        display: flex;
        flex-direction: column;
        min-height: 0; /* чтобы flex-1 у .chat-messages давал скролл */
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    .chat-page .chat-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 20 !important;
        background: rgba(26, 26, 25, 0.5);
        backdrop-filter: blur(12px);
    }

    .chat-page .chat-input-bar {
        position: sticky !important;
        bottom: 0 !important;
        z-index: 20 !important;
        padding: 0.6rem 0.75rem !important;
        background: rgba(20, 20, 19, 0.98) !important;
        border-top: 1px solid #252524 !important;
        backdrop-filter: blur(12px);
        margin-top: auto;
    }

    .chat-page .chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain; /* скролл не уходит на страницу — не вызывает меню браузера */
        padding: 0.75rem 0.9rem !important;
    }

    .bg-dark-light\/50 {
        background-color: rgb(26 26 25) !important;
    }

    /* Модалка генерации изображений: оверлей на весь экран, панель по центру */
    #image-gen-modal {
        padding: 0;
        align-items: stretch !important;
        justify-content: stretch !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }
    #image-gen-modal > div {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: calc(100% - 1.5rem);
        max-width: 36rem;
        max-height: 70dvh;
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0;
    }
    #image-gen-modal > div > div {
        padding-bottom: 1.5rem;
    }
}

/* Small screens (phones) */
@media (max-width: 640px) {
    /* Reduce message padding on mobile */
    .message .rounded-2xl {
        padding: 0.625rem 0.875rem !important;
    }
    
    /* Smaller text in messages */
    .message p, .message .markdown-content {
        font-size: 0.9375rem;
        line-height: 1.5;
    }
    
    /* Контейнеры сообщений - ограничение ширины */
    .message {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .message .max-w-3xl {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Markdown content - предотвращение переполнения */
    .markdown-content {
        max-width: 100% !important;
        overflow-x: hidden !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
    }
    
    /* Блоки кода - ограничение ширины и горизонтальная прокрутка */
    .code-block-wrapper {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .code-block-wrapper pre {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        word-wrap: normal !important;
        white-space: pre !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .code-block-wrapper pre code {
        white-space: pre !important;
        word-wrap: normal !important;
        overflow-wrap: normal !important;
    }
    
    /* Inline code - перенос текста */
    .markdown-content code:not(pre code) {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-all !important;
        white-space: normal !important;
    }
    
    /* Pre элементы в markdown - ограничение ширины */
    .markdown-content pre {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: pre !important;
        word-wrap: normal !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .markdown-content pre code {
        white-space: pre !important;
        word-wrap: normal !important;
        overflow-wrap: normal !important;
    }
    
    /* Контейнеры с контентом сообщений */
    .message .flex-1 {
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }

    /* Mobile input buttons polishing */
    .chat-page .input-container {
        align-items: center !important;
        gap: 0.4rem !important;
    }

    .chat-page #image-gen-btn,
    .chat-page #file-attach-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid #2f2f2e;
        flex-shrink: 0;
    }

    .chat-page #image-gen-btn svg,
    .chat-page #file-attach-btn svg {
        width: 18px !important;
        height: 18px !important;
    }

    .chat-page #image-gen-btn {
        background: rgba(139, 92, 246, 0.12);
        border-color: rgba(139, 92, 246, 0.35);
    }

    .chat-page #image-gen-btn:hover {
        background: rgba(139, 92, 246, 0.2);
    }

    .chat-page #file-attach-btn:hover {
        background: rgba(255, 255, 255, 0.08);
    }

    .chat-page #send-btn {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        padding: 0 !important;
        border-radius: 8px !important;
        right: 6px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
    }

    .chat-page #send-btn svg {
        width: 16px !important;
        height: 16px !important;
    }

    .chat-page #message-input {
        min-height: 40px !important;
        max-height: 120px !important;
        padding: 8px 42px 8px 12px !important;
        font-size: 15px !important;
        line-height: 1.4 !important;
    }
    
    /* Toast notifications - full width on mobile */
    .toast {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        width: auto;
    }
    
    /* Model selector dropdowns - full width */
    #claude-model-dropdown,
    #gemini-model-dropdown,
    #gpt-model-dropdown,
    #perplexity-model-dropdown {
        min-width: 180px;
        max-width: calc(100vw - 2rem);
    }
    
    /* Scrollbar thinner on mobile */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    /* File attachment preview */
    .mb-2.space-y-1 {
        max-width: 100%;
    }
    
    .mb-2.space-y-1 .flex.items-center.gap-2 {
        font-size: 0.875rem;
    }
}

/* Medium screens (tablets) */
@media (min-width: 641px) and (max-width: 1023px) {
    /* Adjust sidebar width if needed */
    #sidebar {
        width: 280px;
    }
}

/* Large screens - sidebar always visible */
@media (min-width: 1024px) {
    #sidebar {
        transform: translateX(0) !important;
    }
    
    #sidebar-overlay {
        display: none !important;
    }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
    /* Larger buttons for touch */
    button, .cursor-pointer {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Model cards - larger touch target */
    .model-card {
        min-height: 80px;
    }
    
    /* Chat items in sidebar */
    .chat-item {
        padding: 0.875rem !important;
    }
    
    /* Disable hover effects on touch devices */
    .hover\:bg-dark-light:active {
        background-color: rgba(26, 26, 25, 0.8);
    }
}

/* Safe area insets for notched devices (iPhone X+) */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    /* Input area respects safe area */
    .bg-dark-light\/30 {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce header height */
    header {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    /* Smaller messages area */
    #messages-container {
        padding: 0.5rem !important;
    }
}

/* High contrast / accessibility */
@media (prefers-contrast: high) {
    .border-gray-800 {
        border-color: #4b5563 !important;
    }
    
    .text-gray-400, .text-gray-500 {
        color: #9ca3af !important;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .fade-in {
        animation: none !important;
    }
    
    .typing-dot {
        animation: none !important;
    }
}

/* Truncated message warning styles */
.truncated-warning {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background-color: rgba(234, 179, 8, 0.1);
    border: 1px solid rgba(234, 179, 8, 0.3);
    border-radius: 0.5rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.truncated-warning button {
    padding: 0.375rem 0.75rem;
    background-color: rgba(234, 179, 8, 0.2);
    color: rgb(254, 240, 138);
    font-size: 0.875rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(234, 179, 8, 0.3);
    transition: background-color 0.2s;
    cursor: pointer;
}

.truncated-warning button:hover {
    background-color: rgba(234, 179, 8, 0.3);
}

.truncated-warning button:active {
    transform: scale(0.98);
}

.truncated-warning button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Chat title editing styles */
.chat-title-input {
    color: #f3f4f6;
    font-size: 0.875rem;
    font-weight: 500;
}

.chat-title-input:focus {
    border-color: #0e7490;
    outline: none;
    box-shadow: 0 0 0 1px rgba(14, 116, 144, 0.5);
}

.chat-title-actions button {
    padding: 2px;
    border-radius: 4px;
    transition: all 0.2s;
}

.chat-title-actions button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.chat-item .edit-chat,
.chat-item .delete-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.chat-item .edit-chat:hover {
    background-color: rgba(14, 116, 144, 0.2);
}

.chat-item .delete-chat:hover {
    background-color: rgba(239, 68, 68, 0.2);
}

/* Мобильная версия: кнопки редактирования и удаления всегда видны */
@media (max-width: 768px) {
    .chat-item .edit-chat,
    .chat-item .delete-chat {
        opacity: 1 !important;
        padding: 2px !important;
        min-width: 20px !important;
        width: 20px !important;
        height: 20px !important;
    }
    
    .chat-item .edit-chat svg,
    .chat-item .delete-chat svg {
        width: 12px !important;
        height: 12px !important;
    }
    
    .chat-item .edit-chat:hover,
    .chat-item .delete-chat:hover {
        opacity: 0.8 !important;
    }
    
    /* Уменьшаем отступы между кнопками */
    .chat-item .flex.items-center.space-x-1 {
        gap: 2px !important;
        margin-left: 4px !important;
    }
    
    /* Уменьшаем отступы в контейнере с заголовком */
    .chat-item .flex.items-center.justify-between.mb-1 {
        gap: 4px !important;
        margin-bottom: 0.25rem !important;
    }
    
    /* Сайдбар должен быть выше всего на мобильных */
    #sidebar {
        z-index: 100 !important;
    }
    
    #sidebar-overlay {
        z-index: 90 !important;
    }
    
    /* Header и панель ввода должны быть ниже сайдбара */
    header.bg-dark-light\/50 {
        z-index: 10 !important;
        position: relative !important;
    }
    
    .bg-dark-light\/30.p-4 {
        z-index: 10 !important;
        position: relative !important;
    }
    
    /* Поле ввода сообщения - гарантируем доступность */
    #message-input {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-user-select: text !important;
        user-select: text !important;
        position: relative !important;
        z-index: 1 !important;
        background-color: #141413 !important;
    }
    

    .button#image-gen-btn {display: flex;
        justify-content: center;
        
        align-items: center;
    }



    /* Контейнер поля ввода */
    #message-input:focus {
        z-index: 1 !important;
        position: relative !important;
    }
    
    /* Убеждаемся, что кнопки не перекрывают поле ввода */
    #send-btn {
        pointer-events: auto !important;
        z-index: 2 !important;
    }
    
    /* Контейнер с полем ввода */
    .flex-1.relative.min-w-0 {
        position: relative !important;
        z-index: 1 !important;
    }
    
    /* Убираем любые блокировки pointer-events на мобильных */
    .max-w-4xl.mx-auto {
        pointer-events: auto !important;
    }
    
    /* Убеждаемся, что textarea доступен для ввода */
    textarea#message-input {
        -webkit-appearance: none !important;
        appearance: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    /* Контейнеры сообщений - ограничение ширины для планшетов и мобильных */
    .message {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .message .max-w-3xl {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Markdown content - предотвращение переполнения */
    .markdown-content {
        max-width: 100% !important;
        overflow-x: hidden !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
    }
    
    /* Блоки кода - ограничение ширины и горизонтальная прокрутка */
    .code-block-wrapper {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .code-block-wrapper pre {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        word-wrap: normal !important;
        white-space: pre !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .code-block-wrapper pre code {
        white-space: pre !important;
        word-wrap: normal !important;
        overflow-wrap: normal !important;
    }
    
    /* Inline code - перенос текста */
    .markdown-content code:not(pre code) {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-all !important;
        white-space: normal !important;
    }
    
    /* Pre элементы в markdown - ограничение ширины */
    .markdown-content pre {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: pre !important;
        word-wrap: normal !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .markdown-content pre code {
        white-space: pre !important;
        word-wrap: normal !important;
        overflow-wrap: normal !important;
    }
    
    /* Контейнеры с контентом сообщений */
    .message .flex-1 {
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }
    
    /* Контейнер с полем ввода и кнопками */
    .flex.items-center.space-x-2 {
        position: relative !important;
        z-index: 1 !important;
        pointer-events: auto !important;
    }
    
    /* Убираем любые блокировки на элементах ввода */
    #file-input,
    label[for="file-input"],
    #image-gen-btn,
    #send-btn {
        pointer-events: auto !important;
        touch-action: manipulation !important;
    }
    
    /* Убеждаемся, что контейнер ввода не блокируется */
    .max-w-4xl.mx-auto.px-2 {
        pointer-events: auto !important;
        position: relative !important;
        z-index: 1 !important;
    }
    
    /* Поле редактирования названия чата - гарантируем доступность */
    .chat-title-input {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-user-select: text !important;
        user-select: text !important;
        -webkit-appearance: none !important;
        appearance: none !important;
        position: relative !important;
        z-index: 10 !important;
        background-color: #1a1a19 !important;
        color: #e5e7eb !important;
        border: 1px solid #0e7490 !important;
        padding: 0.25rem 0.5rem !important;
        font-size: 0.875rem !important;
        width: 100% !important;
        min-width: 0 !important;
        flex: 1 1 auto !important;
        max-width: calc(100% - 50px) !important;
    }
    
    .chat-title-input:focus {
        outline: none !important;
        border-color: #0e7490 !important;
        box-shadow: 0 0 0 2px rgba(14, 116, 144, 0.2) !important;
        z-index: 10 !important;
    }
    
    /* Контейнер редактирования названия */
    .chat-title-editor {
        pointer-events: auto !important;
        position: relative !important;
        z-index: 10 !important;
        width: 100% !important;
        min-width: 0 !important;
        gap: 4px !important;
    }
    
    /* Уменьшаем отступы в контейнере редактирования */
    .flex-1.min-w-0.flex.items-center.space-x-2 {
        gap: 4px !important;
    }
    
    /* Кнопки сохранения/отмены */
    .chat-title-actions button {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        z-index: 11 !important;
        position: relative !important;
        padding: 2px !important;
        min-width: 20px !important;
        width: 20px !important;
        height: 20px !important;
    }
    
    .chat-title-actions button svg {
        width: 12px !important;
        height: 12px !important;
    }
    
    /* Уменьшаем отступы в контейнере редактирования */
    .chat-title-editor {
        gap: 4px !important;
    }
    
    .chat-title-actions {
        gap: 2px !important;
    }
    
    /* Убеждаемся, что элемент чата не блокирует редактирование */
    .chat-item {
        position: relative !important;
    }
    
    .chat-item .flex.items-center.justify-between.mb-1 {
        position: relative !important;
        z-index: 1 !important;
    }
}

/* ============================================
   CUSTOM SELECT DROPDOWN STYLES
   ============================================ */

/* Стили для нативного select - темный фон */
select {
    background-color: #1a1a19 !important;
    color: #e5e7eb !important;
    border: 1px solid #374151 !important;
}

select:focus {
    border-color: #0e7490 !important;
    outline: none !important;
    box-shadow: 0 0 0 1px rgba(14, 116, 144, 0.3) !important;
}

select:hover {
    border-color: #4b5563 !important;
}

/* Стили для option элементов - темный фон */
select option {
    background-color: #1a1a19 !important;
    color: #e5e7eb !important;
    padding: 0.5rem 0.75rem !important;
}

select option:hover {
    background-color: #252524 !important;
}

select option:checked {
    background-color: #0e7490 !important;
    color: #ffffff !important;
}

/* Кастомный dropdown компонент */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select-button {
    width: 100%;
    background: linear-gradient(135deg, #1a1a19 0%, #252524 100%);
    border: 1px solid #374151;
    border-radius: 0.5rem;
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    color: #e5e7eb;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s ease;
    user-select: none;
}

.custom-select-button:hover {
    border-color: #4b5563;
    background: linear-gradient(135deg, #252524 0%, #2a2a29 100%);
}

.custom-select-button:focus {
    outline: none;
    border-color: #0e7490;
    box-shadow: 0 0 0 1px rgba(14, 116, 144, 0.3);
}

.custom-select-button.active {
    border-color: #0e7490;
    box-shadow: 0 0 0 1px rgba(14, 116, 144, 0.3);
}

.custom-select-button .select-arrow {
    position: absolute;
    right: 0.75rem;
    width: 1.25rem;
    height: 1.25rem;
    color: #9ca3af;
    transition: transform 0.2s ease;
    pointer-events: none;
}

.custom-select-button.active .select-arrow {
    transform: rotate(180deg);
    color: #0e7490;
}

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #1a1a19 0%, #252524 100%);
    border: 1px solid #374151;
    border-radius: 0.5rem;
    box-shadow: 
        0 10px 25px -5px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.custom-select-dropdown.show {
    display: block;
}

.custom-select-option {
    padding: 0.625rem 0.75rem;
    color: #e5e7eb;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-option:hover {
    background-color: rgba(14, 116, 144, 0.15);
    color: #ffffff;
}

.custom-select-option.selected {
    background-color: rgba(14, 116, 144, 0.25);
    color: #0e7490;
    font-weight: 500;
}

.custom-select-option.selected:hover {
    background-color: rgba(14, 116, 144, 0.35);
}

/* Скрываем оригинальный select */
.custom-select-wrapper select {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
}

/* Скроллбар для dropdown */
.custom-select-dropdown::-webkit-scrollbar {
    width: 6px;
}

.custom-select-dropdown::-webkit-scrollbar-track {
    background: #1a1a19;
    border-radius: 3px;
}

.custom-select-dropdown::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 3px;
}

.custom-select-dropdown::-webkit-scrollbar-thumb:hover {
    background: #0e7490;
}