* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: pan-x pan-y;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-900: #111827;
}

body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
}

/* Авторизация */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-form {
    background: white;
    padding: 48px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 420px;
}

.login-form h2 {
    text-align: center;
    margin-bottom: 32px;
    color: var(--gray-900);
    font-weight: 700;
    font-size: 28px;
}

/* Основной интерфейс */
.main-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: white;
    padding: 20px 32px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    color: var(--gray-900);
    font-size: 24px;
    font-weight: 700;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info span {
    background: var(--gray-100);
    color: var(--gray-700);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
}

/* Навигация */
.nav {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 32px;
    display: flex;
    gap: 8px;
}

.nav-btn {
    padding: 16px 24px;
    background: transparent;
    color: var(--gray-600);
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-weight: 500;
    font-size: 15px;
    transition: all 0.2s;
}

.nav-btn:hover {
    color: var(--gray-900);
    background: var(--gray-50);
}

.nav-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Контент */
.content {
    flex: 1;
    padding: 14px 32px 28px;
    width: 100%;
}

.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.section h3 {
    margin-bottom: 24px;
    color: var(--gray-900);
    font-size: 20px;
    font-weight: 700;
    text-align: center;
}

/* ПОВНА ШИРИНА ДЛЯ СЕКЦІЇ КОНТЕНТУ */
#content.section {
    padding: 0;
}

#content.section h3 {
    padding: 20px 32px;
    margin: 0 0 0 0;
    text-align: left;
}

#content.section .tree-container {
    border-radius: 0;
}

/* Формы */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.2s;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Кнопки */
.btn {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 15px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Крутилка «идёт…» на кнопках действий */
.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    vertical-align: -2px;
    animation: btn-spin 0.6s linear infinite;
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

.btn.is-busy,
button.is-busy {
    opacity: .8;
    cursor: progress;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-success {
    background: var(--success);
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
}

/* Карточки ботов */
.bots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.bot-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.2s;
}

.bot-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.12);
    transform: translateY(-2px);
}

.bot-card.active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.02);
}

.bot-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.bot-card-header h4 {
    margin: 0;
    color: var(--gray-900);
    font-size: 18px;
    font-weight: 600;
}

.bot-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bot-status.active {
    background: #d1fae5;
    color: #065f46;
}

.bot-status.inactive {
    background: #fee2e2;
    color: #991b1b;
}

.bot-card-body {
    margin-bottom: 20px;
}

.bot-card-body p {
    margin: 8px 0;
    font-size: 14px;
    color: var(--gray-600);
}

.bot-card-body strong {
    color: var(--gray-700);
    font-weight: 500;
}

.bot-card-footer {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Модальные окна */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 1000px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--gray-900);
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: var(--gray-100);
    border: none;
    font-size: 20px;
    color: var(--gray-600);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--gray-200);
    color: var(--gray-900);
}

.modal-body {
    padding: 24px;
    max-height: calc(90vh - 160px);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--gray-200);
}

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

/* Анимации */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Адаптивность */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 16px;
        padding: 20px;
    }

    .nav {
        padding: 0 20px;
        overflow-x: auto;
    }

    .content {
        padding: 20px;
    }

    #content.section {
        padding: 0;
    }

    .bots-grid {
        grid-template-columns: 1fr;
    }

    .login-form {
        padding: 32px 24px;
        margin: 20px;
    }
}

/* Заголовок секции с кнопкой */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.section-header h3 {
    margin: 0;
    color: var(--gray-900);
    font-size: 19px;
    font-weight: 700;
}

.section-header .btn {
    padding: 8px 16px;
    font-size: 13px;
}

.section-header .btn svg {
    width: 16px;
    height: 16px;
}

/* Пустое состояние */
.empty-state {
    text-align: center;
    padding: 64px 32px;
    color: var(--gray-600);
    background: white;
    border-radius: 12px;
    border: 2px dashed var(--gray-300);
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 24px;
}

/* Content Editor */
.content-editor {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px dashed var(--gray-300);
    border-radius: 12px;
    color: var(--gray-600);
    font-size: 16px;
    padding: 32px;
    text-align: center;
}

/* Карточка информации о боте */
.bot-info-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
}

.bot-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.bot-info-header h4 {
    margin: 0;
    color: var(--gray-900);
    font-size: 20px;
    font-weight: 600;
}

.bot-info-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.info-label {
    font-weight: 500;
    color: var(--gray-700);
    min-width: 120px;
}

.info-value {
    color: var(--gray-600);
    word-break: break-all;
}

/* Кастомная кнопка загрузки файла */
.form-group .file-upload-label {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 18px;
    background: #6366f1;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: background 0.2s ease;
    border: none;
    user-select: none;
    margin: 0;
}

.form-group .file-upload-label:hover {
    background: #4f46e5;
}

.form-group .file-upload-label svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Контейнер превью изображения */
#imagePreviewContainer {
    animation: fadeIn 0.3s ease;
    position: relative;
    padding: 10px;
    background: #f9fafb;
    border-radius: 8px;
}

