:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --primary: #0b2a4a;
  --primary-700: #08203a;
  --accent: #1e40af;
  --ok: #1f7a4c;
  --ok-bg: #e8f4ed;
  --warn: #a16207;
  --warn-bg: #fcf5e3;
  --err: #b42318;
  --err-bg: #fbeae9;
  --rev: #475569;
  --rev-bg: #eef1f5;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --radius: 10px;
  --radius-lg: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 9px;
  border: 2px solid rgba(255,255,255,.9); border-radius: 4px;
}
.brand-org { font-size: 12px; letter-spacing: .06em; color: var(--text-soft); text-transform: uppercase; font-weight: 600; }
.brand-title { font-size: 17px; font-weight: 700; color: var(--text); margin-top: 1px; }
.brand-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.topbar-right { display: flex; align-items: center; gap: 18px; }
.updated-at { font-size: 12px; color: var(--text-muted); }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-idle { background: #cbd5e1; }
.dot-ok { background: #1f7a4c; box-shadow: 0 0 0 3px rgba(31,122,76,.15); }
.dot-err { background: #b42318; box-shadow: 0 0 0 3px rgba(180,35,24,.15); }
.dot-loading { background: #b45309; box-shadow: 0 0 0 3px rgba(180,83,9,.15); }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  padding: 8px 14px; border-radius: 8px; font-weight: 500; font-size: 13px;
  color: var(--text); transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-700); }
.btn-ghost { background: var(--surface-2); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface); }

/* Toggle */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle-track {
  width: 36px; height: 20px; border-radius: 999px; background: #d1d5db;
  position: relative; transition: background .15s;
}
.toggle-thumb {
  position: absolute; left: 2px; top: 2px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: transform .15s; box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle-label { font-size: 12px; color: var(--text-muted); }

/* Dev banner */
.dev-banner {
  background: #fef3c7; color: #92400e; padding: 10px 32px;
  font-size: 12.5px; border-bottom: 1px solid #fcd34d;
  font-weight: 500;
}

/* Layout */
.layout { max-width: 1440px; margin: 0 auto; padding: 28px 32px 64px; }
.section { margin-bottom: 36px; }
.section-head { margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.section-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }

/* Cards */
.cards-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
  min-height: 102px;
}
.card-title { font-size: 12px; color: var(--text-soft); font-weight: 500; letter-spacing: .02em; }
.card-value { font-size: 22px; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
.card-value.money { font-variant-numeric: tabular-nums; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: auto; }
.card.tone-ok .card-value { color: var(--ok); }
.card.tone-err .card-value { color: var(--err); }
.card.tone-warn .card-value { color: var(--warn); }

/* Filtros */
.filters {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.filter { display: flex; flex-direction: column; gap: 6px; }
.filter label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.filter select, .filter input {
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; background: var(--surface); color: var(--text);
  width: 100%;
}
.filter select:focus, .filter input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* CFO */
.cfo-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.cfo-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow-sm); min-height: 220px;
}
.cfo-card h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.cfo-card p { margin: 0 0 14px; line-height: 1.6; color: var(--text); font-size: 14px; }
.cfo-card ul { margin: 6px 0 14px 18px; padding: 0; }
.cfo-card li { margin: 4px 0; color: var(--text-muted); font-size: 13.5px; }
.cfo-actions { display: flex; flex-direction: column; gap: 10px; }
.cfo-actions .btn { width: 100%; text-align: left; padding: 12px 14px; }

/* Mapa atenção */
.attention-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.attention {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; position: relative; overflow: hidden;
}
.attention::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.attention.tone-ok::before { background: var(--ok); }
.attention.tone-err::before { background: var(--err); }
.attention.tone-warn::before { background: var(--warn); }
.attention.tone-rev::before { background: var(--rev); }
.attention h4 { margin: 0; font-size: 13px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.attention .att-count { font-size: 26px; font-weight: 700; margin-top: 6px; }
.attention .att-pct { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.attention ul { margin: 0; padding-left: 18px; }
.attention li { font-size: 12.5px; color: var(--text-muted); margin: 2px 0; }

/* Charts */
.charts-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(2, 1fr);
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.chart-card h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text); }
.chart-card-wide { grid-column: span 2; }
.chart-wrap { position: relative; height: 260px; }

/* Tabela */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.table-toolbar input[type="search"] {
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 12px;
  font-size: 13px; min-width: 320px; background: var(--surface);
}
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; max-width: 100%;
}
.table-exec { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table-exec thead th {
  position: sticky; top: 0; background: var(--surface-2);
  text-align: left; padding: 11px 12px; font-weight: 600; color: var(--text-soft);
  border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none;
}
.table-exec thead th.sort-asc::after { content: " ↑"; color: var(--text-muted); }
.table-exec thead th.sort-desc::after { content: " ↓"; color: var(--text-muted); }
.table-exec tbody td {
  padding: 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle; white-space: nowrap;
}
.table-exec tbody tr:hover { background: var(--surface-2); }
.table-exec td.num { font-variant-numeric: tabular-nums; text-align: right; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: .01em;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.rev { background: var(--rev-bg); color: var(--rev); }

.table-pager { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.table-pager button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px; padding: 4px 10px; font-size: 12px; }
.table-pager button[disabled] { opacity: .4; cursor: not-allowed; }
.row-action { background: none; border: 1px solid var(--border-strong); padding: 4px 10px; border-radius: 6px; font-size: 11.5px; color: var(--text); }
.row-action:hover { background: var(--surface-2); }

/* Pendências */
.pendencias { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.pend-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; border-left: 3px solid var(--rev);
}
.pend-card.divergente { border-left-color: var(--err); }
.pend-card.pendente { border-left-color: var(--warn); }
.pend-card.revisar { border-left-color: var(--rev); }
.pend-card h4 { margin: 0 0 4px; font-size: 13px; }
.pend-card .meta { font-size: 11.5px; color: var(--text-soft); margin-bottom: 6px; }
.pend-card .action { font-size: 12.5px; color: var(--text-muted); }

/* Saúde */
.saude-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.saude-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.saude-card h5 { margin: 0; font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.saude-card .v { font-size: 18px; font-weight: 700; margin-top: 6px; }
.saude-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Details Drawer */
.details-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  z-index: 100; backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.details-overlay.open { opacity: 1; pointer-events: auto; }

.details-drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: min(560px, 100%); background: var(--surface);
  z-index: 101; display: flex; flex-direction: column;
  box-shadow: -10px 0 30px rgba(0,0,0,.15);
  transform: translateX(100%); transition: transform .2s ease;
}
.details-drawer.open { transform: translateX(0); }

.details-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.details-header h3 { margin: 0; font-size: 15px; font-weight: 700; }
.details-close {
  background: none; border: none; font-size: 22px; color: var(--text-muted);
  line-height: 1; padding: 0 6px; cursor: pointer;
}
.details-close:hover { color: var(--text); }
.details-content {
  padding: 18px 22px; overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0;
}

/* Shared content classes used inside drawer */
.modal-block { margin-top: 10px; padding-top: 6px; }
.modal-block:first-of-type { margin-top: 0; }
.modal-resumo { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 12px 14px; margin-top: 10px; color: var(--text); font-size: 13px; line-height: 1.55; }
.modal-empty { color: var(--text-soft); }
.modal-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px 12px; margin-top: 6px; }
.modal-grid-3 .cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.modal-grid-3 .cell .k { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .03em; }
.modal-grid-3 .cell .v { font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.modal-row { display: grid; grid-template-columns: 180px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.modal-row .k { color: var(--text-soft); }
.modal-row .v { color: var(--text); font-variant-numeric: tabular-nums; }
.modal-section-title { margin: 18px 0 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-soft); font-weight: 600; }
.details-content details { margin-top: 14px; }
.details-content details summary { cursor: pointer; font-size: 12px; color: var(--text-muted); }
.details-content pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 11.5px; max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow-md); z-index: 200;
}

/* Footer */
.footer {
  margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-soft); display: flex; gap: 8px; align-items: center;
}
.dot-sep { opacity: .5; }

/* Responsivo */
@media (max-width: 1080px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card-wide { grid-column: span 1; }
  .attention-grid { grid-template-columns: repeat(2, 1fr); }
  .cfo-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; padding: 14px 18px; }
  .topbar-right { width: 100%; flex-wrap: wrap; gap: 12px; }
  .layout { padding: 18px; }
  .attention-grid { grid-template-columns: 1fr; }
  .details-drawer { width: 100%; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar input[type="search"] { min-width: 0; width: 100%; }
}
