@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --ai-bg: #ffffff;
    --ai-text: #333333;
    --ai-border: #e2e8f0;
    --ai-header-bg: #f1f5f9;
    --ai-block-bg: #f1f5f9;
    --ai-block-text: #334155;
    --ai-tag-bg: #e0e7ff;
    --ai-tag-text: #4338ca;
    --ai-input-border: #cbd5e1;
}

/* Покрываем все стандарты темной темы (Tailwind, Chatwoot и кастомные) */
html.dark, 
body.dark, 
.dark-mode,
[data-theme="dark"] {
    --ai-bg: #141517;
    --ai-text: #d4d3d3;
    --ai-border: #2d2d35;
    --ai-header-bg: #1c1d20;
    --ai-block-bg: #272a2d;
    --ai-block-text: #cbd5e1;
    --ai-tag-bg: #312e81;
    --ai-tag-text: #c7d2fe;
    --ai-input-border: #475569;
}

/* Основной контейнер модального окна (теперь привязан к reply-box) */
#custom-ai-copilot {
    position: fixed !important;
    /* Координаты left, bottom и width теперь вычисляет JS */
    max-height: 85vh !important;
    background: var(--ai-bg) !important;
    color: var(--ai-text) !important;
    border-radius: 6px 6px 0 0 !important; /* Плоский низ, скругленный верх */
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15) !important; /* Тень падает вверх */
    z-index: 999999 !important;
    display: none;
    flex-direction: column;
    font-family: 'Inter', sans-serif;
    border: 1px solid var(--ai-border);
    border-bottom: none;
    overflow: hidden;
    /* Убрали transition, чтобы окно мгновенно меняло ширину при ресайзе браузера */
}

/* Шапка */
.ai-header {
    padding: 3px 16px; /* Уменьшили отступы */
    border-bottom: 1px solid var(--ai-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    background: var(--ai-header-bg);
}
.ai-close-btn {
    cursor: pointer;
    background: none;
    border: none;
    font-size: 20px;
    color: #64748b;
}

/* Тело виджета */
.ai-body {
    padding: 12px 16px; /* Уменьшили отступы */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px; /* Уменьшили расстояние между блоками */
}

/* Блоки Read-only */
.ai-readonly-block {
    background: var(--ai-block-bg);
    padding: 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--ai-block-text);
}
.ai-block-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 6px;
    font-weight: 600;
}

/* Кнопка генерации */
.ai-generate-btn {
    background: #8b5cf6;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}
.ai-generate-btn:hover { background: #7c3aed; }
.ai-generate-btn:disabled { background: #cbd5e1; cursor: not-allowed; }

/* Теги (Chips) */
.ai-tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.ai-tag {
    background: var(--ai-tag-bg);
    color: var(--ai-tag-text);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.75rem;
    cursor: pointer;
    border: 1px solid transparent;
}
.ai-tag:hover { border-color: var(--ai-tag-text); }

/* Поле ввода */
.ai-textarea {
    width: 100%;
    min-height: 60px; /* Уменьшили стартовую высоту */
    max-height: none; /* Максимальная высота, после которой появится скролл внутри поля */
    padding: 12px;
    border: 1px solid var(--ai-input-border);
    border-radius: 8px;
    resize: none; /* Отключаем ручное изменение размера, так как оно автоматическое */
    font-family: inherit;
    font-size: 0.875rem;
    background: transparent;
    color: inherit;
    overflow-y: auto; /* Скролл появится только если текст превысит max-height */
}

textarea#ai-input {
    min-height: 150px !important;
}

/* Подвал (Отправить) */
.ai-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 4px; /* Уменьшили отступ */
}

.ai-lang-indicator {
    font-size: 0.75rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 4px;
}
.ai-send-btn {
    background: #10b981;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
}
.ai-send-btn:hover { background: #059669; }
.ai-loading { opacity: 0.6; pointer-events: none; }

/* Встроенный блок перевода внутри самого сообщения */
.ai-inline-translation {
    margin-top: 8px;
    background: rgba(128, 128, 128, 0.15); /* Универсальный полупрозрачный фон */
    border: 1px solid rgba(128, 128, 128, 0.2);
    color: inherit; /* Наследует цвет текста самого сообщения (белый или черный) */
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.875rem;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    font-family: 'Inter', sans-serif;
}
.ai-inline-translation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.75rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
    padding-bottom: 6px;
    opacity: 0.9;
}
.ai-inline-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    opacity: 0.6;
}
.ai-inline-close:hover {
    opacity: 1;
}
.ai-inline-translation-body {
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Кнопки подписи и эмодзи */
.ai-footer {
    position: relative; /* Для позиционирования панели эмодзи */
}
.ai-footer-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ai-icon-btn {
    background: transparent;
    border: none;
    color: var(--ai-text);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: all 0.2s;
}
.ai-icon-btn:hover {
    opacity: 1;
    background: var(--ai-block-bg);
}

/* Панель эмодзи */
#ai-emoji-picker {
    position: absolute;
    bottom: 65px; /* Отступ снизу, чтобы панель висела ровно над подвалом */
    left: 20px;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    z-index: 1000000;
}
.ai-emoji-item {
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    text-align: center;
    border-radius: 4px;
    transition: background 0.2s;
}
.ai-emoji-item:hover {
    background: var(--ai-block-bg);
}

/* Правая часть подвала (Язык + Кнопка) */
.ai-footer-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Модальное окно настройки подписи */
#ai-sig-modal {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000001;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px 12px 0 0;
    backdrop-filter: blur(2px);
}
.ai-sig-modal-content {
    background: var(--ai-bg);
    padding: 16px;
    border-radius: 8px;
    width: 85%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    border: 1px solid var(--ai-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-sig-modal-header {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--ai-text);
}
#ai-sig-textarea {
    width: 100%;
    height: 120px;
    padding: 10px;
    border: 1px solid var(--ai-input-border);
    border-radius: 6px;
    background: var(--ai-block-bg);
    color: var(--ai-text);
    font-family: inherit;
    font-size: 0.875rem;
    resize: none;
    box-sizing: border-box;
}
.ai-sig-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.ai-sig-modal-actions button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: opacity 0.2s;
}
.ai-sig-modal-actions button:hover {
    opacity: 0.8;
}
#ai-sig-cancel {
    background: transparent;
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
}
#ai-sig-save {
    background: #8b5cf6;
    color: white;
}