/* ============================================
   СТИЛИ ДЛЯ ЧАТА
   ============================================ */

/* Контейнер чата */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 650px;
    background: var(--bg-primary);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    border: 1px solid var(--gray-100);
    margin-bottom: var(--spacing-xl);
}

/* Заголовок чата */
.chat-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.25rem 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.chat-header h2 {
    margin: 0;
    font-size: 1.375rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-header h2::before {
    content: '\f086';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 1.25rem;
}

/* Информация о чате */
.chat-info {
    padding: 1rem 1.75rem;
    background: linear-gradient(135deg, var(--gray-50), var(--bg-secondary));
    border-bottom: 1px solid var(--gray-200);
}

.ticket-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.75rem;
    margin-bottom: 0;
}

.ticket-meta-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.ticket-meta-item i {
    color: var(--primary-color);
    font-size: 1rem;
}

.ticket-meta-label {
    font-weight: 700;
    color: var(--gray-600);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ticket-meta-value {
    color: var(--gray-900);
    font-weight: 600;
}

/* Область сообщений */
.messages-area {
    flex-grow: 1;
    padding: 1.75rem;
    overflow-y: auto;
    background: linear-gradient(135deg, #f8fafc 0%, #eef2f7 100%);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-height: 90vh;
    border: none;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--gray-100);
}

.messages-area::-webkit-scrollbar {
    width: 8px;
}

.messages-area::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: var(--radius-full);
}

.messages-area::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: var(--radius-full);
}

.messages-area::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--secondary-color));
}

/* Сообщения */
.message {
    max-width: 75%;
    padding: 1rem 1.375rem;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--shadow-md);
    animation: messageSlide 0.3s ease-out;
    line-height: 1.6;
}

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

.message p {
    margin: 0;
    color: inherit;
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.message.operator {
    align-self: flex-start;
    background: white;
    color: var(--gray-900);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--gray-200);
}

.message.system {
    align-self: center;
    background: linear-gradient(135deg, var(--gray-100), var(--gray-200));
    color: var(--gray-600);
    font-style: italic;
    font-size: 0.9375rem;
    max-width: 90%;
    border-radius: 12px;
    border: 1px solid var(--gray-300);
    box-shadow: var(--shadow-sm);
}

.message.system::before {
    content: '\f05a';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-right: 0.5rem;
    color: var(--gray-500);
}

/* Метаданные сообщения */
.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    gap: 0.75rem;
}

.message-sender {
    font-weight: 700;
}

.message-time {
    opacity: 0.8;
    font-weight: 500;
}

.message.user .message-meta {
    color: rgba(255, 255, 255, 0.9);
}

.message.operator .message-meta {
    color: var(--gray-600);
}

/* Вложения в сообщениях */
.message-attachment-image {
    max-width: 320px;
    max-height: 320px;
    border-radius: var(--radius-lg);
    margin-top: 0.75rem;
    display: block;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-base);
    cursor: pointer;
}

.message-attachment-image:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

.file-attachment {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.125rem;
    margin-top: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.9375rem;
    transition: all var(--transition-base);
}

.file-attachment:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(3px);
}

.file-attachment strong {
    color: inherit;
    font-weight: 700;
}

.file-attachment a {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-attachment a:hover {
    text-decoration: underline;
}

.message.user .file-attachment {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.message.operator .file-attachment {
    background: linear-gradient(135deg, var(--success-light), #d1fae5);
    border-color: var(--success-color);
    color: #065f46;
}

/* ============================================
   ОБЛАСТЬ ВВОДА СООБЩЕНИЙ
   ============================================ */

.message-input-area {
    padding: 1.25rem 1.75rem;
    background: linear-gradient(135deg, var(--bg-primary), var(--gray-50));
    border-top: 2px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-input {
    flex-grow: 1;
    padding: 1rem 1.25rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all var(--transition-base);
    background: var(--bg-primary);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100px;
}

.message-input:hover {
    border-color: var(--gray-300);
}

.message-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    background: var(--bg-primary);
}

.message-input::placeholder {
    color: var(--gray-400);
}

.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-actions .btn {
    min-width: 140px;
}

/* Кнопка выбора файла */
.file-input-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    cursor: pointer;
    margin: 0;
    min-width: 180px;
    position: relative;
    transition: all var(--transition-base);
    font-weight: 600;
}

.file-input-label:active {
    transform: scale(0.98);
}

.file-input-label i.fa-check {
    color: var(--success-color);
    animation: checkBounce 0.5s ease;
}

@keyframes checkBounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

.file-input-label i {
    font-size: 1rem;
}

#photo-attachment-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
}

/* ============================================
   ЗАГОЛОВОК СТРАНИЦЫ ТИКЕТА
   ============================================ */

.ticket-page-header {
    margin-bottom: var(--spacing-lg);
    display: flex;
    align-items: center;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    text-decoration: none;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    font-weight: 600;
    transition: all var(--transition-base);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    min-width: 120px;
}

.btn-back:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--primary-color));
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: white;
    text-decoration: none;
}

