:root {
  color-scheme: dark;
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1d2129;
  --surface-3: #252a34;
  --border: #2b313c;
  --text: #f3f4f6;
  --text-2: #c3c7cf;
  --muted: #8d939e;
  --accent: #3987e5;
  --accent-2: #5a9ff0;
  --good: #0ca30c;
  --good-t: #4cc94c;
  --warn: #fab219;
  --serious: #ec835a;
  --bad: #d03b3b;
  --bad-t: #f07474;
  --grid: #2a2f38;
  --radius: 12px;
  --side-w: 236px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin-bottom: 12px; }
h3 { font-size: .95rem; margin: 18px 0 8px; color: var(--text-2); }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strong { font-weight: 600; }
.pos { color: var(--good-t); }
.neg { color: var(--bad-t); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.side {
  width: var(--side-w); flex: 0 0 var(--side-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand.center { justify-content: center; padding-bottom: 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-txt { font-weight: 700; font-size: 1.02rem; line-height: 1.1; }
.brand-txt small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a svg { width: 19px; height: 19px; fill: currentColor; flex: none; opacity: .85; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.on { background: rgba(57, 135, 229, .16); color: #fff; }
.nav a.on svg { color: var(--accent-2); opacity: 1; }
.side-foot { border-top: 1px solid var(--border); padding: 12px 8px 0; }
.who { color: var(--muted); font-size: .8rem; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; padding: 22px 28px 40px; }
.top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.top h1 { font-size: 1.5rem; }
.top .sub { margin: 4px 0 0; color: var(--muted); }
.menu-btn { display: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; width: 40px; height: 40px; padding: 8px; cursor: pointer; flex: none; }
.menu-btn svg { fill: var(--text); width: 100%; height: 100%; }
.scrim { display: none; }
.foot { margin-top: 28px; color: var(--muted); font-size: .8rem; text-align: center; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state p { color: var(--text-2); }
.empty-msg { color: var(--muted); margin: 6px 0; }
.note { background: var(--surface-2); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin: 12px 0; color: var(--text-2); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card .kpis { margin: 4px 0 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; min-width: 0; }
.card .kpi { background: var(--surface-2); }
.kpi-l { color: var(--muted); font-size: .8rem; font-weight: 500; }
.kpi-v { font-size: 1.55rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi-h { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.kpi.accent { border-color: rgba(57, 135, 229, .55); }
.kpi.accent .kpi-v { color: #fff; }
.kpi.pos .kpi-v { color: var(--good-t); }
.kpi.neg .kpi-v { color: var(--bad-t); }
.kpi.warn { border-color: rgba(250, 178, 25, .5); }
.kpi.v-alta { border-color: rgba(57, 135, 229, .55); }
.kpi.v-evitar { border-color: rgba(208, 59, 59, .5); }

/* ---------- Alerts ---------- */
.alert { padding: 11px 14px; border-radius: 9px; margin-bottom: 14px; border: 1px solid; }
.alert.ok { background: rgba(12, 163, 12, .12); border-color: rgba(12, 163, 12, .45); }
.alert.err { background: rgba(208, 59, 59, .13); border-color: rgba(208, 59, 59, .5); }
.alert.warn { background: rgba(250, 178, 25, .1); border-color: rgba(250, 178, 25, .45); }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; color: var(--text-2); font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=file] { padding: 6px; }
.filters, .eval-form, .inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label, .eval-form label, .inline-form label { flex: 1 1 150px; min-width: 130px; }
.eval-form label.wide { flex-basis: 100%; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 22px; }
.settings label span { color: var(--text); font-size: .9rem; }
.settings small { color: var(--muted); font-weight: 400; }
.actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 16px; min-height: 40px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-3); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: rgba(208, 59, 59, .55); color: var(--bad-t); }
.btn.win { background: rgba(12, 163, 12, .18); border-color: rgba(12, 163, 12, .55); color: #8fe28f; }
.btn.loss { background: rgba(208, 59, 59, .16); border-color: rgba(208, 59, 59, .55); color: #f5a0a0; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .82rem; }
.btn.block { width: 100%; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.danger-t { color: var(--bad-t); }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; vertical-align: middle; }
.tbl.compact td { padding: 6px 10px; }
.tbl tbody tr:hover td { background: rgba(255, 255, 255, .025); }
.tbl .num { text-align: right; }
.tbl tr.total td { border-top: 1px solid var(--border); border-bottom: 0; }
.tbl tr.due td { background: rgba(250, 178, 25, .07); }
.sortable th[data-sort] { cursor: pointer; user-select: none; }
.sortable th[data-sort]:hover { color: var(--text); }
.sortable th.asc::after { content: " ▲"; font-size: .65rem; }
.sortable th.desc::after { content: " ▼"; font-size: .65rem; }
.bar-col { width: 32%; min-width: 180px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 14px; color: var(--muted); }
ul.plain { margin: 0; padding-left: 18px; color: var(--text-2); font-size: .88rem; }
ul.plain li { margin: 2px 0; }

/* ---------- Rate bar ---------- */
.rbar { position: relative; height: 16px; background: var(--surface-3); border-radius: 4px; overflow: visible; cursor: default; }
.rbar .fill { position: absolute; left: 0; top: 4px; bottom: 4px; background: var(--accent); border-radius: 0 4px 4px 0; }
.rbar .ci { position: absolute; top: 0; bottom: 0; background: rgba(57, 135, 229, .22); border-radius: 3px; }
.rbar .mk { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; border-radius: 1px; }
.rbar .mk.be { background: var(--serious); }
.rbar .mk.avg { background: #e8e8e8; }
.rbar.few .fill { background: #5b6472; }
.rbar.few .ci { background: rgba(140, 150, 165, .15); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: .78rem; margin: 10px 0 4px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; }
.lg-fill { width: 18px; height: 8px; background: var(--accent); border-radius: 2px; }
.lg-ci { width: 18px; height: 14px; background: rgba(57, 135, 229, .28); border-radius: 2px; }
.lg-be { width: 3px; height: 14px; background: var(--serious); border-radius: 1px; }
.lg-avg { width: 3px; height: 14px; background: #e8e8e8; border-radius: 1px; }
.lg-line { width: 18px; height: 2px; background: var(--accent); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: 99px; font-size: .78rem; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge i { font-style: normal; font-size: .72rem; }
.v-alta { border-color: rgba(57, 135, 229, .6); color: #9cc6f7; background: rgba(57, 135, 229, .14); }
.v-media { border-color: #4a515d; color: var(--text); }
.v-baja { border-color: rgba(250, 178, 25, .5); color: #f7cd6c; background: rgba(250, 178, 25, .08); }
.v-dudosa { border-color: #4a515d; color: var(--muted); border-style: dashed; }
.v-evitar { border-color: rgba(208, 59, 59, .6); color: #f5a0a0; background: rgba(208, 59, 59, .12); }
.s-top { border-color: rgba(57, 135, 229, .6); color: #9cc6f7; }
.s-ok { border-color: rgba(12, 163, 12, .5); color: #8fe28f; }
.s-warn { border-color: rgba(250, 178, 25, .5); color: #f7cd6c; }
.s-low { border-color: rgba(236, 131, 90, .55); color: #f3ab8d; }
.s-bad { border-color: rgba(208, 59, 59, .6); color: #f5a0a0; }
.s-muted { color: var(--muted); border-style: dashed; }
.r-g { border-color: rgba(12, 163, 12, .55); color: #8fe28f; background: rgba(12, 163, 12, .1); }
.r-p { border-color: rgba(208, 59, 59, .6); color: #f5a0a0; background: rgba(208, 59, 59, .1); }
.r-n { color: var(--muted); }
.r-w { border-color: rgba(250, 178, 25, .5); color: #f7cd6c; }

/* ---------- Heatmap ---------- */
.heat { border-collapse: separate; border-spacing: 2px; font-variant-numeric: tabular-nums; margin: 0 auto 0 0; }
.heat th { color: var(--muted); font-size: .74rem; font-weight: 600; padding: 2px 4px; text-align: center; white-space: nowrap; }
.heat th.left { text-align: left; color: var(--text-2); padding-right: 10px; }
.heat tbody th { text-align: right; padding-right: 8px; }
.heat td { width: 52px; min-width: 46px; height: 44px; text-align: center; border-radius: 4px; color: #fff; cursor: default; line-height: 1.05; }
.heat td b { display: block; font-size: .92rem; }
.heat td small { display: block; font-size: .66rem; opacity: .8; }
.heat td.nil { background: transparent; border: 1px dashed #2a2f38; }
.heat td.few { opacity: .45; }
.heat td:hover { outline: 2px solid #fff; outline-offset: 0; }
.heat-legend .grad { display: inline-flex; gap: 2px; }
.heat-legend .grad i { width: 18px; height: 12px; border-radius: 2px; }

/* ---------- Chart ---------- */
.chart-wrap { overflow-x: auto; }
.chart { width: 100%; height: auto; display: block; max-height: 300px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .pt circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .pt .hit { fill: transparent; }
.chart .pt:hover circle { r: 6.5; }
.chart .be-line { stroke: var(--serious); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .be-lbl { fill: var(--serious); font-size: 11px; }
.chart .avg-line { stroke: #cfcfcf; stroke-width: 1; stroke-dasharray: 2 3; }

/* ---------- Tooltip ---------- */
.tip { position: fixed; z-index: 50; pointer-events: none; background: #05070a; color: #fff; border: 1px solid #3a404c; padding: 7px 10px; border-radius: 7px; font-size: .8rem; max-width: 300px; opacity: 0; transition: opacity .08s; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.tip.on { opacity: 1; }

/* ---------- Evaluar ---------- */
.result-main { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; }
.ring { --deg: 0deg; width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--ring-c, var(--accent)) var(--deg), var(--surface-3) 0); }
.ring > div { width: 118px; height: 118px; border-radius: 50%; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring b { font-size: 1.7rem; letter-spacing: -.02em; }
.ring small { color: var(--muted); font-size: .72rem; }
.ring.v-alta { --ring-c: #3987e5; background: conic-gradient(#3987e5 var(--deg), var(--surface-3) 0); border: 0; }
.ring.v-media { background: conic-gradient(#9aa3b0 var(--deg), var(--surface-3) 0); border: 0; color: var(--text); }
.ring.v-baja { background: conic-gradient(#fab219 var(--deg), var(--surface-3) 0); border: 0; color: var(--text); }
.ring.v-dudosa { background: conic-gradient(#6b7380 var(--deg), var(--surface-3) 0); border: 0; color: var(--text); }
.ring.v-evitar { background: conic-gradient(#d03b3b var(--deg), var(--surface-3) 0); border: 0; color: var(--text); }
.result-txt { flex: 1; min-width: 260px; }
.result-signal { font-size: 1.12rem; font-weight: 650; }
.result-verdict { display: flex; align-items: center; gap: 10px; margin: 8px 0; color: var(--text-2); flex-wrap: wrap; }
.result-verdict .badge { font-size: .9rem; padding: 4px 12px 4px 10px; }
.result-facts { list-style: none; padding: 0; margin: 8px 0 12px; display: flex; flex-wrap: wrap; gap: 4px 20px; color: var(--text-2); font-size: .9rem; }
.save-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.save-form input { flex: 1 1 200px; width: auto; }

/* ---------- Recomendaciones ---------- */
.week { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.week a { flex: 1 1 60px; text-align: center; padding: 7px 4px; border-radius: 8px; border: 1px solid var(--border); color: var(--text-2); font-weight: 600; font-size: .85rem; }
.week a small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.week a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.week a.on small { color: #e3eefc; }
.week a:hover { text-decoration: none; border-color: var(--accent); }
.jump { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.jump a { padding: 4px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: .8rem; }
.jump a:hover { text-decoration: none; color: #fff; border-color: var(--accent); }
[id] { scroll-margin-top: 14px; }

/* ---------- Importar ---------- */
.upload { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.drop { width: 100%; border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; align-items: center; cursor: pointer; background: var(--surface-2); }
.drop:hover { border-color: var(--accent); }
.drop input { max-width: 420px; margin-bottom: 8px; }
.drop-t { color: var(--text); font-size: 1rem; font-weight: 600; }
.drop-s { color: var(--muted); font-weight: 400; }
details.mapping { margin: 12px 0; }
details.mapping summary { cursor: pointer; color: var(--accent-2); font-weight: 600; margin-bottom: 10px; }
details.add-box > summary { list-style: none; display: inline-flex; }
details.add-box > summary::-webkit-details-marker { display: none; }
details.add-box[open] > summary { margin-bottom: 14px; }

/* ---------- Auth ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { font-size: 1.25rem; text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.checks li { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; }
.checks li i { font-style: normal; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; flex: none; }
.checks li.ok i { background: rgba(12, 163, 12, .25); color: #8fe28f; }
.checks li.bad i { background: rgba(208, 59, 59, .25); color: #f5a0a0; }
.checks small { display: block; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1700px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
  .menu-btn { display: block; }
  .main { padding: 14px 16px 30px; }
  .top h1 { font-size: 1.25rem; margin-top: 7px; }
  .grid-3, .settings { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-v { font-size: 1.25rem; }
  .bar-col { min-width: 150px; }
  .chart { min-width: 600px; }
  .ring { width: 120px; height: 120px; }
  .ring > div { width: 94px; height: 94px; }
  .ring b { font-size: 1.35rem; }
}
@media (max-width: 420px) {
  .filters label, .eval-form label { flex-basis: 100%; }
}
