/* Estilo inspirado en Sellerboard: oscuro por defecto, claro opcional. */
:root, :root[data-theme="dark"] {
  --bg: #1b1c1f;
  --side: #232427;
  --panel: #26272b;
  --panel-2: #2d2e33;
  --line: #3a3b41;
  --ink: #e8e9ec;
  --muted: #9a9ca5;
  --link: #5b9cf6;
  --accent: #3b82f6;
  --pos: #4ade80;
  --neg: #f87171;
  --warn-bg: #3a2f17;
  --warn-ink: #f5d38a;
  --hover: #2f3035;
  --input: #2d2e33;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
}
:root[data-theme="light"] {
  --bg: #f3f4f7;
  --side: #ffffff;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e2e4ea;
  --ink: #1e2230;
  --muted: #6b7180;
  --link: #2563eb;
  --accent: #2563eb;
  --pos: #12805c;
  --neg: #c2410c;
  --warn-bg: #fff7e6;
  --warn-ink: #7a4b00;
  --hover: #f1f4fa;
  --input: #ffffff;
  --shadow: 0 8px 30px rgba(20, 30, 60, .15);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 13px/1.45 "Segoe UI", system-ui, sans-serif; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.app.collapsed { grid-template-columns: 60px 1fr; }
aside { background: var(--side); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 12px; padding: 14px 16px; font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.logo button { background: none; border: 0; cursor: pointer; padding: 2px; color: var(--muted); display: flex; }
.app.collapsed .logo span, .app.collapsed .nav-label { display: none; }
nav.side { margin-top: 8px; }
nav.side a {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: var(--ink);
  border-bottom: 1px solid var(--line); text-decoration: none;
}
nav.side a:hover { background: var(--hover); }
nav.side a.active { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
nav.side svg, .logo svg { width: 18px; height: 18px; flex: none; }

main { min-width: 0; padding: 0 20px 40px; }
.head { display: flex; align-items: center; gap: 24px; height: 56px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.head h1 { font-size: 20px; margin: 0; font-weight: 600; white-space: nowrap; }
.views { display: flex; gap: 4px; height: 100%; }
.views button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 10px; cursor: pointer;
  color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.views button.active { color: var(--link); border-bottom-color: var(--link); }
.views svg { width: 15px; height: 15px; }
.head-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--muted); display: flex; padding: 4px; border-radius: 50%; }
.icon-btn:hover { color: var(--ink); background: var(--hover); }
.icon-btn svg { width: 18px; height: 18px; }
.sync-msg { color: var(--muted); font-size: 12px; max-width: 320px; text-align: right; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 6px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }
select, input[type="text"], input[type="number"], input[type="date"], input[type="search"], input[type="password"] {
  background: var(--input); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px;
}
input[type="date"] { color-scheme: dark; }
:root[data-theme="light"] input[type="date"] { color-scheme: light; }

/* ---------- barra de filtros */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 10px; }
.search svg { width: 15px; height: 15px; color: var(--muted); }
.search input { border: 0; background: transparent; flex: 1; padding: 8px 0; outline: none; }
.custom-range { display: flex; gap: 6px; align-items: center; }

/* ---------- avisos */
.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: 4px; padding: 8px 12px; margin-bottom: 8px; font-size: 12.5px; }
.notice.err { background: #3d1e1e; color: #fca5a5; }
:root[data-theme="light"] .notice.err { background: #fdecec; color: #8a1c1c; }
.empty { background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 14px 18px; margin-bottom: 12px; }
.empty h2 { margin: 0 0 6px; font-size: 15px; }
.empty ol { margin: 6px 0 0; padding-left: 20px; }

/* ---------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-bottom: 26px; }
.tile { background: var(--panel); cursor: pointer; display: flex; flex-direction: column; border-bottom: 3px solid transparent; transition: transform .08s; }
.tile:hover { transform: translateY(-1px); }
.tile.selected { border-bottom-color: var(--accent); }
.tile-head { padding: 12px 14px 10px; color: #fff; }
.tile-head b { display: block; font-size: 14px; font-weight: 600; }
.tile-head small { font-size: 11.5px; opacity: .9; }
.tile-body { padding: 12px 14px 4px; flex: 1; }
.tile .k { color: var(--muted); font-size: 11.5px; }
.tile .k .d { margin-left: 4px; font-weight: 600; }
.tile .big { font-size: 22px; font-weight: 600; margin: 2px 0 12px; font-variant-numeric: tabular-nums; }
.tile .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.tile .v { font-size: 15px; font-variant-numeric: tabular-nums; }
.tile .v.link { color: var(--link); }
.tile-foot { text-align: center; padding: 8px; border-top: 1px solid var(--line); margin: 0 14px; }

/* ---------- sección de tabla */
.section-head { display: flex; align-items: center; gap: 18px; margin-bottom: 8px; }
.section-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.subtabs { display: flex; gap: 4px; }
.subtabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 8px; cursor: pointer; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.subtabs button.active { color: var(--link); border-bottom-color: var(--link); }
.subtabs svg { width: 14px; height: 14px; }
.section-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:last-child, td:last-child { border-right: 0; }
th { font-weight: 600; font-size: 12px; background: var(--panel); position: sticky; top: 0; cursor: pointer; user-select: none; vertical-align: bottom; white-space: normal; min-width: 64px; }
th.sorted::after { content: " ↓"; color: var(--link); }
th.sorted.asc::after { content: " ↑"; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover td { background: var(--hover); }
tr.zero td { opacity: .5; }
tr.clickable { cursor: pointer; }
tr.total td { font-weight: 700; background: var(--panel-2); }
tr.group-row td { background: var(--panel-2); font-weight: 600; }
.prod { display: flex; gap: 10px; align-items: center; min-width: 360px; max-width: 520px; }
.prod img, .prod .noimg { width: 40px; height: 40px; object-fit: cover; border-radius: 3px; background: #fff; flex: none; }
.prod .t { white-space: normal; line-height: 1.35; }
.prod .t .sku { color: var(--muted); font-size: 11.5px; }
.prod .t .name { display: block; }
.prod .t .meta { color: var(--muted); font-size: 11.5px; }
td.num-missing { color: var(--neg); font-weight: 600; }

/* ---------- P&L */
table.pl td:first-child { min-width: 220px; }
table.pl tr.strong td { font-weight: 700; background: var(--panel-2); }
table.pl tr.ratio td { color: var(--muted); }
table.pl tr.sub td:first-child { padding-left: 26px; color: var(--muted); }
table.pl th { cursor: default; }

/* ---------- chart */
.chart-card { background: var(--panel); border: 1px solid var(--line); padding: 14px; margin-bottom: 16px; }
.chart-wrap { position: relative; height: 340px; }

/* ---------- páginas */
.card { background: var(--panel); border: 1px solid var(--line); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 15px; }
.hint { color: var(--muted); font-size: 12.5px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; margin-bottom: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.form label.wide { grid-column: span 2; }
.status-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--neg); }
.dot.ok { background: var(--pos); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; white-space: normal; min-width: 240px; max-width: 320px; }
.chip { white-space: nowrap; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; font-size: 11.5px; }
.chip b { font-weight: 600; }

/* ---------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); width: min(860px, 100%); border-radius: 6px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head img { width: 44px; height: 44px; object-fit: cover; border-radius: 3px; background: #fff; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; }
.cost-group { margin-bottom: 18px; }
.cost-group h4 { margin: 0 0 6px; font-size: 13px; display: flex; justify-content: space-between; }
.cost-group table td, .cost-group table th { padding: 6px 8px; }
.cost-group table th { cursor: default; }
.breakdown td:first-child { padding-left: 14px; }
.breakdown tr.strong td { font-weight: 700; background: var(--panel-2); }
.breakdown tr.sub td:first-child { padding-left: 28px; color: var(--muted); }
.apply-to { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 10px; }
.apply-to label { flex-direction: row; align-items: center; gap: 4px; color: var(--ink); font-size: 12px; }

@media (max-width: 760px) {
  .app, .app.collapsed { grid-template-columns: 1fr; }
  aside { position: static; height: auto; }
  nav.side { display: flex; overflow-x: auto; }
  nav.side a { border-bottom: 0; white-space: nowrap; }
  main { padding: 0 12px 30px; }
  .head { flex-wrap: wrap; height: auto; padding: 8px 0; gap: 8px; }
  .form label.wide { grid-column: span 1; }
}

/* ---------- biblioteca de anuncios */
.lib-summary { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
.lib-summary b { color: var(--ink); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.ad-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.ad-card:hover { border-color: var(--accent); }
.ad-thumb { position: relative; aspect-ratio: 4 / 5; background: #000; }
.ad-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ad-thumb .badge { position: absolute; top: 8px; left: 8px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.ad-thumb .play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.ad-thumb .play span { width: 46px; height: 46px; border-radius: 50%; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; }
.ad-thumb .play svg { width: 22px; height: 22px; color: #fff; fill: #fff; }
.ad-thumb .com { position: absolute; bottom: 8px; right: 8px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.ad-info { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ad-name { font-weight: 600; font-size: 13px; line-height: 1.3; word-break: break-word; }
.ad-camp { color: var(--muted); font-size: 11.5px; line-height: 1.3; }
.ad-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
.ad-metrics .k { color: var(--muted); font-size: 11px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.status-dot.on { background: var(--pos); }

.ad-modal { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 20px; }
.player { background: #000; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 360px; }
.player video, .player img { width: 100%; max-height: 72vh; display: block; background: #000; }
.player .msg { color: #ddd; padding: 20px; text-align: center; font-size: 13px; }
.player .msg img { opacity: .5; margin-bottom: 10px; }
.vid-tabs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.ad-text { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 10px; font-size: 13px; max-height: 220px; overflow-y: auto; }
.ad-modal table td:first-child { color: var(--muted); }
.ad-modal h4 { margin: 14px 0 6px; font-size: 13px; }
.modal.wide { width: min(1100px, 100%); }

/* ---------- comentarios */
.com-item { display: grid; grid-template-columns: 1fr 260px; gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; margin-bottom: 10px; }
.com-head { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.com-head b { color: var(--ink); font-size: 13px; }
.com-msg { white-space: pre-wrap; font-size: 13.5px; line-height: 1.45; }
.com-reply { margin: 8px 0 0 18px; padding-left: 10px; border-left: 2px solid var(--line); }
.plat { font-size: 10.5px; padding: 1px 7px; border-radius: 9px; color: #fff; font-weight: 600; }
.plat.facebook { background: #1877f2; }
.plat.instagram { background: linear-gradient(45deg, #f58529, #dd2a7b, #8134af); }
.com-src { display: flex; gap: 10px; align-items: flex-start; font-size: 12px; cursor: pointer; }
.com-src img { width: 52px; height: 64px; object-fit: cover; border-radius: 3px; background: #000; flex: none; }
.com-src .muted { font-size: 11.5px; }
@media (max-width: 760px) {
  .ad-modal, .com-item { grid-template-columns: 1fr; }
}

/* ---------- insights de comentarios */
.ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.ins-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.ins-kpi .k { color: var(--muted); font-size: 11.5px; }
.ins-kpi .v { font-size: 20px; font-weight: 600; }
.ins-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.ins-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.ins-card h3 { margin: 0 0 8px; font-size: 13.5px; }
.signal { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.signal:hover, .signal.on { background: var(--hover); }
.signal.on { box-shadow: inset 3px 0 0 var(--accent); }
.signal b { font-variant-numeric: tabular-nums; }
.signal small { color: var(--muted); display: block; font-size: 11px; }
.ins-summary { background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 12px 16px; margin-bottom: 14px; }
.ins-summary h3 { margin: 0 0 4px; font-size: 14px; }
.ins-summary h4 { margin: 12px 0 4px; font-size: 13px; }
.ins-summary ul { margin: 0; padding-left: 18px; }
.ins-summary li { margin: 3px 0; line-height: 1.45; }
@media (max-width: 760px) { .ins-row { grid-template-columns: 1fr; } }

/* ---------- historial de cambios */
.his-day { margin: 16px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.his-item { display: grid; grid-template-columns: 64px 1fr minmax(220px, 300px); gap: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px 14px; margin-bottom: 6px; align-items: start; }
.his-item.auto { opacity: .7; }
.his-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.his-what { font-size: 13.5px; font-weight: 600; }
.his-obj { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.his-obj b { color: var(--ink); font-weight: 500; }
.his-obj .lvl { display: inline-block; font-size: 10.5px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; margin-right: 6px; color: var(--ink); }
.his-who { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.his-note { margin-top: 6px; font-size: 12.5px; background: var(--panel-2); border-left: 3px solid var(--accent); padding: 4px 8px; white-space: pre-wrap; }
.his-note-edit textarea { width: 100%; min-height: 54px; background: var(--input); color: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 6px; font: inherit; }
.his-impact { font-size: 12px; display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px 10px; }
.his-impact .h { color: var(--muted); font-size: 11px; }
.cat-pill { font-size: 10.5px; padding: 1px 7px; border-radius: 9px; margin-left: 6px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 500; }
.cat-pill.budget { border-color: #f59e0b; color: #f59e0b; }
.cat-pill.status { border-color: #60a5fa; color: #60a5fa; }
.cat-pill.created { border-color: #4ade80; color: #4ade80; }
@media (max-width: 760px) { .his-item { grid-template-columns: 1fr; } }

.his-path { display: grid; grid-template-columns: 70px 1fr; gap: 1px 8px; font-size: 12px; margin-top: 4px; color: var(--muted); }
.his-path .k { color: var(--muted); }
.his-path .mine { color: var(--ink); font-weight: 600; }
