/* Blucaro News — oscuro por defecto, pensado para un monitor encendido todo el día. */

:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --line: #30363d;
  --text: #e6edf3;
  --muted: #9da7b3;
  --accent: #58a6ff;
  --live: #ff6b6b;
  --ok: #3fb950;
  --warn: #d29922;
  --up: #3fb950;
  --down: #ff7b72;
  --focus: #f2cc60;
  --panel-bg: #000;
  --radius: 8px;
  --gap: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-2: #ffffff;
  --bg-3: #eaeef2;
  --line: #d0d7de;
  --text: #1f2328;
  --muted: #59636e;
  --accent: #0969da;
  --live: #cf222e;
  --ok: #1a7f37;
  --warn: #9a6700;
  --up: #1a7f37;
  --down: #cf222e;
  --focus: #9a6700;
  --panel-bg: #1f2328;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
}

a { color: var(--accent); }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 50;
  background: var(--bg-2); padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line);
}
.skip:focus { top: 8px; }

/* ---------- barra superior ---------- */

.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.brand { display: flex; align-items: baseline; gap: 8px; margin-right: auto; min-width: 0; }
.brand-mark {
  width: 14px; height: 14px; align-self: center; border-radius: 3px;
  background: linear-gradient(135deg, var(--accent) 0 60%, var(--live) 60%);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand-sub { color: var(--muted); font-size: 12px; }

.controls { display: flex; align-items: center; gap: 4px; }
.controls-label { color: var(--muted); font-size: 12px; margin-right: 4px; }
.seg, .btn, .icon-btn {
  border: 1px solid var(--line); background: var(--bg-3); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; min-height: 32px;
}
.seg { min-width: 36px; font-variant-numeric: tabular-nums; }
.seg[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.seg[aria-pressed="true"]::before { content: "✓ "; }
#theme[aria-pressed="false"] .theme-check { display: none; }
.btn:hover, .seg:hover, .icon-btn:hover { border-color: var(--accent); }
.actions { display: flex; align-items: center; gap: 6px; }
.clock { font-family: var(--mono); color: var(--muted); font-size: 13px; min-width: 9ch; text-align: right; }

/* ---------- datos (dólar / clima) ---------- */

.topbar, .databar, .layout, .footer { min-width: 0; }
.databar {
  display: flex; gap: 18px; align-items: center; padding: 4px 12px;
  border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; font-size: 13px;
  scrollbar-width: thin;
}
.data-group { display: flex; align-items: center; gap: 14px; }
.data-title { font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .6px; color: var(--muted); }
.quote { display: inline-flex; gap: 6px; align-items: baseline; }
.quote b { font-weight: 600; }
.quote .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.trend { font-size: 12px; font-weight: 600; }
.trend.up { color: var(--up); }
.trend.down { color: var(--down); }
.trend.flat { color: var(--muted); }
.stale { color: var(--warn); font-size: 12px; }

/* ---------- grilla + titulares ---------- */

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0;
}
body.news-hidden .layout { grid-template-columns: minmax(0, 1fr); }
body.news-hidden .news { display: none; }

.grid {
  --g: 2;
  display: grid; gap: var(--gap); padding: var(--gap); min-height: 0;
  grid-template-columns: repeat(var(--g), minmax(0, 1fr));
  grid-template-rows: repeat(var(--g), minmax(0, 1fr));
}
.grid:focus { outline: none; }

.panel {
  display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.panel-bar {
  display: flex; align-items: center; gap: 6px; padding: 3px 6px; min-width: 0;
  border-bottom: 1px solid var(--line); font-size: 12px;
}
.panel-bar select {
  min-width: 0; flex: 1 1 auto; max-width: 60%;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px; padding: 2px 4px; min-height: 28px;
}
.icon-btn { padding: 0 8px; min-height: 28px; min-width: 32px; }

.status { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-weight: 600; margin-left: auto; overflow: hidden; text-overflow: ellipsis; }
.status[data-state="live"] { color: var(--live); }
.status[data-state="ok"] { color: var(--ok); }
.status[data-state="error"], .status[data-state="offline"] { color: var(--warn); }
.status[data-state="loading"], .status[data-state="idle"], .status[data-state="empty"] { color: var(--muted); }
.status[data-state="live"] .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.panel-body { position: relative; background: var(--panel-bg); min-height: 0; }
.panel-body iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.panel-body audio { position: absolute; left: 12px; right: 12px; bottom: 12px; width: calc(100% - 24px); }
.audio-card {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 4px; color: #e6edf3; padding: 12px;
}
.audio-card .big { font-size: 34px; }

.fallback {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px;
  text-align: center; padding: 12px; color: #e6edf3; background: #0b0e13;
}
.fallback .title { font-size: 16px; font-weight: 700; }
.fallback .detail { color: #9da7b3; font-size: 12px; max-width: 40ch; }
.fallback .btn { background: #21262d; border-color: #30363d; color: #e6edf3; }

/* ---------- columna de titulares ---------- */

.news {
  display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0;
  border-left: 1px solid var(--line); background: var(--bg-2);
}
.news-head { padding: 8px 10px 6px; border-bottom: 1px solid var(--line); }
.news-head h2 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .6px; }
.news-filters { display: flex; gap: 8px; align-items: center; }
.news-filters select {
  flex: 1; min-width: 0; background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; min-height: 32px;
}
.check { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; white-space: nowrap; }
.news-status { margin: 6px 0 0; font-size: 12px; }
.news-status.warn { color: var(--warn); }

.news-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; scrollbar-width: thin; }
.news-item { padding: 7px 10px; border-bottom: 1px solid var(--line); }
.news-item:hover { background: var(--bg-3); }
.news-meta { display: flex; gap: 6px; align-items: baseline; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.news-src { font-weight: 700; text-transform: uppercase; letter-spacing: .3px; color: var(--text); }
.news-new { font-size: 10px; font-weight: 700; color: var(--bg); background: var(--accent); border-radius: 3px; padding: 0 4px; }
.news-item a { color: var(--text); text-decoration: none; display: block; font-size: 13.5px; line-height: 1.3; }
.news-item a:hover { color: var(--accent); text-decoration: underline; }
.news-item a::after { content: " ↗"; color: var(--muted); font-size: 11px; }
.news-summary { margin: 3px 0 0; color: var(--muted); font-size: 12px; display: none; }
.show-summaries .news-summary { display: block; }

/* ---------- pie + ticker ---------- */

.footer { border-top: 1px solid var(--line); background: var(--bg-2); }
.ticker { display: flex; align-items: stretch; height: 34px; }
.ticker-btn {
  border: 0; border-right: 1px solid var(--line); background: var(--bg-3); padding: 0 10px; cursor: pointer;
  display: inline-flex; gap: 6px; align-items: center; font-size: 12px; flex: none;
}
.ticker-viewport { position: relative; overflow: hidden; flex: 1; display: flex; align-items: center; }
.ticker-track {
  display: inline-flex; white-space: nowrap; will-change: transform;
  animation: ticker var(--ticker-dur, 120s) linear infinite;
}
.ticker:hover .ticker-track, .ticker:focus-within .ticker-track, .ticker.paused .ticker-track { animation-play-state: paused; }
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.ticker-item { padding: 0 18px 0 0; font-size: 13.5px; }
.ticker-item::after { content: "•"; color: var(--muted); padding-left: 18px; }
.ticker-item b { text-transform: uppercase; font-size: 11.5px; letter-spacing: .3px; color: var(--accent); margin-right: 6px; }
.ticker-item a { color: var(--text); text-decoration: none; }
.ticker-item a:hover { text-decoration: underline; }

.footer-links { display: flex; gap: 14px; padding: 3px 12px; font-size: 11.5px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); padding: 8px 14px; border-radius: var(--radius); opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 40;
}
.toast.show { opacity: 1; }
.noscript { padding: 16px; }

@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation: none !important; }
  .ticker-viewport { overflow-x: auto; }
  .status[data-state="live"] .dot { animation: none; }
  .toast { transition: none; }
}

/* ---------- celular: un solo panel con selector ---------- */

@media (max-width: 820px) {
  body { height: auto; min-height: 100dvh; overflow: auto; grid-template-rows: auto auto auto auto; }
  .topbar { padding: 6px 10px; gap: 8px; }
  .brand-sub, .controls, #toggle-news, .clock { display: none; }
  .layout { grid-template-columns: 1fr; }
  .grid { --g: 1 !important; grid-template-rows: auto; padding: 6px; }
  .panel-body { aspect-ratio: 16 / 9; }
  .panel-bar select { max-width: none; }
  .news { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  body.news-hidden .news { display: grid; }
  .news-list { max-height: none; overflow: visible; }
  .footer { position: sticky; bottom: 0; }
  .footer-links { padding-bottom: calc(3px + env(safe-area-inset-bottom)); }
}
