:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-soft: #eef2f7;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;
  --primary: #0b6cff;
  --border: #dbe2ea;
  --success: #0f9d58;
  --danger: #d93025;
  --bg-gradient-start: #dbeafe;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --shadow-card: 0 10px 25px rgba(15, 23, 42, 0.06);
  --shadow-soft: 0 8px 18px rgba(15, 23, 42, 0.15);
}

html[data-theme='dark'] {
  --bg: #020617;
  --surface: #0f172a;
  --surface-muted: #111c32;
  --surface-soft: #1e293b;
  --text: #e2e8f0;
  --text-soft: #cbd5e1;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --border: #334155;
  --success: #22c55e;
  --danger: #ef4444;
  --bg-gradient-start: #0f172a;
  --topbar-bg: rgba(2, 6, 23, 0.92);
  --shadow-card: 0 12px 28px rgba(2, 6, 23, 0.55);
  --shadow-soft: 0 10px 24px rgba(2, 6, 23, 0.42);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  background: radial-gradient(circle at 10% 0%, var(--bg-gradient-start) 0, var(--bg) 40%);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  min-width: 0;
}

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

.brand img { width: 120px; height: auto; }

.brand-user-mini,
.menu-user-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  min-width: 0;
  max-width: 220px;
}

.brand-user-mini img,
.menu-user-mini img {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.brand-user-mini-meta,
.menu-user-mini-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-user-mini-meta strong,
.menu-user-mini-meta strong {
  font-size: 0.74rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-user-mini-meta span,
.menu-user-mini-meta span {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.menu-user-mini {
  display: none;
}

.topbar-nav { display: flex; align-items: center; }
.topbar-nav-links { display: flex; align-items: center; gap: 14px; }
.topbar a { color: var(--text); text-decoration: none; font-weight: 500; }
.topbar a[aria-current="page"] { font-weight: 700; color: var(--primary); }

.topbar-menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  width: 42px;
  height: 38px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text);
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Backdrop eliminado: los overlays fixed bloqueaban taps en movil */
.topbar-menu-backdrop {
  display: none !important;
}

/*
  Menu movil en flujo normal (flex-wrap): empuja el contenido,
  sin position:fixed ni capas que intercepten la navegacion.
*/
.topbar.is-collapsed,
.topbar.is-mobile {
  flex-wrap: wrap;
  gap: 10px;
}

.topbar.is-collapsed .topbar-menu-toggle,
.topbar.is-mobile .topbar-menu-toggle {
  display: inline-flex;
}

.topbar.is-collapsed .brand-user-mini,
.topbar.is-mobile .brand-user-mini {
  display: none;
}

.topbar.is-collapsed .topbar-nav,
.topbar.is-mobile .topbar-nav {
  display: none;
  flex: 1 1 100%;
  width: 100%;
  order: 3;
  position: static;
  pointer-events: auto;
}

.topbar.is-collapsed .topbar-nav.is-open,
.topbar.is-mobile .topbar-nav.is-open {
  display: block;
}

.topbar.is-collapsed .topbar-nav-links,
.topbar.is-mobile .topbar-nav-links {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  max-height: none;
  overflow: visible;
}

.topbar.is-collapsed .topbar-nav-links .menu-user-mini,
.topbar.is-mobile .topbar-nav-links .menu-user-mini {
  display: flex;
  width: 100%;
  max-width: none;
  border-radius: 12px;
  padding: 8px 10px;
}

.topbar.is-collapsed .topbar-nav-links a,
.topbar.is-collapsed .topbar-nav-links .btn,
.topbar.is-collapsed .topbar-nav-links .inline-form,
.topbar.is-mobile .topbar-nav-links a,
.topbar.is-mobile .topbar-nav-links .btn,
.topbar.is-mobile .topbar-nav-links .inline-form {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}

.topbar.is-collapsed .topbar-nav-links .inline-form,
.topbar.is-mobile .topbar-nav-links .inline-form {
  display: block;
}

.topbar.is-collapsed .topbar-nav-links .inline-form .btn,
.topbar.is-mobile .topbar-nav-links .inline-form .btn {
  justify-content: flex-start;
  width: 100%;
}

/* CSS puro: en pantallas angostas siempre modo movil (aunque falle el JS) */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar .topbar-menu-toggle {
    display: inline-flex !important;
  }

  .topbar .brand-user-mini {
    display: none !important;
  }

  .topbar .topbar-nav {
    display: none;
    flex: 1 1 100%;
    width: 100%;
    order: 3;
    position: static !important;
  }

  .topbar .topbar-nav.is-open {
    display: block !important;
  }

  .topbar .topbar-nav-links {
    display: flex;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
  }

  .topbar .topbar-nav-links .menu-user-mini {
    display: flex;
    width: 100%;
    max-width: none;
  }

  .topbar .topbar-nav-links a,
  .topbar .topbar-nav-links .btn,
  .topbar .topbar-nav-links .inline-form {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

.container {
  width: min(100%, calc(100% - 32px));
  max-width: 100%;
  margin: 24px auto 40px;
  display: grid;
  gap: 20px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-card);
  max-width: 100%;
  min-width: 0;
}

.narrow { width: min(560px, 100%); margin: 0 auto; }

.reports-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.reports-kpi {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px;
}

.reports-kpi h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.reports-kpi p {
  margin: 8px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}

.reports-heatmap {
  display: grid;
  gap: 8px;
  margin: 10px 0 16px;
}

.reports-map-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
  margin: 10px 0 14px;
}

.reports-map-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0 12px;
}