.btn-back:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-back i {
    font-size: 0.9rem;
}

/* ============================================
   ИНФОРМАЦИЯ О ТИКЕТЕ
   ============================================ */

.ticket-info {
    margin-bottom: var(--spacing-xl);
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary-light), #fef3ff);
    border-radius: var(--radius-xl);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
}

.ticket-info h2 {
    margin-top: 0;
    margin-bottom: var(--spacing-md);
    color: var(--gray-900);
    font-size: 1.5rem;
}

.ticket-info p {
    margin-bottom: 0.75rem;
    color: var(--gray-700);
    font-size: 0.9375rem;
}

.ticket-info p:last-child {
    margin-bottom: 0;
}

.ticket-info strong {
    color: var(--gray-900);
    font-weight: 700;
}

/* Назначение оператора */
.operator-assignment {
    display: flex;
    align-items: center;
    margin-bottom: var(--spacing-xl);
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 2px solid var(--gray-200);
}

.operator-assignment strong {
    margin-right: 0;
    color: var(--gray-800);
    font-size: 1rem;
}

.operator-assignment form {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin: 0;
    flex-wrap: wrap;
    flex: 1;
}

.operator-assignment select {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem 1.125rem;
    border-radius: var(--radius-lg);
    border: 2px solid var(--gray-200);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--gray-900);
    background: var(--bg-primary);
    transition: all var(--transition-base);
    cursor: pointer;
    overflow: visible;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M10.293 3.293L6 7.586 1.707 3.293A1 1 0 00.293 4.707l5 5a1 1 0 001.414 0l5-5a1 1 0 10-1.414-1.414z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 3rem;
}

.operator-assignment select option {
    padding: 0.5rem;
    background: var(--bg-primary);
    color: var(--gray-900);
    white-space: normal;
    word-wrap: break-word;
}

.operator-assignment select:hover {
    border-color: var(--gray-300);
}

.operator-assignment select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    outline: none;
}

.operator-assignment .btn {
    min-width: 130px;
}

/* Действия с тикетом */
.ticket-actions {
    margin-top: var(--spacing-xl);
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.ticket-actions form {
    display: inline-block;
}

.ticket-actions button,
.ticket-actions .btn {
    min-width: 160px;
}

/* ============================================
   СТАТУС ОТПРАВКИ СООБЩЕНИЯ
   ============================================ */

.message-status {
    margin-top: var(--spacing-md);
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    font-weight: 600;
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.message-status::before {
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 1.125rem;
}

.message-status-success {
    background: linear-gradient(135deg, var(--success-light), #d1fae5);
    color: #065f46;
    border: 2px solid var(--success-color);
}

.message-status-success::before {
    content: '\f058';
    color: var(--success-color);
}

.message-status-error {
    background: linear-gradient(135deg, var(--danger-light), #fee2e2);
    color: #991b1b;
    border: 2px solid var(--danger-color);
}

.message-status-error::before {
    content: '\f06a';
    color: var(--danger-color);
}

.message-status-warning {
    background: linear-gradient(135deg, var(--warning-light), #fef3c7);
    color: #92400e;
    border: 2px solid var(--warning-color);
}

.message-status-warning::before {
    content: '\f071';
    color: var(--warning-color);
}

/* ============================================
   ПРЕВЬЮ ФАЙЛОВ
   ============================================ */

.file-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, var(--gray-50), var(--gray-100));
    border-radius: var(--radius-lg);
    border: 2px dashed var(--gray-300);
}

.file-preview-item {
    position: relative;
    width: 140px;
    height: 140px;
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.file-preview-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-4px);
}

.file-preview-image-wrapper {
    width: 100%;
    height: 85px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: linear-gradient(135deg, var(--gray-50), var(--gray-100));
}

.file-preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.file-preview-icon {
    width: 100%;
    height: 85px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light), #fef3ff);
    color: var(--primary-color);
    font-size: 2.5rem;
}

.file-preview-icon i.fa-file-pdf {
    color: var(--danger-color);
}

.file-preview-icon i.fa-file-word {
    color: var(--info-color);
}

.file-preview-icon i.fa-file-excel {
    color: var(--success-color);
}

.file-preview-icon i.fa-video {
    color: var(--secondary-color);
}

.file-preview-info {
    flex: 1;
    width: 100%;
    padding: 0.5rem 0.625rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: white;
    text-align: center;
    gap: 0.25rem;
    border-top: 1px solid var(--gray-200);
}

.file-preview-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    line-height: 1.3;
}

