* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #0f0f0f;
    color: #e0e0e0;
    height: 100vh;
    height: 100dvh; /* Динамическая высота viewport для мобильных */
    overflow: hidden;
    margin: 0;
    padding: 0;
    position: fixed;
    width: 100%;
    max-width: 100vw;
    top: 0;
    left: 0;
    -webkit-overflow-scrolling: touch;
}

.message-content {
    -webkit-user-select: text;
    user-select: text;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    position: relative;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: #1a1a1a;
    border-right: 1px solid #2a2a2a;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #2a2a2a;
}

.sidebar-header h2 {
    font-size: 20px;
    margin-bottom: 15px;
    color: #fff;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: #4a9eff;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: #3a8eef;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    padding: 12px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    color: #b0b0b0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-item:hover {
    background: #2a2a2a;
}

.chat-item.active {
    background: #2a4a6a;
    color: #fff;
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-delete {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
    opacity: 0;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.chat-item:hover .chat-item-delete {
    opacity: 1;
}

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

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid #2a2a2a;
}

.sidebar-footer select {
    width: 100%;
    padding: 10px;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    font-size: 14px;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0f0f0f;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

.chat-header {
    padding: 20px;
    border-bottom: 1px solid #2a2a2a;
    background: #1a1a1a;
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-btn {
    display: none; /* Скрыто на десктопе */
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: #e0e0e0;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0;
    align-items: center;
    justify-content: center;
}

.menu-btn:hover {
    background: #2a2a2a;
}

.menu-btn svg {
    width: 24px;
    height: 24px;
}

.chat-header h3 {
    font-size: 18px;
    color: #fff;
    flex: 1;
    margin: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.welcome-message {
    text-align: center;
    margin-top: 100px;
    color: #888;
}

.welcome-message h1 {
    font-size: 32px;
    margin-bottom: 15px;
    color: #fff;
}

.message {
    max-width: 80%;
    padding: 15px 18px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    animation: fadeIn 0.3s;
}

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

.message.user {
    align-self: flex-end;
    background: #4a9eff;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #2a2a2a;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
}

.message.thinking {
    align-self: flex-start;
    background: #2a2a2a;
    color: #888;
    font-style: italic;
}

.message-content-wrapper {
    position: relative;
    display: flex;
    align-items: flex-start;
}

.message-content {
    flex: 1;
    white-space: pre-wrap;
}

.message-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    transition: all 0.2s;
    flex-shrink: 0;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.action-btn.copied {
    background: rgba(74, 158, 255, 0.3);
    color: #4a9eff;
}

.action-btn svg {
    width: 16px;
    height: 16px;
}

.copy-btn, .regenerate-btn, .edit-btn {
    /* Наследуем стили от .action-btn */
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
}

/* Input Container */
.input-container {
    padding: 20px;
    background: #1a1a1a;
    border-top: 1px solid #2a2a2a;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.attach-btn {
    width: 44px;
    height: 44px;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: #3a3a3a;
    border-color: #4a9eff;
    color: #4a9eff;
}

.file-preview {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    max-height: 100px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    font-size: 13px;
    color: #e0e0e0;
    max-width: 200px;
}

.file-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item-size {
    color: #888;
    font-size: 11px;
}

.file-item-remove {
    cursor: pointer;
    color: #ff4444;
    font-weight: bold;
    padding: 0 4px;
    transition: color 0.2s;
}

.file-item-remove:hover {
    color: #ff6666;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    min-height: 44px;
}

#messageInput:focus {
    outline: none;
    border-color: #4a9eff;
}

.send-btn {
    width: 44px;
    height: 44px;
    background: #4a9eff;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: #3a8eef;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading Animation */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 15px 18px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #888;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #4a4a4a;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        height: 100vh;
        height: 100dvh;
    }
    
    .app-container {
        height: 100vh;
        height: 100dvh;
    }
    
    .menu-btn {
        display: flex !important; /* Показываем кнопку меню на мобильных */
    }
    
    .sidebar {
        width: 0;
        overflow: hidden;
        transition: width 0.3s ease;
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        height: 100dvh;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }
    
    .sidebar.open {
        width: 280px;
        overflow-y: auto;
    }
    
    .chat-container {
        width: 100%;
    }
    
    .sidebar-overlay {
        display: block;
    }
    
    .message {
        max-width: 85%;
        font-size: 14px;
        padding: 12px 14px;
    }
    
    .input-container {
        padding: 12px;
        gap: 8px;
    }
    
    #messageInput {
        font-size: 16px; /* Предотвращает авто-зум на iOS */
        padding: 10px 14px;
        min-height: 40px;
    }
    
    .send-btn,     .attach-btn {
        width: 40px;
        height: 40px;
        display: flex !important; /* Убеждаемся, что кнопка видна */
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .attach-btn:active {
        transform: scale(0.95);
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-header h3 {
        font-size: 16px;
    }
    
    .messages-container {
        padding: 12px;
        gap: 12px;
    }
    
    .copy-btn {
        width: 28px;
        height: 28px;
        top: 6px;
        right: 6px;
    }
    
    .copy-btn svg {
        width: 14px;
        height: 14px;
    }
}

/* Очень маленькие экраны */
@media (max-width: 480px) {
    .message {
        max-width: 90%;
        font-size: 13px;
        padding: 10px 12px;
    }
    
    .input-container {
        padding: 10px;
    }
    
    .messages-container {
        padding: 10px;
    }
}

/* Предотвращение масштабирования при двойном тапе */
@media (pointer: coarse) {
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    input, textarea, button {
        font-size: 16px; /* Предотвращает авто-зум на iOS */
    }
}

/* Принудительные стили для мобильных устройств */
.mobile-device,
html.mobile-device,
body.mobile-device {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

.mobile-device .app-container {
    width: 100% !important;
    max-width: 100vw !important;
}

.mobile-device .chat-container {
    width: 100% !important;
    max-width: 100vw !important;
}

.mobile-device .sidebar:not(.open) {
    display: none !important;
}

/* Принудительно скрываем горизонтальный скролл */
@media (max-width: 768px) {
    * {
        max-width: 100vw;
    }
    
    html, body {
        overflow-x: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }
}

/* Markdown стили */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 1em 0 0.5em 0;
    font-weight: 600;
    line-height: 1.3;
    color: #fff;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.1em; }

.message-content p {
    margin: 0.5em 0;
    line-height: 1.6;
}

.message-content ul,
.message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-content li {
    margin: 0.25em 0;
}

.message-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 1em 0;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 0.85em;
    line-height: 1.5;
    display: block;
}

.message-content blockquote {
    border-left: 3px solid #4a9eff;
    padding-left: 1em;
    margin: 1em 0;
    color: #aaa;
    font-style: italic;
}

.message-content a {
    color: #4a9eff;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
    overflow-x: auto;
    display: block;
}

.message-content table th,
.message-content table td {
    border: 1px solid #2a2a2a;
    padding: 8px;
    text-align: left;
}

.message-content table th {
    background: #2a2a2a;
    font-weight: 600;
}

/* Подсветка кода */
.message-content .hljs {
    background: #1a1a1a !important;
    color: #e0e0e0;
}

.message-content pre.hljs {
    background: #1a1a1a !important;
}

