:root {
  color-scheme: dark;
  --bg: #070b14;
  --surface: #0f172a;
  --surface-2: #162036;
  --surface-3: #1e293b;
  --border: #26344d;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --gold: #eab308;
  --gold-soft: rgba(234, 179, 8, 0.14);
  --blue: #38bdf8;
  --blue-soft: rgba(56, 189, 248, 0.14);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --scrollbar-thumb: #475569;
  --scrollbar-track: #0f172a;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
}

@supports not (scrollbar-color: auto) {
  :root,
  .scroller {
    scrollbar-width: auto;
  }
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 6px;
  }
  ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #0f1f3d 0%, var(--bg) 52%);
  color: var(--text);
  min-height: 100vh;
}

code,
.mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(7, 11, 20, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #0f172a);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-title {
  font-size: 1.08rem;
  font-weight: 700;
}

.brand-sub {
  color: var(--gold);
  font-weight: 600;
  font-size: 0.9rem;
  margin-left: 6px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.pill-muted { background: var(--surface-2); color: var(--text-muted); }
.pill-info { background: var(--blue-soft); color: var(--blue); border-color: rgba(56, 189, 248, 0.35); }
.pill-ok { background: var(--green-soft); color: var(--green); border-color: rgba(52, 211, 153, 0.35); }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }
.pill-danger { background: var(--red-soft); color: var(--red); border-color: rgba(248, 113, 113, 0.35); }

.topbar-actions,
.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-primary { background: #1d4ed8; border-color: #3b82f6; color: #fff; }
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger { background: rgba(220, 38, 38, 0.2); border-color: var(--red); color: var(--red); }

.tabs-bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.tab-count {
  background: var(--red);
  color: #070b14;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.72rem;
  margin-left: 5px;
  font-weight: 800;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 18px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

input,
select,
textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.86rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.kpi-label { font-size: 0.8rem; color: var(--text-muted); }
.kpi-value { font-size: 1.7rem; font-weight: 800; margin-top: 6px; font-family: "JetBrains Mono", monospace; }
.text-warn { color: var(--warn); }
.text-info { color: var(--blue); }
.text-danger { color: var(--red); }
.text-ok { color: var(--green); }
.muted { color: var(--text-muted); font-size: 0.84rem; }

.split-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
}

@media (max-width: 980px) {
  .split-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

h2 { margin: 0; font-size: 1rem; font-weight: 700; }
h3 { margin: 0 0 8px; font-size: 0.92rem; }

.epf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 12px;
}

.epf-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.epf-card.ausente {
  opacity: 0.72;
  border-style: dashed;
}

.epf-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.epf-name { font-weight: 700; font-size: 0.95rem; }
.epf-login { font-size: 0.76rem; color: var(--text-muted); font-family: "JetBrains Mono", monospace; }
.epf-badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; }
.epf-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  font-size: 0.78rem;
}

.score-num {
  font-family: "JetBrains Mono", monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}

.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; }
.bar-row-head { display: flex; justify-content: space-between; }
.bar-track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #2563eb, #38bdf8); border-radius: 999px; }

.handoffs-box { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.handoffs-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow: auto; }
.handoff-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

.filters-grid {
  display: grid;
  grid-template-columns: 2fr repeat(4, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 960px) {
  .filters-grid { grid-template-columns: 1fr 1fr; }
}

/* TABELA RESPONSIVA COM STICKY HEADER & CONTAINER QUERIES */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(620px, 72vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: 10px;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
}

.table-wrapper table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.83rem;
}

.table-wrapper caption {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface-2);
}

.table-wrapper thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-2);
}

.table-wrapper th,
.table-wrapper td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table-wrapper tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface);
  font-weight: 600;
  z-index: 1;
}

.table-historico table {
  --label-2: "Caso";
  --label-3: "Prioridade";
  --label-4: "Categoria / Regra";
  --label-5: "Destino";
  --label-6: "Pontos";
  --label-7: "Posse / Handoff";
  --label-8: "Status";
  --label-9: "Ações";
}

.table-regras table {
  --label-2: "Prioridade";
  --label-3: "Código / Nome";
  --label-4: "Destino";
  --label-5: "Flags";
  --label-6: "Ações";
}

@container (width < 680px) {
  .table-wrapper table,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper tr,
  .table-wrapper th,
  .table-wrapper td {
    display: block;
  }
  .table-wrapper thead {
    display: none;
  }
  .table-wrapper tr {
    margin-block-end: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
  }
  .table-wrapper tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--surface-2);
  }
  .table-wrapper td:nth-child(2)::before { content: var(--label-2) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(3)::before { content: var(--label-3) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(4)::before { content: var(--label-4) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(5)::before { content: var(--label-5) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(6)::before { content: var(--label-6) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(7)::before { content: var(--label-7) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(8)::before { content: var(--label-8) ": "; color: var(--text-muted); font-weight: 600; }
  .table-wrapper td:nth-child(9)::before { content: var(--label-9) ": "; color: var(--text-muted); font-weight: 600; }
}

/* ADMIN FORMS */
.admin-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}

.stack-form { display: flex; flex-direction: column; gap: 10px; }
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.form-row-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 14px; }
.checkbox-row label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.subbox { border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.subbox legend { font-size: 0.8rem; color: var(--gold); padding: 0 6px; }

.servidores-grid,
.review-list,
.audit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.review-item,
.servidor-row,
.audit-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

/* DIALOGS NATIVOS (TOP LAYER & SCROLL CONTAINMENT) */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  max-width: min(720px, 94vw);
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(2, 6, 23, 0.74);
  backdrop-filter: blur(4px);
}

.dialog-header,
.dialog-footer {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.dialog-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
  gap: 10px;
}

.dialog-body {
  padding: 18px;
  max-height: 70vh;
  overflow: auto;
}

.btn-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
}
