/* ============================================================
 *  SELECTION BUTTONS
 = *=========================================================== */

.selection-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    padding: 6px 10px;

    border-radius: 8px;

    border: 1px solid #1e3d7a;

    background: #08215c;

    color: #cbd5e1;

    font-size: 12px;
    font-weight: 500;

    transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

.selection-button:hover {
    background: #0f3284;
    border-color: #3b82f6;
    color: #ffffff;
}


/* Активный режим "только выбранные" */

.selection-button.selection-active {
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.12);
    color: #a5b4fc;
}


/* ============================================================
 *  COUNTER
 = *=========================================================== */

.selection-counter {
    display: inline-flex;

    min-width: 20px;
    height: 20px;

    align-items: center;
    justify-content: center;

    padding: 0 6px;

    border-radius: 999px;

    background: #27272a;

    color: #a1a1aa;

    font-size: 11px;
    font-weight: 600;

    transition:
    background-color 120ms ease,
    color 120ms ease;
}


.selection-button.selection-active
.selection-counter {
    background: rgba(99, 102, 241, 0.25);
    color: #c7d2fe;
}


/* ============================================================
 *  CLEAR SELECTION
 = *=========================================================== */

/*
 * ВАЖНО:
 *
 * Кнопка НИКОГДА не удаляется из DOM.
 *
 * Благодаря этому toolbar не прыгает.
 */

.clear-selection-button {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    min-width: 105px;

    padding: 6px 10px;

    border-radius: 8px;

    border: 1px solid #1e3d7a;

    background: #08215c;

    color: #cbd5e1;

    font-size: 12px;
    font-weight: 500;

    transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease,
    opacity 120ms ease;
}


.clear-selection-button:hover {
    background: #0f3284;
    border-color: #3b82f6;
    color: #ffffff;
}


/* ============================================================
 *  TABLE ROW SELECTION
 = *=========================================================== */

.row-selected {
    background: rgba(99, 102, 241, 0.075);
}


.row-selected:hover {
    background: rgba(99, 102, 241, 0.11);
}


/* ============================================================
 *  CHECKBOX
 = *=========================================================== */

.row-checkbox {
    width: 16px;
    height: 16px;

    cursor: pointer;

    accent-color: #6366f1;
}


/* ============================================================
 *  STICKY COLUMNS
 = *=========================================================== */

:root {
    --selection-col-width: 48px;
}


/*
 * Колонка с чекбоксом — отдельный столбик.
 */

.selection-column {
    width: var(--selection-col-width);
    min-width: var(--selection-col-width);
    max-width: var(--selection-col-width);

    padding: 0 12px;

    text-align: center;
}


.sticky-selection-column {
    position: sticky;

    left: 0;

    z-index: 16;

    background: #111113;

    border-right: 1px solid #27272a;
}


/*
 * Первая колонка данных
 * остаётся слева при горизонтальном скролле.
 */

th.sticky-first-column,
td.sticky-first-column {
    position: sticky;

    left: var(--selection-col-width);

    z-index: 15;

    background: #111113;
}


/* Фон ячеек в зависимости от состояния строки */

tbody tr.row-selected .sticky-selection-column,
tbody tr.row-selected .sticky-first-column {
    background: #171724;
}


tbody tr.row-selected:hover .sticky-selection-column,
tbody tr.row-selected:hover .sticky-first-column {
    background: #1d1d32;
}


/*
 * Шапка: чекбокс и первая колонка
 * (z-index из header-секции выше)
 */

.sticky-header .sticky-selection-column {
    background: var(--dataset-accent);
}

.sticky-header .sticky-first-column {
    background: var(--dataset-accent);
}


/* ============================================================
 *  ROW HOVER
 * ============================================================ */

/* Управляется в секции ZEBRA STRIPING */


/* ============================================================
 *  COLUMN HOVER
 * ============================================================ */

tbody tr td.column-hover,
tbody tr .sticky-selection-column.column-hover,
tbody tr .sticky-first-column.column-hover {
    background: rgba(255, 255, 255, 0.08) !important;
}

th.column-hover,
.header-names-row .sticky-selection-column.column-hover,
.header-names-row .sticky-first-column.column-hover,
.header-filters-row .sticky-selection-column.column-hover,
.header-filters-row .sticky-first-column.column-hover {
    background: rgba(255, 255, 255, 0.14) !important;
}


/* ============================================================
 *  CHROME PALETTE
 *  Единый цвет верхних частей таблиц и поповеров
 *  для всех датасетов.
 * ============================================================ */

