/* ============================================
   Чат техподдержки M16 - Адаптивные стили
   ============================================ */

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --danger-color: #dc2626;
    --warning-color: #f59e0b;
    --success-color: #10b981;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --message-user-bg: #dbeafe;
    --message-support-bg: #dcfce7;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--bg-color);
    overflow: hidden; /* Предотвращает прокрутку всей страницы */
    position: fixed; /* Фикс для мобильных браузеров */
    width: 100%;
}

/* ============================================
   Страница входа
   ============================================ */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 4px;
}

.login-header .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-bg);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input::placeholder {
    color: var(--text-secondary);
}

.error-message {
    background: #fef2f2;
    color: var(--danger-color);
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
    border: 1px solid #fecaca;
}

.btn {
    width: 100%;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    margin-bottom: 12px;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-color);
    border-color: var(--text-secondary);
}

.btn-secondary.active {
    background: #fef3c7;
    border-color: var(--warning-color);
    color: #92400e;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.forgot-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 14px;
}

.forgot-link:hover {
    text-decoration: underline;
}

.emergency-warning {
    background: #fef3c7;
    border: 1px solid var(--warning-color);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
    color: #92400e;
}

.emergency-warning p {
    margin-bottom: 4px;
}

.emergency-warning p:last-child {
    margin-bottom: 0;
}

/* ============================================
   Страница чата
   ============================================ */

.chat-page {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* Фикс для мобильных браузеров */
    height: 100dvh; /* Dynamic viewport height для современных браузеров */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Фикс для мобильных браузеров где шапка обрезается */
    padding-top: env(safe-area-inset-top, 0);
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    padding-top: max(16px, env(safe-area-inset-top)); /* Учёт выреза на iOS */
    background: var(--primary-color);
    color: white;
    flex-shrink: 0;
    z-index: 100;
}

.header-left h1 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 2px;
}

.user-login {
    font-size: 13px;
    opacity: 0.9;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-balance {
    font-size: 14px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 10px;
    border-radius: 20px;
}

.btn-logout {
    color: white;
    text-decoration: none;
    font-size: 14px;
    opacity: 0.9;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
}

.btn-sound {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s;
}

.btn-sound:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-clear {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s;
    opacity: 0.8;
}

.btn-clear:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
}

.emergency-banner {
    background: #fef3c7;
    color: #92400e;
    padding: 10px 20px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
}

.messages-container {
    flex: 1;
    min-height: 0; /* Важно для правильной работы overflow в flex */
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-color);
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message-user {
    align-self: flex-end;
    background: var(--message-user-bg);
    border-bottom-right-radius: 4px;
}

.message-support {
    align-self: flex-start;
    background: var(--message-support-bg);
    border-bottom-left-radius: 4px;
}

.message-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 6px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.message-sender {
    font-weight: 500;
}

.typing-indicator {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
}

.message-input-container {
    padding: 16px 20px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.message-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

.message-form input {
    flex: 1;
    padding: 14px 18px;
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    transition: border-color 0.2s;
    background: var(--bg-color);
}

.message-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-send {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send:hover {
    background: var(--primary-hover);
}

.btn-send:active {
    transform: scale(0.95);
}

/* Пустой чат */
.empty-chat {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

.empty-chat-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-chat h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
}

.empty-chat p {
    font-size: 14px;
}

/* ============================================
   Кнопка прикрепления файла
   ============================================ */

.btn-attach {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-attach:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

.btn-attach:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Файлы в сообщениях
   ============================================ */

.message-file {
    margin-bottom: 8px;
}

.message-file-image {
    margin-bottom: 8px;
}

.message-file-image img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-file-image img:hover {
    opacity: 0.9;
}

.file-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-color);
    transition: background 0.2s;
}

.file-link:hover {
    background: rgba(0, 0, 0, 0.1);
}

.file-icon {
    font-size: 20px;
}

.file-name {
    flex: 1;
    font-weight: 500;
    word-break: break-all;
}

.file-size {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.file-preview-image {
    display: block;
}

/* ============================================
   Адаптивность - Mobile
   ============================================ */

@media (max-width: 600px) {
    /* Страница входа */
    .login-page {
        padding: 16px;
        align-items: flex-start;
        padding-top: 60px;
    }
    
    .login-card {
        padding: 24px 20px;
        border-radius: 16px;
    }
    
    .login-header h1 {
        font-size: 22px;
    }
    
    /* Страница чата */
    .chat-container {
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    
    .chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top, 0));
        min-height: 56px;
        box-sizing: border-box;
    }
    
    .header-left h1 {
        font-size: 16px;
    }
    
    .user-login {
        font-size: 12px;
    }
    
    .user-balance {
        font-size: 12px;
        padding: 3px 8px;
    }
    
    .btn-logout {
        font-size: 13px;
        padding: 5px 10px;
    }
    
    .messages-container {
        padding: 12px;
    }
    
    .messages-list {
        gap: 8px;
    }
    
    .message {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 15px;
    }
    
    .message-input-container {
        padding: 12px 16px;
        /* Фиксация внизу на iOS */
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .message-form input {
        padding: 12px 16px;
        font-size: 16px; /* Предотвращает зум на iOS */
    }
    
    .btn-send {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
    
    .btn-attach {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .emergency-banner {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .message-file-image img {
        max-height: 200px;
    }
    
    .file-link {
        padding: 8px 12px;
    }
}

/* Очень маленькие экраны */
@media (max-width: 360px) {
    .login-card {
        padding: 20px 16px;
    }
    
    .chat-header {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .header-left {
        flex: 1;
        min-width: 0;
    }
    
    .header-left h1 {
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .user-login {
        font-size: 11px;
    }
    
    .header-right {
        gap: 6px;
        flex-shrink: 0;
    }
    
    .user-balance {
        display: none;
    }
    
    .btn-sound {
        font-size: 16px;
        padding: 4px 6px;
    }
    
    .btn-clear {
        font-size: 14px;
        padding: 4px 6px;
    }
    
    .btn-logout {
        font-size: 12px;
        padding: 4px 8px;
    }
    
    .message-form {
        gap: 6px;
    }
    
    .btn-attach {
        padding: 8px;
        font-size: 16px;
    }
    
    .btn-send {
        padding: 10px 14px;
        font-size: 16px;
    }
    
    #messageInput {
        padding: 10px 12px;
        font-size: 14px;
    }
}

/* ============================================
   Утилиты
   ============================================ */

.hidden {
    display: none !important;
}

/* Скроллбар */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

