@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Literata:wght@600;700&display=swap");

/* ── Shared site navigation ─────────────────────────── */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-family: "Manrope", sans-serif;
}
.site-nav__back {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}
.site-nav__back:hover { text-decoration: underline; }
.site-nav__links {
  display: flex;
  gap: 4px;
}
.site-nav__link {
  text-decoration: none;
  color: var(--text-muted, #5b6b7f);
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.site-nav__link:hover {
  background: var(--surface-soft, #f9fbfe);
  color: var(--text);
}
.site-nav__link--active {
  background: var(--accent, #0d6efd);
  color: #fff !important;
  font-weight: 600;
}
.site-nav__link--active:hover {
  background: var(--accent, #0d6efd);
  opacity: 0.9;
}

:root {
  --bg: #f4f7fb;
  --bg2: #eef3f9;
  --surface: #ffffff;
  --surface-soft: #f9fbfe;
  --text: #1b2430;
  --title: #2f465f;
  --muted: #5b6b7f;
  --line: #dde6f0;
  --line-strong: #cfdbea;
  --brand: #0d6efd;
  --brand-2: #00a3a3;
  --danger: #d83a52;
  --ok: #128266;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(15, 32, 56, 0.08);
  --font-body: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  --font-title: "Literata", "Georgia", serif;
}

/* ── Dark Mode ─────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0f1419;
  --bg2: #131a22;
  --surface: #1a2332;
  --surface-soft: #1e2a3a;
  --text: #d8e2ef;
  --title: #b0c8e8;
  --muted: #7a91aa;
  --line: #263346;
  --line-strong: #2f4060;
  --brand: #4d9aff;
  --brand-2: #22c5c5;
  --danger: #f06070;
  --ok: #30c4a0;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] html,
[data-theme="dark"] body,
html[data-theme="dark"],
body[data-theme="dark"],
[data-theme="dark"] {
  background:
    radial-gradient(1400px 450px at 0% -12%, rgba(77, 154, 255, 0.08), transparent 60%),
    radial-gradient(900px 500px at 95% -10%, rgba(34, 197, 197, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg2), var(--bg));
}

[data-theme="dark"] .topbar {
  background: rgba(26, 35, 50, 0.92);
  border-bottom-color: var(--line);
}

[data-theme="dark"] .table thead th {
  background: #1e2a3a;
}

[data-theme="dark"] .table thead th:first-child {
  background: #1a2538;
}

[data-theme="dark"] .table tbody td:first-child {
  background: #1c2736;
}

[data-theme="dark"] .table tbody tr:hover td {
  background: #22334a;
}

[data-theme="dark"] .btn {
  background: #1e3258;
  color: #8bb8f0;
  border-color: var(--line-strong);
}

[data-theme="dark"] .btn:hover {
  background: #253d66;
  border-color: #4a6fa0;
}

[data-theme="dark"] .btn--ghost {
  background: var(--surface);
  color: #a0bfe0;
}

[data-theme="dark"] .select-hint {
  color: #8ba4c0;
  background: linear-gradient(180deg, #17202e 0%, #1a2536 100%);
}

[data-theme="dark"] .select-hint strong {
  color: #b0c8e8;
}

[data-theme="dark"] .chart-label {
  background: rgba(26, 35, 50, 0.9);
  border-color: var(--line);
}

[data-theme="dark"] .chart-label:hover {
  background: rgba(30, 42, 58, 0.96);
}

[data-theme="dark"] .chart-label__fallback {
  color: #8bb8f0;
}

[data-theme="dark"] .chart-hidden-count {
  background: rgba(26, 35, 50, 0.92);
}

[data-theme="dark"] .checklist__item:hover {
  background: rgba(77, 154, 255, 0.1);
}

[data-theme="dark"] .panel__title {
  color: #7a91aa;
}

/* ── Base Reset ────────────────────────────────────── */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1400px 450px at 0% -12%, rgba(13, 110, 253, 0.12), transparent 60%),
    radial-gradient(900px 500px at 95% -10%, rgba(0, 163, 163, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg2), var(--bg));
}

/* ── Topbar ────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(6px);
}

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

.topbar__logo {
  display: flex;
  align-items: center;
  margin-right: 10px;
}

.topbar__logo img {
  height: 36px;
  width: auto;
  display: block;
}

.topbar__title {
  font-size: 18px;
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--title);
  letter-spacing: 0.01em;
}

.topbar__subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.topbar__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.meta {
  font-size: 12px;
  color: var(--muted);
}

.meta__actions {
  display: flex;
  gap: 8px;
}

/* ── Layout ────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

/* ── Panel ─────────────────────────────────────────── */
.panel {
  position: sticky;
  top: 72px;
  height: calc(100vh - 90px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel__section {
  padding: 14px;
}

.panel__title {
  font-size: 12px;
  font-family: var(--font-title);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5f748a;
  font-weight: 700;
  margin-bottom: 12px;
}

/* ── Fields ────────────────────────────────────────── */
.field {
  margin-bottom: 14px;
}

.field__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.field__head--compact {
  margin-bottom: 8px;
}

.field__actions {
  display: flex;
  gap: 6px;
}

.field__label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field__label--inline {
  margin-bottom: 0;
}

.field__control {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  padding: 9px 10px;
  font-size: 13px;
}

.uf-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.uf-control .field__control {
  flex: 1;
}
.uf-control__flag {
  flex-shrink: 0;
}
.uf-control__flag img {
  width: 36px;
  height: 25px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(23, 43, 68, 0.18);
  display: block;
}

.field__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field__sep {
  font-size: 12px;
  color: var(--muted);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── Checklist ─────────────────────────────────────── */
.checklist {
  max-height: 150px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px;
  background: var(--surface-soft);
}

.checklist--cand {
  max-height: 220px;
}

.checklist__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
}

.checklist__item:hover {
  background: rgba(13, 110, 253, 0.08);
}

.checklist__item input {
  margin: 0;
}

.checklist__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.checklist__tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ok);
  border: 1px solid rgba(18, 130, 102, 0.28);
  border-radius: 999px;
  padding: 1px 6px;
}

/* ── Toggle ────────────────────────────────────────── */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  min-height: 38px;
}

.toggle input {
  accent-color: var(--brand);
}

.toggle--inline {
  min-height: 0;
  font-size: 11px;
}

/* ── Field Accordion ───────────────────────────────── */
.field--accordion {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--surface-soft);
}

.field--accordion .field__head {
  margin-bottom: 6px;
}

.field__summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  margin-bottom: 8px;
}