:root {
    --chrome-bg: #18181B;
    --chrome-border: #27272A;
    --chrome-control-bg: #27272A;
    --chrome-control-hover-bg: #3F3F46;
    --chrome-control-border: #3F3F46;
    --chrome-input-bg: #09090B;
    --chrome-text: #D4D4D8;
    --chrome-text-muted: #A1A1AA;

    /*
     * Основной цвет активного датасета. Проставляется из JS
     * (DATASETS[].accent) в activateDataset().
     */
    --dataset-accent: #27272A;
}


/* ============================================================
 *  TABLE HEADER
 = *=========================================================== */

/*
 * Весь thead закреплён как единый блок.
 * Sticky-ячейки не могут выезжать за границы thead,
 * поэтому две строки (названия + фильтры) прилипают вместе.
 */

.sticky-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--dataset-accent);
}

.header-names-row th {
    z-index: 22;
    background: var(--dataset-accent);
}

.header-filters-row th {
    z-index: 21;
    background: var(--dataset-accent);
}

.header-names-row .sticky-first-column {
    z-index: 33;
}

.header-filters-row .sticky-first-column {
    z-index: 32;
}

.header-names-row .sticky-selection-column {
    z-index: 34;
}

.header-name-cell {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.header-filter-cell {
    text-align: center;
    vertical-align: middle;
    line-height: 1;
}

.header-filter-cell .filter-button {
    line-height: 1;
}

/* Чекбокс: растягивается на обе строки шапки */
.header-names-row .sticky-selection-column,
.header-filters-row .sticky-selection-column,
.sticky-header .sticky-selection-column[rowspan] {
    z-index: 34;
}


/* ============================================================
 *  LAYOUT — прижимаем таблицу к низу
 * ============================================================ */

html, body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
}

#app {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#app > header {
    flex-shrink: 0;
}

#tableSection {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.table-scroll {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    max-width: 100%;
}

.table-scroll table {
    width: 100%;
    min-width: 900px;
}

#tableScroll {
    background: var(--table-bg, #06266F);
}

#mainTable {
    background: var(--table-bg, #06266F);
}


/* ============================================================
 *  ZEBRA STRIPING
 * ============================================================ */

/*
 * Цвета строк можно переопределить темой датасета
 * (currentTheme.rows -> --row-*-bg).
 */

:root {
    --row-odd-bg: #06266F;
    --row-odd-hover-bg: #0a338f;
    --row-even-bg: #2A4480;
    --row-even-hover-bg: #345299;
    --table-bg: #06266F;
}

/* Нечётные строки (темные) */
tbody tr:nth-child(odd):not(.row-selected) {
    background: var(--row-odd-bg);
}

tbody tr:nth-child(odd):not(.row-selected) .sticky-selection-column,
tbody tr:nth-child(odd):not(.row-selected) .sticky-first-column {
    background: var(--row-odd-bg);
}

tbody tr:nth-child(odd):not(.row-selected):hover {
    background: var(--row-odd-hover-bg);
}

tbody tr:nth-child(odd):not(.row-selected):hover .sticky-selection-column,
tbody tr:nth-child(odd):not(.row-selected):hover .sticky-first-column {
    background: var(--row-odd-hover-bg);
}

/* Чётные строки (светлые) */
tbody tr:nth-child(even):not(.row-selected) {
    background: var(--row-even-bg);
}

tbody tr:nth-child(even):not(.row-selected) .sticky-selection-column,
tbody tr:nth-child(even):not(.row-selected) .sticky-first-column {
    background: var(--row-even-bg);
}

tbody tr:nth-child(even):not(.row-selected):hover {
    background: var(--row-even-hover-bg);
}

tbody tr:nth-child(even):not(.row-selected):hover .sticky-selection-column,
tbody tr:nth-child(even):not(.row-selected):hover .sticky-first-column {
    background: var(--row-even-hover-bg);
}


/* ============================================================
 *  FILLER ROWS
 * ============================================================ */

tr.filler-row {
    height: 42px;
}

tr.filler-row td {
    background: inherit;
}

tr.filler-row:hover td {
    background: inherit !important;
}


/* ============================================================
 *  STICKY TOOLBAR
 * ============================================================ */

/* ============================================================
 *  DATASET TABS
 * ============================================================ */

.dataset-tabs {
    display: flex;
    gap: 4px;

    flex-shrink: 0;

    overflow-x: auto;

    position: sticky;
    top: 0;
    z-index: 45;

    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-bottom: none;
    border-radius: 16px 16px 0 0;

    padding: 6px 8px 0;

    scrollbar-width: none;
    -ms-overflow-style: none;
}

.dataset-tabs::-webkit-scrollbar {
    display: none;
}

.dataset-tab {
    flex-shrink: 0;
    white-space: nowrap;

    padding: 8px 14px;

    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;

    background: transparent;
    color: var(--chrome-text-muted);

    font-size: 13px;
    font-weight: 500;

    cursor: pointer;

    transition:
    background-color 120ms ease,
    color 120ms ease,
    border-color 120ms ease;
}

