:root {
  --bg: #f6f7f9; --card: #ffffff; --card2: #f1f3f6; --line: #e3e6eb;
  --tx: #111418; --tx2: #5b6470; --tx3: #8a929c;
  --acc: #16a34a; --acc-tx: #ffffff; --acc-soft: #dcfce7;
  --warn: #b45309; --warn-soft: #fef3c7; --bad: #dc2626; --bad-soft: #fee2e2;
  --blue: #2563eb; --blue-soft: #dbeafe;
  --r: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d10; --card: #15181d; --card2: #1c2027; --line: #262b33;
    --tx: #eef0f3; --tx2: #a3abb6; --tx3: #6f7884;
    --acc: #22c55e; --acc-tx: #04150a; --acc-soft: #0f2a19;
    --warn: #f59e0b; --warn-soft: #2b1f08; --bad: #f87171; --bad-soft: #2c1212;
    --blue: #60a5fa; --blue-soft: #0f1d33; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d10; --card: #15181d; --card2: #1c2027; --line: #262b33;
  --tx: #eef0f3; --tx2: #a3abb6; --tx3: #6f7884;
  --acc: #22c55e; --acc-tx: #04150a; --acc-soft: #0f2a19;
  --warn: #f59e0b; --warn-soft: #2b1f08; --bad: #f87171; --bad-soft: #2c1212;
  --blue: #60a5fa; --blue-soft: #0f1d33; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--tx);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* encabezado */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 12px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.brand-title { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--tx2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--tx3); flex: none; }
.dot.on { background: var(--acc); box-shadow: 0 0 0 0 var(--acc); animation: pulse 2s infinite; }
.dot.warn { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--acc) 60%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.kpis { display: flex; gap: 14px; text-align: right; flex: none; }
.kpi b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--tx3); }
.pos { color: var(--acc); } .neg { color: var(--bad); }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px; }
.tab > h2, .sec-title { font-size: 13px; font-weight: 600; color: var(--tx2); text-transform: uppercase;
  letter-spacing: .04em; margin: 18px 4px 8px; }
.tab > h2:first-child, .sec-title:first-child { margin-top: 4px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.muted { color: var(--tx2); } .small { font-size: 13px; } .tiny { font-size: 12px; color: var(--tx3); }

/* tarjetas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 10px; }
.card.senal { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc) inset, var(--shadow); }
.card.dim { opacity: .62; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.meta { font-size: 12px; color: var(--tx2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.title { font-weight: 600; margin: 2px 0 0; }
.score { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.prob { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }
.prob small { font-size: 12px; color: var(--tx2); font-weight: 500; display: block; text-align: right; margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 12px;
  font-weight: 600; background: var(--card2); color: var(--tx2); white-space: nowrap; }
.pill.ok { background: var(--acc-soft); color: var(--acc); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.bar { height: 6px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--acc); border-radius: 99px; }
.outs { display: flex; gap: 6px; margin-top: 10px; }
.out { flex: 1; background: var(--card2); border-radius: 10px; padding: 6px 8px; min-width: 0; }
.out.top { background: var(--acc-soft); }
.out span { display: block; font-size: 11px; color: var(--tx2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.out b { font-variant-numeric: tabular-nums; }
.checks { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; font-size: 13px; }
.checks li { display: flex; gap: 6px; } .checks li.no { color: var(--tx2); }
.factors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.factor { background: var(--card2); border-radius: 10px; padding: 6px 8px; }
.factor span { display: block; font-size: 11px; color: var(--tx3); }
.factor b { font-variant-numeric: tabular-nums; font-size: 14px; }
.factor.ok b { color: var(--acc); } .factor.no b { color: var(--bad); }
.spark { width: 100%; height: 44px; display: block; margin-top: 10px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
details > summary { cursor: pointer; font-size: 13px; color: var(--tx2); margin-top: 10px; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; } details[open] > summary::before { content: "▾ "; }

/* botones */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 650; background: var(--card2); color: var(--tx);
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--acc); color: var(--acc-tx); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }

/* filtros */
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 7px 10px; font-size: 13px;
  font-weight: 600; color: var(--tx2); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--tx); box-shadow: var(--shadow); }

