/* ========================================
   ГЛОБАЛЬНЫЕ СТИЛИ
   ======================================== */

:root {
    --primary-color: #007bff;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --border-radius: 8px;
    --box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    height: 100%;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
    overflow: hidden;
}

/* ========================================
   ХЕДЕР
   ======================================== */

.app-header {
    background: white;
    padding: 16px 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    z-index: 100;
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 24px;
    color: #333;
    font-weight: 600;
}

/* ========================================
   ОСНОВНОЙ КОНТЕНТ
   ======================================== */

.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ========================================
   ДВУХКОЛОНОЧНЫЙ ЛЕЙАУТ
   ======================================== */

.main-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 16px;
    padding: 16px;
    overflow: hidden;
}

.control-panel {
    width: 320px;
    min-width: 320px;
    max-width: 320px;
    background: white;
    padding: 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.dashboard-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#my-superset-container {
    flex: 1;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 16px;
    padding: 0;
    background: #e9ecef;
    position: relative;
}

.dashboard-placeholder {
    text-align: center;
    padding: 20px;
    color: inherit;
    font-size: inherit;
}

#my-superset-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

#my-superset-container > div {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ========================================
   ФОРМЫ
   ======================================== */

.form-group {
    margin-bottom: 8px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* Кнопки */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(102, 126, 234, 0.3);
    padding: 8px 16px;
    font-size: 14px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653e8a 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(102, 126, 234, 0.4);
}

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

.btn-primary:disabled {
    background: linear-gradient(135deg, #b3b3b3 0%, #8c8c8c 100%);
    color: #e6e6e6;
    cursor: not-allowed;
    opacity: 0.65;
    box-shadow: none;
    transform: none;
    pointer-events: none;
}

/* ========================================
   ФУТЕР
   ======================================== */

.app-footer {
    background: white;
    padding: 12px 24px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    font-size: 13px;
    color: #666;
    flex-shrink: 0;
}



/* ========================================
   КОНТЕКСТНОЕ МЕНЮ
   ======================================== */

#context-menu {
    display: none;
    position: fixed;
    z-index: 10000;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    overflow: hidden;
    min-width: 200px;
    padding: 4px 0;
}

#edit-object-item {
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    color: #1a73e8;
    font-weight: 500;
}

#edit-object-title {
    margin: 4px 0 0 0;
    font-weight: 500;
    font-size: 16px;
    color: #007bff;
    word-break: break-word;
    max-width: 100%;
}

#edit-object-item:hover {
    background: #f0f8ff;
}

/* ========================================
   МОДАЛЬНОЕ ОКНО
   ======================================== */

#edit-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden;
}

#edit-modal > div {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 100%;
    max-width: 800px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 100%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#edit-cancel-btn {
    background: #f8f9fa;
    border: 2px solid rgb(224, 224, 224);
    font-size: 14px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 207.5px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#edit-cancel-btn:hover {
    color: #333;
    background: #f0f0f0;
    border-radius: 8px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0; /* Не сжимается при прокрутке */
    background: white;
    position: sticky;
    bottom: 0;
    z-index: 10;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.05);
}

.control-panel .form-group:last-child {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.control-panel .form-group:last-child > .object-tree-container {
    flex: 1;
    min-height: 0;
}

/* Исправление выравнивания дерева объектов */
.object-tree .folder-header,
.object-tree .leaf label {
    align-items: flex-start !important;
    display: flex !important;
    gap: 8px !important;
    padding: 4px 0 !important;
    width: 100% !important;
}

/* Убираем ненужные отступы для правильного выравнивания */
.object-tree ul {
    padding-left: 0 !important;
    margin: 0 !important;
    list-style: none !important;
}

.object-tree li {
    margin: 4px 0 !important;
    width: 100% !important;
}

/* Иконки и текст должны быть на одной линии */
.object-tree .folder-header span,
.object-tree .leaf label {
    text-align: left !important;
    justify-content: flex-start !important;
    align-items: center !important;
    line-height: 1.4 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    flex: 1 1 auto !important;
}

/* Для чекбоксов */
.object-tree input[type="checkbox"] {
    flex: 0 0 auto !important;
    width: 18px !important;
    height: 18px !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Убираем ненужные отступы для дочерних элементов */
.object-tree .children {
    padding-left: 20px !important;
    margin: 0 !important;
}

.object-tree-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--gray-300);
    padding: 0;
    border-radius: 4px;
    background: var(--gray-100);
    font-size: 14px;
    margin-top: 4px;
    position: relative;
}

