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

html {
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Desktop styles */
@media (min-width: 768px) {
    .container {
        width: 95%;
        max-width: 800px;
        height: 90vh;
        border-radius: 16px;
        box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    border-bottom: 2px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.header-info h1 {
    font-size: 18px;
    margin-bottom: 8px;
    word-break: break-word;
    line-height: 1.3;
}

.status {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.status-badge.connecting {
    background: rgba(255,255,255,0.2);
}

.status-badge.connected {
    background: #10b981;
}

.status-badge.disconnected {
    background: #ef4444;
}

.users-badge {
    padding: 4px 12px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    font-size: 11px;
}

/* Body */
.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    position: relative;
    transition: background-color 0.2s ease;
}

.chat-body.drag-over {
    background-color: rgba(102, 126, 234, 0.05);
}

.chat-body.drag-over::before {
    content: '📎 Перетащите файл сюда';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 40px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
    z-index: 100;
    pointer-events: none;
}

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
    .messages {
        padding: 12px 8px;
    }
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    animation: slideIn 0.2s ease-out;
    max-width: 100%;
}

/* Аватар ассистента */
.message-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
    margin-bottom: 4px;
    flex-shrink: 0;
}

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

.message.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

@media (max-width: 600px) {
    .message-bubble {
        max-width: 75%;
    }
}

.message.specialist .message-bubble {
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.7;
}

.message-text {
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
}

.message-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.6;
}

/* Image in message */
.message-image {
    margin-top: 8px;
    border-radius: 12px;
    overflow: hidden;
}

.message-image img {
    max-width: 100%;
    max-height: 300px;
    display: block;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image img:hover {
    transform: scale(1.02);
}

@media (max-width: 600px) {
    .message-image img {
        max-height: 200px;
    }
}

.system-message {
    text-align: center;
    padding: 8px;
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
}

/* Typing indicator */
.typing-indicator {
    padding: 10px 16px;
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
}

.typing-dots {
    display: inline-block;
    animation: blink 1.4s infinite;
}

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

/* Footer */
.chat-footer {
    border-top: 1px solid #e5e7eb;
    padding: 12px 16px;
    background: #f9fafb;
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#file-preview {
    padding: 8px;
    background: #f3f4f6;
    border-radius: 12px;
    margin-bottom: 8px;
    display: none;
    align-items: center;
    gap: 8px;
}

#file-preview.show {
    display: flex;
}

#preview-image {
    max-width: 60px;
    max-height: 60px;
    border-radius: 8px;
}

#preview-info {
    flex: 1;
    font-size: 12px;
    color: #6b7280;
}

#remove-file {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 18px;
}

#file-input {
    display: none;
}

#attach-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: #e5e7eb;
    color: #6b7280;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

#attach-btn:hover:not(:disabled) {
    background: #d1d5db;
}

#attach-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#message-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    max-height: 100px;
    min-height: 40px;
}

#message-input:focus {
    border-color: #667eea;
}

#message-input:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
}

#send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

#send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.room-closed {
    text-align: center;
    padding: 16px;
    background: #10b981;
    color: white;
    border-radius: 12px;
    font-weight: 500;
}

/* Scrollbar */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Mobile optimizations */
@media (max-width: 600px) {
    .chat-header {
        padding: 12px 8px;
    }
    
    .header-info h1 {
        font-size: 15px;
    }
    
    .chat-footer {
        padding: 10px 8px;
    }
    
    #message-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .status-badge, .users-badge {
        font-size: 10px;
        padding: 3px 8px;
    }
}

@media (max-width: 400px) {
    .message {
        gap: 6px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        font-size: 16px;
    }
}

/* Image lightbox */
.lightbox {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
}

.lightbox.show {
    display: flex;
}

.lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
}

/* Ensure no horizontal overflow */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

.message-text, .message-bubble {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