.reports-map-mode label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-soft);
}

.reports-toolbar {
  margin-top: 12px;
}

.reports-filters-modal-content {
  width: min(720px, 100%);
}

.reports-leaflet-map {
  width: 100%;
  height: min(460px, 50vh);
  background: var(--surface-muted);
}

.reports-map-fallback {
  margin: 0;
  padding: 12px;
  color: #475569;
  font-size: 0.9rem;
}

.reports-map-pin-wrapper {
  background: transparent;
  border: 0;
}

.reports-map-pin {
  --pin-size: 26px;
  --pin-color: #2563eb;
  width: var(--pin-size);
  height: var(--pin-size);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #0f172a;
  background: color-mix(in srgb, var(--pin-color) 28%, #ffffff);
  border: 2px solid var(--pin-color);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.24);
}

#reports-gis-canvas {
  width: 100%;
  height: min(460px, 50vh);
  display: block;
  background: var(--surface-muted);
}

#reports-gis-empty {
  padding: 8px 12px 12px;
}

.heatmap-row {
  display: grid;
  grid-template-columns: minmax(160px, 3fr) minmax(120px, 6fr) auto;
  gap: 8px;
  align-items: center;
}

.heatmap-row-label {
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.heatmap-row-track {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

.heatmap-row-bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #0284c7);
}

.heatmap-row-value {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
}

.leader-cluster-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(280px, 1fr);
  gap: 14px;
  align-items: stretch;
}

.leader-cluster-grid.bottom-row {
  margin-top: 14px;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.leader-cluster-table-wrap {
  max-height: 360px;
  overflow: auto;
}

.reports-chart-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  padding: 12px;
}

.reports-chart-card h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--text);
}

#reports-leader-bar-chart,
#reports-leader-line-chart,
#reports-leader-scatter-chart,
#reports-fc-chart {
  width: 100%;
  max-width: 100%;
  min-height: 220px;
  height: auto;
  display: block;
  border-radius: 10px;
  background: var(--surface-muted);
}

.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.login-brand img {
  width: 120px;
  height: auto;
}

.login-brand span {
  font-weight: 700;
  color: var(--text);
}

.login-forgot {
  margin: -4px 0 0;
  text-align: right;
}

.login-forgot button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary, #1d4ed8);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}

.password-reset-modal-content {
  width: min(440px, 100%);
}

h1, h2, h3 {
  margin-top: 0;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.muted { color: var(--muted); font-size: 0.9rem; }

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

.invite-link-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
}

.form-grid {
  display: grid;
  gap: 14px;
  min-width: 0;
  max-width: 100%;
}
.form-grid.two-col {
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}
.form-grid label {
  display: grid;
  gap: 6px;
  font-weight: 500;
  min-width: 0;
}
input, select, button {
  font: inherit;
}
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
textarea {
  resize: vertical;
  min-height: 120px;
}
.full-width { grid-column: 1 / -1; }

.voter-lookup-actions {
  display: grid;
  gap: 8px;
}

#friend-lookup-feedback.ok {
  color: var(--success);
  font-weight: 600;
}

