/* ===========================================================================
   Mis Países — tema claro minimalista
   =========================================================================== */
:root {
  --bg: #f5f7fb;
  --bg-grad-1: #eef2ff;
  --bg-grad-2: #f5f7fb;
  --surface: #ffffff;
  --border: #e6e9f2;
  --border-strong: #d7dbe8;
  --text: #1f2937;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-soft-2: #e0e7ff;
  --danger: #e11d48;
  --shadow: 0 10px 30px rgba(31, 41, 55, 0.08);
  --shadow-sm: 0 1px 2px rgba(31, 41, 55, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: var(--accent); }

/* ----------------------------- Login --------------------------------------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-grad-1), transparent 60%),
    var(--bg-grad-2);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand .globe { font-size: 26px; }

.login-card h1 {
  font-size: 22px;
  margin: 18px 0 6px;
  letter-spacing: -0.02em;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 14.5px;
  margin: 0 0 26px;
  line-height: 1.5;
}

.field { text-align: left; margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}

input[type="email"],
input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input[type="email"]:focus,
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  transition: background .15s, transform .05s;
}

.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary {
  color: var(--accent);
  background: var(--accent-soft);
}
.btn-secondary:hover { background: var(--accent-soft-2); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  width: auto;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  text-decoration: none;
}
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

.note {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--muted-2);
  line-height: 1.5;
}

.alert {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13.5px;
  text-align: left;
  margin-bottom: 16px;
}
.alert-error { background: #fff1f2; color: var(--danger); border: 1px solid #fecdd3; }
.alert-info { background: var(--accent-soft); color: var(--accent-hover); border: 1px solid var(--accent-soft-2); }

.hidden { display: none !important; }

.success-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}

.dev-link-box {
  margin-top: 16px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fafbff;
  text-align: left;
}
.dev-link-box .label {
  font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: .04em;
}

/* ----------------------------- App layout ---------------------------------- */
.app-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.topbar {
  height: 60px;
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.topbar .brand { font-size: 18px; }
.topbar .brand .globe { font-size: 20px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-email {
  font-size: 13.5px; color: var(--muted);
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.main { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 340px;
  flex: 0 0 340px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-section { padding: 18px 18px 0; }
.sidebar-section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-bottom: 18px; }

.search-wrap { position: relative; }
.search-wrap .clear-input {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; color: var(--muted-2); font-size: 18px; line-height: 1;
  padding: 4px;
}
.search-wrap .clear-input:hover { color: var(--text); }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted-2);
  margin: 18px 0 10px;
}

.count-badge {
  background: var(--accent-soft); color: var(--accent-hover);
  border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700;
  letter-spacing: 0;
}

.results {
  list-style: none; margin: 8px 0 0; padding: 0;
  max-height: 230px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.results:empty { display: none; }

.result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; }
.result-item:hover { background: #f7f8fb; }
.result-item.is-selected { background: var(--accent-soft); }
.result-item .flag { font-size: 18px; width: 22px; text-align: center; }
.result-item .name { flex: 1; }
.result-item .code { font-size: 11px; color: var(--muted-2); font-weight: 600; }
.result-item .check { color: var(--accent); font-weight: 700; opacity: 0; }
.result-item.is-selected .check { opacity: 1; }

/* Distintivo de país desaparecido (histórico) */
.tag-hist {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: #92400e; background: #fef3c7; border: 1px solid #fde68a;
  padding: 1px 6px; border-radius: 999px; white-space: nowrap;
}

.selected-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; flex: 1; min-height: 0;
}
.chip {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; font-size: 14px;
  animation: pop .12s ease-out;
}
.chip .flag { font-size: 17px; }
.chip .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .remove {
  border: none; background: transparent; color: var(--muted-2);
  font-size: 17px; line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.chip .remove:hover { background: #fff1f2; color: var(--danger); }

.empty-hint { color: var(--muted-2); font-size: 13.5px; line-height: 1.5; padding: 6px 2px; }

.toolbar { display: flex; gap: 8px; margin-top: 12px; }
.link-btn {
  border: none; background: transparent; color: var(--accent);
  font-size: 13px; font-weight: 600; padding: 6px 0;
}
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* ----------------------------- Map ---------------------------------------- */
.map-area { flex: 1; min-width: 0; position: relative; background: #fbfcfe; }
#map { width: 100%; height: 100%; }

/* Mantiene el grosor del borde constante al hacer zoom (si no, los países se
   ven con líneas muy gruesas al ampliar el mapa SVG). */
#map path { vector-effect: non-scaling-stroke; }

.map-hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(255,255,255,.92); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 16px; font-size: 12.5px; color: var(--muted);
  box-shadow: var(--shadow-sm); pointer-events: none;
}

.save-status {
  position: absolute; right: 16px; top: 14px;
  font-size: 12px; color: var(--muted-2);
  background: rgba(255,255,255,.9); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; opacity: 0; transition: opacity .2s;
}
.save-status.show { opacity: 1; }

/* jsvectormap tooltip ajustado al tema */
.jvm-tooltip {
  background: var(--text) !important;
  border-radius: 8px !important;
  font-family: inherit !important;
  font-size: 13px !important;
}

@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ----------------------------- Responsive --------------------------------- */
@media (max-width: 820px) {
  .main { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; max-height: 45%; border-right: none; border-bottom: 1px solid var(--border); }
  .map-area { flex: 1; }
  .results { max-height: 160px; }
}

/* ----------------------------- Popup de bienvenida ------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(31, 41, 55, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 460px;
  width: 100%;
  padding: 30px 30px 26px;
  text-align: center;
  animation: pop 0.15s ease-out;
}
.modal-emoji { font-size: 40px; line-height: 1; }
.modal h2 { margin: 8px 0 6px; font-size: 22px; letter-spacing: -0.02em; }
.modal-lead { color: var(--muted); margin: 0 0 16px; font-size: 14.5px; }
.modal-list { text-align: left; margin: 0 0 22px; padding-left: 20px; }
.modal-list li { margin-bottom: 9px; line-height: 1.45; font-size: 14px; color: var(--text); }
.modal .btn { width: 100%; }

/* ----------------------------- Resumen (matriz) ---------------------------- */
.summary-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 24px;
  overflow: hidden;
}
.summary-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.summary-head h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.02em; }
.summary-sub { color: var(--muted); font-size: 13.5px; margin: 0; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--muted); cursor: pointer; user-select: none;
}
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.table-wrap {
  flex: 1; min-height: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff;
}

table.matrix { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.matrix th, table.matrix td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

/* Cabecera (usuarios) */
table.matrix thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f7f8fb; color: var(--muted); font-weight: 600;
  padding: 10px 12px; text-align: center;
}
table.matrix thead th.user span {
  display: inline-block; max-width: 150px;
  overflow: hidden; text-overflow: ellipsis; vertical-align: bottom;
}

/* Primera columna (país) fija a la izquierda */
table.matrix th.country {
  position: sticky; left: 0; z-index: 1;
  background: #fff; text-align: left; padding: 0; font-weight: 500;
}
table.matrix th.country .cc {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; min-width: 200px;
}
table.matrix th.country .flag { font-size: 16px; }
table.matrix th.country .cname { flex: 1; }
table.matrix th.country .ccode { color: var(--muted-2); font-size: 11px; font-weight: 600; }
table.matrix tbody tr:hover th.country { background: #eef2ff; }

/* Esquina superior izquierda */
table.matrix th.corner {
  position: sticky; left: 0; top: 0; z-index: 3;
  background: #eef2ff; color: var(--accent-hover);
  text-align: left; padding: 10px 12px; font-weight: 700;
}

/* Celdas de marca */
table.matrix td {
  text-align: center; padding: 8px 10px;
  color: var(--accent); font-weight: 700; min-width: 44px;
}
table.matrix td.miss { color: var(--border-strong); font-weight: 400; }
table.matrix td.hit { background: var(--accent-soft); }

/* Totales por país (columna derecha) */
table.matrix .total-col, table.matrix .row-total {
  background: #fafbff; color: var(--text); font-weight: 700; text-align: center;
}

/* Totales por usuario (fila inferior: la "suma abajo") */
table.matrix tfoot th, table.matrix tfoot td {
  position: sticky; bottom: 0; z-index: 2;
  background: #f3f4f6; color: var(--text); font-weight: 700;
  text-align: center; padding: 9px 10px;
}
table.matrix tfoot th.foot {
  left: 0; z-index: 3; background: #e0e7ff; color: var(--accent-hover); text-align: left;
}
table.matrix .grand-total { background: var(--accent-soft-2); color: var(--accent-hover); }
