@font-face { font-family: "Roboto"; src: url("fonts/roboto-400.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("fonts/roboto-500.ttf") format("truetype"); font-style: normal; font-weight: 500; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("fonts/roboto-600.ttf") format("truetype"); font-style: normal; font-weight: 600; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("fonts/roboto-700.ttf") format("truetype"); font-style: normal; font-weight: 700; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("fonts/roboto-800.ttf") format("truetype"); font-style: normal; font-weight: 800; font-display: swap; }

:root {
  color-scheme: light;
  --mh-primary: #2563eb;
  --mh-primary-hover: #1d4ed8;
  --mh-primary-light: #e8f0fe;
  --mh-decorative: #1e4fbc;
  --mh-text: #0f172a;
  --mh-text-secondary: #475569;
  --mh-text-muted: #94a3b8;
  --mh-border: #dbe2ea;
  --mh-border-light: #edf0f4;
  --mh-bg-page: #f5f6fa;
  --mh-bg-card: #ffffff;
  --mh-bg-elevated: #e2e8f0;
  --radius-button: 10px;
  --radius-card: 18px;
  --radius-input: 10px;
  --radius-chip: 6px;
  --shadow-subtle: 0 4px 16px 0 rgba(15, 23, 42, .06);
  --shadow-elevated: 0 10px 30px 0 rgba(15, 23, 42, .14);
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 36px;
}

* { box-sizing: border-box; }
html { background: var(--mh-bg-page); }
body {
  margin: 0;
  background: var(--mh-bg-page);
  color: var(--mh-text);
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 64px;
  padding: 0 max(var(--sp-6), calc((100vw - 1040px) / 2));
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--mh-border-light);
  box-shadow: 0 1px 8px rgba(15, 23, 42, .04);
  backdrop-filter: blur(10px);
}
.topbar a { color: var(--mh-text-secondary); text-decoration: none; }
.brand { color: var(--mh-text) !important; font-size: 16px; font-weight: 800; letter-spacing: -.02em; }
nav { display: flex; gap: var(--sp-2); }
nav { align-items: center; }
nav a { padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-chip); font-size: 14px; font-weight: 500; }
nav a:hover { background: var(--mh-primary-light); color: var(--mh-primary-hover); }
.user-name { margin-left: var(--sp-2); color: var(--mh-text-muted); font-size: 13px; font-weight: 500; }
.logout-form { display: block; }
.logout-form button { padding: var(--sp-2) var(--sp-3); border: 1px solid var(--mh-border); border-radius: var(--radius-chip); background: white; color: var(--mh-text-secondary); font: 600 13px "Roboto", sans-serif; cursor: pointer; }
.logout-form button:hover { border-color: var(--mh-primary); color: var(--mh-primary-hover); }