#friend-lookup-feedback.error {
  color: var(--danger);
  font-weight: 600;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

#candidate-message-modal {
  z-index: 240;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.modal-content {
  position: relative;
  width: min(980px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 16px;
  display: grid;
  gap: 10px;
  animation: genealogy-modal-in 0.22s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.friend-share-modal-content {
  width: min(760px, 100%);
}

.friend-share-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: start;
}

.friend-share-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.friend-share-qr-wrap {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.friend-share-qr {
  width: min(240px, 100%);
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  object-fit: cover;
}

.voter-lookup-modal-actions {
  display: flex;
  justify-content: flex-start;
}

#friend-voter-lookup-iframe {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
}

.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-whatsapp {
  background: #25D366;
  color: #fff;
  border-color: #25D366;
}
.btn-whatsapp:hover,
.btn-whatsapp:focus {
  background: #1ebe57;
  border-color: #1ebe57;
  color: #fff;
}
.btn.ghost {
  background: transparent;
}

.inline-form { display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }

.segment-nav {
  margin-top: 12px;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}

.segment-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.segment-btn.is-active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.role-color-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.role-color-field input[type="color"] {
  width: 48px;
  height: 40px;
  padding: 2px;
  border-radius: 10px;
  cursor: pointer;
}

.role-color-field input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
}

.genealogy-tree {
  margin-top: 16px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-muted) 100%);
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

#genealogy-section,
#coordinator-genealogy-section,
#candidate-genealogy-section {
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
}

.genealogy-p5-host {
  display: flex;
  flex-direction: column;
  min-height: 360px;
  max-height: min(85vh, 900px);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
}

.genealogy-p5-host:fullscreen,
.genealogy-p5-host:-webkit-full-screen,
.genealogy-p5-host.is-fullscreen {
  width: 100%;
  height: 100%;
  max-height: none;
  min-height: 100%;
  border-radius: 0;
}

.genealogy-p5-host:fullscreen .genealogy-p5-canvas,
.genealogy-p5-host:-webkit-full-screen .genealogy-p5-canvas,
.genealogy-p5-host.is-fullscreen .genealogy-p5-canvas {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

.genealogy-p5-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, #93c5fd 12%);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  flex: 0 0 auto;
}

.genealogy-p5-toolbar-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  flex: 1 1 200px;
  max-width: 100%;
}

.genealogy-p5-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  max-width: 100%;
}

.genealogy-p5-status {
  font-size: 0.85rem;
  min-height: 1.2em;
}

.genealogy-p5-status.is-error {
  color: #b91c1c;
}

.genealogy-p5-levels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}

.genealogy-level-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.55;
}

.genealogy-role-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}

.genealogy-role-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
}

.genealogy-p5-canvas {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 280px;
  flex: 1 1 auto;
  overflow: hidden;
  touch-action: pan-y;
  position: relative;
}

.genealogy-p5-canvas canvas {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: none !important;
  cursor: grab;
}

/* Modal detalle genealogía — tarjeta centrada (no fullscreen) */
.genealogy-user-modal {
  z-index: 80;
  padding: 16px;
  place-items: center;
}

.genealogy-user-modal.is-open {
  display: grid !important;
}

.genealogy-user-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.genealogy-user-modal-content {
  position: relative;
  z-index: 1;
  width: min(460px, 100%) !important;
  max-width: min(460px, 100%) !important;
  height: auto !important;
  max-height: min(88vh, 640px) !important;
  min-height: 0;
  border-radius: 16px !important;
  border: 1px solid var(--border) !important;
  margin: 0;
  padding: 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow-soft);
  animation: genealogy-modal-in 0.22s ease;
}

.genealogy-user-modal-content .modal-header {
  align-items: flex-start;
}

.genealogy-user-modal-content .modal-header h3 {
  margin: 2px 0 0;
  font-size: 1.15rem;
}

.genealogy-user-modal-content .modal-header .muted {
  margin: 0;
  font-size: 0.85rem;
}

.genealogy-user-modal .genealogy-modal-photo {
  width: 88px;
  height: 88px;
}

.genealogy-user-modal .genealogy-assign-box {
  margin-top: 4px;
}

@keyframes genealogy-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.genealogy-modal-hero {
  display: flex;
  justify-content: center;
  margin: 4px 0 8px;
}

