:root {
  --bg: #0e1015;
  --bg-2: #13161d;
  --panel: #171a22;
  --panel-2: #1c2029;
  --border: #262a35;
  --border-2: #2f3442;
  --text: #e6e8ee;
  --text-2: #c9ccd6;
  --muted: #7d8294;
  --blue: #4f8cff;
  --green: #22c55e;
  --green-2: #34d399;
  --red: #ef4444;
  --red-2: #f87171;
  --amber: #f59e0b;
  --lime: #c6f432;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.4 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 12px 16px; margin: 0; }
.pos { color: var(--green-2); }
.neg { color: var(--red-2); }
.warn { color: var(--amber); }
.info { color: var(--blue); }
.ico { width: 15px; height: 15px; flex: none; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--bg-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 46px; height: 46px; border-radius: 4px; background: var(--lime); display: grid; place-items: center; overflow: hidden; }
.brand-logo span { color: #111; font-weight: 800; font-size: 11px; letter-spacing: -.3px; }
.brand-logo.has-img { background: transparent; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-logo.big { width: 64px; height: 64px; margin: 0 auto 8px; }
.brand-logo.big span { font-size: 14px; }
.brand-title { font-weight: 700; font-size: 15px; }
.badge.demo { background: rgba(245, 158, 11, .15); color: var(--amber); border: 1px solid rgba(245, 158, 11, .4); border-radius: 4px; padding: 2px 6px; font-size: 10px; font-weight: 700; letter-spacing: .5px; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.custom-range { display: flex; align-items: center; gap: 6px; }
.select { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px; padding: 6px 10px; font-size: 12px; font-weight: 500; min-height: 31px; outline: none; }
.select:focus { border-color: var(--blue); }
#accountSel { max-width: 260px; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px; padding: 6px 10px; font-size: 12px; font-weight: 500; cursor: pointer; min-height: 31px; white-space: nowrap; }
.btn:hover { border-color: #3c4354; background: #222734; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; justify-content: center; }
.btn.small { padding: 4px 8px; min-height: 0; margin-top: 6px; }
.icon-btn { padding: 6px 8px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 0 16px; background: var(--bg-2); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; color: var(--text-2); cursor: pointer; font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.main { padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.error-box { background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .4); color: var(--red-2); padding: 10px 14px; border-radius: var(--radius); }
.excluded-note { color: var(--amber); font-size: 12px; margin: 4px 0 8px; min-height: 16px; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.card-label { font-size: 9.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.spark { width: 52px; height: 22px; flex: none; }
.card-value { font-size: 17px; font-weight: 700; margin: 2px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.delta { font-size: 10.5px; font-weight: 500; }

/* ---------- Salud ---------- */
.health { margin-top: 12px; }
.health-bar { display: flex; height: 3px; border-radius: 2px; overflow: hidden; background: var(--border); }
.health-bar .seg { transition: width .3s; }
.seg.excellent { background: var(--green-2); }
.seg.good { background: var(--blue); }
.seg.attention { background: var(--amber); }
.health-legend { display: flex; gap: 14px; font-size: 11px; margin: 6px 0 10px; }

/* ---------- Auditor ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.auditor-head { width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 12px 16px; cursor: pointer; text-align: left; }
.auditor-title { font-weight: 700; }
.chevron { margin-left: auto; color: var(--muted); transition: transform .2s; }
.auditor.collapsed .chevron { transform: rotate(180deg); }
.auditor.collapsed .auditor-list, .auditor.collapsed .auditor-filters { display: none; }
.pill { font-size: 10.5px; padding: 2px 7px; border-radius: 4px; margin-right: 4px; background: var(--panel-2); color: var(--text-2); }
.pill.warn { background: rgba(245, 158, 11, .15); color: var(--amber); }
.pill.pos { background: rgba(34, 197, 94, .15); color: var(--green-2); }
.auditor-filters { display: flex; gap: 6px; padding: 0 16px 8px; }
.chip { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 20px; padding: 3px 10px; font-size: 11px; cursor: pointer; color: var(--text-2); }
.chip.active { border-color: var(--blue); color: var(--blue); }
.auditor-list { max-height: 245px; overflow-y: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.finding { background: #1b1d22; border-left: 3px solid var(--amber); border-radius: 4px; padding: 10px 12px; cursor: pointer; }
.finding.opportunity { border-left-color: var(--green); background: #18201d; }
.finding.alert { background: #201d17; }
.finding:hover { filter: brightness(1.12); }
.finding-head { display: flex; justify-content: space-between; gap: 10px; }
.finding-type { font-size: 9.5px; font-weight: 700; letter-spacing: .5px; }
.finding.alert .finding-type { color: var(--text); }
.finding.alert .finding-type::first-letter { color: var(--amber); }
.finding.opportunity .finding-type::first-letter { color: var(--green); }
.finding-entity { font-size: 11px; color: var(--muted); text-align: right; }
.finding-title { font-weight: 700; margin: 3px 0 2px; }
.finding-desc { color: var(--text-2); font-size: 12px; }
.finding-action { color: var(--blue); font-size: 11.5px; margin-top: 4px; }

/* ---------- Tabla ---------- */
.table-panel { display: flex; flex-direction: column; min-height: 420px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px; padding: 0 10px; width: 256px; max-width: 100%; min-height: 31px; color: var(--muted); }
.search input { background: none; border: 0; outline: none; width: 100%; font-size: 12px; color: var(--text); }
.check-inline { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); cursor: pointer; }
.warn-text { color: var(--amber); font-size: 12px; }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px; padding: 8px; z-index: 30; min-width: 190px; max-height: 380px; overflow-y: auto; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.dropdown-menu label { display: flex; align-items: center; gap: 8px; padding: 4px 4px; font-size: 12px; cursor: pointer; border-radius: 4px; }
.dropdown-menu label:hover { background: var(--panel); }

.table-wrap { position: relative; overflow-x: auto; flex: 1; }
table.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
.grid th { text-align: left; font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; background: var(--panel); position: sticky; top: 0; }
.grid th.sorted { color: var(--blue); }
.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.grid tbody tr.row { cursor: pointer; box-shadow: inset 3px 0 0 transparent; }
.grid tbody tr.row:hover { background: #1e222c; }
.grid tr.excellent { box-shadow: inset 3px 0 0 var(--green-2) !important; }
.grid tr.good { box-shadow: inset 3px 0 0 var(--blue) !important; }
.grid tr.attention { box-shadow: inset 3px 0 0 var(--amber) !important; }
.grid tr.excluded td:not(.col-check) { opacity: .4; }
.grid small { color: var(--muted); font-size: 9.5px; }
.col-check { width: 30px; padding-right: 0 !important; }
.col-health { width: 28px; }
.name-cell { font-weight: 600; display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.sub-cell { display: inline-block; max-width: 200px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.hicon { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font-size: 10px; font-weight: 700; }
.hicon.excellent { background: rgba(52, 211, 153, .15); color: var(--green-2); }
.hicon.good { background: rgba(79, 140, 255, .15); color: var(--blue); }
.hicon.attention { color: var(--amber); font-size: 12px; }
.rank { font-size: 10px; padding: 2px 6px; border-radius: 3px; }
.rank.good { background: rgba(34, 197, 94, .15); color: var(--green-2); }
.rank.bad { background: rgba(239, 68, 68, .15); color: var(--red-2); }
.rank.neutral { background: var(--panel-2); color: var(--text-2); }
.empty { text-align: center; color: var(--muted); padding: 40px !important; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--border); }
.pager { display: flex; gap: 4px; }
.loading { position: absolute; inset: 0; background: rgba(14, 16, 21, .55); display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border-2); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Panel lateral ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 500px; max-width: 100vw; background: var(--bg-2); border-left: 1px solid var(--border); z-index: 50; transform: translateX(100%); transition: transform .25s ease; overflow-y: auto; padding: 18px 18px 30px; }
.drawer.open { transform: none; }
.drawer-close { position: absolute; top: 12px; right: 12px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 4px; width: 26px; height: 26px; cursor: pointer; color: var(--text-2); }
.tag { display: inline-block; background: rgba(79, 140, 255, .15); color: var(--blue); font-size: 9.5px; font-weight: 700; letter-spacing: .6px; padding: 3px 8px; border-radius: 3px; }
.drawer-title { font-size: 17px; margin: 10px 30px 2px 0; word-break: break-word; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 14px 0; padding-top: 14px; border-top: 1px solid var(--border); }
.tile { background: var(--panel-2); border-radius: 6px; padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; position: relative; min-width: 0; }
.tile-label { font-size: 9px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tile-value { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-delta { font-size: 10px; }
.funnel { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.funnel-step { display: grid; grid-template-columns: 70px 1fr 54px 44px; align-items: center; gap: 8px; font-size: 11.5px; }
.funnel-step small { color: var(--muted); text-align: right; }
.funnel-step b { text-align: right; }
.funnel-bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.funnel-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #7aa8ff); border-radius: 4px; }
.drawer-h { font-size: 13px; margin: 20px 0 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.trend-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trend-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 9.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.trend-stats { font-size: 11px; color: var(--muted); margin: 10px 0 6px; }
.trend-stats b { color: var(--text); }
.chart-box { position: relative; height: 260px; }
.drawer .finding { margin-bottom: 6px; cursor: default; }

/* ---------- Vencimiento del token ---------- */
.token-chip { font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 4px; border: 1px solid; cursor: default; }
.token-chip.ok { color: var(--muted); border-color: var(--border-2); }
.token-chip.warn { color: var(--amber); border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .1); }
.token-chip.danger, .token-chip.expired { color: var(--red-2); border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .1); }
.token-banner { padding: 10px 14px; border-radius: var(--radius); border: 1px solid; font-size: 12.5px; }
.token-banner.warn { background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .4); color: #fcd38a; }
.token-banner.danger, .token-banner.expired { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .4); color: var(--red-2); }
.token-banner code { background: rgba(255, 255, 255, .08); padding: 1px 5px; border-radius: 3px; }

/* ---------- Modo privacidad (botón Ocultar) ---------- */
#hideBtn.active { border-color: var(--amber); color: var(--amber); }
body.privacy :is(
  #accountSel, .card-value, .delta,
  .grid td:not(.col-check):not(.col-health):not(.c-name):not(.c-campaign):not(.c-adset):not(.c-quality):not(.c-engagementRank):not(.c-conversionRank),
  .finding-desc, .tile-value, .tile-delta, .funnel-step b, .trend-stats b, .chart-box, .drawer .muted.small
) {
  filter: blur(6px);
  user-select: none;
}
body.privacy .chart-box { pointer-events: none; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; background: var(--bg); z-index: 100; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 320px; max-width: 100%; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-box h1 { font-size: 17px; margin: 0 0 6px; }
.login-box input { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px; padding: 10px 12px; outline: none; }
.login-box input:focus { border-color: var(--blue); }
.login-box .btn { padding: 10px; }
.error-text { color: var(--red-2); font-size: 12px; margin: 0; min-height: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 1500px) { .cards { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 900px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls { width: 100%; }
  .controls .select, #accountSel { flex: 1 1 140px; max-width: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .search { width: 100%; }
}
