:root {
  --bg: #05080f;
  --bg-2: #0a1020;
  --panel: rgba(13, 21, 38, 0.82);
  --panel-solid: #0d1526;
  --line: rgba(120, 180, 255, 0.12);
  --line-2: rgba(120, 180, 255, 0.24);
  --text: #dbe7ff;
  --muted: #7d8db0;
  --dim: #4b5a7a;
  --accent: #22d3ee;
  --accent-2: #818cf8;
  --good: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;
  --crit: #f43f5e;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 80% -10%, rgba(34, 211, 238, 0.08), transparent 60%),
              radial-gradient(900px 600px at -10% 110%, rgba(129, 140, 248, 0.08), transparent 60%), var(--bg);
  color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased;
}
body::before { /* retícula sutil */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px; mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%); opacity: .35;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ── Login ── */
#login { position: relative; z-index: 1; min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 20px; padding: 32px;
  backdrop-filter: blur(12px); box-shadow: 0 0 80px rgba(34, 211, 238, .08); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: conic-gradient(from 200deg, var(--accent), var(--accent-2), var(--accent)); box-shadow: 0 0 24px rgba(34,211,238,.45); }
.brand-mark::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); box-shadow: 0 0 0 3px rgba(255,255,255,.9) inset; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .28em; }
.brand p { margin: 0; font-size: 11px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }
.login-card form { display: grid; gap: 12px; margin-top: 24px; }

/* ── Shell ── */
#app { position: relative; z-index: 1; display: grid; grid-template-columns: 228px 1fr; min-height: 100%; }
#side { border-right: 1px solid var(--line); background: rgba(5, 8, 15, .7); backdrop-filter: blur(10px); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
#side .brand { padding: 4px 8px 18px; }
#side nav { display: grid; gap: 2px; }
#side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
#side nav a:hover { background: rgba(255,255,255,.04); color: var(--text); }
#side nav a.active { background: linear-gradient(90deg, rgba(34,211,238,.16), transparent); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
#side nav a .ico { width: 18px; text-align: center; opacity: .9; }
#side nav a .count { margin-left: auto; font: 11px var(--mono); background: rgba(244,63,94,.18); color: var(--bad); padding: 1px 7px; border-radius: 99px; }
#side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; border-top: 1px solid var(--line); }
#main { min-width: 0; display: flex; flex-direction: column; }
#top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  background: rgba(5, 8, 15, .78); backdrop-filter: blur(10px); }
#top .search { flex: 1; max-width: 560px; position: relative; }
#top .search input { width: 100%; padding-left: 36px; }
#top .search::before { content: "⌕"; position: absolute; left: 12px; top: 50%; transform: translateY(-52%); color: var(--muted); font-size: 18px; }
#searchResults { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: 12px; overflow: hidden; }
#searchResults a { display: flex; justify-content: space-between; gap: 8px; padding: 9px 14px; color: var(--text); border-bottom: 1px solid var(--line); }
#searchResults a:hover { background: rgba(34,211,238,.08); }
#menuBtn { display: none; }
#view { padding: 24px; flex: 1; min-width: 0; }

/* ── Controles ── */
input, select, textarea { background: rgba(255,255,255,.04); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,211,238,.15); }
select option { background: var(--panel-solid); }
textarea { resize: vertical; min-height: 80px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line-2);
  background: rgba(255,255,255,.04); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #0ea5e9); color: #021018; border: none; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: progress; }
label.field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.err { color: var(--bad); font-size: 13px; min-height: 1em; }