.genealogy-modal-photo {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #93c5fd;
  background: var(--surface-muted);
}

.genealogy-modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.genealogy-modal-grid div {
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 10px 12px;
}

.genealogy-modal-grid dt {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.genealogy-modal-id {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.genealogy-assign-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-muted) 80%, #dbeafe 20%);
  display: grid;
  gap: 10px;
}

.genealogy-assign-box[hidden] {
  display: none !important;
}

.genealogy-assign-box h4 {
  margin: 0;
  font-size: 1rem;
}

.genealogy-assign-help {
  margin: 0;
  font-size: 0.85rem;
}

.genealogy-assign-label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.genealogy-assign-label input {
  width: 100%;
  max-width: 100%;
}

.genealogy-assign-preview {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px dashed var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

.genealogy-assign-preview.is-ok {
  border-style: solid;
  border-color: #86efac;
  color: #166534;
  background: color-mix(in srgb, #dcfce7 55%, var(--surface));
}

.genealogy-assign-preview.is-error {
  border-style: solid;
  border-color: #fca5a5;
  color: #991b1b;
  background: color-mix(in srgb, #fee2e2 55%, var(--surface));
}

.genealogy-assign-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.genealogy-assign-feedback {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--muted);
}

.genealogy-assign-feedback.is-error {
  color: #b91c1c;
}

.genealogy-assign-feedback.is-ok {
  color: #166534;
}

.genealogy-root {
  display: flex;
  flex-direction: column;
  gap: 32px;
  align-items: center;
}

.genealogy-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.genealogy-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
  min-width: 120px;
  max-width: 140px;
  cursor: pointer;
}

.genealogy-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  border-color: #3b82f6;
}

.genealogy-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #e2e8f0;
  background: var(--surface-muted);
}

.genealogy-info {
  text-align: center;
  width: 100%;
}

.genealogy-name {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  word-wrap: break-word;
}

.genealogy-role {
  margin: 4px 0 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: capitalize;
}

.genealogy-children {
  display: flex;
  flex-direction: row;
  gap: 24px;
  margin-top: 32px;
  padding-top: 32px;
  position: relative;
  justify-content: center;
  flex-wrap: wrap;
}

.genealogy-children::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 32px;
  background: linear-gradient(180deg, #cbd5e1 0%, transparent 100%);
}

.genealogy-children > .genealogy-node::before {
  content: '';
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 32px;
  background: #cbd5e1;
}

@media (max-width: 768px) {
  .genealogy-children {
    flex-direction: column;
    gap: 16px;
  }

  .genealogy-card {
    min-width: 100px;
    max-width: 120px;
  }

  .genealogy-avatar {
    width: 52px;
    height: 52px;
  }

  .genealogy-modal-grid {
    grid-template-columns: 1fr;
  }

  .genealogy-p5-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .genealogy-p5-actions {
    justify-content: stretch;
  }

  .genealogy-p5-actions .btn {
    flex: 1 1 auto;
  }

  .genealogy-p5-hint {
    font-size: 0.8rem;
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.stats article {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-muted);
}

.profile-home-card {
  max-width: 780px;
  margin: 0 auto;
}

.profile-home-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.profile-mini-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  padding: 4px 8px;
  border: 1px solid var(--text);
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
}

.profile-menu-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 700;
}

