.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 500;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  line-height: 1.4;
}

.btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-xs);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.cd {
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: var(--sp-3);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}

.badge-success {
  background: var(--success-soft);
  color: var(--flash-success-text);
}

[data-theme="dark"] .badge-success {
  color: var(--success);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--flash-error-text);
}

[data-theme="dark"] .badge-danger {
  color: var(--danger);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--flash-warning-text);
}

[data-theme="dark"] .badge-warning {
  color: var(--warning);
}

.badge-info {
  background: var(--info-soft);
  color: var(--flash-info-text);
}

[data-theme="dark"] .badge-info {
  color: var(--info);
}

.badge-pendente {
  background: var(--warning-soft);
  color: var(--flash-warning-text);
}

[data-theme="dark"] .badge-pendente {
  color: var(--warning);
}

.badge-aprovado {
  background: var(--success-soft);
  color: var(--flash-success-text);
}

[data-theme="dark"] .badge-aprovado {
  color: var(--success);
}

.badge-rejeitado {
  background: var(--danger-soft);
  color: var(--flash-error-text);
}

[data-theme="dark"] .badge-rejeitado {
  color: var(--danger);
}

.badge-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
}

.aj-bar {
  --fu-h: 38px;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: flex-end;
  margin-bottom: var(--sp-4);
}

.aj-bar .btn {
  height: var(--fu-h);
  box-sizing: border-box;
}

