:root {
  color-scheme: dark;
  --bg: #0c0a14;
  --surface: #151221;
  --surface-2: #1e1a2e;
  --line: #2d2743;
  --text: #f3f0fa;
  --muted: #9f97b8;
  --accent: #b46bff;
  --accent-2: #ff4f9a;
  --hot: #ff5468;
  --grad: linear-gradient(120deg, #9d5cff 0%, #e04bd0 50%, #ff4f7e 100%);
  --on-accent: #ffffff;
  --good: #3ddc97;
  --good-bg: rgba(61, 220, 151, .13);
  --warn: #ffb454;
  --warn-bg: rgba(255, 180, 84, .13);
  --wait: #c08bff;
  --wait-bg: rgba(180, 107, 255, .15);
  --bad: #ff5468;
  --bad-bg: rgba(255, 84, 104, .14);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --glow: 0 0 0 1px rgba(180, 107, 255, .35), 0 10px 40px -12px rgba(224, 75, 208, .45);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: radial-gradient(900px 500px at 12% -10%, rgba(157, 92, 255, .16), transparent 60%), radial-gradient(800px 480px at 95% 0%, rgba(255, 79, 126, .11), transparent 60%), var(--bg); background-attachment: fixed; color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- cabecera ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; text-decoration: none; letter-spacing: -.02em; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 550; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--text); background: var(--surface-2); }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.dot.live { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- controles ---------- */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 10px; font-weight: 550; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; transition: background .12s, border-color .12s; }
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover { filter: brightness(1.06); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 6px 8px; }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.danger { color: var(--bad); }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0; }
input:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input::placeholder { color: var(--muted); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--text); font-size: 15px; font-weight: 450; margin: 0; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

/* ---------- añadir ---------- */
.add { display: flex; gap: 8px; margin-bottom: 22px; }
.add input[name="input"] { flex: 1; padding: 12px 14px; font-size: 16px; }
.add input[name="target"] { width: 150px; flex: none; }
@media (max-width: 640px) { .add { flex-wrap: wrap; } .add input[name="input"] { flex-basis: 100%; } .add input[name="target"] { flex: 1; } }