.file-preview-size {
    font-size: 0.6875rem;
    color: var(--gray-500);
    font-weight: 500;
}

.file-preview-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border: none;
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
    color: white;
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    transition: all var(--transition-base);
    z-index: 10;
    box-shadow: var(--shadow-md);
}

.file-preview-remove:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.file-preview-remove:active {
    transform: scale(0.95);
}

.file-preview-remove i {
    font-size: 0.75rem;
}

/* ============================================
   АДАПТИВНЫЙ ДИЗАЙН ДЛЯ ЧАТА
   ============================================ */

@media (max-width: 992px) {
    .message {
        max-width: 85%;
    }
    
    .message-attachment-image {
        max-width: 280px;
        max-height: 280px;
    }
    
    .file-preview-item {
        width: 120px;
        height: 120px;
    }
}

@media (max-width: 768px) {
    .chat-container {
        height: 550px;
        margin-bottom: var(--spacing-lg);
        border-radius: var(--radius-xl);
    }
    
    .chat-header {
        padding: 1rem 1.25rem;
    }
    
    .chat-header h2 {
        font-size: 1.125rem;
    }
    
    .message {
        max-width: 90%;
        padding: 0.875rem 1.125rem;
    }
    
    .ticket-meta {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .operator-assignment {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-md);
    }
    
    .operator-assignment form {
        flex-direction: column;
        width: 100%;
    }
    
    .operator-assignment select {
        width: 100%;
        min-width: auto;
    }
    
    .operator-assignment .btn {
        width: 100%;
    }
    
    .message-attachment-image {
        max-width: 240px;
        max-height: 240px;
    }
    
    .ticket-actions {
        flex-direction: column;
    }
    
    .ticket-actions form {
        width: 100%;
    }
    
    .ticket-actions button,
    .ticket-actions .btn {
        width: 100%;
        min-width: auto;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
        min-width: auto;
    }
    
    .file-input-label {
        width: 100%;
        min-width: auto;
    }
}

@media (max-width: 576px) {
    .chat-container {
        height: 500px;
        border-radius: var(--radius-lg);
    }
    
    .chat-header {
        padding: 0.875rem 1rem;
    }
    
    .chat-header h2 {
        font-size: 1rem;
    }
    
    .chat-info {
        padding: 0.875rem 1rem;
    }
    
    .message-input-area {
        padding: 1rem;
    }
    
    .messages-area {
        padding: 1.25rem;
        max-height: 75vh;
    }
    
    .message {
        max-width: 95%;
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }
    
    .message-meta {
        font-size: 0.6875rem;
    }
    
    .message-input {
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
        min-height: 80px;
    }
    
    .ticket-page-header {
        margin-bottom: var(--spacing-md);
    }
    
    .btn-back {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
        min-width: 100px;
    }
    
    .ticket-info {
        padding: 1rem;
        margin-bottom: var(--spacing-lg);
    }
    
    .ticket-info h2 {
        font-size: 1.25rem;
    }
    
    .ticket-info p {
        font-size: 0.875rem;
    }
    
    .operator-assignment {
        padding: 1rem;
    }
    
    .operator-assignment strong {
        font-size: 0.9375rem;
    }
    
    .operator-assignment select {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    .file-preview-container {
        gap: 0.75rem;
        padding: 0.875rem;
    }
    
    .file-preview-item {
        width: 110px;
        height: 110px;
    }
    
    .file-preview-image-wrapper,
    .file-preview-icon {
        height: 70px;
    }
    
    .file-preview-icon {
        font-size: 2rem;
    }
    
    .file-preview-name {
        font-size: 0.6875rem;
    }
    
    .file-preview-size {
        font-size: 0.625rem;
    }
    
    .file-preview-remove {
        width: 24px;
        height: 24px;
        top: 4px;
        right: 4px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        height: 480px;
    }
    
    .message-attachment-image {
        max-width: 200px;
        max-height: 200px;
    }
    
    .file-preview-item {
        width: 100px;
        height: 100px;
    }
    
    .file-preview-image-wrapper,
    .file-preview-icon {
        height: 60px;
    }
    
    .file-preview-icon {
        font-size: 1.75rem;
    }
}