/* ── Encabezados y paneles ── */
.view-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.view-head h2 { margin: 0; font-size: 22px; letter-spacing: .01em; }
.view-head p { margin: 2px 0 0; color: var(--muted); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; backdrop-filter: blur(8px); }
.panel h3 { margin: 0 0 12px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; }
.kpi .v { font: 600 26px var(--mono); }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi.alert .v { color: var(--bad); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filters input { flex: 1 1 220px; }
.filters select { flex: 0 1 190px; }

/* ── Tarjetas de personas ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; display: flex; flex-direction: column; }
.card:hover { transform: translateY(-3px); border-color: var(--pc, var(--accent)); box-shadow: 0 12px 40px -12px var(--pc, var(--accent)); }
.card .photo { aspect-ratio: 1 / 1; background: linear-gradient(160deg, #111a30, #070b14); position: relative; overflow: hidden; }
.card .photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; display: block; filter: saturate(.9); }
.card .photo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(5,8,15,.95), transparent 55%); }
.card .party-bar { height: 3px; background: var(--pc, var(--dim)); box-shadow: 0 0 12px var(--pc, transparent); }
.card .body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.card .name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.card .role { font-size: 12.5px; color: var(--text); opacity: .85; }
.card .party { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { display: inline-block; vertical-align: middle; width: 8px; height: 8px; border-radius: 50%; background: var(--pc, var(--dim)); flex: none; box-shadow: 0 0 8px var(--pc, transparent); }
.card .stats { display: flex; gap: 10px; margin-top: 6px; font: 11px var(--mono); color: var(--muted); }
.card .flags { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; z-index: 2; gap: 6px; }
.avatar { width: 100%; height: 100%; display: grid; place-items: center; font: 600 44px var(--mono); color: var(--pc, var(--accent)); opacity: .85; letter-spacing: .04em; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; font: 600 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.b-demo { color: var(--warn); background: rgba(251,191,36,.08); }
.b-alert { color: var(--bad); background: rgba(244,63,94,.14); }
.b-verificado { color: var(--good); } .b-reportado { color: var(--accent); } .b-supuesto { color: var(--warn); } .b-desmentido { color: var(--dim); text-decoration: line-through; }
.b-critica { color: #fff; background: var(--crit); border-color: var(--crit); } .b-alta { color: var(--bad); } .b-media { color: var(--warn); } .b-baja { color: var(--muted); }
.b-pos { color: var(--good); } .b-neg { color: var(--bad); } .b-neu { color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,.05); border: 1px solid var(--line); font-size: 12px; }

/* ── Perfil ── */
.profile-head { display: grid; grid-template-columns: 168px 1fr auto; gap: 22px; align-items: start; margin-bottom: 18px; }
.profile-photo { width: 168px; aspect-ratio: 1; border-radius: 18px; overflow: hidden; border: 1px solid var(--line-2); background: #0b1222; position: relative;
  box-shadow: 0 0 0 4px rgba(0,0,0,.4), 0 0 40px -6px var(--pc, var(--accent)); }
.profile-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.profile-head h2 { margin: 0 0 4px; font-size: 28px; }
.profile-head .meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.profile-actions { display: flex; flex-direction: column; gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: none; padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs button.active { color: var(--text); border-color: var(--accent); }
.tabs button .n { font: 11px var(--mono); opacity: .7; margin-left: 4px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.list { display: grid; gap: 8px; }
.item { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.02); display: grid; gap: 4px; }
.item .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.item .t { font-weight: 600; }
.item.pos { border-left: 3px solid var(--good); } .item.neg { border-left: 3px solid var(--bad); }
.person-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.person-link:hover { color: var(--accent); }
.mini-av { width: 28px; height: 28px; border-radius: 8px; overflow: hidden; background: #0b1222; display: grid; place-items: center; font: 600 11px var(--mono); color: var(--accent); flex: none; }
.mini-av img { width: 100%; height: 100%; object-fit: cover; }
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.06); position: relative; overflow: hidden; }
.bar > i { position: absolute; top: 0; bottom: 0; border-radius: 99px; }
.footprint { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr 40px; gap: 8px 12px; align-items: center; font-size: 13px; }
.ai-output { white-space: pre-wrap; line-height: 1.6; font-size: 13.5px; }
.ego { height: 420px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #03060c; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line-2); border-radius: 12px; }

/* ── Red y mapa ── */
.stage { position: relative; height: calc(100vh - 170px); min-height: 480px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #02040a; }
.stage .overlay { position: absolute; z-index: 5; top: 12px; left: 12px; display: flex; gap: 8px; flex-wrap: wrap; max-width: calc(100% - 24px); }
.stage .legend { position: absolute; z-index: 5; bottom: 12px; left: 12px; background: rgba(5,8,15,.8); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; max-width: calc(100% - 24px); }
.stage .info { position: absolute; z-index: 5; top: 12px; right: 12px; width: 300px; max-width: calc(100% - 24px); max-height: calc(100% - 24px); overflow: auto; }
.map-layout { display: grid; grid-template-columns: 1fr 360px; gap: 14px; }
.map-layout .stage { height: calc(100vh - 150px); }
.map-side { max-height: calc(100vh - 150px); overflow: auto; }
.leaflet-container { background: #02040a; font: inherit; }
.dark-tiles { filter: invert(1) hue-rotate(185deg) brightness(.75) contrast(1.15) saturate(.5); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line-2); }

/* ── Tablas ── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.table-wrap { overflow-x: auto; }

/* ── Modal ── */
dialog { border: 1px solid var(--line-2); border-radius: 18px; background: var(--panel-solid); color: var(--text); padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(2, 4, 10, .7); backdrop-filter: blur(4px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel-solid); z-index: 1; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; padding: 12px 16px; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--line-2); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.toast.error { border-color: var(--bad); color: var(--bad); }

.capture-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.capture-grid button { text-align: left; padding: 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; display: grid; gap: 4px; }
.capture-grid button:hover { border-color: var(--accent); }
.capture-grid b { font-size: 15px; }

@media (max-width: 960px) {
  #app { grid-template-columns: 1fr; }
  #side { position: fixed; z-index: 50; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; background: var(--bg); }
  #side.open { transform: none; }
  #menuBtn { display: inline-flex; }
  #view, #top { padding-left: 16px; padding-right: 16px; }
  .profile-head { grid-template-columns: 1fr; }
  .profile-photo { width: 120px; }
  .profile-actions { flex-direction: row; flex-wrap: wrap; }
  .map-layout { grid-template-columns: 1fr; }
  .map-layout .stage { height: 60vh; }
  .form-grid { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

.leaflet-control-layers { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line-2) !important; border-radius: 10px; font-size: 12px; }
.leaflet-control-layers label { display: flex; gap: 6px; align-items: center; }
