:root {
  --bg: #f4f6fa; --panel: #fff; --ink: #0f1b2d; --ink2: #475569; --muted: #8a94a6; --line: #e3e8f0;
  --brand: #1747d6; --brand-2: #0e2a80; --brand-soft: #e8eefc;
  --green: #0f9d63; --green-soft: #e3f6ee; --yellow: #c98a04; --yellow-soft: #fff5d9; --red: #d93a3a; --red-soft: #fde8e8;
  --radius: 12px; --shadow: 0 1px 2px rgba(15,27,45,.05), 0 4px 16px rgba(15,27,45,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 Inter, system-ui, sans-serif; color: var(--ink); background: var(--bg); display: flex; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 12px; } .hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* sidebar */
.side { width: 232px; flex: none; background: var(--brand-2); color: #cfd8f5; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; gap: 8px; padding: 4px 4px 20px; }
.client-logo { background: #fff; border-radius: 10px; padding: 10px 12px; display: flex; justify-content: center; }
.client-logo img { width: 100%; max-width: 180px; height: auto; display: block; }
.brand .brand-sub { padding-left: 4px; }
.logo { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #4f7bff, #19c3a5); color: #fff; font-weight: 700; display: grid; place-items: center; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; opacity: .7; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #cfd8f5; font-weight: 500; margin-bottom: 2px; }
nav a span { width: 18px; text-align: center; opacity: .8; }
nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.pill { margin-left: auto; background: #ff6b4a; color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; font-weight: 600; }
.pill:empty { display: none; }
.side-foot { margin-top: auto; padding: 8px; }
.live { font-size: 12px; color: #9ff0d6; display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #19c3a5; box-shadow: 0 0 0 3px rgba(25,195,165,.25); }

/* main */
main { flex: 1; min-width: 0; }
.top { display: flex; gap: 16px; align-items: center; padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top input { flex: 1; max-width: 460px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--bg); }
.top-right { margin-left: auto; display: flex; gap: 14px; align-items: center; }
#view { padding: 24px 28px 60px; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.sub { color: var(--ink2); margin: 0 0 20px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { margin: 0; }

.btn { white-space: nowrap; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; font: 600 13px Inter, sans-serif; cursor: pointer; }
.btn:hover { border-color: #c5cfdf; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0f3bbd; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ok { color: var(--green); } .btn.ko { color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .hint { font-size: 12px; color: var(--ink2); }
.kpi.green .value { color: var(--green); } .kpi.yellow .value { color: var(--yellow); } .kpi.red .value { color: var(--red); } .kpi.blue .value { color: var(--brand); }
.cols-2 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .cols-2 { grid-template-columns: 1fr; } }

.proof { display: flex; gap: 12px; align-items: center; background: linear-gradient(90deg, #eafaf4, #eef3ff); border: 1px solid #cdeee0; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }
.proof b { color: var(--green); }

.semaforo { display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: var(--line); margin: 6px 0 10px; }
.semaforo div { height: 100%; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.bg-verde { background: var(--green); } .bg-amarillo { background: #f0b429; } .bg-rojo { background: var(--red); } .bg-sin-datos { background: #c3cad6; } .bg-sin-precio { background: #8a94a6; }
.cell.own { background: #fff7ef; border-color: #f6d3ad; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfd; position: sticky; top: 0; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f8faff; }
td.r, th.r { text-align: right; }
.prod b { display: block; font-weight: 600; max-width: 340px; }
.prod small { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 11px; }

.cell { display: inline-block; min-width: 118px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); text-align: right; line-height: 1.25; }
.cell .p { font-weight: 700; }
.cell .d { font-size: 11px; }
.cell .meta { font-size: 10.5px; color: var(--ink2); display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.cell.cheaper { background: var(--red-soft); border-color: #f6c7c7; } .cell.cheaper .d { color: var(--red); }
.cell.pricier { background: var(--green-soft); border-color: #bfe8d5; } .cell.pricier .d { color: var(--green); }
.cell.same { background: var(--yellow-soft); border-color: #f3dfa2; } .cell.same .d { color: var(--yellow); }
.cell.best { outline: 2px solid var(--ink); outline-offset: -1px; }
.cell.review { background: #f4f0ff; border-style: dashed; border-color: #b9a6f5; }
.cell.none { color: var(--muted); background: #fafbfd; font-size: 12px; text-align: center; }
.cell.nostock { opacity: .6; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 5px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.tag.promo { background: #ffe9e0; color: #c2410c; } .tag.cuotas { background: #e6f4ff; color: #0369a1; } .tag.warn { background: var(--yellow-soft); color: var(--yellow); }
.tag.ok { background: var(--green-soft); color: var(--green); } .tag.bad { background: var(--red-soft); color: var(--red); } .tag.ia { background: #f1ecff; color: #6d28d9; }
.light { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
select, .filters input, .form input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); }

.src-badge { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-size: 10px; font-weight: 700; color: #fff; flex: none; }
.src-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.src-row:last-child { border: 0; }
.src-row .n { margin-left: auto; font-weight: 600; }

/* alerts */
.alerts { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.alert { border-left: 4px solid var(--brand); display: flex; flex-direction: column; gap: 8px; }
.alert.fuera { border-left-color: var(--red); } .alert.baja { border-left-color: #f97316; } .alert.margen { border-left-color: var(--green); }
.alert.stock { border-left-color: #64748b; } .alert.cuotas { border-left-color: #0ea5e9; } .alert.match { border-left-color: #7c3aed; } .alert.promo { border-left-color: #c2410c; } .alert.suba { border-left-color: #0f9d63; }
.alert .type { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.alert .t { font-weight: 600; }
.alert .acts { display: flex; gap: 8px; margin-top: auto; align-items: center; }
.alert.revisada { opacity: .55; }
.mini-alert { padding: 10px 0; border-bottom: 1px solid var(--line); }
.mini-alert:last-child { border: 0; }

/* agents */
.pipeline { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; margin-bottom: 16px; }
.pipe { flex: 1; min-width: 150px; padding: 12px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.pipe b { display: block; } .pipe small { color: var(--ink2); }
.pipe-arrow { align-self: center; color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar div { height: 100%; background: var(--brand); transition: width .4s; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; }
.status.operativo { background: var(--green-soft); color: var(--green); }
.status.advertencia { background: var(--yellow-soft); color: var(--yellow); }
.status.bloqueado, .status.error { background: var(--red-soft); color: var(--red); }
.status.ejecutando, .status.en.cola { background: var(--brand-soft); color: var(--brand); }
.run-banner { margin: 16px 28px 0; background: var(--brand-soft); border: 1px solid #c8d6fb; border-radius: var(--radius); padding: 12px 16px; display: flex; gap: 18px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.run-banner .agent { min-width: 160px; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-bg { position: absolute; inset: 0; background: rgba(15,27,45,.35); }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(760px, 100%); background: var(--bg); overflow-y: auto; padding: 24px; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.x { float: right; }
.offer { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.offer:last-child { border: 0; }
.offer .pub { font-size: 12.5px; color: var(--ink2); }
.reasons { font-size: 11.5px; color: var(--ink2); }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font: 11px Inter, sans-serif; fill: var(--muted); }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink2); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 30; }
code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
