/**
 * Чат-бот виджет - Стили
 * Портал культуры Калужской области
 */

/* ===========================
   CSS ПЕРЕМЕННЫЕ
   =========================== */
:root {
    /* Основные цвета - в стиле портала культуры Калужской области */
    --chatbot-primary: #00676B;
    --chatbot-primary-hover: #005559;
    --chatbot-primary-dark: #004245;

    /* Цвета фона */
    --chatbot-bg-white: #ffffff;
    --chatbot-bg-light: #f9fafb;
    --chatbot-bg-gray: #f3f4f6;
    --chatbot-bg-dark: #1f2937;

    /* Цвета текста */
    --chatbot-text-primary: #111827;
    --chatbot-text-secondary: #6b7280;
    --chatbot-text-light: #9ca3af;
    --chatbot-text-white: #ffffff;

    /* Цвета границ */
    --chatbot-border-color: #e5e7eb;
    --chatbot-border-light: #f3f4f6;

    /* Цвета состояний */
    --chatbot-success: #10b981;
    --chatbot-error: #ef4444;
    --chatbot-warning: #f59e0b;
    --chatbot-info: #3b82f6;

    /* Тени */
    --chatbot-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --chatbot-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --chatbot-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --chatbot-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Размеры */
    --chatbot-border-radius: 12px;
    --chatbot-border-radius-sm: 8px;
    --chatbot-border-radius-lg: 16px;

    /* Z-индексы */
    --chatbot-z-index-toggle: 9998;
    --chatbot-z-index-container: 9999;

    /* Размеры контейнера */
    --chatbot-width: 400px;
    --chatbot-height: 600px;
    --chatbot-max-width-mobile: 100%;
    --chatbot-max-height-mobile: 100%;

    /* Анимации */
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --chatbot-transition-fast: all 0.15s ease-in-out;
}

/* ===========================
   КНОПКА ОТКРЫТИЯ
   =========================== */
.chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(180deg, #00676B 0%, #00C9D1 100%);
    color: var(--chatbot-text-white);
    border: none;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    z-index: var(--chatbot-z-index-toggle);
    outline: none;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--chatbot-shadow-xl);
}

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

.chatbot-toggle:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.chatbot-toggle svg {
    width: 28px;
    height: 28px;
    transition: var(--chatbot-transition-fast);
}

/* Бейдж с количеством сообщений */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 24px;
    height: 24px;
    border-radius: 12px;
    background: var(--chatbot-error);
    color: var(--chatbot-text-white);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: var(--chatbot-shadow-md);
    animation: chatbot-badge-pulse 2s infinite;
}

.chatbot-badge:empty {
    display: none;
}

@keyframes chatbot-badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ===========================
   КОНТЕЙНЕР ЧАТА
   =========================== */
.chatbot-container {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    background: var(--chatbot-bg-white);
    border-radius: var(--chatbot-border-radius-lg);
    box-shadow: var(--chatbot-shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--chatbot-z-index-container);
    transition: var(--chatbot-transition);
    animation: chatbot-slide-in 0.3s ease-out;
}

@keyframes chatbot-slide-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chatbot-container.minimized {
    height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ===========================
   ЗАГОЛОВОК
   =========================== */
.chatbot-header {
    background: linear-gradient(180deg, #00676B 0%, #00C9D1 100%);
    color: var(--chatbot-text-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-avatar svg {
    width: 24px;
    height: 24px;
}

.chatbot-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

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

.chatbot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-success);
    animation: chatbot-status-pulse 2s infinite;
}

@keyframes chatbot-status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
}

.chatbot-minimize,
.chatbot-close {
    width: 32px;
    height: 32px;
    border-radius: var(--chatbot-border-radius-sm);
    background: transparent;
    color: var(--chatbot-text-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition-fast);
}

.chatbot-minimize:hover,
.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.chatbot-minimize:active,
.chatbot-close:active {
    transform: scale(0.9);
}

/* ===========================
   ОБЛАСТЬ СООБЩЕНИЙ
   =========================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chatbot-bg-light);
    scroll-behavior: smooth;
}

/* Кастомный скроллбар */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border-color);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-light);
}

