:root {
    --bg-app: #0f1012;
    --bg-card: #1b1d21;
    --text-main: #ffffff;
    --text-secondary: #d1d5db;
    --border-color: #333;
    --input-bg: #25282e;
    --input-focus: rgba(16, 185, 129, 0.15);
    --th-bg: #25282e;
    --group-header-bg: #2d3138;
    --group-header-hover: #373b44;
    --id-bg: #1a1a1a;
    --accent-color: #10b981;
    --bg-gradient: radial-gradient(circle at 50% 0%, rgba(16, 185, 129, 0.1), transparent 40%);
    --info-bg: rgba(40, 44, 52, 0.8);
}

[data-theme="light"] {
    --bg-app: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-secondary: #4b5563;
    --border-color: #e5e7eb;
    --input-bg: #ffffff;
    --input-focus: rgba(16, 185, 129, 0.1);
    --th-bg: #f9fafb;
    --group-header-bg: #e5e7eb;
    --group-header-hover: #d1d5db;
    --id-bg: #f9fafb;
    --accent-color: #059669;
    --bg-gradient: radial-gradient(circle at 50% 0%, rgba(5, 150, 105, 0.05), transparent 40%);
    --info-bg: #e5e7eb;
}

/* ГЛОБАЛЬНАЯ ФИКСАЦИЯ ЭКРАНА */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Запрещаем скролл самой страницы */
}

body {
    background-color: var(--bg-app);
    background-image: var(--bg-gradient);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    padding: 15px; /* Небольшой отступ от краев */
}

/* Контейнер на всю высоту */
.container-fluid {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Блок инструкции - не сжимается */
.info-block {
    background: var(--info-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    flex-shrink: 0; /* Запрет на сжатие */
    color: var(--text-main);
}
.info-block ul li { color: var(--text-secondary); }
.info-title { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

/* Основная рабочая область */
.row.h-lg-100 {
    flex: 1; /* Занимает все оставшееся место */
    min-height: 0; /* ВАЖНО: позволяет вложенным элементам скроллиться */
    margin-bottom: 0;
}

/* Карточки */
.main-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    height: 100%; /* Растягиваем на всю высоту родителя */
    transition: background-color 0.3s;
}

/* Текстовое поле слева */
textarea#jsonInput {
    font-family: monospace; 
    font-size: 0.8rem;
    resize: none;
    background-color: var(--input-bg) !important; 
    border: 1px solid var(--border-color) !important; 
    color: var(--text-main) !important;
    flex-grow: 1; /* Растягивается */
}

/* ПРАВАЯ КОЛОНКА (ТАБЛИЦА) */
.col-lg-9 {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Контейнер таблицы с заголовком */
.table-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* Критично для скролла */
    position: relative;
}

.table-header-sticky {
    background: var(--th-bg);
    border-bottom: 2px solid var(--border-color);
    z-index: 20;
    flex-shrink: 0; /* Заголовок не сжимается */
}

/* Сама область скролла */
.table-container {
    flex: 1;
    overflow-y: auto; /* Скролл ТОЛЬКО здесь */
    background: var(--bg-app);
    min-height: 0;
}

/* Стиль скроллбара */
.table-container::-webkit-scrollbar { width: 8px; }
.table-container::-webkit-scrollbar-track { background: var(--bg-app); }
.table-container::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 4px; }
.table-container::-webkit-scrollbar-thumb:hover { background: #6b7280; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; table-layout: fixed; }

th {
    padding: 12px;
    text-align: left;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

td { border-bottom: 1px solid var(--border-color); border-right: 1px solid var(--border-color); padding: 0; }

td input {
    width: 100%; background: var(--input-bg); border: none;
    color: var(--text-main); padding: 10px; outline: none; font-family: inherit;
    transition: background 0.2s;
    height: 100%;
}
td input:focus { background: var(--input-focus); }

/* GROUP HEADERS */
.group-header {
    background: var(--group-header-bg);
    color: var(--text-main);
    padding: 10px 15px;
    cursor: grab; /* Курсор руки */
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s, transform 0.2s;
    user-select: none;
}
.group-header:active { cursor: grabbing; }
.group-header.dragging { opacity: 0.5; background: var(--input-focus); }
.group-header.drag-over { border-top: 2px solid var(--accent-color); }

.group-header:hover { background: var(--group-header-hover); }
.group-header i.fa-chevron-down { transition: transform 0.2s; }
.group-header.collapsed i.fa-chevron-down { transform: rotate(-90deg); }

.group-actions { opacity: 0; transition: opacity 0.2s; }
.group-header:hover .group-actions { opacity: 1; }

.id-cell { background: var(--id-bg); border-right: 2px solid var(--border-color); }
.id-input { color: var(--accent-color) !important; font-weight: bold; }
.input-error { background-color: rgba(239, 68, 68, 0.2) !important; box-shadow: inset 0 0 0 2px #ef4444; }

.action-cell { width: 90px; text-align: center; background: var(--input-bg); white-space: nowrap; }
.btn-icon { color: #6b7280; background: transparent; border: none; cursor: pointer; transition: 0.2s; padding: 5px 8px; }
.btn-icon:hover { color: var(--text-main); transform: scale(1.1); }
.btn-del:hover { color: #ef4444; }
.btn-dup:hover { color: #3b82f6; }

.btn-neon {
    background: linear-gradient(135deg, var(--accent-color) 0%, #3b82f6 100%);
    border: none; color: white; font-weight: 600; padding: 8px 20px; border-radius: 8px; white-space: nowrap;
}
.btn-neon:hover { opacity: 0.9; transform: translateY(-1px); color: white; }

.status-bar { font-size: 0.85rem; color: #9ca3af; margin-top: 5px; display: flex; justify-content: space-between; flex-shrink: 0; }

/* Адаптив для мобильных */
@media (max-width: 991.98px) {
    html, body { overflow-y: auto; height: auto; }
    .container-fluid { height: auto; display: block; }
    .row.h-lg-100 { height: auto; display: block; }
    .col-lg-9 { height: 600px; /* Фикс высота для мобильных, чтобы был скролл */ }
    .mobile-stack { margin-top: 20px; }
    textarea#jsonInput { height: 200px !important; }
}

.modal-content { background-color: var(--bg-card); border: 1px solid var(--border-color); color: var(--text-main); }
.modal-header, .modal-footer { border-color: var(--border-color); }
.btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
[data-theme="light"] .btn-close { filter: none; }
.list-group-item { background-color: var(--input-bg); border-color: var(--border-color); color: var(--text-main); display: flex; justify-content: space-between; align-items: center; }