/* Base compartida: tokens, layout móvil tipo app (iPhone), componentes y gráficos.
   Cada app puede sobrescribir --accent, --c1, --c2 en su propio CSS. */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f6f6f9;
  --text: #111114;
  --muted: #6c6c75;
  --line: #e3e3ea;
  --grid: #e6e6ee;
  --accent: #0a84ff;
  --c1: #0a84ff;
  --c2: #ff7a1a;
  --good: #1f9d55;
  --warn: #d4a106;
  --bad: #d64545;
  --radius: 14px;
  --gutter: 16px;
  --topbar-h: 52px;
  --tabbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --surface: #1c1c1e; --surface-2: #2a2a2d; --text: #f2f2f7; --muted: #9a9aa3;
    --line: #2f2f33; --grid: #2c2c30; --c1: #3d9bff; --c2: #ff9640; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1c1c1e; --surface-2: #2a2a2d; --text: #f2f2f7; --muted: #9a9aa3;
  --line: #2f2f33; --grid: #2c2c30; --c1: #3d9bff; --c2: #ff9640; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button, select { font: inherit; color: inherit; }
img { display: inline-block; }
small { font-size: 12px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 4px 14px; }
.hint a { color: var(--accent); }
.sub { color: var(--muted); margin: 0 4px 10px; font-size: 13px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--gutter) 0;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
}
.topbar .home { flex: none; display: flex; }
.topbar .home img { width: 32px; height: 32px; border-radius: 9px; display: block; }
.topbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view {
  max-width: 720px; margin: 0 auto;
  padding: 12px var(--gutter) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 10.5px; }
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 10px;
  background: var(--surface); color: var(--accent); font-weight: 600; cursor: pointer;
}
.btn.icon { width: 36px; padding: 0; font-size: 22px; line-height: 1; }
.btn.ghost { background: transparent; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--accent); font-size: 12px; font-weight: 600; }
.select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: 38px;
  padding: 6px 30px 6px 12px; border: 0.5px solid var(--line); border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238e8e93' fill='none' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 11px center;
  font-size: 16px; /* evita el zoom automático de iOS */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.select.compact { width: auto; max-width: 52%; min-height: 32px; font-size: 15px; font-weight: 600; }
.seg { display: flex; gap: 2px; padding: 2px; margin-bottom: 12px; border-radius: 10px; background: var(--surface-2); }
.seg button, .seg a { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 32px; padding: 0 4px; border: 0; border-radius: 8px; background: transparent; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button.on, .seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.btn.block { display: flex; width: 100%; margin: 4px 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 0; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--on-accent, #fff); }
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--accent); color: var(--on-accent, #fff); white-space: nowrap; }
.badge.zero { background: var(--surface-2); color: var(--muted); }
.card > h2 .badge { margin-left: 6px; vertical-align: 2px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.checks label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checks input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- contenedores ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; overflow: hidden; }
.card > h2 { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.card details, details.card summary { cursor: pointer; }
details.card summary { font-weight: 600; }
details.card p { color: var(--muted); font-size: 13.5px; }
.list > * + * { border-top: 0.5px solid var(--line); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.kpis > div { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.kpis b { font-size: 20px; font-variant-numeric: tabular-nums; }
.kpis small { color: var(--muted); }

.state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 48px 16px; color: var(--muted); text-align: center; }
.state.error small { max-width: 280px; word-break: break-word; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tablas ---------- */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.table th { font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 4px 3px 6px; text-align: center; }
.table td { padding: 7px 3px; text-align: center; border-top: 0.5px solid var(--line); }
.table .l { text-align: left; }

/* ---------- gráficos ---------- */
.vs-row { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; row-gap: 4px; padding: 6px 0; }
.vs-row + .vs-row { border-top: 0.5px solid var(--line); }
.vs-a { text-align: left; font-variant-numeric: tabular-nums; color: var(--muted); }
.vs-b { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.vs-a.win, .vs-b.win { color: var(--text); font-weight: 700; }
.vs-label { text-align: center; font-size: 13px; color: var(--muted); }
.vs-bar { grid-column: 1 / -1; display: flex; gap: 3px; height: 6px; }
.vs-bar i { display: block; border-radius: 3px; min-width: 2px; }
.vs-bar i:first-child { background: var(--c1); }
.vs-bar i:last-child { background: var(--c2); }

.stack { display: flex; gap: 2px; height: 26px; margin: 8px 0; border-radius: 8px; overflow: hidden; }
.stack i { display: flex; align-items: center; justify-content: center; min-width: 2px; font-style: normal; font-size: 12px; color: #fff; }
.stack i b { font-weight: 700; }

.rank { list-style: none; margin: 0; padding: 0; }
.rank li + li { border-top: 0.5px solid var(--line); }
.rank-item { display: grid; grid-template-columns: 18px 22px minmax(0, 1fr) 60px 42px; align-items: center; gap: 8px; padding: 7px 0; }
.rank-n { color: var(--muted); font-size: 12px; text-align: right; }
.rank-name { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-name small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.rank-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: var(--c1); border-radius: 3px; }
.rank b { text-align: right; font-variant-numeric: tabular-nums; }

.chart { margin: 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid.dash { stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .axis.q { font-weight: 600; opacity: .8; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.heatmap { width: 100%; border-collapse: separate; border-spacing: 3px; font-size: 12px; font-variant-numeric: tabular-nums; }
.heatmap th { color: var(--muted); font-weight: 600; font-size: 11px; }
.heatmap .hm-corner { font-size: 9.5px; white-space: nowrap; }
.heatmap td {
  height: 34px; text-align: center; border-radius: 6px;
  background: color-mix(in srgb, var(--accent) calc(var(--o) * 85%), var(--surface-2));
}

/* ---------- selector de skins (Ajustes) ---------- */
.skin-cat { margin: 12px 0 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.skin-cat:first-of-type { margin-top: 0; }
.skins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.skin-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border: 2px solid transparent; border-radius: 12px; background: var(--surface-2); font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--text); }
.skin-opt.on { border-color: var(--accent); }
.skin-opt i { display: flex; width: 44px; height: 22px; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.skin-opt i b { flex: 1; }

/* ---------- filtros, resúmenes y ajustes (comunes a las apps) ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.filters-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.filters-row.end { justify-content: flex-end; margin-bottom: 10px; }
.minodds { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.minodds .select { width: auto; min-width: 82px; }
.summary { margin: 0 4px 10px; font-size: 14px; color: var(--muted); }
.summary b { color: var(--text); }
.tier-title { display: flex; align-items: center; gap: 6px; margin: 16px 4px 8px; font-size: 15px; font-weight: 700; }
.tier-title small { font-weight: 500; color: var(--muted); }

.settings { display: flex; flex-direction: column; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 0.5px solid var(--line); }
.set-row:first-child { border-top: 0; }
.set-row > span { display: flex; flex-direction: column; min-width: 0; }
.set-row small { color: var(--muted); font-size: 12px; }
.set-row .select { flex: none; width: auto; min-width: 104px; max-width: 46%; }

/* ---------- Capi con bocadillo (cabeceras) ---------- */
.hello { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; }
.hello svg { flex: none; }
.bubble { position: relative; flex: 1; padding: 10px 12px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.bubble::before { content: ""; position: absolute; left: -7px; top: 20px; border: 7px solid transparent; border-left: 0; border-right-color: var(--surface); }
.bubble b { display: block; font-size: 16px; }
.bubble small { color: var(--muted); font-size: 12.5px; }