.aj-bar .g {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.aj-lbl {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
}

.aj-presets {
  display: flex;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: var(--fu-h);
}

.aj-presets button {
  padding: 0 var(--sp-3);
  border: none;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background .15s, color .15s;
  height: var(--fu-h);
  box-sizing: border-box;
}

.aj-presets button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.aj-presets button.on {
  background: var(--accent);
  color: #fff;
}

.campo {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.campo label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}

.campo input,
.campo select,
.campo textarea {
  width: 100%;
  box-sizing: border-box;
  height: 40px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
}

.campo textarea {
  height: auto;
  min-height: 80px;
  padding: var(--sp-2) var(--sp-3);
}

.campo input:focus,
.campo select:focus,
.campo textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.cv-sw {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.cv-sw input {
  display: none;
}

.cv-sw label {
  width: 42px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: background .2s;
}

.cv-sw label::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s;
}

.cv-sw input:checked + label {
  background: #16a34a;
}

.cv-sw input:checked + label::after {
  transform: translateX(18px);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  z-index: 9999;
}

.loading-overlay .spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.loading-overlay .loading-texto {
  color: #fff;
  font-size: var(--fs-base);
  font-weight: 500;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-icone {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1.1rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icone:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-icone.perigo:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

span.btn-icone.desabilitado {
  opacity: .30;
  cursor: not-allowed;
}

span.btn-icone.desabilitado:hover {
  background: transparent;
  color: var(--text-dim);
}

.tabela {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.tabela th {
  text-align: left;
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 2px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.tabela td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tabela tbody tr:hover {
  background: var(--bg-elev);
}

.modal-fundo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-conteudo {
  background: var(--surface);
  border-radius: var(--radius);
  width: 90vw;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--sombra-media);
}

.modal-header {
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: var(--sp-2) var(--sp-4);
}

.modal-footer {
  padding: var(--sp-2) var(--sp-4) var(--sp-4);
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
}

.alerta {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: var(--sp-3);
}

.alerta-success { background: var(--flash-success-bg); color: var(--flash-success-text); border: 1px solid var(--flash-success-border); }
.alerta-error { background: var(--flash-error-bg); color: var(--flash-error-text); border: 1px solid var(--flash-error-border); }
.alerta-warning { background: var(--flash-warning-bg); color: var(--flash-warning-text); border: 1px solid var(--flash-warning-border); }
.alerta-info { background: var(--flash-info-bg); color: var(--flash-info-text); border: 1px solid var(--flash-info-border); }

/* ======================== */
/* SelectBusca              */
/* ======================== */

.selectbusca { position: relative; min-width: 200px; }

.selectbusca .sb-display {
  height: 40px;
  box-sizing: border-box;
  padding: 0 var(--sp-3);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--text);
  transition: border-color .15s;
}

.selectbusca .sb-display:hover { border-color: var(--accent); }

.selectbusca .sb-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selectbusca .sb-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
  display: none;
}

.selectbusca.open .sb-panel { display: block; }

.selectbusca .sb-search {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  box-sizing: border-box;
  background: var(--bg-elev);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.selectbusca .sb-search:focus { border-bottom-color: var(--accent); }

.selectbusca .sb-opt {
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  font-size: 14px;
}

.selectbusca .sb-opt:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ======================== */
/* Modal (vault pattern)    */
/* ======================== */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-bg.visivel { display: flex; }

.modal-caixa {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSobe .2s ease;
}

.modal-caixa.modal-sm { width: 34vw; max-height: 80vh; }
.modal-caixa.modal-md { width: 55vw; max-height: 70vh; }
.modal-caixa.modal-lg { width: 89vw; max-height: 90vh; }

.modal-caixa:not(.modal-sm):not(.modal-md):not(.modal-lg):not(.modal-confirm) {
  width: 55vw;
  max-height: 70vh;
}

@media (max-width: 1280px) {
  .modal-caixa.modal-md,
  .modal-caixa:not(.modal-sm):not(.modal-md):not(.modal-lg):not(.modal-confirm) { width: 68vw; }
}

@media (max-width: 880px) {
  .modal-caixa.modal-sm,
  .modal-caixa.modal-md,
  .modal-caixa.modal-lg,
  .modal-caixa:not(.modal-sm):not(.modal-md):not(.modal-lg):not(.modal-confirm) {
    width: 96vw;
    max-height: 92vh;
  }
}

@keyframes modalSobe {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-cab {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-cab h3 { font-size: 17px; margin: 0; font-weight: 700; }

.modal-x {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  color: var(--text-muted);
  display: grid;
  place-items: center;
}

.modal-x:hover { color: var(--text); }

.modal-corpo {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.modal-rodape {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
}

/* Confirm variant */
.modal-caixa.modal-confirm { text-align: center; }

.confirm-corpo { padding: 32px 28px 12px; }
.confirm-corpo h3 { font-size: 18px; margin-bottom: var(--sp-2); }
.confirm-corpo p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

.confirm-icone {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
}

.confirm-icone i { font-size: 36px; }
.confirm-icone.confirm-perigo { background: var(--danger-soft); color: var(--danger); }
.modal-caixa.modal-confirm .modal-rodape { justify-content: center; }

/* ======================== */
/* Popup centrado (dialog)  */
/* ======================== */

dialog.popup-centrado {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: visible !important;
  box-shadow: var(--shadow-lg);
  animation: modalSobe .2s ease;
  width: 34vw;
  min-width: 320px;
  color: var(--text);
}

dialog.popup-centrado::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

/* ======================== */
/* Tabela: cabecalho + menu */
/* ======================== */

.tabela-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
}

.tabela-titulo { display: flex; align-items: center; gap: var(--sp-2); }
.tabela-titulo h3 { margin: 0; font-size: 15px; font-weight: 700; }
.tabela-contagem { font-size: var(--fs-xs); color: var(--text-dim); }

.ta-menu-wrapper { position: relative; }

.ta-menu-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-dim);
}

.ta-menu-btn:hover { border-color: var(--accent); color: var(--accent); }
.ta-menu-btn i { font-size: 18px; }

.ta-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 50;
}

.ta-menu.aberto { display: block; }

.ta-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

.ta-menu-item:hover { background: var(--bg); color: var(--accent); }
.ta-menu-item i { font-size: 16px; color: var(--text-dim); }
.ta-menu-item:hover i { color: var(--accent); }
.ta-menu-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ======================== */
/* Tabela: filtro + sort    */
/* ======================== */

.filtro-row td { padding: var(--sp-1) var(--sp-3); }

.filtro-input {
  width: 100%;
  padding: var(--sp-1) var(--sp-2);
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 12px;
}

.filtro-input:focus { border-color: var(--accent); outline: none; }

.tabela th.sortable { cursor: pointer; user-select: none; }
.tabela th.sortable:hover { color: var(--accent); }
.tabela th.sort-asc::after { content: ' \25B2'; font-size: 10px; }
.tabela th.sort-desc::after { content: ' \25BC'; font-size: 10px; }

/* ======================== */
/* Coluna de acoes          */
/* ======================== */

.celula-acoes {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

/* ======================== */
/* Estado vazio             */
/* ======================== */

.estado-vazio {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-dim);
}

.estado-vazio p { margin-top: var(--sp-3); font-size: var(--fs-sm); }

/* ======================== */
/* Dashboard: KPIs          */
/* ======================== */

.db-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
@media (max-width: 1300px) { .db-kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px)  { .db-kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; } }

.db-kpi {
  background: var(--surface);
  border: none;
  border-radius: 12px;
  padding: 14px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
}

.db-kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border);
}

