/* ==========================================
   Hub Tables — Tabelas Operacionais e Heatmap
   Tokens: var(--hub-*) como fonte da verdade
   ========================================== */

/* --- .hub-table / .hub-table (Tabela Operacional Canônica) --- */
.hub-table {
    width: 100%;
    border-collapse: collapse;
}
.hub-table th,
.hub-table td {
    white-space: nowrap;
    text-align: left;
    height: var(--hub-row-height);
    padding: var(--hub-cell-padding-y) var(--hub-cell-padding-x);
    font-size: var(--hub-text-body-compact);
    line-height: var(--hub-leading-snug);
}
.hub-table th {
    position: sticky;
    top: 0;
    z-index: var(--hub-z-raised);
    background: var(--hub-surface-soft);
    box-shadow: inset 0 -1px 0 var(--hub-border);
    font-size: var(--hub-text-overline);
    font-weight: var(--hub-weight-semibold);
    color: var(--hub-text-muted);
    text-transform: var(--hub-case-eyebrow);
    letter-spacing: var(--hub-tracking-wide);
}
.hub-table td {
    font-weight: var(--hub-weight-regular);
    font-variant-numeric: tabular-nums;
    color: var(--hub-text-muted);
    border-bottom: 1px solid var(--hub-border-subtle);
    background: var(--hub-surface-soft);
}
.hub-table td:first-child {
    color: var(--hub-text);
    font-weight: var(--hub-weight-medium);
}

/* --- .hub-table-wrap / .hub-table-wrap (Container de Tabela Canônico) --- */
.hub-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    max-width: 100%;
    max-height: 100%;
    background: var(--hub-surface-soft);
    border-radius: var(--hub-radius);
    clip-path: inset(0 round var(--hub-radius));
}

/* --- Sub-componentes Internos Canônicos e Legados --- */
.hub-table__primary-cell {
    font-weight: var(--hub-weight-bold);
    color: var(--hub-text);
}
.hub-table tbody tr:last-child td {
    border-bottom: none;
}

/* --- .hub-table--action / Tabela com botões de ação (Estratégias, Fechamentos) --- */
/* padding menor compensa altura do hub-table-action (24px): 13+13+24 = 50px */
.hub-table--action th,
.hub-table--action td {
    padding-top: var(--hub-cell-padding-y-action);
    padding-bottom: var(--hub-cell-padding-y-action);
}

/* --- .hub-table--dense / Tabela compacta (Tarefas) --- */
.hub-table--dense th,
.hub-table--dense td {
    padding-top: var(--hub-cell-padding-y-dense);
    padding-bottom: var(--hub-cell-padding-y-dense);
}

/* --- .hub-cell-sub / Dado secundário dentro de célula --- */
.hub-cell-sub {
    display: block;
    font-size: var(--hub-text-label);
    color: var(--hub-text-muted);
    font-weight: var(--hub-weight-regular);
    line-height: 1.3;
    margin-top: 2px;
}
/* Ação compacta inline de tabela — 24px fecha linha em 50px com padding-y 13px */
.hub-table-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 0 var(--hub-space-3);
    border: 1px solid var(--hub-border-strong);
    border-radius: var(--hub-radius);
    background: var(--hub-surface-hover);
    color: var(--hub-text-muted);
    font: inherit;
    font-size: var(--hub-text-label);
    font-weight: var(--hub-weight-bold);
    letter-spacing: var(--hub-tracking-wide);
    text-transform: var(--hub-case-eyebrow);
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
}
.hub-table-action:hover {
    border-color: rgba(var(--hub-primary-rgb), 0.48);
    background: rgba(var(--hub-primary-rgb), 0.08);
    color: var(--hub-text);
}
.hub-table-action--primary {
    background: var(--hub-primary);
    border-color: var(--hub-primary);
    color: var(--hub-text-inverse);
}
.hub-table-action--primary:hover {
    background: var(--hub-primary-hover);
    border-color: var(--hub-primary-hover);
    color: var(--hub-text-inverse);
}
.hub-table-action--danger {
    color: var(--hub-danger);
    border-color: rgba(var(--hub-danger-rgb), 0.35);
}
.hub-table-action--danger:hover {
    background: rgba(var(--hub-danger-rgb), 0.1);
    border-color: var(--hub-danger);
    color: var(--hub-danger);
}

.hub-table-badge {
    display: inline-flex;
    align-items: center;
    min-height: 16px;
    padding: 2px var(--hub-space-2);
    border: 1px solid rgba(var(--hub-info-rgb), 0.28);
    border-radius: 999px;
    background: rgba(var(--hub-info-rgb), 0.12);
    color: var(--hub-info);
    font-size: var(--hub-text-label);
    font-weight: var(--hub-weight-chip);
    letter-spacing: var(--hub-tracking-snug);
}