.dataset-tab:hover {
    background: var(--chrome-control-bg);
    color: #ffffff;
}

.dataset-tab.is-active {
    background: var(--dataset-accent);
    border-color: var(--dataset-accent);
    color: #ffffff;
}

.dataset-tab-upload {
    color: var(--chrome-text);
}

.dataset-tab-upload::before {
    content: '+';
    margin-right: 6px;
    color: var(--chrome-text-muted);
}


/* ============================================================
 *  TOOLBAR & BUTTONS
 * ============================================================ */

#tableToolbar {
    position: sticky;
    top: var(--tabs-height, 0px);
    z-index: 40;
    background: var(--dataset-accent);
    border-color: var(--chrome-border);
}

#tableToolbar button,
#tableToolbar label,
#toolbarButtons label {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(255, 255, 255, 0.28) !important;
    color: #ffffff !important;
}

#tableToolbar button:hover,
#tableToolbar label:hover,
#toolbarButtons label:hover {
    background: rgba(255, 255, 255, 0.22) !important;
    border-color: rgba(255, 255, 255, 0.45) !important;
    color: #ffffff !important;
}

#tableToolbar #globalSearch {
    background: rgba(0, 0, 0, 0.20);
    border-color: rgba(255, 255, 255, 0.28);
    color: #ffffff;
}

#tableToolbar #globalSearch::placeholder {
    color: rgba(255, 255, 255, 0.65);
}

#tableToolbar #globalSearch:focus {
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3);
}

#tableToolbar #resultCounter {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

#tableToolbar #selectedCount,
.selected-count {
    background: rgba(255, 255, 255, 0.28) !important;
    color: #ffffff !important;
}

#selectedOnlyBtn.active {
    background: rgba(255, 255, 255, 0.28) !important;
    border-color: rgba(255, 255, 255, 0.55) !important;
    color: #ffffff !important;
}

#tableSection {
    border-color: var(--chrome-border);
}


/* ============================================================
 *  POPOVERS — единый фон
 * ============================================================ */

#columnVisibilityPopover,
#fontSizePopover,
.filter-popover {
    background: var(--chrome-bg);
    border-color: var(--chrome-border);
}


/* ============================================================
 *  FULLSCREEN
 = *=========================================================== */

body.fullscreen-mode #app {
    max-width: none;

    width: 100%;

    padding-left: 24px;
    padding-right: 24px;
}


body.fullscreen-mode #tableSection {
    width: 100%;
}


/* ============================================================
 *  GENERAL
 = *=========================================================== */

.glass {
    background: var(--table-bg, #06266F);
}


.table-row {
    transition:
    background-color 120ms ease;
}


.button-secondary {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    gap: 8px;

    border-radius: 8px;

    border: 1px solid #1e3d7a;

    background: #08215c;

    padding: 10px 16px;

    font-size: 14px;
    font-weight: 500;

    color: #cbd5e1;

    cursor: pointer;

    transition:
    border-color 120ms ease,
    background-color 120ms ease,
    color 120ms ease;
}


.button-secondary:hover {
    border-color: #3b82f6;

    background: #0f3284;

    color: #ffffff;
}


/* ============================================================
 *  METRIC CELLS (bar / gradient)
 *  ============================================================ */

.metric-cell {
    position: relative;

    min-width: 60px;
    max-width: 120px;

    padding: 4px 10px;

    border-radius: 6px;

    background: rgba(0, 0, 0, 0.25);

    overflow: hidden;
}


.metric-bar {
    position: absolute;

    left: 0;
    top: 0;
    bottom: 0;

    border-radius: 6px;

    opacity: 1;

    transition: width 200ms ease;
}


.metric-background {
    position: absolute;

    left: 0;
    top: 0;
    bottom: 0;

    border-radius: 6px;
}


.metric-value {
    position: relative;

    z-index: 1;

    font-size: 13px;

    font-variant-numeric: tabular-nums;

    font-weight: 600;

    color: #ffffff;

    text-shadow:
        0 1px 3px rgba(0, 0, 0, 0.9),
        0 0 2px rgba(0, 0, 0, 0.8);
}


.metric-gradient {
    position: relative;

    padding: 4px 10px;

    border-radius: 6px;

    font-size: 13px;

    font-variant-numeric: tabular-nums;

    color: #e4e4e7;

    background: linear-gradient(
        to right,
        rgba(var(--metric-color), 0.35) var(--metric-value),
        rgba(var(--metric-color), 0.08) var(--metric-value)
    );
}


/* ============================================================
 *  PILL (temperature badge)
 * ============================================================ */

.metric-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 34px;
    height: 22px;
    padding: 0 8px;

    border-radius: 999px;

    font-size: var(--body-font-size, 14px);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1;

    color: #fff;
    transition: background 200ms ease;
}