/* Сообщение */
.chatbot-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: chatbot-message-appear 0.3s ease-out;
}

@keyframes chatbot-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message:last-child {
    margin-bottom: 0;
}

/* Сообщение бота */
.chatbot-message-bot {
    align-items: flex-start;
}

.chatbot-message-bot .chatbot-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(180deg, #00676B 0%, #00C9D1 100%);
    color: var(--chatbot-text-white);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-message-bot .chatbot-message-avatar svg {
    width: 20px;
    height: 20px;
}

.chatbot-message-content {
    flex: 1;
    min-width: 0;
}

.chatbot-message-bubble {
    background: var(--chatbot-bg-white);
    border-radius: var(--chatbot-border-radius);
    padding: 12px 16px;
    box-shadow: var(--chatbot-shadow-sm);
    word-wrap: break-word;
}

.chatbot-message-bot .chatbot-message-bubble {
    border-top-left-radius: 4px;
}

.chatbot-message-bubble p {
    margin: 0 0 8px 0;
    line-height: 1.5;
    font-size: 14px;
    color: var(--chatbot-text-primary);
}

.chatbot-message-bubble p:last-child {
    margin-bottom: 0;
}

.chatbot-message-bubble ul,
.chatbot-message-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chatbot-message-bubble li {
    margin: 4px 0;
    line-height: 1.5;
    font-size: 14px;
    color: var(--chatbot-text-primary);
}

.chatbot-message-time {
    font-size: 12px;
    color: var(--chatbot-text-light);
    margin-top: 4px;
}

/* Кнопки обратной связи */
.chatbot-message-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.chatbot-feedback-button {
    width: 32px;
    height: 32px;
    border-radius: var(--chatbot-border-radius-sm);
    background: transparent;
    border: 1px solid var(--chatbot-border-color);
    color: var(--chatbot-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition-fast);
}

.chatbot-feedback-button:hover {
    background: var(--chatbot-bg-gray);
    border-color: var(--chatbot-text-secondary);
}

.chatbot-feedback-button.active {
    background: var(--chatbot-primary);
    border-color: var(--chatbot-primary);
    color: var(--chatbot-text-white);
}

.chatbot-feedback-button svg {
    width: 16px;
    height: 16px;
}

/* Сообщение пользователя */
.chatbot-message-user {
    flex-direction: row-reverse;
    align-items: flex-end;
}

.chatbot-message-user .chatbot-message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chatbot-message-user .chatbot-message-bubble {
    background: linear-gradient(180deg, #00676B 0%, #00C9D1 100%);
    color: var(--chatbot-text-white);
    border-top-right-radius: 4px;
}

.chatbot-message-user .chatbot-message-bubble p,
.chatbot-message-user .chatbot-message-bubble li {
    color: var(--chatbot-text-white);
}

/* ===========================
   ИНДИКАТОР ПЕЧАТИ
   =========================== */
.chatbot-typing {
    display: flex;
    gap: 12px;
    padding: 0 20px 20px 20px;
    background: var(--chatbot-bg-light);
}

.chatbot-typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(180deg, #00676B 0%, #00C9D1 100%);
    color: var(--chatbot-text-white);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-typing-avatar svg {
    width: 20px;
    height: 20px;
}

.chatbot-typing-dots {
    background: var(--chatbot-bg-white);
    border-radius: var(--chatbot-border-radius);
    padding: 12px 16px;
    display: flex;
    gap: 4px;
    box-shadow: var(--chatbot-shadow-sm);
}

.chatbot-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-text-light);
    animation: chatbot-typing-animation 1.4s infinite;
}

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

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

@keyframes chatbot-typing-animation {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ===========================
   ФОРМА ВВОДА
   =========================== */
.chatbot-input {
    background: var(--chatbot-bg-white);
    border-top: 1px solid var(--chatbot-border-color);
    padding: 16px 20px;
    flex-shrink: 0;
}

.chatbot-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.chatbot-textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 12px 16px;
    border: 1px solid var(--chatbot-border-color);
    border-radius: var(--chatbot-border-radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: var(--chatbot-transition-fast);
    line-height: 1.5;
}

.chatbot-textarea:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chatbot-textarea::placeholder {
    color: var(--chatbot-text-light);
}

.chatbot-send-button {
    width: 44px;
    height: 44px;
    border-radius: var(--chatbot-border-radius);
    background: linear-gradient(180deg, #00676B 0%, #00C9D1 100%);
    color: var(--chatbot-text-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition-fast);
    flex-shrink: 0;
}

.chatbot-send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--chatbot-shadow-md);
}

.chatbot-send-button:active:not(:disabled) {
    transform: scale(0.95);
}

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

.chatbot-send-button svg {
    width: 20px;
    height: 20px;
}

.chatbot-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--chatbot-text-secondary);
}