.db-kpi-accent::before { background: linear-gradient(90deg, var(--accent), var(--accent-hover)); }
.db-kpi-info::before   { background: linear-gradient(90deg, var(--info), var(--info-dark)); }
.db-kpi-pos::before    { background: linear-gradient(90deg, var(--success), var(--success-dark)); }
.db-kpi-neg::before    { background: linear-gradient(90deg, var(--danger), var(--danger-dark)); }
.db-kpi-warning::before { background: linear-gradient(90deg, var(--warning), var(--warning-dark)); }

.db-kpi-ico {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}

.db-kpi-accent .db-kpi-ico  { background: var(--accent-soft); color: var(--accent); }
.db-kpi-info .db-kpi-ico    { background: var(--info-soft); color: var(--info); }
.db-kpi-pos .db-kpi-ico     { background: var(--success-soft); color: var(--success-text); }
.db-kpi-neg .db-kpi-ico     { background: var(--danger-soft); color: var(--danger-text); }
.db-kpi-warning .db-kpi-ico { background: var(--warning-soft); color: var(--warning-text); }

.db-kpi-corpo { min-width: 0; flex: 1; display: flex; flex-direction: column; }

.db-kpi-lbl {
  font-size: 10.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 700;
  line-height: 1.2;
  min-height: 25px;
  display: flex;
  align-items: flex-end;
}

.db-kpi-val {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

.db-kpi-disc {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.2;
  font-style: italic;
  min-height: 14px;
}

.db-kpi-pos { background: var(--flash-success-bg); border-color: var(--flash-success-border); }
.db-kpi-pos .db-kpi-lbl,
.db-kpi-pos .db-kpi-val { color: var(--flash-success-text); }

.db-kpi-neg { background: var(--flash-error-bg); border-color: var(--flash-error-border); }
.db-kpi-neg .db-kpi-lbl,
.db-kpi-neg .db-kpi-val { color: var(--flash-error-text); }

@media (max-width: 720px) {
  .db-kpi { padding: 12px 11px; gap: 9px; }
  .db-kpi-ico { width: 36px; height: 36px; font-size: 18px; border-radius: 9px; }
  .db-kpi-lbl { font-size: 9.5px; min-height: 23px; }
  .db-kpi-val { font-size: 18px; }
  .db-kpi-disc { font-size: 10px; min-height: 13px; }
}

/* ======================== */
/* Dashboard: filtros       */
/* ======================== */

.db-bar {
  --fu-h: 38px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}

.db-bar .g { display: flex; flex-direction: column; gap: 4px; }

.db-lbl {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
}

.db-bar input[type="date"],
.db-bar .btn {
  height: var(--fu-h);
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  background: var(--bg-elev);
  color: var(--text);
}

.db-presets {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  height: var(--fu-h);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.db-presets button {
  height: calc(var(--fu-h) - 8px);
  border: 1px solid transparent;
  background: var(--surface);
  border-radius: 5px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.db-presets button:hover { color: var(--accent); }
.db-presets button.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.db-bar .selectbusca { min-width: 180px; }
.db-bar .selectbusca .sb-display { height: var(--fu-h); }

@media (max-width: 720px) {
  .db-bar .g { flex: 1 1 100%; }
  .db-presets { flex-wrap: wrap; height: auto; }
}

/* ======================== */
/* Dashboard: tabs          */
/* ======================== */

.db-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.db-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
}

.db-tab:hover { color: var(--text); }

.db-tab.ativo {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.db-pane { display: none; }
.db-pane.ativo { display: block; }

/* ======================== */
/* Dashboard: alertas rows  */
/* ======================== */

.alerta-row-vencido { background: var(--flash-error-bg); }
.alerta-row-vencido td { color: var(--flash-error-text); font-weight: 600; }

.alerta-row-critico { background: var(--flash-warning-bg); }

.alerta-row-alto { background: var(--warning-subtle); }

.db-alerta-legenda {
  margin-top: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