.field__summary::-webkit-details-marker {
  display: none;
}

.field__summary::after {
  content: "\25B8";
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  transition: transform 0.14s ease;
}

.field--accordion[open] .field__summary::after {
  transform: rotate(90deg);
}

.field__summary-meta {
  font-size: 11px;
  color: var(--muted);
}

/* ── Panel Stats ───────────────────────────────────── */
.panel__stats {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

/* ── Content / Cards ───────────────────────────────── */
.content {
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card__head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.card__title {
  font-size: 14px;
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--title);
}

.card__caption {
  font-size: 12px;
  color: var(--muted);
}

.card__head--chart {
  align-items: flex-start;
}

/* ── Chart Controls ────────────────────────────────── */
.chart-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-control .field__label {
  margin-bottom: 4px;
}

.chart-control {
  width: 210px;
}

.chart-control select {
  width: 100%;
}

.select-hint {
  padding: 8px 14px;
  font-size: 11px;
  color: #50657d;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f7fbff 0%, #f2f8ff 100%);
}

.select-hint strong {
  color: #354f6a;
}

/* ── Insights ──────────────────────────────────────── */
.insights {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.insight-chip {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  border-radius: 999px;
  padding: 6px 10px;
}

/* ── Chart Shell / Labels ──────────────────────────── */
.chart-shell {
  position: relative;
  height: 540px;
}

.chart {
  height: 100%;
  position: relative;
  z-index: 1;
}

.chart-connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.chart-labels {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 156px;
  pointer-events: none;
  z-index: 3;
}

.chart-label {
  position: absolute;
  right: 3px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 152px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(3px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px 3px 4px;
  box-shadow: 0 4px 10px rgba(17, 36, 62, 0.08);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  pointer-events: auto;
}

.chart-label:hover {
  transform: translateY(-50%) translateX(-2px) scale(1.06);
  box-shadow: 0 10px 16px rgba(17, 36, 62, 0.16);
  background: rgba(255, 255, 255, 0.96);
}

.chart-label--dense {
  gap: 6px;
  max-width: 148px;
  padding: 2px 6px 2px 3px;
}

.chart-label__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 4px rgba(13, 25, 44, 0.25);
  flex: 0 0 auto;
  background: #d7e6fa;
  transition: transform 0.14s ease;
}

.chart-label--dense .chart-label__avatar {
  width: 27px;
  height: 27px;
}

.chart-label:hover .chart-label__avatar {
  transform: scale(1.08);
}

.chart-label__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
  transform: translateZ(0);
  filter: none;
}

.chart-label__fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #234774;
  text-transform: uppercase;
}