#imagePreview {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 2px dashed #cbd5e1 !important;
    padding: 8px;
    background: #f9fafb;
}

/* Кнопка удаления изображения */
.remove-image-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: #ef4444;
    color: white;
    border: 2px solid white;
    border-radius: 6px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    padding: 0;
    font-weight: 300;
}

.remove-image-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.remove-image-btn:active {
    transform: scale(0.95);
}

/* Компактное модальное окно */
.modal.compact {
    max-width: 400px;
    width: 90%;
}

.modal.compact .modal-body {
    padding: 20px;
}

.modal.compact .modal-body p {
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 20px;
}

/* ПОВНА ШИРИНА ДЛЯ СЕКЦІЇ КОНТЕНТУ */
#content.section {
    padding: 0;
}

#content.section h3 {
    padding: 20px 32px;
    margin: 0;
    text-align: left;
}

#content.section #contentEditor {
    margin: 0;
    padding: 0;
}

#content.section .tree-container {
    border-radius: 0;
    width: 100vw;
    height: calc(100vh - 200px);
}

.btn-danger-outline {
    color: #dc2626 !important;
    border: 1px solid #dc2626 !important;
    background: transparent !important;
}

.btn-danger-outline:hover {
    background: #dc2626 !important;
    color: white !important;
}

/* Управление блоками */
.blocks-management {
    max-height: 70vh;
    overflow-y: auto;
}

.blocks-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8fafc;
    border-radius: 8px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: #0f172a;
}

.stat-label {
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
}

.blocks-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.block-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    transition: all 0.2s;
}

.block-item:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.block-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.block-info strong {
    color: #0f172a;
    font-size: 14px;
}

.block-info code {
    color: #64748b;
    font-size: 12px;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
}

.block-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-secondary {
    background: #f1f5f9;
    color: #64748b;
}

/* Bot Selector */
.bot-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.bot-selector label {
    font-weight: 600;
    color: #475569;
    margin: 0;
    white-space: nowrap;
}

.bot-selector select {
    flex: 1;
    max-width: 400px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #64748b;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 20px;
}

/* Blocks Management */
.blocks-management {
    max-height: 70vh;
    overflow-y: auto;
}

.blocks-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 8px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: #0ea5e9;
}

.stat-label {
    font-size: 12px;
    color: #64748b;
    text-transform: uppercase;
}

.blocks-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.block-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    transition: all 0.2s;
}

.block-item:hover {
    border-color: #0ea5e9;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.1);
}

.block-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.block-info strong {
    color: #1e293b;
    font-size: 14px;
}

.block-info code {
    font-size: 12px;
    color: #64748b;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
}

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

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-secondary {
    background: #f1f5f9;
    color: #64748b;
}



/* Кнопка удаления ключевого слова */
.keyword-tag {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.keyword-delete {
    display: none;
    width: 16px;
    height: 16px;
    border: none;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: 4px;
}

.keyword-tag:hover .keyword-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.keyword-delete:hover {
    background: #dc2626;
}

/* === TOGGLE SWITCH INLINE === */
.toggle-inline {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-inline input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #444;
    border-radius: 24px;
    transition: background 0.25s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
}

.toggle-inline input:checked + .toggle-slider {
    background: #4CAF50;
}

.toggle-inline input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* === Карточки ботов (вместо выпадашки) === */
.bot-cards { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.bot-card { display: flex; align-items: center; gap: 12px; min-width: 210px; padding: 12px 14px; background: #fff; border: 1.5px solid #e5e7eb; border-radius: 14px; cursor: pointer; transition: all .15s ease; text-align: left; font: inherit; }
.bot-card:hover { border-color: #c7b3ff; box-shadow: 0 4px 14px rgba(124,58,237,.10); transform: translateY(-1px); }
.bot-card.is-active { border-color: #7c3aed; background: #f5f0ff; box-shadow: 0 4px 14px rgba(124,58,237,.15); }
.bot-card-avatar { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; color: #fff; background: linear-gradient(135deg, #7c3aed, #a855f7); }
.bot-card-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.bot-card-name { font-weight: 600; color: #1f2937; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-card-user { font-size: 12px; color: #9ca3af; }
.bot-card-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; margin-left: auto; background: #9ca3af; }
.bot-card-dot.active { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.15); }
.bot-card-dot.inactive { background: #9ca3af; }
.bot-card-add { justify-content: center; color: #7c3aed; border-style: dashed; }
.bot-card-add .bot-card-name { color: #7c3aed; }

/* === Лого в шапке === */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #7c3aed, #a855f7); box-shadow: 0 4px 12px rgba(124,58,237,.25); }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-sub { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: #9ca3af; }
.brand-name { font-size: 22px; font-weight: 800; color: #1f2937; letter-spacing: -.01em; }

/* === Переключатель бота в шапке === */
.header-bot-select { padding: 7px 12px; margin-right: 12px; border: 1.5px solid var(--gray-200, #e5e7eb); border-radius: 10px; background: #fff; font-size: 13px; font-weight: 600; color: #1f2937; cursor: pointer; max-width: 260px; }
.header-bot-select:hover { border-color: #c7b3ff; }
