/* ========================================
   CHAT WIDGET - Стили клиентского чата
   ======================================== */

/* === Основные переменные === */
:root {
    --chat-primary: #22c55e;
    --chat-primary-hover: #16a34a;
    --chat-primary-dark: #15803d;
    --chat-gray-50: #f9fafb;
    --chat-gray-100: #f3f4f6;
    --chat-gray-200: #e5e7eb;
    --chat-gray-300: #d1d5db;
    --chat-gray-600: #4b5563;
    --chat-gray-700: #374151;
    --chat-gray-800: #1f2937;
    --chat-gray-900: #111827;
    --chat-red: #ef4444;
    --chat-blue: #3b82f6;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    --chat-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --chat-z-index: 9999;
}

/* === Основной контейнер === */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* === Кнопка открытия чата === */
.chat-toggle-btn {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    transition: var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    animation: chatButtonAppear 0.4s ease-out, chatButtonPulse 2.5s ease-in-out infinite 1s;
}

.chat-toggle-btn::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border-radius: 50%;
    border: 2px solid var(--chat-primary);
    opacity: 0;
    animation: chatButtonRing 2.5s ease-in-out infinite 1s;
}

.chat-toggle-btn::after {
    content: 'Напишите нам!';
    position: absolute;
    right: 70px;
    top: 50%;
    transform: translateY(-50%);
    background: white;
    color: var(--chat-gray-800);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--chat-shadow);
    opacity: 0;
    pointer-events: none;
    animation: chatTooltipAppear 2.5s ease-in-out infinite 1s;
}

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

@keyframes chatButtonRing {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.3);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes chatTooltipAppear {
    0%, 45% {
        opacity: 0;
        transform: translateY(-50%) translateX(10px);
    }
    50%, 95% {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-50%) translateX(10px);
    }
}

.chat-toggle-btn:hover {
    background: var(--chat-primary-hover);
    transform: scale(1.05);
    box-shadow: var(--chat-shadow-lg);
    animation: none;
}

.chat-toggle-btn:hover::before,
.chat-toggle-btn:hover::after {
    animation: none;
    opacity: 0;
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

.chat-toggle-btn.chat-open {
    background: var(--chat-gray-700);
    animation: none;
}

.chat-toggle-btn.chat-open::before,
.chat-toggle-btn.chat-open::after {
    animation: none;
    opacity: 0;
}

@keyframes chatButtonAppear {
    from {
        opacity: 0;
        transform: scale(0) translateY(100px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* === Бейдж непрочитанных === */
.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--chat-red);
    color: white;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    animation: badgePulse 1.5s ease-in-out infinite;
}

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

.chat-unread-badge.hidden {
    display: none;
}

/* === Окно чата === */
.chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: var(--chat-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--chat-transition);
    animation: chatWindowAppear 0.3s ease-out;
}

@keyframes chatWindowAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-window.hidden {
    display: none;
}

/* === Заголовок чата === */
.chat-header {
    background: var(--chat-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
}

.chat-header-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    opacity: 0.9;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fbbf24;
    animation: statusPulse 2s ease-in-out infinite;
}

.status-indicator.online {
    background: #10b981;
}

.status-indicator.offline {
    background: #ef4444;
    animation: none;
}

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

.chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* === Область сообщений === */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat-gray-50);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(229, 231, 235, 0.6) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(229, 231, 235, 0.6);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(209, 213, 219, 0.8);
}

/* === Сообщения === */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: messageAppear 0.2s ease-out;
}

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

/* Сообщения диспетчера */
.chat-message.dispatcher {
    align-self: flex-start;
}

.chat-message.dispatcher .chat-message-content {
    background: white;
    border: 1px solid var(--chat-gray-200);
}

.chat-message.dispatcher .chat-message-text {
    color: var(--chat-gray-800);
}

/* Сообщения клиента */
.chat-message.client {
    align-self: flex-end;
}

.chat-message.client .chat-message-content {
    background: var(--chat-primary);
    color: white;
}

/* Системные сообщения */
.chat-message.system {
    align-self: center;
    max-width: 90%;
}

.chat-message.system .chat-message-content {
    background: var(--chat-gray-200);
    text-align: center;
    font-size: 13px;
}

.chat-message.system .chat-message-text {
    color: var(--chat-gray-700);
}

.chat-message-content {
    padding: 10px 14px;
    border-radius: 12px;
    position: relative;
}

.chat-message-text {
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
    white-space: pre-wrap;
}

.chat-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Галочки прочтения (WhatsApp style) */
.chat-message-status {
    display: inline-flex;
    gap: 1px;
}

.checkmark {
    width: 14px;
    height: 10px;
    display: inline-block;
}

.checkmark.single {
    color: var(--chat-gray-400);
}

.checkmark.double {
    color: var(--chat-primary);
}