.object-tree {
    min-height: 0;
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}

.object-tree .folder-header span:first-child,
.object-tree .leaf label span:first-child {
    flex: 0 0 auto !important;
    margin-right: 4px !important;
}

.object-tree .folder-header span:last-child,
.object-tree .leaf label span:last-child {
    flex: 1 1 auto !important;
    text-align: left !important;
    padding-left: 4px !important;
}

/* ========================================
   ВКЛАДКИ МОДАЛЬНОГО ОКНА
   ======================================== */

.dashboard-tabs-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tabs-header {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.tab-button {
    padding: 8px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: #666;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
    font-size: 14px;
    border-radius: 4px 4px 0 0;
}

.tab-button:hover {
    background: #f8f9fa;
    color: #007bff;
}

.tab-button:active {
    background: #e9ecef;
}

.tab-button.active {
    color: #007bff;
    border-bottom: 2px solid #007bff;
    font-weight: 600;
}

.add-dashboard-tab {
    color: #28a745 !important;
    font-weight: 600 !important;
}

.add-dashboard-tab:hover {
    background: #e8f5e9 !important;
    color: #218838 !important;
}

.add-dashboard-tab.active {
    color: #28a745 !important;
    border-bottom: 2px solid #28a745 !important;
}

.tabs-content {
    padding: 16px 0;
    min-height: 200px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Стили для контента вкладок */
.tab-content > div {
    padding: 16px;
    background: #f8f9fa;
    border-radius: 4px;
}

.tab-content h4 {
    margin: 0 0 12px 0;
    color: #333;
    font-size: 16px;
}

.tab-content p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

.tab-content p + p {
    margin-top: 8px;
}

/* Стили для селекта и кнопки */
#add-dashboard-select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-bottom: 12px;
    font-size: 14px;
}

#add-dashboard-select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

#add-to-dashboard-btn {
    width: 100%;
    padding: 10px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
}

#add-to-dashboard-btn:hover {
    background: #218838;
}

#add-to-dashboard-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

#add-dashboard-status {
    margin-top: 12px;
    padding: 8px;
    border-radius: 4px;
    display: none;
    font-size: 13px;
}

/* Стили для скролла вкладок */
.tabs-header::-webkit-scrollbar {
    height: 4px;
}

.tabs-header::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.tabs-header::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.tabs-header::-webkit-scrollbar-track {
    background: #f1f1f1;
}

/* ========================================
   АГРЕГАТОРЫ В МОДАЛЬНОМ ОКНЕ
   ======================================== */

.aggregator-group {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 12px;
    background: #f8f9fa;
}

