:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-2: #1d2540;
  --border: #2a3350;
  --text: #e7ebf5;
  --text-dim: #9aa5c0;
  --accent: #5b8def;
  --accent-2: #7c5bef;
  --good: #35c46f;
  --warn: #e6b23a;
  --bad: #e6534a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
  gap: 12px;
}
.topbar-title h1 { margin: 0; font-size: 20px; }
.subtitle { color: var(--text-dim); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.loaded-range { color: var(--text-dim); font-size: 13px; margin-right: 6px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #08101f; font-weight: 600; }
.btn-ai { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border: none; color: white; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: 12px; }

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.filter-group { position: relative; }
.filter-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
}
.filter-btn.active { border-color: var(--accent); color: var(--accent); }
.filter-dropdown {
  position: absolute;
  top: 34px;
  left: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  width: 240px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.filter-dropdown input[type="text"] {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.filter-option { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 0; }
.filter-actions { display: flex; justify-content: space-between; margin-top: 8px; }

.btn-clear-all {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 20px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
}

main { padding: 20px 24px 60px; max-width: 1700px; margin: 0 auto; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0; /* deixa o filho encolher em vez de estourar a grade */
}
.kpi .label { color: var(--text-dim); font-size: 12px; margin-bottom: 6px; }
.kpi .value {
  font-size: clamp(15px, 1.1vw + 11px, 20px);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi .sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.kpi.warn .value { color: var(--warn); }
.kpi.bad .value { color: var(--bad); }
.kpi.good .value { color: var(--good); }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.chart-card.span-2, .table-section .card, .analysis-panel .card { grid-column: span 2; }
.card-title { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; font-weight: 600; }
.card-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-title-row .card-title { margin-bottom: 0; }

.hint { font-size: 11px; color: var(--text-dim); margin-top: 6px; }

.table-section { margin-bottom: 20px; }
.table-section .card-title-row input[type="text"] {
  padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 13px; width: 260px;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); cursor: pointer; position: sticky; top: 0; background: var(--panel); }
tr:hover td { background: rgba(255,255,255,0.02); }
td.num, th.num { text-align: right; }
.tag { padding: 2px 7px; border-radius: 10px; font-size: 11px; }
.tag.yes { background: rgba(53,196,111,0.15); color: var(--good); }
.tag.no { background: rgba(230,83,74,0.15); color: var(--bad); }
.atraso-ok { color: var(--good); }
.atraso-warn { color: var(--warn); }
.atraso-bad { color: var(--bad); }

.table-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--text-dim); font-size: 12px; }
.pager { display: flex; align-items: center; gap: 8px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: 680px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-body label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 4px; margin-top: 12px; }
.modal-body input[type="month"], .modal-body input[type="date"] {
  padding: 9px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px; width: 100%;
  color-scheme: dark; /* faz o calendário nativo (Chromium) usar tema escuro, não branco */
}
.modal-lead { font-size: 13.5px; line-height: 1.5; color: var(--text); margin: 0 0 4px; }
.date-range-row { display: flex; gap: 14px; margin-top: 8px; }
.date-field { flex: 1; }
.date-field label { margin-top: 0; }
.modal-footer-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border);
}
.timeline-bar-context { height: 26px; }
.timeline-dates { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-top: 10px; }
.month-status-list { margin-top: 12px; max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.month-status-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.month-status-row:last-child { border-bottom: none; }
.month-status-row .badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.badge.loaded { background: rgba(53,196,111,0.15); color: var(--good); }
.badge.missing { background: rgba(230,178,58,0.15); color: var(--warn); }
.overwrite-choice { display: flex; gap: 10px; align-items: center; font-size: 12px; }
textarea.prompt-box {
  width: 100%; min-height: 160px; margin-top: 10px; padding: 10px;
  background: var(--bg); color: var(--good); border: 1px solid var(--border); border-radius: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
}

.analysis-panel { grid-column: 1 / -1; margin-bottom: 20px; }
.analysis-panel.hidden { display: none; }
.finding { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.finding .fh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.finding .ft { font-weight: 700; }
.finding .fs { font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.fs.alta { background: rgba(230,83,74,0.15); color: var(--bad); }
.fs.media { background: rgba(230,178,58,0.15); color: var(--warn); }
.fs.baixa { background: rgba(53,196,111,0.15); color: var(--good); }
.finding .fd { font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.finding .fr { font-size: 13px; }
.finding .fe { font-size: 12px; color: var(--text-dim); font-style: italic; margin-top: 4px; }

.hint-inline { cursor: help; font-size: 12px; opacity: 0.8; }
.modal.modal-wide { width: 1040px; max-height: none; }
.modal.modal-wide .modal-body { max-height: none; overflow: visible; }
.chart-expand-canvas-wrap {
  width: 100%; height: 460px; /* ~19 barras visíveis por vez */
  overflow-y: scroll; overflow-x: hidden;
  border: 1px solid var(--border); border-radius: 8px;
}
#chartExpandCanvasInner { position: relative; width: 100%; }
#chartExpandCanvas { width: 100% !important; }

.heatmap-wrap { overflow-x: auto; }
table.heatmap-table { border-collapse: collapse; font-size: 11px; width: 100%; }
table.heatmap-table th, table.heatmap-table td { padding: 6px 8px; text-align: center; white-space: nowrap; }
table.heatmap-table th { color: var(--text-dim); font-weight: 500; }
th.hm-rowlabel { text-align: left; color: var(--text); max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
td.hm-cell { cursor: pointer; color: #fff; border: 1px solid var(--bg); }
td.hm-cell:hover { outline: 2px solid var(--accent); }

.vpn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  background: #4a2a12; color: #ffd9a8; border-bottom: 1px solid #7a4a1a;
  padding: 9px 20px; font-size: 13px; text-align: center; font-weight: 600;
}
body:has(#vpnBanner:not(.hidden)) .auth-gate,
body:has(#vpnBanner:not(.hidden)) .topbar { padding-top: 38px; }

.auth-gate {
  position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.auth-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.auth-card h1 { font-size: 22px; margin: 0 0 8px; }
.auth-card label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-dim); display: block; margin: 14px 0 6px; }
.auth-card input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; box-sizing: border-box;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-submit { width: 100%; margin-top: 16px; padding: 10px; font-size: 14px; }
.auth-link { width: 100%; margin-top: 8px; font-size: 12px; }
.auth-error { margin-top: 12px; font-size: 13px; color: var(--bad); background: rgba(230,83,74,0.1); border: 1px solid rgba(230,83,74,0.3); border-radius: 8px; padding: 8px 10px; }
.auth-success { margin-top: 12px; font-size: 13px; color: var(--good); background: rgba(53,196,111,0.1); border: 1px solid rgba(53,196,111,0.3); border-radius: 8px; padding: 8px 10px; }

.progress-track { width: 100%; height: 10px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin: 10px 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }
.progress-label { font-size: 12px; color: var(--text-dim); }

.timeline-bar { display: flex; width: 100%; height: 22px; border-radius: 6px; overflow: hidden; margin: 12px 0 8px; border: 1px solid var(--border); }
.timeline-seg { height: 100%; }
.timeline-seg + .timeline-seg { border-left: 1px solid var(--bg); }
.timeline-detail { list-style: none; margin: 0; padding: 0; font-size: 12.5px; color: var(--text-dim); }
.timeline-detail li { padding: 3px 0; display: flex; align-items: center; gap: 6px; }
.timeline-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.settings-section { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.settings-section h3 { margin: 0 0 6px; font-size: 14px; }
.settings-section .hint { margin-bottom: 10px; }
.btn-danger { background: rgba(230,83,74,0.15); border-color: rgba(230,83,74,0.4); color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }

.hidden { display: none !important; }

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.span-2 { grid-column: span 1; }
}
