.ai-text-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #333;
    position: relative;
}
.ai-text-container h3 {
    color: #0073aa;
    margin-top: 0;
    margin-bottom: 8px;
}
.ai-text-container > p {
    color: #555;
    line-height: 1.5;
    margin-bottom: 20px;
    font-size: 15px;
}

.ai-text-form {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #eee;
}

.ai-field {
    margin-bottom: 16px;
}
.ai-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 14px;
}
.ai-field textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
}
.ai-field textarea:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0,115,170,0.1);
}
.ai-field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    box-sizing: border-box;
}

/* Кнопки */
.ai-text-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}
.ai-button {
    background: #0073aa;
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    display: inline-block;
}
.ai-button:hover:not(:disabled) { background: #005a87; }
.ai-button:active:not(:disabled) { transform: scale(0.98); }
.ai-button:disabled { opacity: 0.6; cursor: not-allowed; }
.ai-btn-gray { background: #6c757d; color: #fff; }
.ai-btn-gray:hover { background: #5a6268; }

/* «История» — третья кнопка в ряду: не должна спорить с главной
   «Сгенерировать» по весу, поэтому прозрачная. */
.ai-btn-ghost {
    background: transparent;
    color: #0073aa;
    border: 1px solid #c3d9e6;
    position: relative;
}
.ai-btn-ghost:hover:not(:disabled) { background: #eef6fb; color: #005a87; }

.ai-hist-count {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    margin-left: 6px;
    border-radius: 9px;
    background: #0073aa;
    color: #fff;
    font-size: 11px;
    line-height: 16px;
    text-align: center;
    vertical-align: middle;
}
.ai-hist-count[hidden] { display: none; }

/* Счётчик символов под полем ввода */
.ai-char-count {
    margin-top: 6px;
    font-size: 12.5px;
    color: #6b7280;
    text-align: right;
    transition: color .15s ease;
}
.ai-char-count.near { color: #b45309; }
.ai-char-count.over { color: #b91c1c; font-weight: 600; }

/* Строка превышения лимита.
   Появляется только когда текст длиннее лимита и кнопка заблокирована:
   человек должен понимать, почему кнопка серая, и что именно сделать. */
.ai-limit-note {
    margin-top: 6px;
    padding: 8px 12px;
    border-radius: 6px;
    background: #fdecec;
    color: #a11d1d;
    font-size: 13px;
    line-height: 1.45;
    border-left: 3px solid #d63638;
}

/* Заблокированная кнопка генерации: приглушена сильнее прочих disabled,
   потому что это не «идёт запрос», а «сейчас нельзя» — разные причины,
   и путать их нельзя. */
#ai-text-generate:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: #7a8b96;
}

/* Подсказка про разбиение на части.
   Нейтральнее плашки превышения: это не ошибка, а предложение решения. */
.ai-split-note {
    margin-top: 6px;
    padding: 8px 12px;
    border-radius: 6px;
    background: #eef4fb;
    color: #1f4e79;
    font-size: 13px;
    line-height: 1.45;
    border-left: 3px solid #0073aa;
}

/* Кнопка нарезки. Отдельный оттенок, чтобы не путалась с основной:
   это другое действие с другим расходом токенов. */
.ai-btn-split {
    background: #2271b1;
}
.ai-btn-split:hover:not(:disabled) {
    background: #1a5a8e;
}

/* Панель прогресса пакетной обработки.
   Остаётся видимой после отмены: человек должен видеть, сколько частей
   успело обработаться — за них уже списаны токены. */
.ai-split-progress {
    margin-top: 16px;
    padding: 14px 16px;
    border: 1px solid #d6e4f0;
    border-radius: 8px;
    background: #f7fbff;
}

.ai-split-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
    color: #1f4e79;
    margin-bottom: 10px;
}

.ai-split-cancel {
    padding: 4px 12px;
    font-size: 13px;
    border: 1px solid #c3d3e2;
    border-radius: 5px;
    background: #fff;
    color: #1f4e79;
    cursor: pointer;
}
.ai-split-cancel:hover:not(:disabled) {
    background: #eef4fb;
}
.ai-split-cancel:disabled {
    opacity: 0.55;
    cursor: default;
}

/* Полоса прогресса: тонкая, без анимаций — при 8 частях она меняется
   каждые несколько секунд, плавность только мешает читать. */
.ai-split-track {
    height: 8px;
    border-radius: 4px;
    background: #e2ecf5;
    overflow: hidden;
}

.ai-split-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #0073aa, #2271b1);
    transition: width 0.3s ease;
}

.ai-split-estimate {
    margin-top: 10px;
    font-size: 13px;
    color: #55636e;
    line-height: 1.5;
}

@media (max-width: 600px) {
    .ai-split-head { flex-direction: column; align-items: flex-start; }
    .ai-split-cancel { width: 100%; }
}

/* Вывод */
.ai-output {
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    line-height: 1.7;
    font-size: 15px;
    min-height: 60px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.ai-result-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Строка расхода токенов */
.ai-usage-note {
    margin-top: 10px;
    font-size: 12.5px;
    color: #6b7280;
    font-variant-numeric: tabular-nums;
}

/* Пометка о сохранении под результатом */
.ai-save-note {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13.5px;
    line-height: 1.5;
}
.ai-save-ok {
    background: #edf9f0;
    color: #1c6b32;
    border-left: 3px solid #2e9e4f;
}
.ai-save-warn {
    background: #fff8e5;
    color: #7a5b00;
    border-left: 3px solid #e0a800;
}
/* Гостю — не серое «не сохранено», а действие: это приглашение, а не ошибка. */
.ai-save-guest {
    background: #eef6fb;
    color: #14425c;
    border-left: 3px solid #0073aa;
}
.ai-save-guest a {
    color: #005a87;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px dashed rgba(0,90,135,.4);
}
.ai-save-guest a:hover { border-bottom-style: solid; }
.ai-save-or { color: #6b8a9c; }

/* SEO-блок */
.ai-seo-block {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-seo-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 6px;
    border: 1px solid #eee;
}
.ai-seo-label {
    font-weight: 700;
    font-size: 13px;
    color: #0073aa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 100px;
    padding-top: 2px;
}
.ai-seo-value {
    font-size: 14px;
    color: #333;
    flex: 1;
}
.ai-seo-value small {
    color: #999;
    font-size: 12px;
}

/* Список заголовков / идей */
.ai-items-list {
    margin: 0;
    padding-left: 24px;
}
.ai-items-list li {
    margin-bottom: 8px;
    line-height: 1.5;
    font-size: 15px;
}

/* Текстовый вывод */
.ai-text-output {
    line-height: 1.7;
}

/* Ошибка */
.ai-error {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border-radius: 4px;
    border-left: 4px solid #dc3545;
    font-size: 14px;
    margin-top: 16px;
}

/* === Панель истории === */
.ai-hist-drawer {
    display: none;
    margin-top: 20px;
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    /* Появление без анимации сдвига: панель стоит в потоке под формой,
       поэтому «выезжание» здесь только мешало бы читать. */
}
.ai-hist-drawer.open { display: block; }

.ai-hist-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f5f8fa;
    border-bottom: 1px solid #e6ecef;
}
.ai-hist-title { font-weight: 600; font-size: 14px; color: #22323c; }
.ai-hist-x {
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    color: #8798a3;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.ai-hist-x:hover { background: #e6ecef; color: #22323c; }

.ai-hist-items { max-height: 340px; overflow-y: auto; }
.ai-hist-loading,
.ai-hist-empty {
    padding: 24px 16px;
    text-align: center;
    color: #8798a3;
    font-size: 13.5px;
    line-height: 1.6;
}
.ai-hist-empty-hint { font-size: 12.5px; color: #a6b4bd; }

.ai-hist-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.15s;
}
.ai-hist-row:last-child { border-bottom: none; }
.ai-hist-row:hover { background: #f7fafc; }
.ai-hist-row:focus { outline: 2px solid #b9d8ea; outline-offset: -2px; }

.ai-hist-row-main { flex: 1; min-width: 0; }
.ai-hist-row-title {
    font-size: 14px;
    color: #22323c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-hist-row-meta { font-size: 12px; color: #9aa9b2; margin-top: 2px; }

.ai-hist-del {
    background: none;
    border: none;
    color: #b7c3ca;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex: 0 0 auto;
}
.ai-hist-del:hover { background: #fdeaea; color: #c0392b; }

.ai-hist-footer {
    padding: 10px 16px;
    border-top: 1px solid #eef1f3;
    background: #fafcfd;
    text-align: right;
    font-size: 13px;
}
.ai-hist-footer a { color: #0073aa; text-decoration: none; }
.ai-hist-footer a:hover { text-decoration: underline; }

/* Приглашение гостю */
.ai-hist-gate {
    padding: 28px 22px;
    text-align: center;
}
.ai-hist-gate-icon { font-size: 28px; line-height: 1; margin-bottom: 10px; }
.ai-hist-gate-title {
    font-size: 16px;
    font-weight: 600;
    color: #22323c;
    margin: 0 0 8px;
}
.ai-hist-gate-text {
    font-size: 14px;
    color: #5b6b75;
    line-height: 1.6;
    margin: 0 auto 18px;
    max-width: 460px;
}
.ai-hist-gate-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}
.ai-hist-cta { padding: 10px 20px; font-size: 14px; }
.ai-hist-gate-note {
    margin: 16px 0 0;
    font-size: 12.5px;
    color: #9aa9b2;
}

/* Адаптив */
@media (max-width: 600px) {
    .ai-seo-row { flex-direction: column; gap: 4px; }
    .ai-seo-label { min-width: auto; }
    .ai-text-actions { flex-direction: column; align-items: stretch; }
    .ai-text-actions .ai-button { width: 100%; text-align: center; }
    .ai-hist-gate-actions { flex-direction: column; }
    .ai-hist-gate-actions .ai-button { width: 100%; text-align: center; }
}