.chatbot-char-counter {
    font-variant-numeric: tabular-nums;
}

.chatbot-clear-button {
    background: transparent;
    border: none;
    color: var(--chatbot-text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--chatbot-border-radius-sm);
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    transition: var(--chatbot-transition-fast);
}

.chatbot-clear-button:hover {
    background: var(--chatbot-bg-gray);
    color: var(--chatbot-text-primary);
}

.chatbot-clear-button svg {
    width: 16px;
    height: 16px;
}

/* ===========================
   СООБЩЕНИЕ ОБ ОШИБКЕ
   =========================== */
.chatbot-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--chatbot-border-radius-sm);
    padding: 12px 16px;
    margin: 0 20px 20px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: chatbot-error-shake 0.5s;
}

@keyframes chatbot-error-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.chatbot-error svg {
    flex-shrink: 0;
}

.chatbot-error span {
    font-size: 13px;
    color: #991b1b;
}

/* ===========================
   АДАПТИВНОСТЬ
   =========================== */
@media (max-width: 768px) {
    .chatbot-toggle {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .chatbot-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: var(--chatbot-max-height-mobile);
        border-radius: 0;
    }

    .chatbot-messages {
        padding: 16px;
    }

    .chatbot-input {
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    .chatbot-toggle {
        width: 52px;
        height: 52px;
    }

    .chatbot-toggle svg {
        width: 24px;
        height: 24px;
    }

    .chatbot-header {
        padding: 12px 16px;
    }

    .chatbot-title h3 {
        font-size: 15px;
    }

    .chatbot-status {
        font-size: 12px;
    }
}

/* ===========================
   ВЫСОКАЯ КОНТРАСТНОСТЬ
   =========================== */
@media (prefers-contrast: high) {
    .chatbot-toggle,
    .chatbot-send-button {
        border: 2px solid var(--chatbot-text-white);
    }

    .chatbot-message-bubble {
        border: 1px solid var(--chatbot-border-color);
    }

    .chatbot-textarea:focus {
        border-width: 2px;
    }
}

/* ===========================
   УМЕНЬШЕННОЕ ДВИЖЕНИЕ
   =========================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===========================
   ТЕМНАЯ ТЕМА (опционально)
   =========================== */
@media (prefers-color-scheme: dark) {
    .chatbot-container[data-theme="auto"] {
        --chatbot-bg-white: #1f2937;
        --chatbot-bg-light: #111827;
        --chatbot-bg-gray: #374151;
        --chatbot-text-primary: #f9fafb;
        --chatbot-text-secondary: #d1d5db;
        --chatbot-text-light: #9ca3af;
        --chatbot-border-color: #374151;
    }

    .chatbot-container[data-theme="auto"] .chatbot-message-bubble {
        background: #374151;
    }

    .chatbot-container[data-theme="auto"] .chatbot-textarea {
        background: #374151;
        color: var(--chatbot-text-primary);
        border-color: #4b5563;
    }
}

/* ===========================
   ФОКУС ДЛЯ КЛАВИАТУРНОЙ НАВИГАЦИИ
   =========================== */
.chatbot-toggle:focus-visible,
.chatbot-minimize:focus-visible,
.chatbot-close:focus-visible,
.chatbot-send-button:focus-visible,
.chatbot-clear-button:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.chatbot-textarea:focus-visible {
    outline: none;
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ===========================
   MARKDOWN ФОРМАТИРОВАНИЕ
   =========================== */
.chatbot-message-bubble strong {
    font-weight: 700;
    color: var(--chatbot-primary);
}

.chatbot-message-bubble em {
    font-style: italic;
}

.chatbot-message-bubble code {
    background-color: var(--chatbot-bg-gray);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.chatbot-message-bubble del {
    text-decoration: line-through;
    opacity: 0.7;
}

.chatbot-message-bubble a {
    color: var(--chatbot-primary);
    text-decoration: underline;
}

.chatbot-message-bubble a:hover {
    color: var(--chatbot-primary-hover);
}

/* ===========================
   УЛУЧШЕННАЯ ТИПОГРАФИКА И ЧИТАЕМОСТЬ
   =========================== */
.chatbot-message-bubble {
    line-height: 1.7 !important;
    font-size: 14px;
}

.chatbot-message-bubble p {
    margin: 0 0 14px 0;
    line-height: 1.7;
}

.chatbot-message-bubble p:last-child {
    margin-bottom: 0;
}

.chatbot-message-bubble ul,
.chatbot-message-bubble ol {
    margin: 14px 0;
    padding-left: 20px;
}

.chatbot-message-bubble li {
    margin: 10px 0;
    line-height: 1.7;
    padding-left: 6px;
}

.chatbot-message-bubble li + li {
    margin-top: 10px;
}

/* Больше отступов для strong элементов */
.chatbot-message-bubble strong {
    display: inline-block;
    margin-top: 8px;
    margin-bottom: 4px;
}

.chatbot-message-bubble p strong:first-child {
    display: block;
    margin-top: 0;
    margin-bottom: 8px;
}

/* Детали мероприятий - меньший размер */
.chatbot-message-bubble li p {
    font-size: 13px;
    margin: 4px 0;
    color: var(--chatbot-text-secondary);
    line-height: 1.6;
}

/* Эмодзи - отступ справа */
.chatbot-message-bubble li::marker {
    font-size: 1.1em;
}

/* Разделители */
.chatbot-message-bubble hr {
    border: none;
    border-top: 1px solid var(--chatbot-border-light);
    margin: 20px 0;
}

/* Улучшенные списки */
.chatbot-message-bubble ul {
    list-style: none;
    padding-left: 0;
}

.chatbot-message-bubble ul li {
    position: relative;
    padding-left: 28px;
}

.chatbot-message-bubble ul li::before {
    content: "•";
    position: absolute;
    left: 10px;
    color: var(--chatbot-primary);
    font-weight: bold;
    font-size: 1.2em;
}

/* Заголовки секций */
.chatbot-message-bubble h3,
.chatbot-message-bubble h4 {
    font-size: 15px;
    font-weight: 700;
    color: var(--chatbot-primary);
    margin: 18px 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--chatbot-border-light);
}

.chatbot-message-bubble h3:first-child,
.chatbot-message-bubble h4:first-child {
    margin-top: 0;
}

/* Код и ссылки - больше контраста */
.chatbot-message-bubble code {
    background-color: #e8f4f5;
    color: #004245;
    padding: 3px 8px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    font-weight: 500;
}

.chatbot-message-bubble a {
    font-weight: 500;
    padding-bottom: 1px;
    border-bottom: 1.5px solid var(--chatbot-primary);
    text-decoration: none;
}

.chatbot-message-bubble a:hover {
    background-color: #e8f4f5;
    border-bottom-color: var(--chatbot-primary-dark);
}

/* Карточки событий */
.event-card {
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
    border-left: 4px solid var(--chatbot-primary);
    padding: 14px 16px;
    margin: 14px 0;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.event-card strong {
    font-size: 15px;
    color: var(--chatbot-primary-dark);
}
