:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #14213d;
  --muted: #667085;
  --line: #d9e1ec;
  --blue: #1455d9;
  --green: #168a5b;
  --yellow: #b7791f;
  --red: #c24141;
  --shadow: 0 14px 40px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#app {
  width: min(100%, 1600px);
  margin: 0 auto;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.loading-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef4ff 0%, #f9fbfd 52%, #edf8f2 100%);
}

.loading-panel {
  display: grid;
  justify-items: center;
  gap: 18px;
}

.loading-logo {
  width: 180px;
  height: auto;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #dbe7fb;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef4ff 0%, #f9fbfd 48%, #edf8f2 100%);
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

h3 {
  margin-bottom: 6px;
  font-size: 15px;
}

.muted {
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 85, 217, 0.12);
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 9px 14px;
  font-weight: 800;
}

.primary-btn {
  background: var(--blue);
  color: #fff;
}

.secondary-btn {
  background: #fff;
  color: var(--blue);
  border-color: #b7c8ee;
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.icon-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff5f5;
  color: #dc2626;
}

.icon-close-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-close-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

.message {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--red);
  font-weight: 700;
}

.dashboard {
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  background: rgba(245, 247, 251, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  display: block;
  flex: 0 0 auto;
  width: 165px;
  height: auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.refresh-status {
  min-width: 0;
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-badge {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  display: grid;
  gap: 18px;
  padding: 22px 28px 40px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

.kpi {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
  min-height: 96px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 18px rgba(16, 24, 40, 0.04);
}

.kpi-icon {
  display: grid;
  width: 48px;
  min-height: 100%;
  place-items: center;
  align-self: stretch;
  color: var(--blue);
  background: #eaf2ff;
  border: 1px solid #c9daf8;
  border-radius: 8px;
}

.kpi-icon svg {
  width: 22px;
  height: 22px;
}

.kpi-body {
  display: grid;
  align-content: center;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 27px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(480px, 0.85fr);
  gap: 18px;
  align-items: stretch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 18px rgba(16, 24, 40, 0.04);
  padding: 18px;
}

.content-grid > .panel {
  min-height: 760px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin-bottom: 4px;
}

.map-subtitle {
  max-width: 360px;
  margin-bottom: 0;
  font-size: 14px;
  line-height: 1.35;
}

.map-metric-select {
  width: min(230px, 42%);
  min-width: 180px;
  flex: 0 0 auto;
}

.brazil-map {
  position: relative;
  min-height: 420px;
}

.map-panel {
  display: flex;
  flex-direction: column;
}

.map-panel .brazil-map {
  flex: 1;
}

.map-canvas {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(180deg, #f3f7ff 0%, #e8f1ff 100%);
  border-radius: 8px;
}

.brazil-map svg {
  width: 100%;
  height: auto;
  min-height: 0;
  display: block;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.map-canvas.map-loaded svg {
  opacity: 1;
  transform: translateY(0);
}

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  min-height: 420px;
  color: #174ea6;
  font-size: 13px;
  font-weight: 800;
  background:
    radial-gradient(circle at 50% 38%, rgba(20, 85, 217, 0.12), transparent 30%),
    linear-gradient(180deg, #f7fbff 0%, #e7f1ff 100%);
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.map-canvas.map-loaded .map-loading {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.map-spinner {
  width: 34px;
  height: 34px;
  border: 4px solid rgba(20, 85, 217, 0.16);
  border-top-color: #1455d9;
  border-radius: 50%;
  animation: spin 0.78s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.brazil-map image {
  opacity: 0.9;
}

.map-bubbles {
  filter: drop-shadow(0 8px 16px rgba(20, 85, 217, 0.18));
}

.uf-node {
  cursor: pointer;
  transition: transform 0.15s ease;
  transform-box: fill-box;
  transform-origin: center;
}

.uf-node:hover {
  transform: translateY(-2px);
}

.uf-node.selected {
  transform: scale(1.04);
}

.map-tooltip {
  position: absolute;
  z-index: 3;
  display: grid;
  min-width: 220px;
  gap: 5px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #b7c8ee;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform: translate(-50%, calc(-100% - 16px));
}

.map-tooltip::after {
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 1px solid #b7c8ee;
  border-bottom: 1px solid #b7c8ee;
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

.map-tooltip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tooltip-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 18px;
  line-height: 1;
}

.tooltip-action {
  position: relative;
  z-index: 2;
  margin-top: 6px;
  min-height: 32px;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.map-source {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.tier-bars {
  display: grid;
  gap: 18px;
}

.tier-panel {
  padding: 22px;
  border-color: #cbd8ea;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.06);
}

.tier-panel .panel-head {
  margin-bottom: 18px;
}

.tier-panel .muted {
  font-size: 14px;
  line-height: 1.4;
  font-weight: 400;
}

.tier-donut-wrap {
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(240px, 1.15fr);
  gap: 22px;
  align-items: center;
}

.tier-donut {
  position: relative;
  width: min(210px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(20, 85, 217, 0.08), 0 12px 24px rgba(16, 24, 40, 0.08);
}

.tier-donut::after {
  position: absolute;
  inset: 44px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
}

.tier-donut-center {
  position: absolute;
  inset: 54px;
  z-index: 1;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}

.tier-donut-center span,
.tier-donut-center small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.tier-donut-center strong {
  color: var(--ink);
  font-size: 34px;
  font-weight: 600;
  line-height: 1;
}

.tier-legend {
  display: grid;
  gap: 0;
}

.tier-legend-row {
  display: grid;
  grid-template-columns: 10px 70px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
}

.tier-legend-row:last-child {
  border-bottom: 0;
}

.tier-legend-row strong {
  font-size: 18px;
  font-weight: 600;
}

.tier-tone-green strong,
.tier-tone-green .tier-percent,
.tier-tone-green .tier-courses svg,
.tier-tone-green .rule-icon {
  color: var(--green);
}

.tier-tone-amber strong,
.tier-tone-amber .tier-percent,
.tier-tone-amber .tier-courses svg,
.tier-tone-amber .rule-icon {
  color: var(--yellow);
}

.tier-tone-slate strong,
.tier-tone-slate .tier-percent,
.tier-tone-slate .tier-courses svg,
.tier-tone-slate .rule-icon {
  color: #52657f;
}

.tier-orgs {
  color: var(--ink);
  font-weight: 600;
}

.tier-percent {
  font-size: 15px;
  font-weight: 600;
}

.tier-legend-row span:last-child {
  grid-column: 3 / -1;
  font-size: 13px;
}

.tier-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(16, 24, 40, 0.14);
}

.tier-courses {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.tier-courses svg {
  width: 16px;
  height: 16px;
}

.tier-score-rules {
  display: grid;
  gap: 14px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.tier-score-rules h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.tier-thresholds,
.score-weights {
  display: grid;
  gap: 10px;
}

.tier-thresholds {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tier-threshold-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #dbe7fb;
  border-radius: 8px;
  box-shadow: 0 6px 14px rgba(16, 24, 40, 0.03);
}

.tier-threshold-card div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.score-weight-card {
  display: grid;
  grid-template-columns: 40px 62px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #dbe7fb;
  border-radius: 8px;
  box-shadow: 0 6px 14px rgba(16, 24, 40, 0.03);
}

.rule-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--green);
  background: #e8f7ef;
  border-radius: 9px;
}

.tier-tone-amber .rule-icon {
  background: #fff4d8;
}

.tier-tone-slate .rule-icon {
  background: #eef2f7;
}

.rule-icon svg {
  width: 20px;
  height: 20px;
}

.tier-thresholds strong,
.score-weights strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.tier-thresholds span,
.score-weights span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.25;
}

.score-weight-card .rule-icon {
  color: var(--green);
  background: #e8f7ef;
}

.score-weight-card strong {
  color: var(--green);
  font-size: 17px;
  font-weight: 600;
}

.tier-row {
  display: grid;
  gap: 7px;
}

.tier-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  background: #edf1f7;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(150px, 0.6fr));
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.org-name {
  max-width: 420px;
  font-weight: 800;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
}

.crm-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 9px;
  color: #123466;
  background: #eaf2ff;
  border: 1px solid #c9daf8;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.crm-status-prospecting {
  color: #7a4a00;
  background: #fff4d8;
  border-color: #f0d28a;
}

.crm-status-in_treatment {
  color: #1d4ed8;
  background: #eaf2ff;
  border-color: #bfd3ff;
}

.crm-status-contacted,
.crm-status-converted,
.crm-status-qualified {
  color: #0d6848;
  background: #e8f7ef;
  border-color: #bce6ce;
}

.crm-status-discarded {
  color: #8a1f1f;
  background: #fff0f0;
  border-color: #f0caca;
}

.crm-contact {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.tier-a {
  background: var(--green);
}

.tier-b {
  background: var(--yellow);
}

.tier-c {
  background: #65758b;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
}

#pageInfo {
  font-size: 13px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: flex-end;
  background: rgba(15, 23, 42, 0.35);
}

.drawer-content {
  width: min(720px, 100%);
  height: 100%;
  overflow: auto;
  background: #fff;
  padding: 22px;
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.crm-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.crm-form label:last-of-type {
  grid-column: 1 / -1;
}

.course-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.course-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.course-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.course-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.course-meta-item svg {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  color: #8a99ad;
  stroke-width: 2;
}

@media (max-width: 1180px) {
  .kpi-grid,
  .content-grid,
  .filters {
    grid-template-columns: 1fr;
  }

  .content-grid > .panel {
    min-height: 0;
  }

  .tier-donut-wrap,
  .tier-thresholds {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-brand {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .refresh-status {
    max-width: 100%;
  }

  .map-metric-select {
    width: min(260px, 48%);
  }
}

@media (max-width: 640px) {
  main,
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .auth-panel {
    padding: 22px;
  }

  .topbar-brand {
    gap: 12px;
  }

  .brand-logo {
    width: 135px;
  }

  .detail-grid,
  .crm-form {
    grid-template-columns: 1fr;
  }

  .tier-panel {
    padding: 20px;
  }

  .map-metric-select {
    width: 100%;
    min-width: 0;
  }

  .tier-legend-row {
    grid-template-columns: 10px 70px minmax(0, 1fr) auto;
  }

  .score-weight-card {
    grid-template-columns: 40px minmax(58px, auto);
  }

  .score-weight-card span:last-child {
    grid-column: 2 / -1;
  }
}