.container { width: min(1040px, calc(100% - 32px)); margin: 0 auto; padding: 56px 0 72px; }
.hero { max-width: 760px; margin-bottom: var(--sp-7); }
.hero.compact { margin-bottom: var(--sp-6); }
.eyebrow { margin: 0; color: var(--mh-text-muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3 { color: var(--mh-text); }
h1 { margin: var(--sp-2) 0 var(--sp-3); font-size: clamp(34px, 5vw, 52px); font-weight: 800; line-height: 1.04; letter-spacing: -.04em; }
h2 { margin: var(--sp-1) 0 0; font-size: clamp(24px, 3vw, 30px); font-weight: 800; line-height: 1.15; letter-spacing: -.025em; }
h3 { margin: 0 0 var(--sp-1); font-size: 17px; font-weight: 700; line-height: 1.3; }
.compact h1 { font-size: clamp(30px, 4vw, 44px); }
.hero > p:last-child { margin: 0; color: var(--mh-text-secondary); font-size: 17px; line-height: 1.6; }

.card,
.result-card,
.geography-card,
.gender-card {
  background: var(--mh-bg-card);
  border: 1px solid var(--mh-border-light);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-subtle);
  transition: box-shadow .18s ease, transform .18s ease;
}
.card:hover,
.result-card:hover { box-shadow: var(--shadow-elevated); transform: translateY(-2px); }
.card { padding: var(--sp-7); }
.narrow-card { max-width: 640px; }
.flash-message { margin: 0 0 var(--sp-5); }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-6); background: linear-gradient(135deg, #eff4ff 0%, var(--mh-bg-page) 58%); }
.auth-shell { width: min(920px, 100%); display: grid; grid-template-columns: 1fr minmax(340px, .8fr); gap: 64px; align-items: center; }
.auth-intro h1 { max-width: 540px; }
.auth-intro > p:last-child { max-width: 500px; color: var(--mh-text-secondary); font-size: 17px; }
.auth-card h2 { margin-top: 0; }
.auth-help { margin: var(--sp-2) 0 var(--sp-5); color: var(--mh-text-secondary); }
.auth-card .status { margin: 0 0 var(--sp-3); }
.role-chip { display: inline-flex; padding: 3px 8px; border-radius: var(--radius-chip); background: var(--mh-primary-light); color: var(--mh-primary-hover); font-size: 12px; font-weight: 700; text-transform: capitalize; }

form { display: grid; gap: var(--sp-3); }
label { margin-top: var(--sp-2); color: var(--mh-text-secondary); font-size: 12px; font-weight: 600; }
input { width: 100%; min-height: 44px; padding: 10px 13px; border: 1px solid var(--mh-border); border-radius: var(--radius-input); outline: none; background: var(--mh-bg-card); color: var(--mh-text); font: 400 14px "Roboto", sans-serif; transition: border-color .15s ease, box-shadow .15s ease; }
input::placeholder { color: var(--mh-text-muted); }
input:focus { border-color: var(--mh-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
small { color: var(--mh-text-muted); font-size: 13px; line-height: 1.5; }
.file-drop { padding: var(--sp-6); border: 1px dashed var(--mh-border); border-radius: var(--radius-input); background: #fafbfc; text-align: center; transition: border-color .15s ease, background .15s ease; }
.file-drop:hover { border-color: var(--mh-primary); background: var(--mh-primary-light); }
.file-drop input { min-height: auto; padding: 0; border: 0; box-shadow: none; background: transparent; }
.file-drop input::file-selector-button { margin-right: var(--sp-3); padding: 9px 12px; border: 1px solid var(--mh-border); border-radius: var(--radius-button); background: white; color: var(--mh-text-secondary); font: 600 13px "Roboto", sans-serif; cursor: pointer; }
.file-drop p { margin: var(--sp-3) 0 var(--sp-1); font-weight: 700; }

.button { padding: 12px 13px; border-radius: var(--radius-button); font: 700 14px "Roboto", sans-serif; cursor: pointer; white-space: nowrap; transition: background .15s ease, border-color .15s ease, box-shadow .18s ease, transform .18s ease; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible { outline: 3px solid rgba(37, 99, 235, .2); outline-offset: 2px; }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.primary { margin-top: var(--sp-4); border: 0; background: var(--mh-primary); color: #fff; }
.primary:hover { background: var(--mh-primary-hover); box-shadow: var(--shadow-subtle); }
.secondary { border: 1px solid var(--mh-border); background: white; color: var(--mh-text-secondary); }
.secondary:hover { border-color: var(--mh-primary); color: var(--mh-primary-hover); }
.ghost { border: 1px solid var(--mh-border-light); background: white; color: var(--mh-text-secondary); }
.ghost:hover { background: var(--mh-primary-light); color: var(--mh-primary-hover); }
.compact-button { display: inline-flex; align-items: center; justify-content: center; margin-top: 0; text-decoration: none; }
.model-row, .folder-row { display: flex; align-items: end; gap: var(--sp-3); }
.grow { flex: 1; display: grid; gap: var(--sp-3); }

.status { display: none; margin-top: var(--sp-5); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-input); line-height: 1.5; overflow-wrap: anywhere; }
.status.visible { display: block; background: var(--mh-primary-light); color: var(--mh-decorative); }
.status.success { background: #f0fdf4; color: #16a34a; }
.status.error { background: #fef2f2; color: #dc2626; }

.results-section { margin-top: 48px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: var(--sp-5); margin-bottom: var(--sp-5); }
.result-list { display: grid; gap: var(--sp-3); }
.result-card { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-6); padding: var(--sp-5) var(--sp-6); }
.result-meta { margin: 0; color: var(--mh-text-secondary); font-size: 14px; font-weight: 500; }
.result-filename { margin: var(--sp-2) 0 0; color: var(--mh-text-muted); font-size: 12px; overflow-wrap: anywhere; }
.result-actions { display: flex; flex-shrink: 0; gap: var(--sp-2); }

.geography-card { margin-top: var(--sp-6); padding: var(--sp-7); }
.geography-heading { display: flex; justify-content: space-between; align-items: end; gap: var(--sp-6); margin-bottom: var(--sp-6); }
.geography-summary { margin: var(--sp-2) 0 0; color: var(--mh-text-secondary); line-height: 1.5; }
.geography-stats { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: var(--sp-2); }
.geography-stat { min-width: 120px; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-input); background: var(--mh-primary-light); }
.geography-stat strong, .geography-stat span { display: block; }
.geography-stat strong { color: var(--mh-decorative); font-size: 22px; font-weight: 800; line-height: 1.1; }
.geography-stat span { margin-top: var(--sp-1); color: var(--mh-text-secondary); font-size: 12px; font-weight: 500; }
.geography-layout { display: grid; grid-template-columns: minmax(300px, .95fr) minmax(340px, 1.05fr); gap: var(--sp-6); align-items: start; }
.map-figure { margin: 0; padding: var(--sp-4); border: 1px solid var(--mh-border-light); border-radius: var(--radius-card); background: #fafbfc; }
.map-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); }
.map-legend > span { display: inline-flex; align-items: center; gap: 6px; color: var(--mh-text-secondary); font-size: 12px; font-weight: 500; line-height: 1.3; }
.map-legend i { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; }
.map-stage { position: relative; }
.map-stage > img { display: block; width: 100%; height: auto; aspect-ratio: 573 / 600; object-fit: contain; }
.map-markers { position: absolute; inset: 0; pointer-events: none; }
.map-marker { position: absolute; left: var(--marker-x); top: var(--marker-y); z-index: 2; width: var(--marker-size); height: var(--marker-size); padding: 0; border-radius: 50%; transform: translate(-50%, -50%) translate(var(--marker-offset-x), var(--marker-offset-y)); pointer-events: auto; cursor: help; }
.map-marker.municipality { border: 2px solid #fff; background: var(--marker-color); box-shadow: 0 0 0 2px #fff, 0 2px 7px rgba(15, 23, 42, .25); }
.map-marker.department { z-index: 1; border: 3px solid var(--marker-color); background: rgba(255, 255, 255, .9); box-shadow: 0 0 0 2px #fff; }
.map-marker:focus-visible { z-index: 5; outline: 3px solid var(--mh-primary); outline-offset: 3px; }
.map-marker:hover { z-index: 5; filter: brightness(.96); }
.marker-tooltip { display: none; position: absolute; left: 50%; bottom: calc(100% + 8px); width: max-content; max-width: 240px; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-chip); transform: translateX(-50%); background: var(--mh-text); color: white; font-size: 12px; font-weight: 500; line-height: 1.35; text-align: left; box-shadow: var(--shadow-elevated); }
.map-marker:hover .marker-tooltip, .map-marker:focus .marker-tooltip { display: block; }
.map-figure figcaption { margin-top: var(--sp-3); color: var(--mh-text-muted); font-size: 12px; line-height: 1.5; }
.map-figure a { color: var(--mh-primary); }

.location-panel h3 { margin-bottom: var(--sp-1); }
.location-help { margin: 0 0 var(--sp-3); color: var(--mh-text-secondary); font-size: 13px; }
.location-list { display: grid; align-content: start; gap: var(--sp-2); height: 520px; padding: 0 var(--sp-2) var(--sp-3) 0; overflow-y: auto; scroll-padding-bottom: var(--sp-5); scrollbar-gutter: stable; overscroll-behavior: contain; }
.location-item { overflow: hidden; border: 1px solid var(--mh-border-light); border-radius: var(--radius-input); background: white; }
.location-toggle { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 0; background: white; color: var(--mh-text); cursor: pointer; font: 700 14px "Roboto", sans-serif; text-align: left; }
.location-toggle:hover { background: #fafbfc; }
.location-toggle:focus-visible { outline: 3px solid rgba(37, 99, 235, .18); outline-offset: -3px; }
.location-toggle strong { min-width: 30px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-chip); background: var(--mh-primary-light); color: var(--mh-primary-hover); font-size: 12px; }
.location-content[hidden] { display: none; }
.location-content { padding-bottom: var(--sp-1); }
.location-bar { height: 5px; margin: 0 var(--sp-4) var(--sp-3); overflow: hidden; border-radius: 999px; background: var(--mh-bg-elevated); }
.location-bar span { display: block; height: 100%; border-radius: inherit; background: var(--mh-primary); }
.municipality-list { padding: 0 var(--sp-4) var(--sp-3); }
.municipality-list p { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-4); margin: 0; padding: var(--sp-2) 0; border-top: 1px solid var(--mh-border-light); color: var(--mh-text-secondary); font-size: 13px; line-height: 1.4; }
.municipality-list p > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.municipality-list strong { flex: 0 0 auto; color: var(--mh-text); }
.location-empty { color: var(--mh-text-muted); }
.geography-card.has-error { box-shadow: 0 0 0 1px #dc2626, var(--shadow-subtle); }

.gender-card { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(320px, 1.15fr); gap: var(--sp-7); align-items: center; margin-top: var(--sp-6); padding: var(--sp-7); }
.gender-layout { display: flex; align-items: center; justify-content: center; gap: var(--sp-7); }
.gender-pie { position: relative; width: 176px; height: 176px; flex: 0 0 auto; display: grid; place-content: center; border-radius: 50%; text-align: center; }
.gender-pie::after { content: ""; position: absolute; inset: 30px; border-radius: 50%; background: white; box-shadow: inset 0 0 0 1px var(--mh-border-light); }
.gender-pie span, .gender-pie small { position: relative; z-index: 1; display: block; }
.gender-pie span { color: var(--mh-text); font-size: 32px; font-weight: 800; line-height: 1; }
.gender-pie small { margin-top: var(--sp-1); color: var(--mh-text-muted); }
.gender-legend { display: grid; min-width: 220px; gap: var(--sp-3); }
.gender-legend > div { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: var(--sp-2); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--mh-border-light); }
.gender-legend > div:last-child { border-bottom: 0; }
.gender-legend i { width: 12px; height: 12px; border-radius: 50%; }
.gender-legend span { color: var(--mh-text-secondary); }
.gender-legend strong { color: var(--mh-text); }
.data-note { grid-column: 1 / -1; margin: -12px 0 0; color: var(--mh-text-muted); font-size: 12px; line-height: 1.5; }

.preview-dialog { width: min(1040px, calc(100% - 32px)); max-height: min(800px, calc(100vh - 48px)); padding: var(--sp-7); border: 1px solid var(--mh-border-light); border-radius: var(--radius-card); color: var(--mh-text); box-shadow: 0 24px 64px rgba(15, 23, 42, .38); }
.preview-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; gap: var(--sp-5); }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--mh-border); border-radius: 50%; background: white; color: var(--mh-text-secondary); font: 400 24px/1 "Roboto", sans-serif; cursor: pointer; }
.icon-button:hover { border-color: var(--mh-primary); color: var(--mh-primary); }
.preview-summary { color: var(--mh-text-secondary); }
.table-scroll { overflow: auto; border: 1px solid var(--mh-border-light); border-radius: var(--radius-input); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: 14px; }
th { background: var(--mh-primary); color: white; font-weight: 700; text-align: left; }
th, td { padding: 10px var(--sp-3); border-bottom: 1px solid var(--mh-border-light); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: #fafbfc; }
code { padding: 2px 6px; border-radius: var(--radius-chip); background: var(--mh-bg-elevated); color: var(--mh-text-secondary); }

@media (max-width: 760px) {
  .container { padding: var(--sp-7) 0 56px; }
  .topbar { min-height: 56px; padding: 0 var(--sp-4); }
  .user-name { display: none; }
  .auth-shell { grid-template-columns: 1fr; gap: var(--sp-6); }
  .auth-intro { text-align: center; }
  nav { gap: 0; }
  .card, .geography-card, .gender-card { padding: var(--sp-5); }
  .model-row, .folder-row { align-items: stretch; flex-direction: column; }
  .section-heading, .result-card, .result-actions { align-items: stretch; flex-direction: column; }
  .result-actions .button { width: 100%; }
  .geography-heading { align-items: stretch; flex-direction: column; }
  .geography-stats { grid-template-columns: 1fr; }
  .geography-layout { grid-template-columns: 1fr; }
  .location-list { height: 440px; }
  .gender-card { grid-template-columns: 1fr; }
  .gender-layout { align-items: stretch; flex-direction: column; }
  .gender-pie { align-self: center; }
  .gender-legend { min-width: 0; }
  .preview-dialog { padding: var(--sp-5); }
}

@media (max-width: 460px) {
  .container { width: min(100% - 24px, 1040px); }
  .brand { font-size: 14px; }
  nav a { padding: var(--sp-2); font-size: 13px; }
  h1 { font-size: 34px; }
  .geography-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .geography-stat { min-width: 0; padding: var(--sp-3) var(--sp-2); }
  .geography-stat span { font-size: 11px; }
}
