:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #1a232e;
  --line: #233040;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #2fd27a;
  --red: #ff4d4f;
  --orange: #ff9f2e;
  --yellow: #f5d142;
  --gray: #5b6b7e;
  --gold: #e8b923;
  --nq: #4da3ff;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-top: calc(84px + var(--safe-top));
  padding-bottom: calc(64px + var(--safe-bottom));
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.top {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; row-gap: 4px;
  background: rgba(11, 15, 20, 0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: 0.2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gray); }
.dot.live { background: var(--accent); box-shadow: 0 0 0 0 rgba(47, 210, 122, 0.6); animation: pulse 2s infinite; }
.dot.error { background: var(--red); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47,210,122,.6); } 70% { box-shadow: 0 0 0 8px rgba(47,210,122,0); } 100% { box-shadow: 0 0 0 0 rgba(47,210,122,0); } }
.updated { color: var(--muted); font-size: 12px; }

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; scrollbar-width: none;
  position: sticky; top: calc(84px + var(--safe-top)); z-index: 5; background: var(--bg);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: var(--muted);
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

.feed { list-style: none; margin: 0; padding: 0 12px; }
.item {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px 10px 16px; margin-bottom: 8px; overflow: hidden;
}
.item::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--gray); }
.item.i5::before { background: var(--red); }
.item.i4::before { background: var(--orange); }
.item.i3::before { background: var(--yellow); }
.item.fresh { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: #213246; } to { background: var(--panel); } }
.item.context { background: transparent; }
.item .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 5px; align-items: center; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 5px; background: var(--panel-2); color: var(--muted); letter-spacing: .3px; }
.tag.NQ { color: var(--nq); background: rgba(77,163,255,.12); }
.tag.GOLD { color: var(--gold); background: rgba(232,185,35,.12); }
.tag.trump { color: #ff7a7a; background: rgba(255,77,79,.12); }
.tag.imp { margin-left: auto; }
.tag.imp.i5 { color: var(--red); }
.tag.imp.i4 { color: var(--orange); }
.item h4 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.35; }
.item.context h4 { font-weight: 500; color: #c9d4e0; }
.item .why { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.item .meta { margin-top: 6px; color: var(--muted); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.item .details { display: none; margin-top: 8px; font-size: 14px; color: #c9d4e0; }
.item.open .details { display: block; }
.item .details a { display: inline-block; margin-top: 8px; color: var(--accent); text-decoration: none; font-weight: 600; }
.feed-end { text-align: center; color: var(--muted); padding: 18px; font-size: 13px; }

.new-pill {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(136px + var(--safe-top)); z-index: 20;
  background: var(--accent); color: #04130a; border: 0; border-radius: 999px; padding: 7px 14px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

.next-event { margin: 12px; padding: 14px; border-radius: 12px; background: linear-gradient(135deg, #2a1416, #1a1012); border: 1px solid #5a2326; }
.next-event .label { color: #ff9a9c; font-size: 12px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.next-event .title { font-size: 17px; font-weight: 700; margin: 4px 0; }
.next-event .count { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.day { padding: 0 12px; margin-bottom: 14px; }
.day h3 { font-size: 13px; color: var(--muted); margin: 10px 4px 6px; }
.day h3::first-letter { text-transform: uppercase; }
.day.today h3 { color: var(--accent); }
.ev { display: grid; grid-template-columns: 52px 44px 1fr; gap: 8px; align-items: center; padding: 9px 10px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 14px; }
.ev:first-of-type { border-radius: 10px 10px 0 0; }
.ev:last-child { border-radius: 0 0 10px 10px; border-bottom: 0; }
.ev:only-of-type { border-radius: 10px; }
.ev.past { opacity: .45; }
.ev .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.ev .cur { font-weight: 700; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.ev .cur::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--gray); }
.ev.High .cur::before { background: var(--red); }
.ev.Medium .cur::before { background: var(--orange); }
.ev.Low .cur::before { background: var(--yellow); }
.ev.Holiday { background: #18202a; }
.ev.Holiday .cur::before { background: #8b9bb0; }
.ev .fc { color: var(--muted); font-size: 12px; }

.view .card { margin: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.card h3 { margin: 4px 0 10px; font-size: 15px; }
.card h3:not(:first-child) { margin-top: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 15px; }
.row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.countries { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.countries label { font-size: 12px; background: var(--panel-2); padding: 4px 8px; border-radius: 6px; display: flex; gap: 4px; align-items: center; }
.btn { display: block; width: 100%; margin-top: 10px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; }
.btn.primary { background: var(--accent); color: #04130a; border-color: var(--accent); }
.btn:disabled { opacity: .5; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sources { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.sources li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.sources .ok { color: var(--accent); }
.sources .bad { color: var(--red); }

.gate { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.gate-box { width: 100%; max-width: 340px; }
.gate input { width: 100%; padding: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 16px; }
.error { color: var(--red); font-size: 13px; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: flex;
  padding-bottom: var(--safe-bottom); background: rgba(11,15,20,.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--muted); text-decoration: none; font-size: 11px; }
.tabs a span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs a.active { color: var(--text); }
.tabs a.active span { filter: none; opacity: 1; }

@media (min-width: 720px) {
  main, .chips { max-width: 680px; margin: 0 auto; }
}

/* ---- precios en vivo ---- */
.ticker { flex-basis: 100%; display: flex; gap: 14px; font-size: 13px; font-variant-numeric: tabular-nums; min-height: 20px; }
.ticker .px { display: flex; gap: 6px; align-items: baseline; }
.ticker .sym { font-weight: 800; font-size: 12px; }
.ticker .sym.NQ { color: var(--nq); }
.ticker .sym.GOLD { color: var(--gold); }
.ticker .up { color: var(--accent); }
.ticker .down { color: var(--red); }
.ticker .stale { color: var(--muted); font-size: 11px; }

/* ---- tarjeta Hoy ---- */
.today { margin: 0 12px 10px; padding: 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.today .t-row { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.today .t-row + .t-row { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.today .t-ico { flex: none; width: 20px; text-align: center; }
.today a { color: inherit; text-decoration: none; display: contents; }
.today .count { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- banner de última hora ---- */
.breaking { position: sticky; top: calc(136px + var(--safe-top)); z-index: 6; margin: 0 12px 10px; padding: 11px 12px; border-radius: 12px;
  background: linear-gradient(135deg, #5c1215, #3a0d0f); border: 1px solid #a3262b; box-shadow: 0 6px 18px rgba(0,0,0,.45); }
.breaking .b-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; font-weight: 800; letter-spacing: .5px; color: #ffb3b5; }
.breaking .b-head button { background: none; border: 0; color: #ffb3b5; font-size: 16px; padding: 0 2px; }
.breaking .b-title { font-weight: 700; margin-top: 4px; }
.breaking .b-why { font-size: 13px; color: #ffd6d7; margin-top: 3px; }
.breaking a { color: inherit; text-decoration: none; }

/* ---- leyenda ---- */
.legend { margin: 0 12px 10px; padding: 12px; border-radius: 12px; background: #10202f; border: 1px solid #24435e; font-size: 13px; }
.legend-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.legend-head button { background: none; border: 0; color: var(--muted); font-size: 16px; }
.legend-row { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.legend .bar { width: 4px; height: 16px; border-radius: 2px; background: var(--gray); }
.legend .bar.i5 { background: var(--red); } .legend .bar.i4 { background: var(--orange); } .legend .bar.i3 { background: var(--yellow); }
.legend .dots { font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.legend .dots.i5 { color: var(--red); } .legend .dots.i4 { color: var(--orange); }

/* ---- bajar para actualizar ---- */
.ptr { text-align: center; color: var(--muted); font-size: 13px; height: 0; overflow: hidden; transition: height .15s; }
.ptr.show { height: 34px; line-height: 34px; }

.advanced summary { font-weight: 600; cursor: pointer; }
.advanced[open] summary { margin-bottom: 8px; }
.feed-end .retry { display: inline-block; margin-top: 8px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
