:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e3e6eb;
  --text: #16191f; --muted: #667085; --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e6f4f2;
  --good: #15803d; --warn: #b45309; --bad: #b91c1c; --bar: #99d5cd;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --surface: #161b22; --surface-2: #1d232c; --border: #2a313c;
    --text: #e6e9ee; --muted: #9aa4b2; --accent: #2dd4bf; --accent-ink: #062b27; --accent-soft: #123532;
    --good: #4ade80; --warn: #fbbf24; --bad: #f87171; --bar: #1f6f66;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
h2 { font-size: 1rem; margin: 0 0 4px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .85rem; margin: 0 0 10px; }

/* ---------- topbar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs button { border: 0; background: none; color: var(--muted); padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { margin: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- controls */
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-ghost { background: transparent; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.toolbar-right { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-bottom: 12px; }
.filters input[type=search] { grid-column: span 2; }
.range { display: flex; gap: 6px; }
.range input { width: 50%; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--muted); padding: 8px 12px; font: inherit; cursor: pointer; }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- cards & KPIs */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .8rem; }
.kpi .d { font-size: .8rem; }

/* ---------- tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.bar { position: relative; }
.bar::before { content: ""; position: absolute; inset: 6px auto 6px 0; width: var(--w, 0%); background: var(--bar); border-radius: 3px; opacity: .55; z-index: 0; }
.bar > span { position: relative; z-index: 1; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--surface-2); display: block; }
.title-cell { max-width: 360px; }
.title-cell a { color: var(--text); text-decoration: none; font-weight: 500; }
.title-cell small { display: block; color: var(--muted); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.vendido, .tag.original { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.tag.replica, .tag.retirado, .tag.fallido { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.tag.activo, .tag.lanzado, .tag.procesando { background: var(--accent-soft); color: var(--accent); }
.tag.indeterminado, .tag.fuera_ventana { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 16px 0; }

/* ---------- reports */
.reports { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.report-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); max-height: 75vh; overflow: auto; }
.report-list li { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.report-list li:last-child { border-bottom: 0; }
.report-list li.active, .report-list li:hover { background: var(--accent-soft); }
.report-list small { display: block; color: var(--muted); }
.report-view { overflow-wrap: anywhere; }
.report-view h1 { font-size: 1.3rem; margin-top: 0; }
.report-view h2 { font-size: 1.05rem; margin-top: 1.4em; }
.report-view table { margin: 8px 0; display: block; max-width: 100%; overflow-x: auto; }

/* ---------- misc */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(720px, calc(100vw - 32px)); max-height: 85vh; padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.photos { display: flex; gap: 8px; overflow-x: auto; margin: 8px 0; }
.photos img { height: 140px; border-radius: 8px; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
.empty { color: var(--muted); padding: 12px 0; }
.alert { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }

/* ---------- login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: 14px; margin-top: 16px; }

/* ---------- responsive */
@media (max-width: 900px) {
  .grid-2, .reports { grid-template-columns: minmax(0, 1fr); }
  .report-list { max-height: 260px; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .topbar .brand span:last-child { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .logout { margin-left: auto; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { grid-column: 1 / -1; }
  .toolbar-right { margin-left: 0; }
  /* Tabla de productos → tarjetas */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 10px; background: var(--surface); }
  table.cards td { border: 0; padding: 3px 0; text-align: left; display: flex; justify-content: space-between; gap: 12px; }
  table.cards td::before { content: attr(data-l); color: var(--muted); font-size: .8rem; }
  table.cards td.title-cell { display: flex; justify-content: flex-start; }
  table.cards td.title-cell::before, table.cards td.ph::before { content: none; }
  table.cards td.ph { float: left; width: auto; margin-right: 10px; }
}

/* ---------- plataformas */
#c-plataformas { margin-bottom: 16px; }
.grid-2.tight { margin-bottom: 0; }
.tag.vinted { background: color-mix(in srgb, #09b1ba 18%, transparent); color: #078a91; }
.tag.wallapop { background: color-mix(in srgb, #13c1ac 18%, transparent); color: #0b8a7a; }
.tag.resubido { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
@media (prefers-color-scheme: dark) {
  .tag.vinted { color: #5fd8de; }
  .tag.wallapop { color: #5fe0cf; }
}

/* ---------- ranking */
.rank-card { margin-bottom: 16px; }