/* tablas y listas */
.list .item { display: flex; justify-content: space-between; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; padding-top: 0; }
.list .item:last-child { padding-bottom: 0; }
.item-main { min-width: 0; }
.item-main .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-side { text-align: right; flex: none; }
.grid-kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
@media (min-width: 560px) { .grid-kpi { grid-template-columns: repeat(4, 1fr); } }
.kbox { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; box-shadow: var(--shadow); }
.kbox span { font-size: 12px; color: var(--tx2); display: block; }
.kbox b { font-size: 21px; font-variant-numeric: tabular-nums; display: block; margin-top: 2px; }
.kbox small { font-size: 11px; color: var(--tx3); }
.chart { width: 100%; height: 160px; display: block; }
.cal { display: grid; gap: 10px; }
.cal-row { display: grid; grid-template-columns: 78px 1fr 64px; gap: 10px; align-items: center; font-size: 13px; }
.cal-bars { position: relative; height: 18px; background: var(--card2); border-radius: 6px; overflow: hidden; }
.cal-bars .real { position: absolute; inset: 0 auto 0 0; background: var(--acc); opacity: .85; border-radius: 6px; }
.cal-bars .prom { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--tx); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--tx2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ajustes */
.field { padding: 12px 0; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; padding-top: 0; }
.field:last-child { padding-bottom: 0; }
.field label { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.field label output { font-variant-numeric: tabular-nums; color: var(--acc); }
.field p { margin: 3px 0 8px; font-size: 12px; color: var(--tx2); }
input[type=range] { width: 100%; accent-color: var(--acc); height: 28px; }
.input { width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  min-height: 44px; outline: none; font-variant-numeric: tabular-nums; }
.input:focus { border-color: var(--acc); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--acc); }
.switch input:checked + span::after { transform: translateX(20px); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card2); border-radius: 999px; padding: 7px 12px; font-size: 13px;
  font-weight: 600; min-height: 36px; }
.chip.on { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.savebar { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); margin-top: 12px; padding: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 6px 24px rgba(0,0,0,.18); }
[hidden] { display: none !important; }

/* navegación inferior */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.tabs button { position: relative; flex: 1; max-width: 140px; border: 0; background: transparent; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--tx3); font-weight: 600; }
.tabs .ti { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--tx); } .tabs button.on .ti { filter: none; opacity: 1; }
.badge { position: absolute; top: 2px; right: calc(50% - 22px); min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--acc); color: var(--acc-tx); font-size: 11px; font-style: normal; font-weight: 700; line-height: 18px; padding: 0 5px; }

/* hoja de apuesta */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-radius: 20px 20px 0 0;
  max-width: 560px; margin: 0 auto; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,.25); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 0; font-size: 18px; }
.sheet .lbl { font-size: 12px; font-weight: 600; color: var(--tx2); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px; }
.opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.opt { border: 1.5px solid var(--line); background: var(--card2); border-radius: 12px; padding: 10px 4px; font-weight: 700;
  font-variant-numeric: tabular-nums; min-height: 48px; }
.opt.on { border-color: var(--acc); background: var(--acc-soft); color: var(--acc); }
.opt small { display: block; font-size: 10px; font-weight: 600; color: var(--tx3); }
.ev { display: flex; justify-content: space-between; background: var(--card2); border-radius: 12px; padding: 12px; margin-top: 14px; font-size: 14px; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-top: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--tx); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.empty { text-align: center; padding: 40px 16px; color: var(--tx2); }
.empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty h2 { color: var(--tx); font-size: 18px; margin: 0 0 6px; }
.empty p { margin: 0 auto; max-width: 340px; font-size: 14px; }
.note { font-size: 12px; color: var(--tx3); margin: 8px 4px 0; }
.skeleton { height: 120px; border-radius: var(--r); background: linear-gradient(90deg, var(--card2), var(--card), var(--card2));
  background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 10px; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (max-width: 430px) { .kpis .kpi:nth-child(2) { display: none; } }
@media (max-width: 360px) { .factors { grid-template-columns: repeat(2, 1fr); } }
