/* ==========================================================================
   SmartTable — motor reutilizável de tabelas (resize, fixar, filtros, DnD)
   Progressive enhancement sobre <table> existentes. Tema claro + escuro.
   ========================================================================== */

/* Véu anti-flash: a tabela nasce oculta e o SmartTable a revela após aplicar
   o layout salvo (cache local). O keyframe é um failsafe que a revela sozinha
   caso o JS falhe ou não inicialize. */
table.st-loading {
    visibility: hidden;
    animation: st-loading-reveal 0s 1.5s forwards;
}
@keyframes st-loading-reveal {
    to { visibility: visible; }
}

.st-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: auto !important; /* vence .table-responsive { overflow: hidden } das telas */
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.st-wrap table.st-table {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;        /* essencial p/ larguras controladas + wrap */
    width: max-content;
    min-width: 100%;
    margin-bottom: 0;
}

/* ---- Cabeçalho fixo no topo durante rolagem vertical ---- */
.st-table thead th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--st-head-bg, #f1f3f6);
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
}

.st-table th.st-th {
    padding: 0;                 /* o conteúdo interno controla o padding */
}

.st-th-inner {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.3rem 0.5rem;
    min-height: 32px;
    position: relative;
}

.st-th-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
}

/* indicadores de estado (ordenado / filtrado / fixado) */
.st-th-badges {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.62rem;
    color: var(--st-accent, #0d6efd);
    flex: 0 0 auto;
}
.st-th-badges .st-badge { line-height: 1; }
.st-th-badges .st-filter-count {
    background: var(--st-accent, #0d6efd);
    color: #fff;
    border-radius: 8px;
    padding: 0 5px;
    font-weight: 600;
}
.st-sort-ind { font-size: 0.7rem; color: var(--st-accent, #0d6efd); }

.st-th-menu-btn {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: #8a93a2;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity .12s, background .12s;
    font-size: 0.72rem;
}
.st-th:hover .st-th-menu-btn,
.st-th-menu-btn:focus-visible,
.st-th.st-has-state .st-th-menu-btn { opacity: 1; }
.st-th-menu-btn:hover { background: rgba(0,0,0,.07); color: #333; }

/* ---- alça de redimensionamento ---- */
.st-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 7px;
    height: 100%;
    cursor: col-resize;
    z-index: 6;
    touch-action: none;
}
.st-resizer::after {
    content: "";
    position: absolute;
    top: 15%;
    right: 3px;
    height: 70%;
    width: 2px;
    background: transparent;
    border-radius: 2px;
    transition: background .12s;
}
.st-th:hover .st-resizer::after,
.st-resizer:hover::after { background: var(--st-accent, #0d6efd); }
.st-resizing, .st-resizing * { cursor: col-resize !important; user-select: none !important; }

/* ---- células ---- */
.st-table td {
    vertical-align: top;
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
    overflow: hidden;
}
/* base / modo auto: quebra de linha integral, sem reticências */
.st-cell {
    display: block;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}
/* modo manual (coluna redimensionada): limita a 4 linhas + reticências */
.st-table td.st-clamp .st-cell {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: var(--st-clamp, 4);
    overflow: hidden;
}
/* colunas de ações / nowrap: nunca quebram */
.st-table td.st-nowrap-cell .st-cell,
.st-table td.st-nowrap-cell {
    white-space: nowrap;
}
.st-cell.st-truncated { cursor: help; }

/* ---- colunas fixadas (sticky horizontal) ---- */
.st-table th.st-pinned,
.st-table td.st-pinned {
    position: -webkit-sticky;
    position: sticky;
    z-index: 4;
    background: var(--st-cell-bg, #fff);
}
.st-table thead th.st-pinned { z-index: 7; background: var(--st-head-bg, #f1f3f6); }
.st-table th.st-pin-left-last,
.st-table td.st-pin-left-last { box-shadow: 2px 0 5px -2px rgba(0,0,0,.25); }
.st-table th.st-pin-right-first,
.st-table td.st-pin-right-first { box-shadow: -2px 0 5px -2px rgba(0,0,0,.25); }

/* linha de hover preserva fundo nas fixas */
.st-table tbody tr:hover td { background: var(--st-row-hover, #f5f8ff); }
.st-table tbody tr:hover td.st-pinned { background: var(--st-row-hover, #f5f8ff); }

/* ---- indicador de drop no reorder ---- */
.st-th.st-drag-over-left { box-shadow: inset 3px 0 0 var(--st-accent, #0d6efd); }
.st-th.st-drag-over-right { box-shadow: inset -3px 0 0 var(--st-accent, #0d6efd); }
.st-th.st-dragging { opacity: .5; }
.st-th.st-col-selected .st-th-inner { background: rgba(13,110,253,.12); }

/* ==========================================================================
   Menu de contexto do cabeçalho
   ========================================================================== */
.st-menu {
    position: fixed;
    z-index: 1080;
    min-width: 210px;
    background: var(--st-menu-bg, #fff);
    border: 1px solid var(--st-border, #e0e3e8);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,.18);
    padding: 5px;
    font-size: 0.84rem;
    color: var(--st-text, #1d2630);
}
.st-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 7px 10px;
    border-radius: 7px;
    cursor: pointer;
    color: inherit;
}
.st-menu-item:hover, .st-menu-item:focus-visible { background: rgba(13,110,253,.10); outline: none; }
.st-menu-item i { width: 16px; text-align: center; color: #6b7382; }
.st-menu-sep { height: 1px; background: var(--st-border, #e9ecef); margin: 5px 4px; }
.st-menu-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .03em; color: #8a93a2; padding: 4px 10px 2px; }

/* ---- painel de filtro ---- */
.st-filter-pop { min-width: 250px; padding: 10px; }
.st-filter-pop .st-field { width: 100%; margin-bottom: 7px; }
.st-filter-pop select.st-field,
.st-filter-pop input.st-field {
    border: 1px solid var(--st-border, #ced4da);
    border-radius: 7px;
    padding: 5px 8px;
    font-size: 0.82rem;
    background: var(--st-cell-bg, #fff);
    color: var(--st-text, #1d2630);
}
.st-filter-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.st-filter-status-list { max-height: 190px; overflow: auto; border: 1px solid var(--st-border,#e9ecef); border-radius: 7px; padding: 4px; }
.st-filter-status-list label { display: flex; gap: 7px; align-items: center; padding: 3px 5px; font-size: 0.82rem; cursor: pointer; border-radius: 5px; }
.st-filter-status-list label:hover { background: rgba(13,110,253,.08); }

/* busca rápida embutida no cabeçalho */
.st-quick-search {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 5px;
    padding: 2px 6px;
    font-size: 0.75rem;
    background: rgba(0,0,0,.04);
    color: var(--st-text, #1d2630);
}
.st-quick-search:focus { border-color: var(--st-accent,#0d6efd); background: #fff; outline: none; }

/* ==========================================================================
   Toolbar + ícone de engrenagem
   ========================================================================== */
.st-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.st-toolbar .st-spacer { flex: 1 1 auto; }
.st-active-filters {
    font-size: 0.78rem;
    color: var(--st-accent, #0d6efd);
    background: rgba(13,110,253,.10);
    border-radius: 16px;
    padding: 3px 11px;
    display: none;
    align-items: center;
    gap: 6px;
}
.st-active-filters.st-show { display: inline-flex; }
.st-active-filters button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 0.7rem; }

.st-btn {
    border: 1px solid var(--st-border, #ced4da);
    background: var(--st-cell-bg, #fff);
    color: var(--st-text, #344050);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.st-btn:hover { border-color: var(--st-accent, #0d6efd); color: var(--st-accent, #0d6efd); }
.st-btn-icon { padding: 5px 9px; }

.st-views-select { max-width: 200px; }

/* ==========================================================================
   Drawer de configuração
   ========================================================================== */
.st-drawer-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 1090; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.st-drawer-backdrop.st-open { opacity: 1; pointer-events: auto; }
.st-drawer {
    position: fixed; top: 0; right: 0; height: 100%; width: 360px; max-width: 92vw;
    background: var(--st-menu-bg, #fff); color: var(--st-text, #1d2630);
    z-index: 1091; box-shadow: -8px 0 30px rgba(0,0,0,.2);
    transform: translateX(100%); transition: transform .25s ease;
    display: flex; flex-direction: column;
}
.st-drawer.st-open { transform: translateX(0); }
.st-drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--st-border,#e9ecef); }
.st-drawer-head h5 { margin: 0; font-size: 1rem; }
.st-drawer-body { padding: 12px 16px; overflow: auto; flex: 1 1 auto; }
.st-drawer-foot { padding: 12px 16px; border-top: 1px solid var(--st-border,#e9ecef); display: flex; gap: 8px; flex-wrap: wrap; }

.st-col-search { width: 100%; margin-bottom: 10px; border: 1px solid var(--st-border,#ced4da); border-radius: 8px; padding: 7px 10px; }
.st-col-list { list-style: none; margin: 0; padding: 0; }
.st-col-item {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 8px; border-radius: 8px; cursor: grab;
    border: 1px solid transparent;
}
.st-col-item:hover { background: rgba(13,110,253,.06); }
.st-col-item.st-dragging { opacity: .5; }
.st-col-item.st-over { border-color: var(--st-accent,#0d6efd); }
.st-col-item .st-grip { color: #adb5bd; cursor: grab; }
.st-col-item label { flex: 1 1 auto; margin: 0; cursor: pointer; font-size: 0.86rem; }

/* ==========================================================================
   Tooltip de conteúdo truncado
   ========================================================================== */
.st-tooltip {
    position: fixed; z-index: 1100; max-width: 420px;
    background: #1d2630; color: #fff; border-radius: 8px;
    padding: 8px 10px; font-size: 0.8rem; line-height: 1.35;
    box-shadow: 0 6px 22px rgba(0,0,0,.3); white-space: pre-wrap;
    overflow-wrap: anywhere; pointer-events: auto;
}
.st-tooltip .st-tooltip-copy {
    margin-top: 6px; border: 0; background: rgba(255,255,255,.16); color: #fff;
    border-radius: 6px; padding: 3px 9px; font-size: 0.72rem; cursor: pointer;
}
.st-tooltip .st-tooltip-copy:hover { background: rgba(255,255,255,.3); }

/* ==========================================================================
   Acessibilidade / alto contraste
   ========================================================================== */
.st-menu-item:focus-visible,
.st-btn:focus-visible,
.st-th-menu-btn:focus-visible,
.st-th-label:focus-visible { outline: 2px solid var(--st-accent, #0d6efd); outline-offset: 1px; }

@media (prefers-contrast: more) {
    .st-table th, .st-table td { border-color: #000 !important; }
    .st-th-menu-btn { opacity: 1; color: #000; }
}

.st-sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Tema escuro — acompanha o tema do app (html.agil-theme-dark)
   Os menus/drawer/tooltip são anexados ao <body>, então ficam dentro de
   html.agil-theme-dark e recebem o tema. Especificidade reforçada para vencer
   as regras genéricas do app (ex.: `html.agil-theme-dark label { color !important }`).
   ========================================================================== */
html.agil-theme-dark .st-wrap {
    --st-head-bg: #232a36;
    --st-cell-bg: #1b2230;
    --st-text: #e6eaf0;
    --st-border: #333d4d;
    --st-row-hover: #243043;
    --st-menu-bg: #1f2733;
    --st-accent: #4c8dff;
}

/* superfícies flutuantes */
html.agil-theme-dark .st-menu,
html.agil-theme-dark .st-drawer {
    background: #1f2733;
    color: #e6eaf0;
    border-color: #333d4d;
}
html.agil-theme-dark .st-drawer-head,
html.agil-theme-dark .st-drawer-foot { border-color: #333d4d; }
html.agil-theme-dark .st-menu-sep { background: #333d4d; }
html.agil-theme-dark .st-menu-label { color: #8a93a2; }

/* itens de menu e seus ícones */
html.agil-theme-dark .st-menu .st-menu-item { color: #e6eaf0; }
html.agil-theme-dark .st-menu .st-menu-item:hover,
html.agil-theme-dark .st-menu .st-menu-item:focus-visible { background: rgba(76,141,255,.18); }
html.agil-theme-dark .st-menu .st-menu-item i { color: #9aa4b2; }

/* rótulos dentro dos widgets (o app força a cor com !important; reforçamos) */
html.agil-theme-dark .st-menu label,
html.agil-theme-dark .st-menu .st-menu-item span,
html.agil-theme-dark .st-drawer label,
html.agil-theme-dark .st-drawer .st-col-item label { color: #e6eaf0 !important; }

/* campos (inputs/selects) dentro dos widgets */
html.agil-theme-dark .st-filter-pop input.st-field,
html.agil-theme-dark .st-filter-pop select.st-field,
html.agil-theme-dark .st-col-search,
html.agil-theme-dark .st-filter-status-list {
    background: #161c27;
    color: #e6eaf0;
    border-color: #333d4d;
}
html.agil-theme-dark .st-filter-status-list label:hover { background: rgba(76,141,255,.14); }

/* botões da toolbar e do popup */
html.agil-theme-dark .st-btn {
    background: #232a36;
    color: #e6eaf0;
    border-color: #3a4556;
}
html.agil-theme-dark .st-btn:hover { border-color: #4c8dff; color: #cfe0ff; }
html.agil-theme-dark .st-quick-search { background: rgba(255,255,255,.06); color: #e6eaf0; }
html.agil-theme-dark .st-col-item:hover { background: rgba(76,141,255,.12); }
html.agil-theme-dark .st-th-menu-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ==========================================================================
   Robustez do popup de filtro (independe do tema)
   ========================================================================== */
.st-filter-pop { max-width: 300px; }
/* a lista de status é SEMPRE vertical e rolável — vence regras genéricas do app */
.st-menu .st-filter-status-list { display: block; }
.st-menu .st-filter-status-list label {
    display: flex;
    width: 100%;
    white-space: normal;
    margin: 0;
}
