:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #8b97a6;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --green: #2ea043;
  --red: #f85149;
  --amber: #d29922;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Sidebar ── */
.sidebar {
  width: 256px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px 22px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8957e5);
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; background: none; border: none; color: var(--text-dim);
  padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
  transition: .15s; font-family: inherit;
}
.nav-item:hover { background: var(--bg-elev2); color: var(--text); }
.nav-item.active { background: var(--accent-2); color: #fff; font-weight: 600; }
.user-section {
  background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin-bottom: 16px;
  font-size: 11px; color: var(--text-dim);
}
.user-header { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.user-name { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.user-email { font-size: 10px; color: var(--text-dim); margin-bottom: 8px; word-break: break-all; }
.user-filial-label { font-weight: 500; color: var(--text-dim); margin-top: 8px; margin-bottom: 2px; }
.user-filial { font-size: 10px; color: var(--text); }

.sidebar-foot {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  color: var(--text-dim); padding: 10px 8px 0; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.btn-logout {
  background: none; border: none; color: var(--red); cursor: pointer;
  font-size: 12px; padding: 4px 6px; margin-left: auto; transition: .15s;
}
.btn-logout:hover { color: var(--red); opacity: 0.8; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); }
.dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.off { background: var(--red); }

/* ── Content ── */
.content { flex: 1; padding: 32px 40px; max-width: 1100px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to {opacity:1;transform:none;} }

.page-head { margin-bottom: 24px; position: relative; }
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { color: var(--text-dim); margin-top: 4px; }
.head-actions { position: absolute; right: 0; top: 4px; display: flex; gap: 8px; }

/* ── Panels & cards ── */
.panel {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.panel h2 { font-size: 15px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card .k { font-size: 12px; color: var(--text-dim); }
.card .v { font-size: 22px; font-weight: 700; margin-top: 6px; }
.card .sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.card.missing { opacity: .55; }

/* ── Buttons ── */
.btn {
  background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
  font-family: inherit; transition: .15s; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-primary:hover { background: var(--accent); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(248,81,73,.12); }

/* ── Pipeline steps ── */
.step {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 16px;
}
.step-info { flex: 1; }
.step-info .t { font-weight: 600; }
.step-info .d { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.step-meta { font-size: 11px; color: var(--text-dim); text-align: right; min-width: 90px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border);
}
.badge.idle { color: var(--text-dim); }
.badge.running { color: var(--amber); border-color: var(--amber); }
.badge.success { color: var(--green); border-color: var(--green); }
.badge.failed { color: var(--red); border-color: var(--red); }

/* ── Log ── */
.logbox-head { display: flex; justify-content: space-between; align-items: center; }
.log {
  background: #0a0d11; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; font-family: "Cascadia Code", Consolas, monospace; font-size: 12px;
  color: #c9d1d9; height: 340px; overflow-y: auto; white-space: pre-wrap;
  margin-top: 12px; line-height: 1.5;
}
.mini-list .mini-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.mini-list .mini-row:last-child { border: none; }

/* ── Progress ── */
.progress-wrap { display: flex; align-items: center; gap: 14px; margin: 16px 0; }
.progress-bar { flex: 1; height: 12px; background: var(--bg-elev2); border-radius: 8px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg,var(--accent),#8957e5); transition: width .4s; }
.progress-label { font-weight: 700; min-width: 50px; }
.enricher-top { display: flex; justify-content: space-between; align-items: center; }
.enricher-status { display: flex; gap: 12px; align-items: center; }
.enricher-status #enr-last { font-size: 12px; color: var(--text-dim); }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); }
label.full { margin-top: 14px; }
input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 7px; font-size: 13px; font-family: inherit;
}
input:focus { outline: none; border-color: var(--accent); }
.form-actions { display: flex; align-items: center; gap: 14px; }
.test-result { font-size: 13px; }
.test-result.ok { color: var(--green); }
.test-result.err { color: var(--red); }

.hint { font-size: 12px; color: var(--text-dim); margin: 4px 0 12px; }
.switch-row { flex-direction: row; align-items: center; gap: 9px; color: var(--text); font-size: 13px; cursor: pointer; }
.switch-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.checks { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 6px; }

/* ── Maps ── */
.map-frame { width: 100%; height: calc(100vh - 200px); min-height: 560px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* Mapas & Dashboards: mapa preenche todo o espaço vazio (largura total + altura restante) */
.content:has(#view-mapas.active) { max-width: none; display: flex; flex-direction: column; }
#view-mapas.active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#view-mapas .panel:has(.map-frame) { flex: 1; display: flex; padding: 0; border: none; background: none; min-height: 0; }
#view-mapas .map-frame { flex: 1; width: 100%; height: auto; min-height: 400px; }

/* modo "só mapa": esconde título e cards, deixando apenas o mapa */
#view-mapas.map-only .page-head,
#view-mapas.map-only .cards { display: none; }
.card.map-card { cursor: pointer; }
.card.map-card:hover { border-color: var(--accent); }

/* ── Assistente IA ── */
.ia-quick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ia-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 7px; font-size: 13px; font-family: inherit;
}
.ia-status { font-size: 12px; color: var(--text-dim); margin-left: auto; }
.chat-panel { display: flex; flex-direction: column; height: 560px; padding: 0; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 82%; padding: 12px 16px; border-radius: 14px; font-size: 13.5px;
  line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.chat-msg.assistant .chat-bubble { background: var(--bg-elev2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg.user .chat-bubble { background: var(--accent-2); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble table { border-collapse: collapse; margin: 8px 0; font-size: 12px; width: 100%; }
.chat-bubble th, .chat-bubble td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.chat-bubble th { background: var(--bg); }
.chat-bubble code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.chat-input-row {
  display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.chat-input-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 11px 14px; border-radius: 9px; font-size: 14px; font-family: inherit;
}
.chat-input-row input:focus { outline: none; border-color: var(--accent); }
.chat-typing { display: inline-block; }
.chat-typing span {
  display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
  background: var(--text-dim); animation: blink 1.2s infinite both;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--bg-elev2);
  border: 1px solid var(--border); padding: 13px 18px; border-radius: 10px;
  opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* ── Dashboard one-page ── */
.content:has(#view-dashboard.active) { max-width: none; }
.dash-filters { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px; }
.dash-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.dash-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi-card { background: linear-gradient(160deg, #171f2b, #12171f); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; }
.kpi-v { font-size: 24px; font-weight: 700; color: #fff; line-height: 1.1; }
.kpi-l { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; margin-top: 6px; }
.dash-src { font-size: 10px; color: #7b90ad; border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; font-weight: 400; vertical-align: middle; margin-left: 4px; }
.dash-empty { color: var(--text-dim); font-size: 12px; padding: 10px 0; }
.dash-hero h2 { margin-bottom: 10px; }

/* ── Métricas: barras horizontais ── */
.m-bars { display: flex; flex-direction: column; gap: 7px; }
.m-bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.m-bar-lbl { width: 130px; flex: none; color: var(--text-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.m-bar-track { flex: 1; height: 14px; background: var(--bg-elev2); border-radius: 7px; overflow: hidden; }
.m-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: 7px; min-width: 2px; }
.m-bar-val { width: 150px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
.m-bar-sub { color: var(--text-dim); font-size: 11px; }