/* ✅ ЭТАП 2.4: Иконка часов для pending сообщений */
.clock-icon {
    width: 14px;
    height: 14px;
    display: inline-block;
    color: var(--chat-gray-400);
    opacity: 0.6;
}

.chat-message-status.pending {
    opacity: 0.7;
}

.message-pending {
    opacity: 0.8;
}

.message-sent {
    opacity: 1;
}

/* === Индикатор печати === */
.chat-typing-indicator {
    padding: 10px 20px;
    background: white;
    border-top: 1px solid var(--chat-gray-200);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--chat-gray-600);
}

.chat-typing-indicator.hidden {
    display: none;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-gray-400);
    animation: typingDot 1.4s infinite;
}

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

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

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* === Ввод сообщения === */
.chat-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid var(--chat-gray-200);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--chat-gray-300);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.2s;
    scrollbar-width: thin;
    scrollbar-color: rgba(209, 213, 219, 0.5) transparent;
}

.chat-input:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-input::-webkit-scrollbar {
    width: 3px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input::-webkit-scrollbar-thumb {
    background: rgba(209, 213, 219, 0.5);
    border-radius: 2px;
}

.chat-input::-webkit-scrollbar-thumb:hover {
    background: rgba(209, 213, 219, 0.8);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chat-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--chat-primary-hover);
    transform: scale(1.05);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    background: var(--chat-gray-300);
    cursor: not-allowed;
    transform: none;
}

/* === Формы === */
.chat-form {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 10;
    display: flex;
    flex-direction: column;
    animation: formSlideIn 0.3s ease-out;
}

@keyframes formSlideIn {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-form.hidden {
    display: none;
}

.chat-form-content {
    padding: 40px 30px;
    overflow-y: auto;
    flex: 1;
}

.chat-form-content h3 {
    font-size: 24px;
    font-weight: 700;
    color: var(--chat-gray-900);
    margin: 0 0 8px 0;
}

.chat-form-content p {
    font-size: 14px;
    color: var(--chat-gray-600);
    margin: 0 0 24px 0;
}

.chat-form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--chat-gray-700);
    margin-bottom: 6px;
}

.chat-form-input,
.chat-form-select,
.chat-form-textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--chat-gray-300);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.chat-form-input:focus,
.chat-form-select:focus,
.chat-form-textarea:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-form-textarea {
    resize: vertical;
    min-height: 80px;
}

.chat-form-submit {
    width: 100%;
    padding: 14px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-form-submit:hover {
    background: var(--chat-primary-hover);
}

.chat-form-submit:active {
    transform: scale(0.98);
}

.chat-form-submit:disabled {
    background: var(--chat-gray-300);
    cursor: not-allowed;
}

.chat-form-skip {
    width: 100%;
    padding: 12px;
    background: transparent;
    color: var(--chat-gray-600);
    border: none;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    transition: color 0.2s;
}

.chat-form-skip:hover {
    color: var(--chat-gray-900);
}

.chat-form-note {
    font-size: 12px;
    color: var(--chat-gray-500);
    text-align: center;
    margin-top: 12px;
}

/* === Оценка звёздами === */
.chat-rating-stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
}

.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    transition: transform 0.2s;
}

.star-btn:hover {
    transform: scale(1.1);
}

.star-btn .star-icon {
    stroke: var(--chat-gray-300);
    fill: transparent;
    transition: all 0.2s;
}

.star-btn:hover .star-icon,
.star-btn.active .star-icon {
    stroke: #fbbf24;
    fill: #fbbf24;
}

/* === Адаптивность для мобильных === */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
    }
    
    .chat-toggle-btn {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        z-index: var(--chat-z-index);
    }
    
    /* Скрываем кнопку когда чат открыт */
    .chat-toggle-btn.chat-open {
        display: none;
    }
    
    /* Убираем подсказку на мобильных */
    .chat-toggle-btn::after {
        display: none;
    }
    
    .chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        animation: chatWindowMobileAppear 0.3s ease-out;
    }
    
    @keyframes chatWindowMobileAppear {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .chat-header {
        padding: 16px 20px;
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    .chat-header-title {
        font-size: 19px;
    }
    
    .chat-status {
        font-size: 14px;
    }
    
    .chat-message-text {
        font-size: 15px;
        line-height: 1.5;
    }
    
    .chat-input-container {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    
    .chat-input {
        font-size: 16px;
        padding: 12px 16px;
        min-height: 44px;
    }
    
    .chat-send-btn {
        width: 44px;
        height: 44px;
    }
    
    .chat-form-input,
    .chat-form-textarea {
        font-size: 16px;
        padding: 14px 16px;
        min-height: 48px;
    }
    
    .chat-form-submit {
        font-size: 16px;
        padding: 14px 24px;
        min-height: 48px;
    }
}

/* === Утилиты === */
.hidden {
    display: none !important;
}