/* --- Linhas Clicáveis --- */
.hub-table tbody tr[data-reservation-row],
.hub-table tbody tr[data-unit-row],
.hub-table tbody tr[data-application-row],
.hub-table tbody tr[data-task-id],
.hub-table tbody tr[data-report-row],
.hub-table tbody tr[data-edit-record],
.hub-table tbody tr[data-strategy-detail],
.hub-table tbody tr[data-market-row] {
    cursor: pointer;
}

/* --- Hover Sutil — Linhas Não-Clicáveis --- */
.hub-table tbody tr:hover td {
    background: var(--hub-surface-hover);
}

/* --- Hover Azul — Linhas Clicáveis --- */
.hub-table tbody tr[data-reservation-row]:hover td,
.hub-table tbody tr[data-unit-row]:hover td,
.hub-table tbody tr[data-application-row]:hover td,
.hub-table tbody tr[data-task-id]:hover td,
.hub-table tbody tr[data-report-row]:hover td,
.hub-table tbody tr[data-edit-record]:hover td,
.hub-table tbody tr[data-strategy-detail]:hover td,
.hub-table tbody tr[data-market-row]:hover td {
    background: rgba(var(--hub-primary-rgb), 0.055);
}

/* --- Hover em Coluna Sticky (primeira coluna) — Linhas Clicáveis --- */
.hub-table tbody tr[data-reservation-row]:hover td:first-child,
.hub-table tbody tr[data-unit-row]:hover td:first-child,
.hub-table tbody tr[data-application-row]:hover td:first-child,
.hub-table tbody tr[data-task-id]:hover td:first-child,
.hub-table tbody tr[data-report-row]:hover td:first-child,
.hub-table tbody tr[data-edit-record]:hover td:first-child,
.hub-table tbody tr[data-strategy-detail]:hover td:first-child,
.hub-table tbody tr[data-market-row]:hover td:first-child {
    background: linear-gradient(rgba(var(--hub-primary-rgb), 0.055), rgba(var(--hub-primary-rgb), 0.055)), var(--hub-surface-soft);
}

/* --- .hub-table-panel / .hub-table-panel (Painel de Tabela Canônico) --- */
.hub-table-panel {
    width: 100%;
    padding: var(--hub-panel-padding);
    border: 1px solid var(--hub-border);
    border-radius: var(--hub-radius);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent),
        var(--hub-surface-raised);
    overflow-y: auto;
}

.hub-table-panel > :first-child {
    border-top-left-radius: calc(var(--hub-radius) - 1px);
    border-top-right-radius: calc(var(--hub-radius) - 1px);
}

.hub-table-panel > :last-child {
    border-bottom-left-radius: calc(var(--hub-radius) - 1px);
    border-bottom-right-radius: calc(var(--hub-radius) - 1px);
}

@media (min-width: 861px) {
    .hub-table-panel {
        border-color: var(--hub-border);
        border-radius: var(--hub-radius);
        background:
            linear-gradient(180deg, rgba(255, 255, 255, 0.012), transparent 68%),
            var(--hub-surface-raised);
        max-height: calc(100vh - (var(--hub-view-section-gap) * 2) - var(--hub-shell-header-height) - var(--hub-view-section-gap) - 2px);
    }
}

/* --- Heatmap (Matrizes) --- */
.hub-heatmap {
    border-collapse: separate;
    border-spacing: 4px;
}

.hub-heatmap th,
.hub-heatmap td {
    border: none;
}

.hub-heatmap th:not(:first-child),
.hub-heatmap td.hm-cell {
    width: 60px;
    text-align: center;
    font-weight: var(--hub-weight-semibold);
}

.hub-heatmap td.hm-cell {
    border-radius: var(--hub-radius-sm);
    font-size: var(--hub-text-overline);
    line-height: 1.2;
    padding: var(--hub-space-2) var(--hub-space-1);
}

.hub-heatmap td.hm-cell:hover {
    filter: brightness(1.3);
    cursor: default;
}

