:root {
  --bg: #0b0e14;
  --panel: #131722;
  --panel-2: #171c29;
  --border: #232a3b;
  --text: #e7ebf3;
  --muted: #8b93a7;
  --accent: #f7931a;
  --green: #16c784;
  --red: #ea3943;
  --blue: #4f8cff;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1a2033 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  /* Red de contención: ningún tooltip cerca del borde puede generar scroll lateral.
     "clip" no crea contexto de scroll (a diferencia de "hidden"). */
  overflow-x: clip;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-size: 34px;
  color: var(--accent);
  background: rgba(247, 147, 26, 0.12);
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.asset-switch {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.asset-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.asset-btn.active { background: var(--accent); color: #17130a; }

.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(255,255,255,0.4);
}
.dot.live { background: var(--green); animation: pulse 1.6s infinite; }
.dot.error { background: var(--red); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22,199,132,0.5); }
  70% { box-shadow: 0 0 0 8px rgba(22,199,132,0); }
  100% { box-shadow: 0 0 0 0 rgba(22,199,132,0); }
}

.ticker-row {
  display: grid;
  grid-template-columns: 1.4fr repeat(5, 1fr);
  gap: 12px;
}

.ticker-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.price-card { background: linear-gradient(135deg, #1c2233, #171c29); border-color: rgba(247,147,26,0.35); }

.ticker-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ticker-value { font-size: 26px; font-weight: 700; }
.ticker-value.small { font-size: 17px; font-weight: 600; }
.ticker-sub { font-size: 13px; font-weight: 600; color: var(--muted); }
.ticker-sub.up { color: var(--green); }
.ticker-sub.down { color: var(--red); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.panel h2 { margin: 0 0 14px; font-size: 16px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-header h2 { margin: 0; }

.chart-controls { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.btn:hover { color: var(--text); }
.btn.active { background: var(--accent); color: #17130a; border-color: var(--accent); font-weight: 700; }

.chart-wrap { position: relative; height: 380px; }
.chart-wrap.small { height: 260px; }

.chart-note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.stat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stat-table td { padding: 9px 4px; border-bottom: 1px solid var(--border); }
.stat-table td:first-child { color: var(--muted); }
.stat-table td:last-child { text-align: right; font-weight: 600; }
.stat-table tr:last-child td { border-bottom: none; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.audit-box { display: flex; flex-direction: column; gap: 10px; font-size: 14px; line-height: 1.55; }
.audit-box p { margin: 0; }
.audit-box .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 6px;
  margin-right: 8px;
}
.tag.bull { background: rgba(22,199,132,0.15); color: var(--green); }
.tag.bear { background: rgba(234,57,67,0.15); color: var(--red); }
.tag.neutral { background: rgba(79,140,255,0.15); color: var(--blue); }
.tag.warn { background: rgba(215,194,74,0.15); color: #d7c24a; }
.muted { color: var(--muted); }

.src-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}

/* ---- Pills de zona (on-chain, derivados, sentimiento) ---- */
.pill.tone-bull { background: rgba(22,199,132,0.15); color: var(--green); }
.pill.tone-bear { background: rgba(234,57,67,0.15); color: var(--red); }
.pill.tone-neutral { background: rgba(79,140,255,0.15); color: var(--blue); }
.pill.tone-warn { background: rgba(215,194,74,0.15); color: #d7c24a; }
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.zone-badge {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.zone-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Derivados ---- */
.deriv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.deriv-stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.d-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.d-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Salud de red ---- */
.net-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.net-stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.n-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.n-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.n-sub { font-size: 11px; color: var(--muted); }

/* ---- Score de tensión de ciclo ---- */
.tension-box { margin-bottom: 22px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.tension-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.tension-score {
  font-size: 42px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tension-score span { font-size: 18px; color: var(--muted); font-weight: 600; }

.gauge-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(to right, #4f8cff, #16c784, #d7c24a, #ea3943);
  margin: 6px 0 6px;
}
.gauge-marker {
  position: absolute;
  top: -4px;
  width: 3px;
  height: 18px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-1.5px);
  box-shadow: 0 0 4px rgba(0,0,0,0.6);
}
.gauge-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 16px;
}

.tension-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.tension-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  background: var(--panel-2);
  border-radius: 8px;
}
.tr-name { font-weight: 600; }
.tr-raw { color: var(--muted); font-variant-numeric: tabular-nums; }
.tr-pull { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.tr-pull.up { color: var(--red); }
.tr-pull.down { color: var(--green); }

/* ---- Formulario de alertas ---- */
.channel-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin: 14px 0 18px;
  padding: 16px 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}
.channel-cta-text { flex: 1; min-width: 260px; }
.channel-cta-text strong { display: block; margin-bottom: 4px; font-size: 14px; }
.channel-cta-text p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.channel-cta-btn { white-space: nowrap; text-decoration: none; }

.alert-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 6px;
}
.alert-form input, .alert-form select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.alert-form input[type="email"] { flex: 2; min-width: 200px; }
.alert-form input[type="number"] { width: 110px; }
.btn-primary {
  background: var(--accent);
  color: #17130a;
  border-color: var(--accent);
  font-weight: 700;
}
.turnstile-slot:empty { display: none; }
.cooldown-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.cooldown-wrap input[type="number"] { width: 70px; }
.cooldown-wrap[hidden] { display: none; }
.alert-advanced { flex-basis: 100%; margin-top: 4px; }
.alert-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 0;
}
.alert-advanced summary:hover { color: var(--text); }
.alert-advanced .alert-form { margin: 8px 0 0; }
.alert-advanced input[type="url"] { flex: 1; min-width: 260px; }
.alert-form select[hidden] { display: none; }

/* ---- Glosario: ícono de info con tooltip ---- */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  margin-left: 6px;
  cursor: help;
  position: relative;
  vertical-align: middle;
}
.info-icon:hover, .info-icon:focus {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
}
/* El tooltip usa display:none en reposo. Con visibility:hidden seguía ocupando
   240px de ancho y ampliaba el área scrollable, provocando scroll horizontal
   de toda la página en pantallas angostas. */
.info-icon::after {
  content: attr(data-tooltip);
  display: none;
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  max-width: min(240px, calc(100vw - 32px));
  background: #0a0d13;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  text-align: left;
  z-index: 20;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.info-icon:hover::after, .info-icon:focus::after {
  display: block;
}

/* ---- Exportar informe / impresión ---- */
@media print {
  body { background: #fff !important; }
  .header-actions, .ad-slot, .affiliate-panel, .chart-controls,
  .footer .src-tag, #exportPdfBtn { display: none !important; }
  .app { max-width: 100%; padding: 0; }
  .panel, .grid-2 > .panel, section.panel {
    break-inside: avoid;
    border: 1px solid #ccc !important;
    background: #fff !important;
  }
  :root {
    --bg: #fff; --panel: #fff; --panel-2: #f4f4f4; --border: #ccc; --text: #111; --muted: #555;
  }
  .chart-wrap { height: 260px !important; }
  .info-icon::after { display: none; }
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-left: 2px solid var(--border);
  margin-left: 8px;
  padding-left: 20px;
}
.timeline-item { position: relative; padding: 10px 0; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -26px;
  top: 16px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
.timeline-date { font-size: 12px; color: var(--accent); font-weight: 700; }
.timeline-text { font-size: 14px; margin-top: 2px; }

.footer { color: var(--muted); font-size: 12px; text-align: center; line-height: 1.6; }

.ad-slot {
  display: none;
  min-height: 90px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
}
.ad-slot.ready { display: flex; background: var(--panel); }

.affiliate-disclosure { color: var(--muted); font-size: 12px; margin: -6px 0 14px; }

.affiliate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.affiliate-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.affiliate-card h3 { margin: 0; font-size: 16px; }
.affiliate-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; flex: 1; }
.affiliate-card .btn-cta {
  display: inline-block;
  text-align: center;
  background: var(--accent);
  color: #17130a;
  font-weight: 700;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 8px;
  text-decoration: none;
}
.affiliate-card .btn-cta:hover { filter: brightness(1.08); }
.affiliate-empty { color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .ticker-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
