/*!
 * FreeAnalytics — estilos del panel
 * Paleta: tinta #14171F, índigo #3B4CCA, naranja #E07A1F, fondo #F4F5F8.
 * Tipografía del sistema (sin cargar fuentes externas: más rápido y más privado).
 */

:root {
  --ink: #14171F;
  --ink-2: #3F4553;
  --muted: #5B6170;
  --line: #E3E6EC;
  --line-2: #EEF0F4;
  --bg: #F4F5F8;
  --card: #FFFFFF;
  --accent: #3B4CCA;
  --accent-soft: #EEF0FB;
  --accent-2: #AEB6F0;
  --orange: #E07A1F;
  --green: #2BA36F;
  --radius: 14px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: #2F3DB0; }
a:hover { color: #1E2880; }
h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 16px; font-weight: 700; }
h3 { margin: 18px 0 10px; font-size: 14px; font-weight: 700; }
code { font-family: var(--mono); font-size: 12px; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid #8F9AE8; outline-offset: 2px; }

/* Utilidades ---------------------------------------------------------------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.mono { font-family: var(--mono); }
.path { color: #2F3DB0; font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.grow-1 { flex: 1; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1360px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* Marca --------------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-size: 18px; letter-spacing: -0.01em; }
.brand b { font-weight: 800; }
.brand span { font-weight: 500; }
.brand:hover { color: inherit; }
.brand-lg { font-size: 22px; margin-bottom: 18px; }

/* Botones y formularios ----------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:hover { background: #2F3DB0; color: #fff; }
.btn-ghost {
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid #DDE0E7;
  background: #fff; color: var(--ink); font-weight: 600; cursor: pointer;
}
.btn-ghost:hover { background: #F7F8FA; }
.btn-ghost.danger { color: #A52A1A; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
input:not([type=hidden]), select {
  min-height: 44px; padding: 0 12px; border: 1px solid #DDE0E7; border-radius: 10px;
  background: #fff; color: var(--ink); font-weight: 400;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px #DDE1FA; }

/* Mensajes ------------------------------------------------------------------ */
.ok, .err, .warn, .flash { border-radius: 10px; padding: 10px 14px; margin: 0; }
.ok { background: #E3F4EC; color: #17704F; }
.err { background: #FDE8E5; color: #A52A1A; }
.warn { background: #FFF4E6; color: #7A3E0A; }

/* Login e instalador -------------------------------------------------------- */
body.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 10px 30px rgba(20, 23, 31, .06);
}
.auth-card h1 { font-size: 22px; }
.auth-card p { margin: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }

/* Cabecera del panel -------------------------------------------------------- */
.top { background: var(--ink); color: #F4F5F8; }
.top-in { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; padding-top: 10px; padding-bottom: 10px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.nav a { color: #C9CEDA; text-decoration: none; font-weight: 600; padding: 0 12px; min-height: 44px; display: inline-flex; align-items: center; border-radius: 8px; }
.nav a:hover { background: #2A2F3D; color: #fff; }
.live { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; background: #1F3A2F; color: #BFF0D6; font-weight: 600; font-size: 13px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #3CCB8B; box-shadow: 0 0 0 4px rgba(60, 203, 139, .25); }
.logout { margin: 0; }
.logout .btn-ghost { background: transparent; color: #C9CEDA; border-color: #3A4050; }
.logout .btn-ghost:hover { background: #2A2F3D; color: #fff; }

/* Estructura ---------------------------------------------------------------- */
.main { display: flex; flex-direction: column; gap: 20px; padding-top: 24px; padding-bottom: 56px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.toolbar p { margin: 4px 0 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; }
.filters select { min-width: 200px; font-weight: 600; }
.seg { display: flex; flex-wrap: wrap; gap: 2px; background: #fff; border: 1px solid #DDE0E7; border-radius: 12px; padding: 3px; }
.seg button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.row { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card.grow { flex: 999 1 600px; }
.card.side { flex: 1 1 340px; }
.card.half { flex: 1 1 420px; }
.card.flush { padding: 20px 0 8px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-head.pad { padding: 0 20px 14px; align-items: center; }
.card-head p, .card > p { margin: 4px 0 0; }

/* Indicadores --------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.delta { font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.delta.up { background: #E3F4EC; color: #17704F; }
.delta.down { background: #FCEBDC; color: #9A4508; }
.delta.flat { background: #ECEEF2; color: var(--ink-2); }

/* Gráfico ------------------------------------------------------------------- */
.legend { display: flex; gap: 16px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.sw-a { background: var(--accent); }
.sw-b { background: var(--accent-2); }
.chart { display: grid; grid-template-columns: 48px 1fr; column-gap: 10px; margin-top: 20px; }
.y-axis { position: relative; height: 240px; font: 11px var(--mono); color: var(--muted); text-align: right; }
.y-axis span { position: absolute; right: 0; transform: translateY(-50%); }
.y-top { top: 0; }
.y-mid { top: 50%; }
.y-zero { top: 100%; }
.plot { position: relative; height: 240px; border-bottom: 1px solid #C9CEDA; }
.grid-top, .grid-mid { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); }
.grid-top { top: 0; }
.grid-mid { top: 50%; }
.cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 3px; }
.col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; padding: 0 1px; border: 0; border-radius: 6px 6px 0 0; background: transparent; cursor: pointer; }
.col:hover, .col.on { background: var(--accent-soft); }
.b-a, .b-b { width: 45%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 0; }
.b-a { background: var(--accent); }
.b-b { background: var(--accent-2); }
.x-labels { grid-column: 2; display: flex; gap: 3px; margin-top: 8px; }
.x-labels span { flex: 1; min-width: 0; text-align: center; font: 11px var(--mono); color: var(--muted); white-space: nowrap; overflow: visible; }

/* Listas con barra (orígenes, países, páginas) ------------------------------ */
.stack { display: flex; gap: 2px; height: 14px; border-radius: 999px; overflow: hidden; margin: 14px 0 6px; }
.li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.li:last-child { border-bottom: 0; }
.li-name { flex: 1; min-width: 0; font-weight: 600; }
.li-num { width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
.li-pct { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.li-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.li-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.track { height: 6px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 999px; }
.fill-b { background: var(--orange); }
#countries, #pages { margin-top: 10px; }

.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; align-self: flex-start; }
.t-search { background: #E7E9FA; color: #2F3DB0; }
.t-social { background: #FCEBDC; color: #9A4508; }
.t-ref { background: #DDF1EE; color: #1D6B62; }
.t-camp { background: #F1E6FB; color: #6B2FA8; }
.t-direct { background: #ECEEF2; color: var(--ink-2); }

/* Banderas ------------------------------------------------------------------ */
.flag { display: inline-block; width: 24px; height: 16px; border-radius: 3px; overflow: hidden; background: #DDE0E7; box-shadow: 0 0 0 1px rgba(20, 23, 31, .12); flex: none; }
.flag img { display: block; width: 100%; height: 100%; object-fit: cover; }
.flag-sm { width: 18px; height: 12px; border-radius: 2px; }
.flag-lg { width: 42px; height: 28px; border-radius: 4px; }

/* Tabla de visitantes ------------------------------------------------------- */
.search input { min-width: 240px; }
.table-box { overflow-x: auto; }
.vt { width: 100%; min-width: 1000px; border-collapse: collapse; }
.vt th { font-size: 12px; font-weight: 700; color: var(--muted); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FAFBFC; white-space: nowrap; }
.vt td { padding: 6px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; white-space: nowrap; }
.vt tr.sel td { background: var(--accent-soft); }
.vt tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.who { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0; border: 0; background: none; color: var(--ink); text-align: left; cursor: pointer; }
.who:hover .mono { text-decoration: underline; }
.who-txt { display: flex; flex-direction: column; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #C9CEDA; flex: none; }
.dot.on { background: var(--green); }
.cell { display: flex; align-items: center; gap: 8px; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px 6px; }
.chips { display: flex; align-items: center; gap: 4px; }
.chip { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: #F1F2F6; color: var(--ink-2); }

/* Ficha del visitante ------------------------------------------------------- */
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 14px; }
.det-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.det-id { font-size: 18px; font-weight: 600; }
.pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-on { background: #E3F4EC; color: #17704F; }
.pill-off { background: #ECEEF2; color: var(--ink-2); }
.facts-grid { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.facts-grid dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.facts-grid dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.journey { list-style: none; margin: 0; padding: 0; }
.journey li { position: relative; display: flex; justify-content: space-between; gap: 8px; padding: 0 0 12px 22px; }
.journey li::before { content: ""; position: absolute; left: 0; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.journey li::after { content: ""; position: absolute; left: 4px; top: 17px; bottom: 0; width: 2px; background: #DDE0E7; }
.journey li:last-child::after { display: none; }
.journey li.now::before { background: var(--green); box-shadow: 0 0 0 4px rgba(43, 163, 111, .2); }
.j-txt { display: flex; flex-direction: column; min-width: 0; }
.history .h-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--line-2); font-size: 13px; }

/* Ajustes ------------------------------------------------------------------- */
.site { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 0; border-bottom: 1px solid var(--line-2); }
.site form { margin: 0; }
.status { font-size: 12px; font-weight: 700; margin-top: 2px; }
.ok-txt { color: #17704F; }
.warn-txt { color: #9A4508; }
.link-btn { display: inline-flex; align-items: center; text-decoration: none; }
.checks { list-style: none; margin: 16px 0 0; padding: 0; }
.checks li { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.check-ico { width: 22px; height: 22px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; color: #fff; }
.check-ok .check-ico { background: var(--green); }
.check-aviso .check-ico { background: var(--orange); }
.check-error .check-ico { background: #D64545; }
.site-info { display: flex; flex-direction: column; min-width: 180px; }
.snippet { flex: 1 1 380px; min-width: 0; background: var(--ink); color: #E6E8EE; border-radius: 10px; padding: 12px 14px; overflow-x: auto; white-space: nowrap; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-top: 16px; }
.inline-form label { flex: 1 1 200px; }
.stack-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.stack-form .btn { align-self: flex-start; }
.facts { list-style: none; margin: 12px 0 0; padding: 0; }
.facts li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.foot { text-align: center; margin: 0; }

/* Móvil --------------------------------------------------------------------- */
@media (max-width: 640px) {
  h1 { font-size: 24px; }
  .filters, .filters select, .seg { width: 100%; }
  .seg button { flex: 1; padding: 0 8px; }
  .search, .search input { width: 100%; min-width: 0; }
  .chart { grid-template-columns: 36px 1fr; }
  .card.grow, .card.side, .card.half { flex-basis: 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 24px; }
}