/* --- Table Wrap para Matrizes --- */
.hub-table-wrap:has(#hub-matrix-checkin),
.hub-table-wrap:has(#hub-matrix-booking),
.hub-table-wrap:has(#hub-matrix-active),
.hub-table-wrap:has(#hub-matrix-checkin),
.hub-table-wrap:has(#hub-matrix-booking),
.hub-table-wrap:has(#hub-matrix-active) {
    max-height: 420px;
    overflow-y: auto;
}

.hub-matrix-modal .hub-table-wrap:has(#hub-matrix-active),
.hub-matrix-modal .hub-table-wrap:has(#hub-matrix-checkin),
.hub-matrix-modal .hub-table-wrap:has(#hub-matrix-booking),
.hub-matrix-modal .hub-table-wrap:has(#hub-matrix-active),
.hub-matrix-modal .hub-table-wrap:has(#hub-matrix-checkin),
.hub-matrix-modal .hub-table-wrap:has(#hub-matrix-booking) {
    max-height: none;
    height: 100%;
}

/* --- Tabela Paginação Canônica --- */
.hub-table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--hub-space-3) var(--hub-space-4);
    border-top: 1px solid var(--hub-border);
    background: transparent;
    font-size: var(--hub-text-label);
    color: var(--hub-text-muted);
}
.hub-pagination-buttons {
    display: flex;
    gap: var(--hub-space-2);
}


/* =========================================================
   Matrix & Heatmap Styles
   ========================================================= */
#hub-matrix-checkin .hub-matrix__unit,
#hub-matrix-booking .hub-matrix__unit,
#hub-matrix-active .hub-matrix__unit {
    min-width: 360px;
    width: 360px;
    max-width: 480px;
    position: sticky;
    left: 0;
    z-index: 10;
    white-space: nowrap;
    border-right: 1px solid var(--hub-border);
    border-bottom: 1px solid var(--hub-border) !important;
}

#hub-matrix-checkin th.hub-matrix__unit,
#hub-matrix-booking th.hub-matrix__unit,
#hub-matrix-active th.hub-matrix__unit {
    z-index: calc(var(--hub-z-raised) + 10);
}

:is(#hub-matrix-checkin, #hub-matrix-booking, #hub-matrix-active) tbody tr:hover td {
    background: var(--hub-white-alpha-3);
}

#hub-matrix-checkin :is(td, th).hub-matrix__unit,
#hub-matrix-booking :is(td, th).hub-matrix__unit,
#hub-matrix-active :is(td, th).hub-matrix__unit {
    background: var(--hub-surface);
}

.hub-matrix-cell {
    border-radius: var(--hub-radius-sm);
    font-weight: inherit;
    transition: filter var(--hub-transition-base), transform var(--hub-transition-base);
}

.hub-matrix-cell:hover {
    filter: brightness(1.15);
}

.hub-matrix__total,
.hub-matrix__total td,
.hub-matrix__total-cell {
    font-weight: var(--hub-weight-semibold);
}

.hub-sensitivity--base td {
    color: var(--hub-primary);
    font-weight: var(--hub-weight-bold);
}

.hub-heatmap {
    border-collapse: separate;
    border-spacing: 4px;
}

.hub-heatmap th,
.hub-heatmap td {
    border: none;
}

.hub-heatmap th:not(:first-child),
.hub-heatmap td.hm-cell {
    min-width: 184px;
}

.hub-heatmap td.hm-cell {
    border-radius: var(--hub-radius);
    color: var(--hub-text) !important;
    font-weight: var(--hub-weight-semibold);
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    transition: transform var(--hub-transition-slow);
}

.hub-heatmap td.hm-cell:hover {
    cursor: crosshair;
    transform: scale(1.05);
    border-radius: var(--hub-radius);
}

/* ==========================================
   Tabelas Interativas
   ========================================== */

.hub-table th.is-sortable:hover {
    background-color: var(--hub-surface-soft);
    background-image: linear-gradient(var(--hub-surface-hover), var(--hub-surface-hover));
    color: var(--hub-text);
}

.hub-table-sort-indicator {
    display: inline-block;
    margin-left: var(--hub-space-1);
    font-size: var(--hub-text-overline);
    transition: opacity var(--hub-transition-slow);
}

/*
 * Popover de seleção de colunas
 * Nota: montado em document.body (escapa overflow:hidden do header).
 * Os tokens de design e as regras de scrollbar são explícitos aqui
 * porque o elemento vive fora do contexto .hub-app.
 */
.hub-table-column-selector-popover {
    display: none;
    background: var(--hub-surface-raised);        /* #1d1d1d — nível modal */
    border: 1px solid var(--hub-border-strong);   /* borda mais visível que border-subtle */
    border-radius: var(--hub-radius);
    padding: var(--hub-space-xs);                      /* var(--hub-space-2) — token Hub canônico */
    box-shadow: var(--hub-modal-shadow);           /* 0 10px 25px rgba(0,0,0,0.5) */
    flex-direction: column;
    gap: var(--hub-space-1);
    min-width: 190px;
    max-height: 300px;
    overflow-y: auto;

    /* Scrollbar fina — paridade com .hub-app *::-webkit-scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--hub-white-alpha-15) transparent;
}

/* Exibido via JS (popover.style.display = 'flex') */
.hub-table-column-selector-popover.is-active {
    display: flex;
}

/* Scrollbar — réplica exata de hub-core.css (.hub-app *::-webkit-scrollbar) */
.hub-table-column-selector-popover::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.hub-table-column-selector-popover::-webkit-scrollbar-track {
    background: transparent;
}

.hub-table-column-selector-popover::-webkit-scrollbar-thumb {
    border-radius: 8px; /* exceção intencional — scrollbar thumb */
    background: var(--hub-white-alpha-15);
}

.hub-table-column-selector-popover::-webkit-scrollbar-thumb:hover {
    background: var(--hub-highlight-context-border);
}

.hub-table-popover-title {
    font-size: var(--hub-text-overline);
    font-weight: var(--hub-weight-bold);
    color: var(--hub-text-muted);
    text-transform: var(--hub-case-eyebrow);
    letter-spacing: var(--hub-tracking-widest);
    border-bottom: 1px solid var(--hub-border);
    padding: 2px var(--hub-space-xs) var(--hub-space-xs);  /* espaçamento interno consistente */
    margin-bottom: 2px;
}

.hub-table-popover-item {
    display: flex;
    align-items: center;
    gap: var(--hub-space-2);
    font-size: var(--hub-text-body-compact);
    color: var(--hub-text);
    cursor: pointer;
    user-select: none;
    padding: 3px var(--hub-space-2);
    margin: 0;
    min-height: 26px;
    line-height: 1.2;
    border-radius: var(--hub-radius-sm);
    transition: background var(--hub-transition-fast), color var(--hub-transition-fast);
}

.hub-table-popover-item:hover {
    background: var(--hub-surface-hover, rgba(255,255,255,0.04));
    color: var(--hub-primary);
}

.hub-table-popover-item input[type="checkbox"] {
    accent-color: var(--hub-primary);
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;                                     /* remove margin padrão do browser */
}

/* Wrapper do seletor dentro do th */
.hub-table-column-selector-wrapper {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    z-index: var(--hub-z-raised);
}

/* Botão de engrenagem discreto */
.hub-table-col-select-btn {
    border: none;
    background: transparent;
    padding: var(--hub-space-1);
    cursor: pointer;
    font-size: var(--hub-text-body);
    line-height: 1;
    color: var(--hub-text-muted);
    opacity: 0.6;
    transition: opacity var(--hub-transition-base), color var(--hub-transition-base), transform var(--hub-transition-slow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.hub-table-col-select-btn:hover {
    opacity: 1;
    color: var(--hub-text);
    transform: rotate(30deg); /* Micro-animação premium */
}

/* Botão de lupa de filtro no th */
.hub-table-filter-btn {
    border: none;
    background: transparent;
    padding: 2px var(--hub-space-1);
    cursor: pointer;
    font-size: var(--hub-text-overline);
    color: var(--hub-text-muted);
    opacity: 0;
    transition: opacity var(--hub-transition-base), color var(--hub-transition-base);
    margin-left: var(--hub-space-2);
    vertical-align: middle;
}

.hub-table th:hover .hub-table-filter-btn {
    opacity: 0.5;
}

.hub-table-filter-btn:hover {
    opacity: 1 !important;
    color: var(--hub-primary) !important;
}

.hub-table-filter-btn.is-active {
    opacity: 1 !important;
    color: var(--hub-primary) !important;
}

/* Popover de entrada de filtro por coluna */
.hub-table-column-filter-popover {
    display: none;
    background: var(--hub-surface-raised);
    border: 1px solid var(--hub-border-strong);
    border-radius: var(--hub-radius);
    padding: var(--hub-space-3);
    box-shadow: var(--hub-modal-shadow);
    flex-direction: column;
    gap: var(--hub-space-2);
    width: 220px;
    z-index: 10000;
}

.hub-table-column-filter-popover input {
    width: 100%;
    background: var(--hub-input-bg);
    border: 1px solid var(--hub-border-strong);
    color: var(--hub-text);
    padding: var(--hub-space-2) var(--hub-space-2);
    font-size: var(--hub-text-body-compact);
    border-radius: var(--hub-radius-sm);
}

.hub-table-column-filter-popover input:focus {
    outline: none;
    border-color: var(--hub-primary);
    box-shadow: var(--hub-shadow-focus);
}

.hub-table-filter-popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--hub-space-2);
}

/* --- Estado de carregamento suave --- */
.hub-table--loading,
.hub-table-loading {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity var(--hub-transition-base);
}