/* ---------- tarjetas ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
a.card { text-decoration: none; display: flex; flex-direction: column; gap: 12px; transition: border-color .12s, transform .12s; }
a.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); transform: translateY(-1px); }
.card.paused { opacity: .55; }
.card-top { display: flex; gap: 12px; align-items: flex-start; }
.thumb { width: 52px; height: 52px; border-radius: 10px; background: #fff; object-fit: contain; flex: none; padding: 4px; }
.thumb.empty { background: var(--surface-2); }
.card-title { font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.price-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.price { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.delta { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.down { color: var(--good); }
.delta.up { color: var(--bad); }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.spark { width: 100%; height: 34px; display: block; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 650; white-space: nowrap; }
.badge.comprar { color: var(--good); background: var(--good-bg); }
.badge.buen_precio { color: var(--warn); background: var(--warn-bg); }
.badge.esperar { color: var(--wait); background: var(--wait-bg); }
.badge.sin_datos, .badge.neutral { color: var(--muted); background: var(--surface-2); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- detalle ---------- */
.back { color: var(--muted); text-decoration: none; font-size: 14px; display: inline-flex; gap: 6px; margin-bottom: 14px; }
.back:hover { color: var(--text); }
.detail-head { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.detail-head .thumb { width: 72px; height: 72px; }
.detail-head .grow { flex: 1; min-width: 220px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cols { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
.section { margin-bottom: 14px; }
.section > h2, .card > h2 { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.verdict { display: flex; flex-direction: column; gap: 14px; }
.verdict .big { font-size: 40px; font-weight: 750; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.verdict .where { color: var(--muted); font-size: 14px; }
.forecast { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kpi b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi span { font-size: 12px; color: var(--muted); }
.reasons { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.reasons li { padding-left: 16px; position: relative; color: color-mix(in srgb, var(--text) 86%, var(--muted)); }
.reasons li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }

.chart-wrap { position: relative; }
.chart { width: 100%; height: 250px; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--accent); opacity: .08; }
.chart .target { stroke: var(--good); stroke-dasharray: 5 4; stroke-width: 1.5; }
.chart .expected { stroke: var(--wait); stroke-dasharray: 2 4; stroke-width: 1.5; }
.chart .deal { fill: var(--surface); stroke: var(--wait); stroke-width: 1.5; }
.chart .deal.mp { stroke: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: 5px; }
.legend i.t { border-top: 2px dashed var(--good); }
.legend i.e { border-top: 2px dotted var(--wait); }
.legend i.d { width: 8px; height: 8px; border: 1.5px solid var(--wait); border-radius: 50%; }
.tip { position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -115%); box-shadow: var(--shadow); z-index: 2; }
.keepa { width: 100%; border-radius: 10px; background: #fff; display: block; }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
td.num { white-space: nowrap; }
tr.off td { opacity: .5; }
tr.top td { background: color-mix(in srgb, var(--good) 6%, transparent); }
td a { text-decoration: none; }
td a:hover { text-decoration: underline; }
.shop { font-weight: 600; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 6px; white-space: nowrap; font-weight: 550; }
.pill.alta { color: var(--good); background: var(--good-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- etiquetas ---------- */
.tag-groups { display: grid; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); padding: 2px 4px 2px 10px; border-radius: 999px; font-size: 13px; }
.chip.fixed { padding-right: 10px; color: var(--muted); }
.chip button { border: 0; background: none; padding: 0 5px; color: var(--muted); font-size: 15px; line-height: 1; border-radius: 50%; }
.chip button:hover { color: var(--bad); background: none; }
.chip-add { width: 130px; padding: 3px 10px; border-radius: 999px; font-size: 13px; }

/* ---------- formularios ---------- */
.form { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }
.help { font-size: 13px; color: var(--muted); margin-top: 6px; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; overflow-wrap: anywhere; }
.steps { margin: 8px 0 0; padding-left: 20px; font-size: 14px; display: grid; gap: 4px; }

.login { max-width: 340px; margin: 12vh auto 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .topbar { gap: 8px 10px; flex-wrap: wrap; justify-content: space-between; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs a { flex: 1; text-align: center; padding: 6px 8px; }
  .status { font-size: 12px; }
  .verdict .big { font-size: 34px; }
  .forecast { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- tema morado / rosa ---------- */
.brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tabs a.on { background: linear-gradient(120deg, rgba(157, 92, 255, .22), rgba(255, 79, 126, .16)); box-shadow: inset 0 0 0 1px rgba(180, 107, 255, .3); }
button.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 22px -8px rgba(224, 75, 208, .7); }
button.primary:hover { background: var(--grad); filter: brightness(1.12); }
.card { background: linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 40%), var(--surface); }
a.card:hover { border-color: transparent; box-shadow: var(--glow); transform: translateY(-2px); }
.price, .verdict .big { background: linear-gradient(120deg, #ffffff 30%, #f3b8ff 70%, #ff9fbf 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.verdict { border-color: rgba(180, 107, 255, .35); box-shadow: 0 20px 60px -30px rgba(224, 75, 208, .55); }
.kpi { background: linear-gradient(180deg, rgba(180, 107, 255, .1), rgba(255, 79, 126, .05)); border: 1px solid rgba(180, 107, 255, .16); }
.reasons li::before { background: var(--accent-2); }
.chart .line { stroke: url(#lineGrad); stroke-width: 2.4; }
.chart .area { fill: url(#areaGrad); opacity: 1; }
.chart .deal { stroke: var(--accent); }
.chart .expected { stroke: var(--accent-2); }
.legend i { border-top-color: var(--accent-2); }
.legend i.e { border-top-color: var(--accent-2); }
.legend i.d { border-color: var(--accent); }
tr.top td { background: linear-gradient(90deg, rgba(180, 107, 255, .13), rgba(255, 79, 126, .05)); }
tr.top td:first-child { box-shadow: inset 3px 0 0 var(--accent-2); }
.badge.comprar { box-shadow: inset 0 0 0 1px rgba(61, 220, 151, .3); }
.badge.esperar { box-shadow: inset 0 0 0 1px rgba(180, 107, 255, .35); }
.chip { border-color: rgba(180, 107, 255, .25); }
.dot.live { background: var(--accent-2); box-shadow: 0 0 0 3px rgba(255, 79, 154, .2); }
input:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible { outline-color: var(--accent-2); }
.switch input { accent-color: var(--accent-2); }
::selection { background: rgba(224, 75, 208, .4); }

/* desglose del precio */
.breakdown { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; gap: 6px 10px; flex-wrap: wrap; align-items: center; }
.breakdown b { color: var(--text); font-weight: 600; }
.ship { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; }
.ship.free { color: var(--good); border-color: rgba(61, 220, 151, .3); background: var(--good-bg); }
.ship.unknown { color: var(--warn); border-color: rgba(255, 180, 84, .3); background: var(--warn-bg); }
.net { color: var(--wait); }