.chart-label__text {
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-label--dense .chart-label__text {
  font-size: 11px;
}

.chart-hidden-count {
  position: absolute;
  right: 6px;
  bottom: 34px;
  z-index: 4;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--muted);
}

/* ── Card Footer ───────────────────────────────────── */
.card__footer {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
}

/* ── Table ─────────────────────────────────────────── */
.table__tools {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 10px;
}

.table__wrap {
  max-height: 560px;
  overflow: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f3f8ff;
  border-bottom: 1px solid var(--line-strong);
  padding: 9px 8px;
  text-align: center;
  min-width: 90px;
  white-space: nowrap;
}

.table thead th:first-child {
  left: 0;
  z-index: 7;
  text-align: left;
  min-width: 220px;
  background: #edf4fe;
}

.table tbody td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: center;
}

.table tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  text-align: left;
  background: #f9fbff;
  border-right: 1px solid var(--line);
}

.table tbody tr:hover td {
  background: #eef5ff;
}

.cand-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cand-name {
  font-weight: 700;
}

.cand-meta {
  font-size: 11px;
  color: var(--muted);
}

.poll-head {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
}

.poll-inst {
  font-size: 11px;
  font-weight: 700;
}

.poll-date {
  font-size: 11px;
  color: var(--muted);
}

/* ── Heatmap Cells ─────────────────────────────────── */
.heatmap-cell {
  padding: 6px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s ease;
}

.heatmap-cell--high {
  background: rgba(18, 130, 102, 0.14);
  color: #0a6b4f;
}

.heatmap-cell--mid {
  background: rgba(230, 180, 30, 0.16);
  color: #7a6100;
}

.heatmap-cell--low {
  background: rgba(216, 58, 82, 0.14);
  color: #a82040;
}

[data-theme="dark"] .heatmap-cell--high {
  background: rgba(48, 196, 160, 0.18);
  color: #5ee8c0;
}

[data-theme="dark"] .heatmap-cell--mid {
  background: rgba(240, 200, 60, 0.16);
  color: #e8d06a;
}

[data-theme="dark"] .heatmap-cell--low {
  background: rgba(240, 96, 112, 0.18);
  color: #f08898;
}

/* ── Map Section ───────────────────────────────────── */
.card--map {
  padding: 14px;
}

.card--map .card__head {
  padding: 0 0 12px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.map-shell {
  display: flex;
  gap: 16px;
  min-height: 320px;
}

.brasil-map {
  flex: 1;
  min-height: 300px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.map-legend {
  width: 200px;
  font-size: 12px;
  color: var(--text);
  flex-shrink: 0;
}

.map-legend__title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.map-legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.map-legend__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.map-legend__label {
  font-size: 12px;
  line-height: 1.3;
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #e9f2ff;
  color: #174b9a;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
}

.btn:hover {
  border-color: #a7c6ef;
  background: #dcebff;
}

.btn--ghost {
  background: #ffffff;
  color: #2e4d75;
}

.btn--tiny {
  padding: 5px 8px;
  font-size: 11px;
}

.btn--block {
  width: 100%;
}

.btn--icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn--icon:hover {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--brand);
}

.btn--icon svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn--export {
  background: #e9f2ff;
  color: #174b9a;
  font-weight: 600;
}

.btn--export:hover {
  background: #dcebff;
  border-color: #a7c6ef;
}

[data-theme="dark"] .btn--icon {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--line-strong);
}

[data-theme="dark"] .btn--icon:hover {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--brand);
}

[data-theme="dark"] .btn--export {
  background: #1e3258;
  color: #8bb8f0;
}

[data-theme="dark"] .btn--export:hover {
  background: #253d66;
  border-color: #4a6fa0;
}

/* ── Footer ────────────────────────────────────────── */
.footer {
  padding: 12px 18px 18px;
  font-size: 12px;
  color: var(--muted);
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel {
    position: relative;
    top: auto;
    height: auto;
  }

  .chart {
    height: 100%;
  }

  .chart-shell {
    height: 480px;
  }

  .chart-controls {
    width: 100%;
  }

  .chart-control {
    width: 100%;
  }

  .chart-labels {
    width: 136px;
  }

  .chart-label {
    max-width: 128px;
  }

  .map-shell {
    flex-direction: column;
  }

  .map-legend {
    width: 100%;
  }
}