/* ============================================================
 *  DISCRETE BAR
 * ============================================================ */

.metric-discrete-bar {
    display: flex;
    align-items: center;
    gap: 6px;

    height: 32px;
    padding: 0 4px;
}

.metric-discrete-bar .dbar-track {
    flex: 1;
    height: 100%;
    border-radius: 4px;
    background: #14141e;
    overflow: hidden;
    position: relative;
    min-width: 30px;
}

.metric-discrete-bar .dbar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 200ms ease;
}

.metric-discrete-bar .dbar-segs {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.metric-discrete-bar .dbar-seg {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(0, 0, 0, 0.35);
}

.metric-discrete-bar .dbar-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: var(--body-font-size, 14px);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #e4e4e7;

    text-shadow:
        0 0 4px rgba(0,0,0,0.8),
        0 0 2px rgba(0,0,0,0.6);

    pointer-events: none;
}


/* ============================================================
 *  SELECTED COUNT BADGE
 * ============================================================ */

.selected-count {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    min-width: 18px;
    height: 18px;

    padding: 0 5px;

    border-radius: 999px;

    background: #27272a;

    color: #a1a1aa;

    font-size: 11px;
    font-weight: 600;

    line-height: 1;

    transition:
    background-color 120ms ease,
    color 120ms ease;
}


/* Активное состояние кнопки «Только выбранные» */

#selectedOnlyBtn.active {
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.12);
    color: #a5b4fc;
}


#selectedOnlyBtn.active .selected-count {
    background: rgba(99, 102, 241, 0.25);
    color: #c7d2fe;
}


/* ============================================================
 *  INLINE FILTER CONTROLS
 * ============================================================ */

.cycle-op-btn {
    padding: 0;
    line-height: 1;
    cursor: pointer;
    border-right: 1px solid rgba(255, 255, 255, 0.28);
    align-self: stretch;
}

.cycle-op-btn.op-active {
    border-right-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.28);
    color: #ffffff;
}

.filter-value-inline::placeholder {
    color: rgba(255, 255, 255, 0.6);
    font-size: 10px;
}


/* ============================================================
 *  FONT SIZE
 * ============================================================ */

:root {
    --header-font-size: 12px;
    --body-font-size: 14px;
}

.header-names-row th,
.header-names-row .sort-button {
    font-size: var(--header-font-size) !important;
    color: #ffffff !important;
}

.header-names-row .sort-icon {
    color: rgba(255, 255, 255, 0.8);
}

.header-names-row .sort-button:hover {
    color: #ffffff !important;
    opacity: 0.9;
}

.header-filters-row th {
    font-size: var(--header-font-size);
}

#mainTable tbody td {
    font-size: var(--body-font-size);
    text-align: center;
    white-space: nowrap;
}

/*
 * Метрики тоже должны реагировать на размер шрифта
 */
.metric-cell .metric-value,
.metric-gradient {
    font-size: var(--body-font-size) !important;
}


/* ============================================================
 *  HEADER NAMES — перенос текста
 * ============================================================ */

.header-name-cell {
    white-space: normal;
    overflow-wrap: break-word;
    line-height: 1.3;
    vertical-align: middle;
    text-align: center;
}

.sort-button {
    line-height: 1.3;
    white-space: normal;
    overflow-wrap: break-word;
}

.sort-icon {
    font-size: 1.4em;
    line-height: 1;
    vertical-align: middle;
}


/* ============================================================
 *  FILTER STYLE FIXES
 * ============================================================ */

/* Инлайн-блок фильтра — убираем артефакты */
.inline-filter-wrap {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.18);
}

.inline-filter-wrap .cycle-op-btn {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    border-right-color: rgba(255, 255, 255, 0.28);
}

.inline-filter-wrap .cycle-op-btn:hover {
    background: rgba(255, 255, 255, 0.24);
    color: #ffffff;
}

.filter-value-inline {
    border: none;
    height: 100%;
    line-height: 1;
    vertical-align: middle;
    width: 52px;
    background: rgba(0, 0, 0, 0.20);
    color: #ffffff;
}

/* Текстовая кнопка фильтра — единый стиль с инлайн-блоком */
.header-filter-cell .filter-button {
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 2px 6px;
    height: 25px;
    width: 100%;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    transition: all 120ms ease;
}

.header-filter-cell .filter-button:hover {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.24);
    color: #ffffff;
}

.header-filter-cell .filter-button.filter-active {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.3);
    color: #ffffff;
}