.profile-home-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.profile-home-welcome {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

.profile-home-name {
  margin: 2px 0 6px;
  font-size: clamp(1.45rem, 2vw, 1.9rem);
}

.profile-home-meta {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.profile-avatar-placeholder {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  border: 1px solid var(--text);
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 0.72rem;
  padding: 10px;
  cursor: pointer;
}

.profile-photo-upload {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.profile-photo-input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.profile-photo-preview {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--text);
  background: var(--surface);
  cursor: pointer;
}

.profile-qr-block {
  margin-top: 18px;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.profile-qr-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.profile-qr-help {
  margin: 0;
  text-align: center;
  max-width: 380px;
}

.profile-qr-image {
  width: 240px;
  max-width: 100%;
  border: 6px solid var(--surface);
  box-shadow: var(--shadow-soft);
}

.profile-cta-group {
  margin-top: 14px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.profile-cta-dropdown {
  position: relative;
  display: inline-block;
}

.profile-cta-dropdown > summary {
  list-style: none;
}

.profile-cta-dropdown > summary::-webkit-details-marker {
  display: none;
}

.profile-cta-dropdown > summary::after {
  content: "▾";
  font-size: 0.8em;
  line-height: 1;
}

.profile-cta-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 240px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
}

.profile-cta-menu a {
  display: block;
  padding: 10px 12px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  border-radius: 8px;
}

.profile-cta-menu a:hover,
.profile-cta-menu a:focus {
  background: var(--surface-soft);
}

.hidden-accessory-fields {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.profile-total-banner {
  margin: 14px auto 0;
  width: min(420px, 100%);
  text-align: center;
  padding: 10px 14px;
  border: 1px solid #0b6cff;
  border-radius: 0;
  background: #16a6db;
  color: #fff;
  font-weight: 800;
  font-size: 1.25rem;
  line-height: 1.25;
}

.profile-legal-note {
  margin: 10px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.68rem;
}

.profile-counts {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  font-size: 1.05rem;
  font-weight: 700;
}

.profile-counts strong {
  font-size: 1.35rem;
}

.site-footer {
  margin-top: 32px;
  padding: 18px 16px 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer p {
  margin: 0;
}

.topbar-notify-btn {
  position: relative;
  width: 40px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-notify-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.candidate-message-modal-content {
  width: min(520px, 100%);
}

.candidate-message-modal-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.candidate-message-channels {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.form-grid .channel-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin: 0;
}

.form-grid .channel-check input {
  width: auto;
  margin: 0;
}

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-weight: 600;
}
.alert.error { background: #fdecea; color: var(--danger); border: 1px solid #f7c7c3; }
.alert.success { background: #e9f8ef; color: #0a7d42; border: 1px solid #b6e7ca; }
.hidden { display: none !important; }

.captcha-status {
  border: 1px dashed #94a3b8;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface-muted);
  font-weight: 600;
}

.captcha-status.ok {
  border-style: solid;
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}

.captcha-status.error {
  border-style: solid;
  border-color: #fecaca;
  color: #b91c1c;
  background: #fef2f2;
}

table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--border); padding: 10px 8px; text-align: left; font-size: 0.95rem; }
.table-wrap { overflow-x: auto; }

button:disabled,
.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.permissions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.permission-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface);
  font-weight: 500;
}

.permission-item input {
  margin-top: 2px;
}

.permission-item span {
  display: grid;
  gap: 3px;
}

.permission-item small {
  color: var(--muted);
  font-size: 0.82rem;
}

.user-photo-preview {
  display: grid;
  justify-items: start;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.user-avatar {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface);
}

.user-avatar.list {
  width: 44px;
  height: 44px;
  border-radius: 10px;
}

.map-placeholder {
  height: 180px;
  border: 1px dashed #94a3b8;
  border-radius: 12px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  background: repeating-linear-gradient(45deg, var(--surface-muted), var(--surface-muted) 12px, var(--surface-soft) 12px, var(--surface-soft) 24px);
}

.theme-toggle-btn {
  min-width: 112px;
}

@media (max-width: 768px) {
  .topbar { gap: 10px; }
  .brand {
    gap: 8px;
    min-width: 0;
    flex: 1;
  }
  .brand-head {
    min-width: 0;
    gap: 6px;
  }
  .brand-head span {
    font-size: 0.95rem;
    line-height: 1.1;
    white-space: nowrap;
  }
  .brand img { width: 100px; }
  .brand-user-mini {
    display: none;
  }

  .topbar-menu-toggle {
    width: 36px;
    height: 34px;
  }

  .login-brand img {
    width: 104px;
  }

  .login-brand span {
    font-size: 0.95rem;
    line-height: 1.1;
  }

  .profile-home-head {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .heatmap-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .reports-map-mode {
    gap: 8px;
  }

  .reports-map-mode label {
    font-size: 0.82rem;
  }

  #reports-gis-canvas {
    height: min(340px, 46vh);
  }

  .reports-leaflet-map {
    height: min(340px, 46vh);
  }

  .leader-cluster-grid,
  .leader-cluster-grid.bottom-row {
    grid-template-columns: 1fr;
  }

  .profile-home-meta {
    font-size: 0.72rem;
  }

  .profile-total-banner {
    font-size: 1.3rem;
  }

  .segment-nav {
    width: 100%;
  }

  .segment-btn {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
}
