/* Radar de Precios — sistema de diseño (tema claro). Sin build ni CDN. */

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e7ef;
  --border-strong: #cfd6e3;
  --text: #182033;
  --muted: #5d6882;
  --faint: #8a94ab;
  --accent: #2563eb;
  --accent-hover: #1d4fd8;
  --accent-soft: #e8efff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --danger: #c2272d;
  --danger-soft: #fdecec;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header .inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px;
  height: 58px; display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 16px;
}
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav a {
  padding: 7px 12px; border-radius: var(--radius-sm); color: var(--muted);
  font-weight: 550; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.header-extra { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .titles { flex: 1 1 280px; min-width: 0; }
.page-head .titles p { margin-top: 4px; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb span.sep { margin: 0 6px; color: var(--faint); }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.spacer { flex: 1; }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value.ok { color: var(--ok); }
.stat .value.warn { color: var(--warn); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 550 13.5px/1 var(--font); cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, .input:focus-visible, .select:focus-visible, .textarea:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.94); background: var(--ok); }
.btn-danger { color: var(--danger); border-color: #f1c4c6; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent;
  animation: girar .7s linear infinite;
}
.btn-primary.is-loading::after, .btn-ok.is-loading::after { border-color: #fff transparent #fff transparent; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #c5e8d1; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f4dcb4; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: #f4c7c9; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: #cddcff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.danger { background: var(--danger); }

/* ---------- Alerts ---------- */
.alert {
  border-radius: var(--radius); padding: 12px 16px; border: 1px solid;
  display: flex; gap: 10px; align-items: flex-start;
}
.alert.warn { background: var(--warn-soft); border-color: #f4dcb4; color: #7c3d06; }
.alert.danger { background: var(--danger-soft); border-color: #f4c7c9; color: #8f1d22; }
.alert.info { background: var(--accent-soft); border-color: #cddcff; color: #1e3a8a; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 14px var(--font);
}
.textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.input.sm, .select.sm { height: 30px; font-size: 13px; }
.fields { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong);
  position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.form-section { display: grid; grid-template-columns: minmax(200px, 280px) 1fr; gap: 24px; padding: 20px 0; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: 0; padding-top: 4px; }
.form-section .about h3 { margin-bottom: 4px; }
.form-section .about p { color: var(--muted); font-size: 13px; }
.form-section .controls { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.toggle-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.toggle-row .txt { min-width: 0; }
.toggle-row .txt .hint { margin-top: 2px; }
@media (max-width: 760px) { .form-section { grid-template-columns: 1fr; gap: 12px; } }

.save-bar {
  position: sticky; bottom: 0; z-index: 10; margin-top: 16px;
  display: flex; align-items: center; gap: 12px; justify-content: flex-end;
  padding: 12px 18px; background: rgba(255, 255, 255, .96);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.save-bar .estado { margin-right: auto; color: var(--muted); font-size: 13px; }
.save-bar .estado.sucio { color: var(--warn); font-weight: 600; }

/* ---------- Tabs / segmented ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  font: 600 14px var(--font); color: var(--muted); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.segmented button {
  appearance: none; border: 0; background: none; cursor: pointer; height: 28px; padding: 0 12px;
  border-radius: 5px; font: 600 13px var(--font); color: var(--muted);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--muted);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: #fafbfe; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .desc { max-width: 340px; color: var(--muted); }
.table tr.sel { background: var(--accent-soft) !important; }

.pager { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager .btns { display: flex; gap: 6px; }

/* ---------- Empty / skeleton ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .icon { font-size: 28px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #eef1f6 25%, #f6f8fb 37%, #eef1f6 63%);
  background-size: 400% 100%; animation: brillo 1.3s ease infinite;
}
@keyframes brillo { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Toast / dialog ---------- */
.toast-stack { position: fixed; right: 16px; top: 70px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: #1f2937; color: #fff; padding: 11px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; display: flex; gap: 8px; align-items: flex-start;
  animation: entrar .18s ease-out;
}
.toast.ok { background: #14532d; } .toast.error { background: #8f1d22; } .toast.warn { background: #7c3d06; }
@keyframes entrar { from { transform: translateY(8px); opacity: 0; } }
dialog.confirm {
  border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg); color: var(--text);
}
dialog.confirm::backdrop { background: rgba(15, 23, 42, .4); }
dialog.confirm .cuerpo { padding: 20px 22px 8px; }
dialog.confirm .cuerpo p { margin-top: 6px; color: var(--muted); white-space: pre-line; }
dialog.confirm .pie { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; }

/* ---------- Panel / log ---------- */
.log {
  font: 12.5px/1.55 var(--mono); background: #0f172a; color: #cbd5e1;
  border-radius: 0 0 var(--radius) var(--radius); height: 460px; overflow-y: auto; padding: 12px 16px;
}
.log .exito { color: #4ade80; } .log .advertencia { color: #fbbf24; } .log .error { color: #f87171; }
.log .hora { color: #64748b; margin-right: 6px; }

/* ---------- Radar hub ---------- */
.marca { margin-top: 28px; }
.marca:first-child { margin-top: 0; }
.marca-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.marca-head h2 { text-transform: capitalize; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.model-card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color .12s, box-shadow .12s, transform .12s;
}
.model-card:hover { text-decoration: none; border-color: #b9c8ee; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.model-card .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.model-card .nombre { font-weight: 650; font-size: 15px; text-transform: capitalize; }
.model-card .variante { font-size: 12px; color: var(--muted); }
.model-card .precio { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.model-card .precio small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.model-card .meta { display: flex; gap: 12px; font-size: 12.5px; color: var(--muted); }
.model-card .sin-linea { height: 44px; display: grid; place-items: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); font-size: 12px; color: var(--faint); }
.spark { display: block; width: 100%; height: 44px; }

/* ---------- Gráfico de modelo ---------- */
.grafico svg { display: block; width: 100%; height: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 12.5px; cursor: pointer; background: var(--surface); }
.chip input { accent-color: var(--accent); }
.chip .muestra { width: 10px; height: 10px; border-radius: 50%; }

/* Barra de acciones del modo entrenamiento */
.action-bar {
  position: sticky; bottom: 0; z-index: 10; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 12px 18px; background: var(--accent-soft); border: 1px solid #cddcff;
  border-radius: var(--radius); margin-top: 14px; box-shadow: var(--shadow-lg);
}
.action-bar .txt { margin-right: auto; color: #1e3a8a; font-size: 13.5px; }

@media (max-width: 640px) {
  .app-header .inner { gap: 12px; padding: 0 16px; }
  .brand .nombre-app { display: none; }
  .container { padding: 18px 16px 48px; }
  .card-body { padding: 14px; }
}

/* Puntos clicables del gráfico + ficha del anuncio */
.grafico circle.punto { cursor: pointer; transition: r .1s; }
.grafico circle.punto:hover, .grafico circle.punto:focus { r: 7; stroke: var(--accent); stroke-width: 2; outline: none; }
.grafico circle.punto.activo { r: 8; stroke: var(--accent); stroke-width: 3; }
dialog.ficha { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: var(--shadow-lg); color: var(--text); }
dialog.ficha::backdrop { background: rgba(15, 23, 42, .4); }
dialog.ficha .cab { display: flex; gap: 10px; align-items: flex-start; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
dialog.ficha .cab h2 { flex: 1; font-size: 16px; }
dialog.ficha .cuerpo { padding: 16px 20px; overflow-y: auto; max-height: 60vh; display: flex; flex-direction: column; gap: 14px; }
dialog.ficha .precio-grande { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
dialog.ficha .datos { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px 16px; }
dialog.ficha .datos .k { font-size: 12px; color: var(--muted); }
dialog.ficha .datos .v { font-weight: 600; }
dialog.ficha .descripcion { white-space: pre-line; font-size: 13.5px; color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
dialog.ficha .pie { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }

/* Tooltip instantáneo de los puntos */
.tip-punto {
  position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -100%);
  background: #1f2937; color: #fff; border-radius: 8px; padding: 7px 10px; box-shadow: var(--shadow-lg);
  font-size: 12.5px; line-height: 1.35; white-space: nowrap; opacity: 0; transition: opacity .08s;
}
.tip-punto.visible { opacity: 1; }
.tip-punto b { font-size: 14px; font-variant-numeric: tabular-nums; }
.tip-punto .sec { color: #cbd5e1; }
.tip-punto .ayuda { color: #94a3b8; font-size: 11.5px; margin-top: 2px; }
.tip-punto::after {
  content: ""; position: absolute; left: var(--flecha, 50%); top: 100%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #1f2937;
}

/* Mira del gráfico */
.grafico.con-mira svg { cursor: crosshair; }
.grafico .mira-capa { pointer-events: none; }
.grafico .mira-capa-sup { pointer-events: none; }
