:root {
  /* EGT palette */
  --ink: #140C22;        /* texto principal / oscuro */
  --red: #E42314;        /* EGT RED — primario */
  --red-deep: #790713;   /* granate — hover / destructivo */
  --slate: #494F76;      /* azul-pizarra — secundario */
  --cream: #E6E1D4;      /* fondo crema */

  --bg: #ECE8DE;
  --panel: #ffffff;
  --panel-2: #F4F1EA;
  --line: #E0DBCE;
  --line-soft: #ECE7DB;
  --text: #140C22;
  --muted: #7A7E90;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20,12,34,.04), 0 8px 24px -12px rgba(20,12,34,.14);
  --shadow-lg: 0 2px 4px rgba(20,12,34,.05), 0 20px 40px -20px rgba(20,12,34,.28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(228,35,20,.06), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, rgba(73,79,118,.07), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 14px 24px;
  background: rgba(255,255,255,.75);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 500;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 750; letter-spacing: -.2px; color: var(--ink); }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; letter-spacing: .2px; }
.chip {
  width: 46px; height: 46px; display: grid; place-items: center;
  background: linear-gradient(160deg, #fff, var(--panel-2));
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(20,12,34,.05);
}
.chip img { width: 30px; height: 30px; display: block; }

/* Segmented tabs */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.tab {
  background: transparent; color: var(--muted); border: none;
  padding: 8px 20px; border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 600;
  transition: color .15s, background .15s, box-shadow .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); background: #fff; box-shadow: 0 1px 2px rgba(20,12,34,.12); }

/* Layout */
main { padding: 24px; max-width: 1240px; margin: 0 auto; }
.tab-panel { display: none; animation: fade .25s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card > h2 {
  margin: 0 0 16px; font-size: 13px; font-weight: 700; color: var(--slate);
  text-transform: uppercase; letter-spacing: .8px;
  display: flex; align-items: center; gap: 9px;
}
.card > h2::before { content: ""; width: 3px; height: 14px; background: var(--red); border-radius: 2px; }
.muted { color: var(--muted); font-size: 13px; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; color: var(--slate); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
@media (max-width: 700px) { .kpis { grid-template-columns: 1fr 1fr; } }
.kpi {
  background: linear-gradient(165deg, #fff, #FBFAF6);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px;
  background: radial-gradient(circle, rgba(228,35,20,.10), transparent 70%); border-radius: 50%;
}
.kpi-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.kpi-num { color: var(--ink); font-size: 38px; font-weight: 800; line-height: 1; letter-spacing: -1px; font-variant-numeric: tabular-nums; }

/* Resumen por país — ranking de magnitud (una sola tinta) */
.report-list { display: flex; flex-direction: column; gap: 18px; }
.rep-row { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; align-items: baseline; }
.rep-name { color: var(--ink); font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 9px; }
.rep-flag {
  font-size: 15px; width: 30px; height: 30px; display: inline-grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; line-height: 1;
}
.rep-count { color: var(--ink); font-weight: 800; font-size: 17px; text-align: right; font-variant-numeric: tabular-nums; }
.rep-pct { color: var(--muted); font-weight: 600; font-size: 12px; margin-left: 7px; }
.rep-bar-wrap {
  grid-column: 1 / -1; height: 9px; background: var(--panel-2);
  border-radius: 6px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(20,12,34,.06);
}
.rep-bar {
  height: 100%; border-radius: 6px; min-width: 4px;
  background: linear-gradient(90deg, var(--red-deep), var(--red));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
  transition: width .4s cubic-bezier(.2,.7,.2,1);
}
.rep-sub { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; letter-spacing: .1px; }
.rep-bar.bar-act { background: linear-gradient(90deg, #363b5c, var(--slate)); }

/* dos charts lado a lado */
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 820px) { .report-grid { grid-template-columns: 1fr; } }
.report-grid .card { margin-bottom: 0; }

/* tabla de activaciones */
.act-row.sel td { background: rgba(228,35,20,.06); }
.row-actions .btn { padding: 5px 11px; font-size: 12px; }

/* Login */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(1000px 500px at 100% -10%, rgba(228,35,20,.10), transparent 60%),
    radial-gradient(900px 450px at -10% 110%, rgba(73,79,118,.12), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand h1 { margin: 0; font-size: 18px; color: var(--ink); font-weight: 750; }
.login-brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.login-error { background: #fbeceb; border: 1px solid rgba(228,35,20,.3); color: var(--red-deep); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; }

/* Topbar right (tabs + usuario) */
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.user-box { display: flex; align-items: center; gap: 12px; padding-left: 12px; border-left: 1px solid var(--line); }
.user-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.user-name { font-size: 13px; font-weight: 700; color: var(--ink); }

/* Banner de scope de captura + input bloqueado */
.cap-scope { background: rgba(228,35,20,.07); border: 1px solid rgba(228,35,20,.22); color: var(--ink); padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.cap-scope b { color: var(--red-deep); }
input.locked { background: var(--panel-2); color: var(--muted); cursor: not-allowed; }
.nowrap { white-space: nowrap; }

/* Vista Capturar */
.btn-lg { padding: 13px 20px; font-size: 15px; margin-top: 4px; }

/* Preview de importación */
#import-preview { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.preview-actions { display: flex; gap: 8px; }
.preview-scroll { max-height: 340px; overflow: auto; }
tr.row-dup td { background: rgba(228,35,20,.06); }
.tag-dup { display: inline-block; background: rgba(228,35,20,.14); color: var(--red-deep); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.tag-ok { display: inline-block; background: rgba(73,79,118,.12); color: var(--slate); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }

/* Banderas SVG (flag-icons) */
.fi { border-radius: 2px; vertical-align: -0.12em; box-shadow: 0 0 0 1px rgba(20,12,34,.08); }
.rep-flag .fi { width: 20px; height: 15px; vertical-align: 0; }
.flag-na { opacity: .6; }

/* Picker de países */
.pais-picker-wrap { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.pais-picker { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: var(--panel-2); }
.pais-picker .pp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px 10px; margin-top: 10px; max-height: 190px; overflow: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); font-weight: 500; cursor: pointer; }
.check input { width: auto; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(20,12,34,.45); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 1000; }
.modal-card { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-lg); }
.modal-card h2 { margin: 0 0 16px; font-size: 15px; color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.row-actions { display: flex; gap: 8px; }
.row-edit { color: var(--muted); cursor: pointer; background: none; border: none; font-size: 14px; transition: color .12s; }
.row-edit:hover { color: var(--slate); }

/* Badge de rol */
.rol-badge { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; text-transform: uppercase; letter-spacing: .4px; }
.rol-admin { background: rgba(228,35,20,.12); color: var(--red-deep); }
.rol-capturador { background: rgba(73,79,118,.14); color: var(--slate); }

/* Forms */
.form { display: flex; flex-direction: column; gap: 13px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 13px; }
@media (max-width: 560px) { .row2, .row3 { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select {
  background: #fff; border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #b7b3a8; }
input:focus, select:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(228,35,20,.13); }

.btn {
  background: #fff; border: 1px solid var(--line); color: var(--ink);
  padding: 10px 15px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; transition: border-color .15s, background .15s, transform .1s;
}
.btn:hover { border-color: var(--slate); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 4px 12px -4px rgba(228,35,20,.5); }
.btn.primary:hover { background: var(--red-deep); border-color: var(--red-deep); }
.btn.danger { color: var(--red-deep); }
.btn.danger:hover { border-color: var(--red-deep); background: #fbeceb; }
.btn.file { position: relative; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.report { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--panel-2); font-size: 13px; }
.report.ok { border-left: 3px solid var(--slate); }
.report.err { border-left: 3px solid var(--red); }

/* Table */
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.table-head h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--slate); text-transform: uppercase; letter-spacing: .8px; display: flex; align-items: center; gap: 10px; }
.badge { background: var(--red); color: #fff; font-size: 12px; padding: 2px 9px; border-radius: 20px; font-weight: 700; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 130px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
th { color: var(--slate); font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; background: var(--panel-2); }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--panel-2); }
.row-del { color: var(--muted); cursor: pointer; background: none; border: none; font-size: 15px; transition: color .12s; }
.row-del:hover { color: var(--red); }
.empty { color: var(--muted); text-align: center; padding: 26px; font-size: 14px; }

/* Map */
.map-card { padding: 0; overflow: hidden; }
.map-head { padding: 18px 22px; border-bottom: 1px solid var(--line); }
.map-head h2 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--slate); text-transform: uppercase; letter-spacing: .8px; display: flex; align-items: center; gap: 9px; }
.map-head h2::before { content: ""; width: 3px; height: 14px; background: var(--red); border-radius: 2px; }
.map-legend { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-legend .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(228,35,20,.2); display: inline-block; }
.geo-status { margin-left: auto; font-style: italic; }
.map-countries { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.map-countries:empty { margin-top: 0; }
.country-btn {
  background: #fff; border: 1px solid var(--line); color: var(--ink);
  padding: 6px 13px; border-radius: 20px; cursor: pointer; font-size: 13px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; gap: 7px; transition: all .14s;
}
.country-btn:hover { border-color: var(--slate); }
.country-btn.active { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 4px 12px -4px rgba(228,35,20,.5); }
.country-btn .cnt { font-size: 11px; opacity: .8; font-weight: 800; }
#map { height: 42vh; min-height: 300px; max-height: 440px; width: 100%; background: var(--cream); }

/* Leaflet tooltip theming */
.leaflet-tooltip.act-tip {
  background: #fff; color: var(--ink); border: 1px solid var(--red);
  box-shadow: var(--shadow-lg); font-size: 12px; border-radius: 10px; padding: 9px 11px;
}
.leaflet-tooltip.act-tip.leaflet-tooltip-top:before { border-top-color: var(--red); }
.act-tip b { color: var(--red-deep); }
.act-tip .n { font-size: 20px; font-weight: 800; color: var(--red); line-height: 1; }
