/* ======================================================= */
/* === ESTILOS GERAIS E RESET BÁSICO ===================== */
/* ======================================================= */
:root {
  --ui-font-size: 16px;
  --ui-line: 1.30;
  --row-y: 10px;
  --ui-action-btn-size: 32px;

  /* Larguras fixas das extremidades da tabela */
  --col-drag-w: 40px;
  /* 4 botões (32) + 3 gaps (8) + padding lateral ~16 */
  --col-actions-w: calc((var(--ui-action-btn-size) * 4) + (8px * 3) + 16px);
  --font-base: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-base);
  margin: 0;
  padding: 0;
  background: #f9fafb;
  color: #1f2937;
  font-size: var(--ui-font-size);
  line-height: var(--ui-line);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.container { padding: 20px; }

/* ======================================================= */
/* === TOPBAR E BOTÕES PRINCIPAIS ======================== */
/* ======================================================= */
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 10px 20px;
  background: #ffffff;
  color: #1f2937;
  border-bottom: 1px solid #e5e7eb;
}

.btn {
  padding: .6rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  border-radius: 8px;
  font-weight: 500;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.btn:not(:disabled):hover { filter: brightness(95%); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.btn:active { transform: translateY(1px); filter: brightness(90%); }
.btn-primary { background:#4f46e5; color:#fff; border-color:#4f46e5; }
.btn-success{ background:#22c55e; border-color:#16a34a; }
.btn-danger { background:#ef4444; border-color:#dc2626; }
.btn-primary{ background:#3b82f6; border-color:#2563eb; }


.health { margin-left: auto; font-size: .9rem; opacity: .8; }

/* ======================================================= */
/* === FILTROS =========================================== */
/* ======================================================= */
.filters {
  margin: 10px 0 16px;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: end;
}
.filter-item { display:flex; flex-direction:column; gap:6px; min-width:0; }
.filters .filter-item input,
.filters .filter-item select {
  display: block; width: 100%; height: 44px; padding: 10px 12px;
  border: 1px solid #d1d5db; border-radius: 8px; font: inherit; line-height: 1.2; background:#fff; box-sizing: border-box;
}
.filters-actions { display:flex; align-items:center; justify-content:flex-end; gap:8px; }
.filters-actions .btn { height:44px; display:inline-flex; align-items:center; justify-content:center; padding:0 16px; border-radius:8px; background:#f3f4f6; border:1px solid #e5e7eb; color:#374151; }
@media (min-width:1024px){ .filters{ grid-template-columns: repeat(4, minmax(0, 1fr)) auto; } }

/* ======================================================= */
/* === TABELA (FLEX) — EXTREMIDADES FIXAS, MEIO PROPORC. == */
/* ======================================================= */
.table-wrap {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  overflow: hidden; /* respeita borda arredondada */
}
body.theme-dark .table-wrap { border-color:#374151; background:#1f2937; }

.table { width: 100%; border-collapse: separate; border-spacing: 0; }

/* cada linha é um flex-container */
.table thead tr,
.table tbody tr { display:flex; width:100%; border-bottom:1px solid #f3f4f6; }
.table tbody tr:last-child { border-bottom: 0; }
body.theme-dark .table tbody tr { border-bottom-color:#374151; }

/* células padrão = dividem o espaço restante de forma proporcional */
.table th,
.table td {
  display:flex;
  align-items:center;
  padding: var(--row-y) 12px;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 0;
}

/* cabeçalho */
.table th { font-weight:600; font-size:.9rem; color:#4b5563; background:#f9fafb; }
body.theme-dark .table th { color:#9ca3af; background:#111827; }

/* ===== extremidades: mesmas larguras no THEAD e TBODY ===== */
/* alça (esquerda) */
.table th.col-__drag,
.table td.col-__drag {
  flex: 0 0 var(--col-drag-w) !important;
  width: var(--col-drag-w);
  justify-content: center;
  padding-left: 8px;
  padding-right: 8px;
}

/* ações (direita) */
.table th.col-__actions,
.table td.col-__actions {
  flex: 0 0 var(--col-actions-w) !important;
  width: var(--col-actions-w);
  margin-left: auto;       /* gruda na extrema direita */
  padding-right: 8px;
}
.table td.col-__actions .actions { display:flex; gap:8px; justify-content:flex-end; flex-wrap:nowrap; }

/* linha hover */
.table tbody tr:hover { background:#f9fafb; }
body.theme-dark .table tbody tr:hover { background:#111827; }

/* mensagem de vazio ocupa toda a largura */
.table .full-width-message {
  flex: 1 1 auto; justify-content: center; padding: 20px; color:#6b7280; font-style: italic;
}

/* ======================================================= */
/* === DRAG & DROP (alça e estados) ====================== */
/* ======================================================= */
.col-drag { text-align:center; color:#9ca3af; }
.drag-handle {
  display:inline-flex; align-items:center; justify-content:center;
  width:28px; height:28px; border-radius:6px; border:1px solid transparent; background:transparent;
  font-size:16px; line-height:1; padding:0; cursor: default;
}
.drag-enabled .drag-handle { cursor: grab; }
.drag-enabled .drag-handle:active { cursor: grabbing; }
tr.dragging { opacity:.65; background:#eef2ff; }
tr.drop-hint-top    { box-shadow: inset 0 3px 0 0 #4f46e5; }
tr.drop-hint-bottom { box-shadow: inset 0 -3px 0 0 #4f46e5; }
.table, .table * { user-select: none; }

/* ======================================================= */
/* === BOTÕES DE AÇÃO NA TABELA ========================== */
/* ======================================================= */
.actions { display:flex; gap:8px; justify-content:flex-start; }
.btn-square {
  width: var(--ui-action-btn-size); height: var(--ui-action-btn-size);
  border-radius: 8px; display:inline-flex; align-items:center; justify-content:center;
  border:1px solid #d1d5db; background:#f9fafb; cursor:pointer;
  transition: background-color .2s ease, transform .1s ease, border-color .2s ease;
}
.btn-square.success { background:#ecfdf5; border-color:#a7f3d0; }
.btn-square.info    { background:#eef2ff; border-color:#c7d2fe; }
.btn-square.warn    { background:#fee2e2; border-color:#fecaca; }
.btn-square:active  { transform: translateY(1px); }
.btn-square .ico    { font-size: calc(var(--ui-action-btn-size) * .5); line-height:1; }

/* ======================================================= */
/* === MODAIS ============================================ */
/* ======================================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display:flex; align-items:center; justify-content:center; z-index: 9999;
}
.modal-box {
  background:#fff; border-radius:12px; width:min(960px,96vw); max-height:90vh;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); box-sizing:border-box;
  display:flex; flex-direction:column; overflow:hidden;
}
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:14px 16px; border-bottom:1px solid #e5e7eb; flex-shrink:0; }
.modal-body { padding:20px; flex-grow:1; overflow-y:auto; }
.modal-footer { display:flex; gap:.5rem; justify-content:flex-end; padding:12px 16px; border-top:1px solid #e5e7eb; background:#f9fafb; border-bottom-left-radius:12px; border-bottom-right-radius:12px; flex-shrink:0; }
.modal-box h2 { margin:0; font-size:1.25rem; }
.btn-icon { width:32px; height:32px; border-radius:8px; background:#f3f4f6; border:0; cursor:pointer; display:flex; align-items:center; justify-content:center; font-size:16px; }
.modal-box.modal-sm { width:min(560px,92vw); max-height:80vh; }
.modal-box.modal-lg { width:min(1100px,96vw); max-height:86vh; }

/* ======================================================= */
/* === FORMULÁRIOS (MODAIS) ============================== */
/* ======================================================= */
.modal-body form { display:flex; flex-direction:column; gap:16px; }
.field { display:flex; flex-direction:column; gap:6px; min-width:0; }
.field label { font-weight:500; font-size:.9rem; color:#374151; margin:0; }
.field input, .field select, .field textarea {
  width:100%; height:44px; padding:10px 12px; border:1px solid #d1d5db; border-radius:8px; font:inherit; line-height:1.3; background:#fff; box-sizing:border-box;
}
.field textarea { height:auto; min-height:90px; }
.grid-2, .grid-3 { display:grid; grid-template-columns:1fr; gap:14px; }
@media (min-width:900px){ .grid-2{ grid-template-columns:repeat(2,minmax(0,1fr)); } .grid-3{ grid-template-columns:repeat(3,minmax(0,1fr)); } }

/* ======================================================= */
/* === ABAS / GRADE / HISTÓRICO ========================== */
/* ======================================================= */
.tabs { display:flex; gap:8px; margin:8px 0 12px; flex-wrap:wrap; border-bottom:1px solid #e5e7eb; }
.tab-btn { padding:.5rem .8rem; border:none; background:transparent; border-bottom:3px solid transparent; cursor:pointer; font-weight:500; color:#6b7280; transition: color .2s, border-color .2s; }
.tab-btn:hover { color:#374151; }
.tab-btn.active { color:#4f46e5; border-color:#4f46e5; }
.tab-panel { margin-top:8px; }

.grid-2col { display:grid; gap:12px; grid-template-columns:1fr; }
@media (min-width:960px){ .grid-2col{ grid-template-columns:1fr 1fr; } }

.grid-card { border:1px solid #e5e7eb; border-radius:12px; padding:12px; background:#fff; }
.grid-card-title { font-weight:700; margin-bottom:8px; }
.grid-empty { color:#6b7280; font-style:italic; padding:8px 4px; }
.section-title { font-weight:600; margin:8px 0; }

.hist-list { display:grid; gap:8px; }
.hist-item { padding:8px; border:1px solid #e5e7eb; border-radius:6px; background:#f9fafb; }
.hist-item .hist-meta { font-size:.85em; color:#6b7280; margin-top:4px; }

/* ======================================================= */
/* === TOASTS (NOTIFICAÇÕES) ============================= */
/* ======================================================= */
.toast-container { position:fixed; top:16px; right:16px; display:grid; gap:10px; z-index:10000; }
.toast {
  display:flex; align-items:center; gap:10px; background:#334155; color:#fff; padding:12px 16px; border-radius:10px;
  box-shadow:0 6px 22px rgba(0,0,0,.18); min-width:260px; max-width:420px; opacity:0; transform: translateY(-6px); animation: toast-in .18s ease forwards;
}
.toast.success{ background:#15803d; }
.toast.info{ background:#2563eb; }
.toast.warn{ background:#b45309; }
.toast.error{ background:#b91c1c; }
.toast .toast-close{ margin-left:auto; cursor:pointer; opacity:.8; font-weight:700; border:0; background:transparent; color:inherit; }
@keyframes toast-in { to { opacity:1; transform: translateY(0); } }
@keyframes toast-out { to { opacity:0; transform: translateY(-6px); } }

/* ======================================================= */
/* === CONFIGURAÇÕES (MODAL UI) ========================== */
/* ======================================================= */
.section-block { border:1px solid #e5e7eb; border-radius:10px; padding:12px; background:#fcfcfc; margin-bottom:12px; }
.range-row { display:flex; flex-direction:column; gap:6px; margin-bottom:10px; }
.range-wrap { display:flex; align-items:center; gap:10px; }
.range-wrap output { min-width:56px; text-align:center; font-variant-numeric:tabular-nums; border:1px solid #d1d5db; border-radius:8px; padding:4px 8px; background:#f9fafb; }
.mini-preview { margin-top:10px; }
.mini-title { font-weight:600; margin-bottom:6px; }
.mini-table { font-size:.95em; }

body.table-zebra .table tbody tr:nth-child(odd){ background:#f9fafb; }
body.density-compact { --row-y: 6px; }
body.density-cozy { --row-y: 10px; }
body.density-comfortable { --row-y: 14px; }

.reorder-list { list-style:none; padding:0; margin:0; display:grid; gap:8px; }
.re-item { display:grid; grid-template-columns:32px 1fr; align-items:center; gap:10px; border:1px solid #e5e7eb; background:#fff; border-radius:10px; padding:8px 10px; }
.re-handle { display:inline-flex; align-items:center; justify-content:center; width:28px; height:28px; border:1px solid #d1d5db; background:#f3f4f6; border-radius:6px; cursor:grab; }
.re-item.dragging { opacity:.6; }
.muted { color:#6b7280; }

#modalConfig .modal-box { width:min(960px,96vw); }
.fields-toolbar { display:flex; gap:8px; align-items:center; margin-bottom:12px; }
.fields-toolbar .section-title { margin-bottom:0; }
.fields-toolbar .btn { margin-left:auto; }

/* tabela de configuração de colunas */
.config-table { width:100%; min-width:800px; border-collapse:collapse; }
.config-table th, .config-table td { padding:8px 10px; text-align:left; vertical-align:middle; border-bottom:1px solid #e5e7eb; white-space:nowrap; }
.config-table thead th { font-size:.9em; background:#f9fafb; }
.config-table tbody tr:last-child td { border-bottom:0; }
.config-table tr[data-core="true"] { background:#f9fafb; }
.config-table tr[data-core="true"] .cfg-label { font-weight:500; }
.config-table .col-handle { width:48px; text-align:center; }
.config-table .col-label { width:25%; }
.config-table .col-type { width:20%; }
.config-table .col-options { width:25%; }
.config-table .col-width { width:120px; }
.config-table .col-visible, .config-table .col-required, .config-table .col-actions { width:80px; text-align:center; }
.cfg-handle { cursor:grab; }
.cfg-col-row input[type="text"], .cfg-col-row input[type="number"], .cfg-col-row select, .cfg-col-row textarea {
  width:100%; height:38px; padding:6px 10px; border:1px solid #d1d5db; border-radius:8px; background:#fff; box-sizing:border-box; font:inherit;
}
.cfg-col-row textarea { height:auto; min-height:38px; resize:vertical; }
.cfg-col-row input[type="checkbox"] { width:18px; height:18px; vertical-align:middle; }
.cfg-options[data-hidden="true"] { visibility:hidden; }
.cfg-del { width:36px; height:36px; border-radius:8px; border:1px solid transparent; background:transparent; cursor:pointer; font-size:18px; color:#9ca3af; }
.cfg-del:not(:disabled):hover { background:#fee2e2; border-color:#fecaca; color:#ef4444; }
.cfg-del:disabled { cursor:not-allowed; opacity:.5; }
.cfg-col-row input:disabled, .cfg-col-row select:disabled { background:#f3f4f6; cursor:not-allowed; opacity:.7; }
.config-table tr.has-options td { vertical-align:top; padding-top:16px; }

/* ======================================================= */
/* === SELETOR DE VISUALIZAÇÃO =========================== */
/* ======================================================= */
.view-toggle { display:flex; align-items:center; gap:4px; margin-left:16px; background:#f3f4f6; padding:4px; border-radius:8px; }
.view-btn {
  background:transparent; border:1px solid transparent; color:#4b5563; padding:6px 12px; border-radius:6px; cursor:pointer; font-size:.9rem; font-weight:500; display:flex; align-items:center; gap:6px;
  transition: background-color .2s, color .2s, box-shadow .2s;
}
.view-btn:not(.active):hover { background: rgba(0,0,0,.05); }
.view-btn.active { background:#fff; color:#4f46e5; font-weight:600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.view-btn .icon { font-size:1.1em; }

/* ======================================================= */
/* === MENU DE ORDENAÇÃO ================================= */
/* ======================================================= */
.sort-menu { position:relative; display:inline-block; }
#sort-menu-btn { font-weight:500; }
.sort-dropdown {
  position:absolute; top:calc(100% + 4px); right:0; background:#fff; border:1px solid #e5e7eb; border-radius:8px;
  box-shadow:0 4px 12px rgba(0,0,0,.1); z-index:1000; width:220px; padding:6px; display:grid; gap:4px;
}
.sort-option { display:flex; justify-content:space-between; align-items:center; padding:8px 12px; border-radius:6px; cursor:default; }
.sort-option>span { font-weight:500; color:#374151; }
.sort-dir-btns { display:flex; gap:4px; }
.sort-dir-btns button { width:28px; height:28px; border:1px solid #d1d5db; background:#f9fafb; border-radius:6px; cursor:pointer; font-weight:bold; color:#4b5563; transition: background-color .2s, border-color .2s; }
.sort-dir-btns button:hover { background:#e5e7eb; border-color:#9ca3af; }
.sort-option.active { background:#eef2ff; }
.sort-dir-btns button.active { background:#4f46e5; color:#fff; border-color:#4f46e5; }

/* ======================================================= */
/* === SPLIT.JS (GRADE REDIMENSIONÁVEL) ================= */
/* ======================================================= */
.split-container { display:flex; flex-direction:row; width:100%; height:100%; }
.split-panel { overflow-y:auto; padding:0 5px; }
.gutter { background:#e5e7eb; background-repeat:no-repeat; background-position:50%; transition: background-color .2s; }
.gutter.gutter-horizontal { background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg=='); cursor: col-resize; }
.gutter:hover { background-color:#4f46e5; }

/* ======================================================= */
/* === TEMA ESCURO ======================================= */
/* ======================================================= */
body.theme-dark { background:#111827; color:#d1d5db; }
body.theme-dark .topbar, body.theme-dark .filters, body.theme-dark .grid-card { background:#1f2937; border-color:#374151; }
body.theme-dark .table thead th { background:#111827; border-color:#374151; color:#9ca3af; }
body.theme-dark .table tbody td { border-color:#374151; }
body.theme-dark .modal-box { background:#1f2937; border-color:#374151; }
body.theme-dark .modal-header, body.theme-dark .modal-footer { border-color:#374151; }
body.theme-dark .modal-footer { background:#111827; }
body.theme-dark .btn-icon { background:#374151; }
body.theme-dark .field input, body.theme-dark .field select, body.theme-dark .field textarea,
body.theme-dark .filters .filter-item input, body.theme-dark .filters .filter-item select { background:#374151; border-color:#4b5563; color:inherit; }
body.theme-dark .section-block { background:#111827; border-color:#374151; }
body.theme-dark .re-item { background:#374151; border-color:#4b5563; }
body.theme-dark .re-handle { background:#4b5563; border-color:#6b7280; }
body.theme-dark .config-table th, body.theme-dark .config-table td { border-color:#374151; }
body.theme-dark .config-table thead th { background:#111827; }
body.theme-dark .config-table tr[data-core="true"] { background:#111827; }
body.theme-dark .cfg-col-row input, body.theme-dark .cfg-col-row select, body.theme-dark .cfg-col-row textarea { background:#374151; border-color:#4b5563; color:inherit; }
body.theme-dark .cfg-del:not(:disabled):hover { background:#4b5563; color:#fca5a5; }
body.theme-dark #sort-menu-btn, body.theme-dark .filters-actions .btn { background:#374151; border-color:#4b5563; color:#d1d5db; }
body.theme-dark .sort-dropdown { background:#1f2937; border-color:#4b5563; }
body.theme-dark .sort-option>span { color:#d1d5db; }
body.theme-dark .sort-dir-btns button { background:#374151; border-color:#4b5563; color:#9ca3af; }
body.theme-dark .sort-option.active { background:#312e81; }
body.theme-dark .sort-dir-btns button.active { background:#6366f1; color:#fff; border-color:#6366f1; }
body.theme-dark .view-toggle { background:#374151; }
body.theme-dark .view-btn { color:#9ca3af; }
body.theme-dark .view-btn.active { background:#111827; color:#a5b4fc; }
body.theme-dark .gutter { background:#374151; }
body.theme-dark .gutter:hover { background:#6366f1; }

/* ======================================================= */
/* === ACESSIBILIDADE (FOCO) ============================= */
/* ======================================================= */
.btn:focus-visible, .btn-square:focus-visible, .tab-btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline:2px solid #4f46e5; outline-offset:2px; box-shadow:0 0 0 4px rgba(79,70,229,.2);
}

/* ======================================================= */
/* === UI MELHORADA: Reordenar Seções (cfgGridSections) === */
/* ======================================================= */

/* numeração automática e espaçamento levemente maior */
.reorder-list{
  counter-reset: sec;
  gap: 10px;
}

/* cartão da seção + micro animações */
.re-item{
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr; /* alça | label */
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 10px;
  transition: box-shadow .2s ease, transform .08s ease,
              background-color .2s ease, border-color .2s ease;
}
.re-item:hover{
  background: #f9fafb;
  border-color: #d1d5db;
}
.re-item.dragging{
  background: #eef2ff;
  border-color: #6366f1;
  transform: scale(1.01);
  box-shadow: 0 8px 24px rgba(79,70,229,.18);
  opacity: .95;
}

/* alça mais visível */
.re-item .re-handle{
  width: 28px; height: 28px;
  border-radius: 8px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  color: #6b7280;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: grab;
}
.re-item .re-handle:active{ cursor: grabbing; }

/* linhas-guia de soltar (topo/fundo) */
.re-item.drop-hint-top::before,
.re-item.drop-hint-bottom::after{
  content: "";
  position: absolute;
  left: 8px; right: 8px;
  height: 3px;
  background: #6366f1;
  border-radius: 2px;
}
.re-item.drop-hint-top::before{
  top: -2px;
  box-shadow: 0 -1px 0 rgba(99,102,241,.35);
}
.re-item.drop-hint-bottom::after{
  bottom: -2px;
  box-shadow: 0 1px 0 rgba(99,102,241,.35);
}

/* foco por teclado (acessibilidade) */
.re-item:focus-within{
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}

/* --- tema escuro --- */
body.theme-dark .re-item{
  background: #1f2937; border-color: #374151;
}
body.theme-dark .re-item:hover{
  background: #111827; border-color: #4b5563;
}
body.theme-dark .re-item.dragging{
  background: #312e81; border-color: #6366f1;
}
body.theme-dark .re-item .re-handle{
  background: #374151; border-color: #4b5563; color: #9ca3af;
}
body.theme-dark .re-item .re-label{ color: #d1d5db; }
body.theme-dark .re-item .re-label::before{
  background: #3730a3; color: #c7d2fe;
}

/* ======================================================= */
/* === Reordenar (UI unificada p/ seções, listas, colunas) */
/* ======================================================= */

/* ------ SEÇÕES (cfgGridSections) ------ */
/* mantém o estilo melhorado, mas remove a bolinha numérica */
.reorder-list{ gap:10px; }
.re-item{
  position:relative;
  display:grid;
  grid-template-columns:36px 1fr;
  align-items:center;
  padding:10px 12px;
  border:1px solid #e5e7eb;
  background:#fff;
  border-radius:10px;
  transition: box-shadow .2s, transform .08s, background-color .2s, border-color .2s;
}
.re-item:hover{ background:#f9fafb; border-color:#d1d5db; }
.re-item.dragging{
  background:#eef2ff; border-color:#6366f1;
  transform:scale(1.01);
  box-shadow:0 8px 24px rgba(79,70,229,.18);
  opacity:.95;
}
/* alça */
.re-item .re-handle{
  width:28px; height:28px; border-radius:8px;
  background:#f3f4f6; border:1px solid #d1d5db; color:#6b7280;
  display:inline-flex; align-items:center; justify-content:center;
  cursor:grab;
}
.re-item .re-handle:active{ cursor:grabbing; }
/* label (sem numeração) */
.re-item .re-label{ display:flex; align-items:center; gap:8px; font-weight:500; color:#374151; }
.re-item .re-label::before{ content:none !important; }

/* linhas-guia topo/fundo */
.re-item.drop-hint-top::before,
.re-item.drop-hint-bottom::after{
  content:"";
  position:absolute; left:8px; right:8px; height:3px; background:#6366f1; border-radius:2px;
}
.re-item.drop-hint-top::before{ top:-2px; box-shadow:0 -1px 0 rgba(99,102,241,.35); }
.re-item.drop-hint-bottom::after{ bottom:-2px; box-shadow:0 1px 0 rgba(99,102,241,.35); }

/* ------ COLUNAS/CAMPOS (tabela do editor .config-table) ------ */
.config-table .cfg-col-row{
  position:relative;          /* permite as linhas-guia */
  transition: background-color .2s, box-shadow .2s, transform .08s, border-color .2s;
}
.config-table .cfg-col-row:hover{ background:#f9fafb; }
.config-table .cfg-col-row.dragging{
  background:#eef2ff;
  transform:scale(1.005);
  box-shadow:0 8px 24px rgba(79,70,229,.14);
}
/* alça do editor */
.config-table .cfg-handle{
  width:28px; height:28px; border-radius:8px;
  background:#f3f4f6; border:1px solid #d1d5db; color:#6b7280;
  display:inline-flex; align-items:center; justify-content:center;
  cursor:grab;
}
.config-table .cfg-handle:active{ cursor:grabbing; }
/* linhas-guia topo/fundo para as linhas da tabela */
.config-table .cfg-col-row.drop-hint-top::before,
.config-table .cfg-col-row.drop-hint-bottom::after{
  content:"";
  position:absolute; left:10px; right:10px; height:3px; background:#6366f1; border-radius:2px;
}
.config-table .cfg-col-row.drop-hint-top::before{ top:-2px; box-shadow:0 -1px 0 rgba(99,102,241,.3); }
.config-table .cfg-col-row.drop-hint-bottom::after{ bottom:-2px; box-shadow:0 1px 0 rgba(99,102,241,.3); }

/* ------ LISTAS/TABELAS de atividades (refino das dicas) ------ */
.table tbody tr.drop-hint-top{
  box-shadow: inset 0 3px 0 #6366f1, 0 -1px 0 rgba(99,102,241,.28);
}
.table tbody tr.drop-hint-bottom{
  box-shadow: inset 0 -3px 0 #6366f1, 0 1px 0 rgba(99,102,241,.28);
}
.table tbody tr.dragging{
  background:#eef2ff;
  box-shadow:0 8px 24px rgba(79,70,229,.12) inset;
}

/* ------ Tema escuro ------ */
body.theme-dark .re-item{ background:#1f2937; border-color:#374151; }
body.theme-dark .re-item:hover{ background:#111827; border-color:#4b5563; }
body.theme-dark .re-item.dragging{ background:#312e81; border-color:#6366f1; }
body.theme-dark .re-item .re-handle,
body.theme-dark .config-table .cfg-handle{ background:#374151; border-color:#4b5563; color:#9ca3af; }
body.theme-dark .config-table .cfg-col-row:hover{ background:#111827; }
body.theme-dark .config-table .cfg-col-row.dragging{ background:#312e81; }

/* ======================================================= */
/* === Editor: Matriz Campos x Seções (Grade/Abas) ======= */
/* ======================================================= */
.matrix-table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border:1px solid #e5e7eb;
  border-radius:10px;
  background:#fff;
}
.matrix-table thead th{
  background:#f9fafb;
  border-bottom:1px solid #e5e7eb;
  padding:10px 12px;
  text-align:left;
  font-weight:600;
  font-size:.9rem;
  color:#4b5563;
  white-space:nowrap;
}
.matrix-table tbody td,
.matrix-table tbody th{
  border-bottom:1px solid #f3f4f6;
  padding:10px 12px;
  vertical-align:middle;
}
.matrix-table tbody tr:last-child td{ border-bottom:0; }

.mx-field{ font-weight:500; color:#374151; }
.mx-cell-td{ text-align:center; }
.mx-cell{ width:18px; height:18px; cursor:pointer; }

body.theme-dark .matrix-table{ background:#1f2937; border-color:#374151; }
body.theme-dark .matrix-table thead th{ background:#111827; border-color:#374151; color:#9ca3af; }
body.theme-dark .matrix-table tbody td,
body.theme-dark .matrix-table tbody th{ border-color:#374151; }

:root { --anchor-offset: 72px; }           /* ajuste se seu topo fixo tiver outra altura */
[id] { scroll-margin-top: var(--anchor-offset); }

/* realce rápido quando você chega por âncora */
.anchor-flash { animation: anchorFlash 1.2s ease; }
@keyframes anchorFlash {
  0%   { box-shadow: 0 0 0 4px rgba(255, 221, 87, .85); }
  100% { box-shadow: 0 0 0 0   rgba(255, 221, 87, 0); }
}

/* linkzinho “#” na barra do card da seção (apenas no hover) */
.grid-card-title .anchor-link { opacity: 0; margin-left: 6px; text-decoration: none; }
.grid-card:hover .anchor-link { opacity: .85; }

/* Cores apenas no modal de Atrasos */
#modalAtrasos tr.due-overdue td { background: #ffe6e6; } /* vermelho claro */
#modalAtrasos tr.due-today   td { background: #fff6cc; } /* amarelo claro */

.modal-overlay{ position: fixed; inset: 0; z-index: 1000; }
#modalAtrasos { z-index: 1010; } /* fica acima do base */
#modalInfo    { z-index: 1020; } /* fica acima do Atrasos */
#modalConfirm { z-index: 1030; } /* sempre no topo */
.modal-overlay{ position: fixed; inset: 0; z-index: 1000; }

/* ====== UI tokens (cores neutras + foco) ====== */
:root{
  --ui-surface-0:#ffffff;
  --ui-surface-1:#f8fafc;   /* bg de campos */
  --ui-surface-2:#f1f5f9;   /* cabeçalho/rodapé do modal */
  --ui-border:#d1d5db;
  --ui-border-strong:#9ca3af;
  --ui-text:#0f172a;
  --ui-muted:#64748b;
  --ui-focus:#2563eb;
  --ui-ring:0 0 0 3px rgba(37,99,235,.25);
}

body.theme-dark{
  --ui-surface-0:#0f172a;   /* slate-900 */
  --ui-surface-1:#111827;   /* gray-900 */
  --ui-surface-2:#1f2937;   /* gray-800 */
  --ui-border:#334155;      /* slate-700 */
  --ui-border-strong:#475569;
  --ui-text:#e5e7eb;
  --ui-muted:#94a3b8;
  --ui-focus:#60a5fa;
  --ui-ring:0 0 0 3px rgba(96,165,250,.35);
}

/* ====== Modal ====== */
.modal-overlay{
  background:rgba(15,23,42,.55);       /* backdrop mais escuro e opaco */
}
body:not(.theme-dark) .modal-overlay{
  background:rgba(2,6,23,.35);
}
.modal-box{
  background:var(--ui-surface-0);
  color:var(--ui-text);
  border:1px solid var(--ui-border-strong);
  border-radius:14px;
  box-shadow:0 20px 60px rgba(0,0,0,.35), 0 4px 16px rgba(0,0,0,.18);
  overflow:hidden;
}
.modal-header, .modal-footer{
  background:var(--ui-surface-2);
  border-color:var(--ui-border);
}
.modal-header{
  border-bottom:1px solid var(--ui-border);
}
.modal-footer{
  border-top:1px solid var(--ui-border);
}
.modal-body{
  background:var(--ui-surface-0);
  max-height:calc(100vh - 220px);      /* evita cortar conteúdo */
  overflow:auto;
}

/* ====== Campos (inputs / selects / textarea) ====== */
.field label{
  color:var(--ui-muted);
  font-weight:600;
}
.field input,
.field select,
.field textarea{
  width:100%;
  background:var(--ui-surface-1);
  color:var(--ui-text);
  border:1px solid var(--ui-border);
  border-radius:10px;
  padding:.6rem .75rem;
  line-height:1.3;
  transition:border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.field textarea{ min-height:96px; resize:vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus{
  outline:0;
  border-color:var(--ui-focus);
  box-shadow:var(--ui-ring);
  background:var(--ui-surface-0);
}
.field input::placeholder,
.field textarea::placeholder{ color:var(--ui-muted); opacity:.85; }

/* Select com “seta” visível no dark */
.field select{
  appearance:none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'><path d='M6 8l4 4 4-4' stroke='%2394a3b8' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat:no-repeat;
  background-position:right .6rem center;
  padding-right:2rem;
}

/* Sliders e checkboxes mais legíveis */
input[type="range"]{ accent-color:var(--ui-focus); }
input[type="checkbox"]{ accent-color:var(--ui-focus); }

/* Botão ícone visível nos dois temas */
.btn-icon{
  background:transparent;
  border:1px solid var(--ui-border);
  color:var(--ui-text);
  border-radius:8px;
}
.btn-icon:hover{ background:var(--ui-surface-1); }

/* ====== Histórico de Reprogramações (no modal info) ====== */
.hist-list{ display:grid; gap:10px; }
.hist-item{
  background:var(--ui-surface-1);
  border:1px solid var(--ui-border);
  border-radius:10px;
  padding:10px 12px;
  color:var(--ui-text);
}
.hist-item .hist-meta{ color:var(--ui-muted); font-size:.9em; }

/* ====== Tabela da mini-prévia e tabelas no dark ====== */
.table,
.table thead th,
.table td{
  border-color:var(--ui-border) !important;
}
.table thead th{
  background:var(--ui-surface-2);
  color:var(--ui-muted);
  font-weight:700;
}
.table tbody tr{
  background:var(--ui-surface-0);
}
.table-zebra .table tbody tr:nth-child(odd){
  background:var(--ui-surface-1);
}

/* Aumenta legibilidade de “muted” em dark em lugares críticos */
.theme-dark .muted{ color:var(--ui-muted); }

/* ====== Cor do foco dos botões principais ====== */
.btn-primary:focus,
.btn-success:focus,
.btn-danger:focus,
.btn:focus{
  outline:0;
  box-shadow:var(--ui-ring);
}

/* Melhor contraste dos toasts no dark */
.toast{
  background:var(--ui-surface-1);
  border:1px solid var(--ui-border);
  color:var(--ui-text);
}

/* ========= Botões fortes e texto branco (inclui modal de confirmação) ========= */

/* === OVERRIDES FINAIS (mantenha só isto no fim do arquivo) === */

/* Variantes e texto branco */
:root { --btn-primary:#2563eb; --btn-success:#16a34a; --btn-danger:#dc2626; }
body.theme-dark { --btn-primary:#3b82f6; --btn-success:#22c55e; --btn-danger:#ef4444; }

.btn-primary, .btn-success, .btn-danger { color:#fff !important; }
.btn-primary{ background:var(--btn-primary); }
.btn-success{ background:var(--btn-success); }
.btn-danger { background:var(--btn-danger); }
.btn-primary:hover, .btn-success:hover, .btn-danger:hover{ filter:brightness(.95); }

/* Dark: botões base mais escuros */
.theme-dark .btn,
.theme-dark .btn-icon,
.theme-dark .btn-square{
  background:#2b3442;
  border:1px solid #3b4657;
  color:#e7eef5;
}
.theme-dark .btn:hover,
.theme-dark .btn-icon:hover,
.theme-dark .btn-square:hover{ background:#364151; }

/* Modal Atrasos: legibilidade */
#modalAtrasos .modal-box{ font-weight:400; }
#modalAtrasos .modal-header h2{ font-weight:600; }
.theme-dark #modalAtrasos .row-late  { background:#3a1f24; }
.theme-dark #modalAtrasos .row-today { background:#3a321f; }
.theme-dark #modalAtrasos .row-future{ background:transparent; }

/* Campos mais visíveis no dark */
.theme-dark input[type="text"],
.theme-dark input[type="number"],
.theme-dark input[type="date"],
.theme-dark select,
.theme-dark textarea{
  background:#1f2733;
  border:1px solid #334155;
  color:#e2e8f0;
}
.theme-dark input::placeholder,
.theme-dark textarea::placeholder{ color:#9aa7b5; }
.theme-dark input:focus,
.theme-dark select:focus,
.theme-dark textarea:focus{
  outline:0;
  border-color:#4f46e5;
  box-shadow:0 0 0 3px rgba(79,70,229,.35);
}

/* Modal Confirmar: garanta texto branco */
#modalConfirm .btn-success,
#modalConfirm .btn-danger{ color:#fff !important; }

/* Empilhamento dos modais */
#modalAtrasos{ z-index:1010; }
#modalInfo   { z-index:1020; }
#modalConfirm{ z-index:1030; }

/* === Estilos para sistema de login === */
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  margin-right: 16px;
}

.user-name {
  color: #4a5568;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 12px;
  background: #f7fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.btn-logout {
  background: #fed7d7 !important;
  color: #c53030 !important;
  border: 1px solid #feb2b2 !important;
  font-size: 14px !important;
  padding: 8px 12px !important;
}

.btn-logout:hover {
  background: #fbb6ce !important;
  border-color: #f687b3 !important;
  transform: translateY(-1px);
}

/* Responsividade para user-info */
@media (max-width: 768px) {
  .user-info {
    flex-direction: column;
    gap: 8px;
    margin-right: 8px;
  }
  
  .user-name {
    font-size: 12px;
    padding: 6px 8px;
  }
  
  .btn-logout {
    font-size: 12px !important;
    padding: 6px 8px !important;
  }
}

@media (max-width: 480px) {
  .user-info .user-name {
    display: none; /* Ocultar nome em telas muito pequenas */
  }
}

/* === THEME COLORS (fallbacks) =================================== */
:root{
  --c-bg:#f6f8fa;           /* fundo da página */
  --c-surface:#ffffff;      /* cartões, modais, tabelas */
  --c-text:#0f172a;         /* texto principal */
  --c-muted:#64748b;        /* textos secundários */
  --c-border:#e5e7eb;       /* linhas e bordas */
  --c-primary:#1f883d;      /* botões primários */
  --c-primary-contrast:#ffffff;
  --c-success:#16a34a;
  --c-warn:#d97706;
  --c-danger:#dc2626;
}

/* aplica nas principais áreas (não remove seu estilo atual, só colore) */
body{ background:var(--c-bg); color:var(--c-text); }
.card,.modal-box,.table-wrap,.config-table{
  background:var(--c-surface);
  border-color:var(--c-border);
}
.table thead th{ border-color:var(--c-border); color:var(--c-muted); }
.table tbody td{ border-color:var(--c-border); }
.btn{ border-color:var(--c-border); color:var(--c-text); background:var(--c-surface); }
.btn:hover{ background:rgba(0,0,0,.04); }
.btn-primary,.btn-success{ color:var(--c-primary-contrast); background:var(--c-primary); border-color:var(--c-primary); }
.btn-primary:hover,.btn-success:hover{ filter:brightness(.95); }
.btn-warn{ background:var(--c-warn); color:#fff; border-color:var(--c-warn); }
.btn-warn:hover{ filter:brightness(.95); }
.btn-danger{ background:var(--c-danger); color:#fff; border-color:var(--c-danger); }
.btn-danger:hover{ filter:brightness(.95); }

/* tema escuro automático que você já usa (opcional reforço) */
.theme-dark{
  --c-bg:#0b1220;
  --c-surface:#0f172a;
  --c-text:#e5e7eb;
  --c-muted:#94a3b8;
  --c-border:#1f2937;
  --c-primary:#22c55e;
  --c-primary-contrast:#081016;
  --c-success:#22c55e;
  --c-warn:#f59e0b;
  --c-danger:#ef4444;
}

/* --- Kanban --- */
.kanban-board {
    display: grid;
    grid-auto-flow: column;                /* empilha colunas na horizontal */
    grid-auto-columns: minmax(260px, 1fr); /* largura mínima de cada coluna */
    gap: 12px;
    align-items: start;
    overflow-x: auto;                      /* scroll horizontal quando precisar */
    padding-bottom: 6px;                   /* evita sobrepor com a barra de rolagem */
  }
  /* opcional: estiliza a barra de rolagem horizontal (WebKit) */
  .kanban-board::-webkit-scrollbar { height: 10px; }
  .kanban-board::-webkit-scrollbar-thumb {
    background: var(--c-border, #e5e7eb);
    border-radius: 8px;
  }
.kanban-col {
  background: var(--c-surface, #fff);
  border: 1px solid var(--c-border, #e5e7eb);
  border-radius: 10px;
  padding: 8px;
  min-height: 420px;
  display: grid;
  grid-template-rows: auto 1fr;
}
.kanban-header {
  font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 8px;
}
.kanban-list {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 360px;
}
.kanban-list.is-over { outline: 2px dashed var(--c-primary, #1f883d); outline-offset: 4px; }

.kanban-card {
  background: var(--c-bg, #f6f8fa);
  border: 1px solid var(--c-border, #e5e7eb);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 6px;
  cursor: grab;
}
.kanban-card.dragging { opacity: .6; }
.kc-title { font-weight: 600; line-height: 1.25; }
.kc-meta { font-size: .9em; color: var(--c-muted, #64748b); display:flex; gap:8px; flex-wrap:wrap; }
.kc-actions { display:flex; gap:6px; }

.badge { border-radius: 999px; padding: 2px 8px; border: 1px solid var(--c-border,#e5e7eb); }
.badge.date { }
.badge.prio-urgente { background:#fee2e2; }
.badge.prio-alta { background:#ffedd5; }
.badge.prio-media { background:#f1f5f9; }
.badge.prio-baixa { background:#f8fafc; }

/* Neutraliza zebra mesmo que a classe seja aplicada */
body.table-zebra .table tbody tr:nth-child(odd),
.table-zebra .table tbody tr:nth-child(odd) {
  background: var(--c-surface, #fff) !important;
}

/* célula que tem ponto */
#rt_calendar_grid .rt-has-dot { position: relative; }

#rt_calendar_grid .rt-dot {
  position: absolute;
  bottom: 6px; left: 50%;
  transform: translateX(-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: #1677ff; /* azul */
}