.group-header {
    font-weight: 600;
    color: #007bff;
    font-size: 14px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.aggregators-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.aggregator-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.aggregator-item:hover {
    background: #e9ecef;
}

.aggregator-name {
    flex: 1;
    font-size: 14px;
    color: #333;
}

.btn-secondary {
    background: #e9ecef;
    color: #333;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.btn-secondary:hover {
    background: #dee2e6;
    border-color: #adb5bd;
}

.btn-delete-aggregator {
    padding: 4px 12px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-delete-aggregator:hover {
    background: #c82333;
}

/* Стили для удаленных агрегаторов */
.aggregator-item.deleted .aggregator-name {
    text-decoration: line-through;
    color: #dc3545;
    text-decoration-color: #dc3545;
    text-decoration-thickness: 2px;
}

.btn-undo-delete {
    background: #28a745 !important;
}

.btn-undo-delete:hover {
    background: #218838 !important;
}

/* Анимация для индикатора загрузки */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   СОСТОЯНИЯ В МОДАЛЬНОМ ОКНЕ
   ======================================== */

.state-section {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    background: #fff;
}

.state-group {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 12px;
    background: #f8f9fa;
}

.state-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.state-item:hover {
    background: #e9ecef;
}

.state-name {
    flex: 1;
    font-size: 14px;
    color: #333;
}

.btn-delete-state {
    padding: 4px 12px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-delete-state:hover {
    background: #c82333;
}

/* Стили для удаленных состояний */
.state-item.deleted .state-name {
    text-decoration: line-through;
    color: #dc3545;
    text-decoration-color: #dc3545;
    text-decoration-thickness: 2px;
}

/* Разделители секций */
.aggregator-section,
.state-section {
    margin-bottom: 10px;
}

.empty-section {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 24px;
    background: #fff;
    text-align: center;
}

.empty-section h3 {
    margin: 0 0 12px 0;
    color: #6c757d;
    font-size: 18px;
    font-weight: 600;
}

.empty-section p {
    margin: 0;
    color: #6c757d;
    font-size: 14px;
}

/* Стили для кнопок добавления */
.btn-add-aggregator,
.btn-add-state {
    padding: 4px 8px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-add-state {
    background: #28a745;
}

.btn-add-aggregator:hover {
    background: #0069d9;
}

.btn-add-state:hover {
    background: #218838;
}

/* Стили для нового добавленного элемента */
.new-addition {
    border-left: 3px solid #28a745 !important;
    background: #d4edda !important;
}

.new-addition.state-item {
    border-left: 3px solid #ffc107 !important;
    background: #fff3cd !important;
}

.new-addition .aggregator-name,
.new-addition .state-name {
    font-weight: 500 !important;
}

/* Стили для кнопок подтверждения и отмены добавления */
.btn-confirm-add {
    padding: 4px 8px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
    margin-right: 4px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close:hover {
    color: #333;
    background: #f0f0f0;
}

.btn-confirm-add:hover {
    background: #218838;
}

.btn-cancel-add {
    padding: 4px 8px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-cancel-add:hover {
    background: #5a6268;
}

.btn-undo-add-aggregator,
.btn-undo-add-state {
    padding: 4px 12px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-undo-add-aggregator:hover,
.btn-undo-add-state:hover {
    background: #5a6268;
}

/* Контейнер для кнопки добавления */
.add-button-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.add-aggregator-select,
.add-state-select {
    width: 150px;
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-right: 8px;
    font-size: 12px;
}

/* Стили для новых дашбордов (до сохранения) */
.new-dashboard-tab {
    background: #d4edda !important;
    color: #155724 !important;
    font-weight: 600 !important;
    position: relative;
}

.new-dashboard-tab::after {
    content: "●";
    color: #28a745;
    font-size: 10px;
    position: absolute;
    top: 2px;
    right: 4px;
    animation: pulse 2s infinite;
}

.new-dashboard-content {
    border-left: 3px solid #28a745 !important;
    background: #f8fdf8 !important;
    padding-left: 12px !important;
}

@keyframes pulse {
    0% { opacity: 0.6; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.6; transform: scale(0.8); }
}

/* Стили для уведомления о новом дашборде */
.new-dashboard-notice {
    background: #d4edda;
    border-left: 4px solid #28a745;
    padding: 12px;
    margin: 12px 0;
    border-radius: 4px;
    font-size: 14px;
    color: #155724;
}

#object-tree li.highlighted {
    background-color: #fffacd !important;
    transition: background-color 0.3s;
    border-left: 3px solid #ffc107;
}

#search-navigation {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#reset-selections-btn {
    width: 100%;
    padding: 8px 16px;
    color: white;
    border: none;
    cursor: pointer;
    margin-top: 8px;
    font-size: 13px;
}

/* Кнопка выхода в том же стиле, что и кнопка входа */
#dots-logout-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(102, 126, 234, 0.3);
}

#dots-logout-btn:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653e8a 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(102, 126, 234, 0.4);
}

#dots-logout-btn:active {
    transform: translateY(0);
}