/* CSS переменные для цветов */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-input: #ffffff;
    --border-color: #d1d5db;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --modal-bg: #ffffff;
    --message-user-bg: transparent;
    --message-user-border: #d1d5db;
    --message-user-text: #111827;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1c1c1e;
        --bg-secondary: #2c2c2e;
        --bg-input: #2d2d30;
        --border-color: #333333;
        --text-primary: #ffffff;
        --text-secondary: #9ca3af;
        --modal-bg: #1c1c1e;
        --message-user-bg: transparent;
        --message-user-border: #333333;
        --message-user-text: #ffffff;
    }
}

/* Адаптивные классы для элементов */
.adaptive-bg-primary {
    background: var(--bg-primary) !important;
}

.adaptive-bg-input {
    background: var(--bg-input) !important;
}

.adaptive-text-primary {
    color: var(--text-primary) !important;
}

.adaptive-text-secondary {
    color: var(--text-secondary) !important;
}

.adaptive-border {
    border-color: var(--border-color) !important;
}

.user-message-bubble {
    background: var(--message-user-bg) !important;
    border-color: var(--message-user-border) !important;
    color: var(--message-user-text) !important;
}

.modal-bg {
    background: var(--modal-bg) !important;
}

.chat-item-bg {
    background: var(--modal-bg) !important;
}

.chat-item-bg:active {
    background: var(--bg-secondary) !important;
}

/* iOS Safari viewport fix */
html {
    height: 100%;
    height: -webkit-fill-available;
    scroll-behavior: smooth;
    background: var(--bg-primary);
    color-scheme: light dark;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    margin: 0;
    padding: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Header styling */
header {
    background: var(--bg-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
}

/* Mobile restrictions */
@media screen and (max-width: 768px) and (-webkit-touch-callout: none) {
    body {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    
    body.keyboard-open {
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    input, textarea, select {
        font-size: 16px;
        -webkit-user-select: none;
        user-select: none;
    }
    
    input:focus, textarea:focus {
        -webkit-user-select: text;
        user-select: text;
    }
    
    .input-fixed {
        transform: translateY(0) translateZ(0);
        -webkit-transform: translateY(0) translateZ(0);
        will-change: transform;
    }
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: -webkit-fill-available;
    position: relative;
    width: 100%;
    background: var(--bg-primary);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Увеличенный отступ снизу для desktop */
    padding-bottom: 180px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    background: var(--bg-primary);
}

/* Desktop отступ больше */
@media screen and (min-width: 769px) {
    .messages-container {
        padding-bottom: 200px;
    }
}

.input-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    bottom: env(safe-area-inset-bottom);
    height: auto;
    min-height: 110px;
    background: var(--bg-primary);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
}

.input-fixed .relative > div {
    transition: border-color 0.2s ease;
    background: var(--bg-input);
    border-color: var(--border-color);
}

.input-fixed .relative > div:focus-within {
    border-color: #9CA3AF;
}

.message {
    animation: fadeIn 0.4s ease-out;
}

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

/* Анимация печатания для AI ответов */
.typewriter {
    overflow: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.typewriter-cursor::after {
    content: '▌';
    color: var(--text-secondary);
    animation: blink 1s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.typing-indicator::after {
    content: '●●●';
    animation: typing 1.4s infinite;
    color: var(--text-secondary);
}

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

#messageInput {
    field-sizing: content;
    line-height: 1.5;
    -webkit-appearance: none;
    resize: none;
    outline: none;
    padding: 0;
    margin: 0;
    background: var(--bg-input);
    color: var(--text-primary);
    border: none;
}

#sendBtn.send-btn-active {
    background-color: rgba(249, 115, 22, 0.8) !important;
}

#sendBtn.send-btn-active svg {
    color: white !important;
}

.input-fixed button {
    transition: all 0.2s ease;
    border: 1.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    color: var(--text-secondary);
}

.input-fixed button:active {
    transform: scale(0.95);
}

.input-fixed .flex.items-center button {
    background: transparent !important;
}

/* Voice button active state */
#voiceBtn.text-red-500 {
    color: #ef4444 !important;
    background: rgba(239, 68, 68, 0.1) !important;
    border-color: #ef4444 !important;
}

#voiceBtn.text-red-500 svg {
    color: #ef4444 !important;
}

/* Voice button animation when recording */
#voiceBtn.text-red-500 {
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    70% { 
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
    100% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.user-message {
    max-width: 85%;
    margin-left: auto;
    transition: transform 0.2s ease;
}

.ai-message {
    max-width: 85%;
    transition: transform 0.2s ease;
}

.message-content {
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
    color: var(--text-primary);
}

.message-content code {
    background: var(--bg-secondary);
    color: #f87171;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
}

.messages-container::-webkit-scrollbar {
    width: 4px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 2px;
}

@media screen and (max-width: 768px) {
    .input-fixed {
        min-height: 80px;
    }
    
    .messages-container {
        padding-bottom: 100px;
    }
    
    .input-fixed button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Modal styling */
#historyModal .modal-backdrop {
    background: rgba(0, 0, 0, 0.5);
}

#historyModal .modal-content {
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
}

#historyModal .border-b {
    border-color: var(--border-color);
}

#historyContent {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.chat-item {
    background: var(--modal-bg);
    border-color: var(--border-color);
    touch-action: manipulation;
}

.chat-item:active {
    background: var(--bg-secondary);
}

.chat-item button {
    background: var(--modal-bg);
    border-color: var(--border-color);
    color: var(--text-secondary);
    touch-action: manipulation;
}
