/* Ads Engine — Puesto de mando. Estética "instrumento de sala de control":
   tinta profunda + marfil + latón sobrio + señal jade. Fraunces / Hanken Grotesk / IBM Plex Mono. */
:root {
  --ink: #0a0c0f;
  --ink-2: #0c0f13;
  --surface: #12161c;
  --surface-2: #161b22;
  --hair: rgba(236, 233, 226, 0.085);
  --hair-2: rgba(236, 233, 226, 0.16);
  --ivory: #ece9e2;
  --muted: #99a0aa;
  --faint: #6a727d;
  --brass: #cda35e;
  --brass-2: #a9853f;
  --jade: #59d3a4;
  --jade-dim: rgba(89, 211, 164, 0.16);
  --warn: #e2a850;
  --danger: #e06a60;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-io: cubic-bezier(0.77, 0, 0.175, 1);
  --r: 14px;
  --maxw: 1180px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  color: var(--ivory);
  background:
    radial-gradient(120% 80% at 78% -8%, rgba(205, 163, 94, 0.10), transparent 55%),
    radial-gradient(90% 70% at 8% 0%, rgba(89, 211, 164, 0.05), transparent 50%),
    var(--ink);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-feature-settings: "tnum" 1; letter-spacing: -0.01em; }

/* Grain: textura fina de sala de control, muy sutil */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.eyebrow {
  font-size: 0.66rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--brass); font-weight: 600;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px clamp(20px, 5vw, 56px);
  background: linear-gradient(var(--ink), rgba(10, 12, 15, 0.72));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--hair);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand__mark { color: var(--brass); font-size: 0.7rem; transform: translateY(-2px); }
.brand__word { font-family: "Fraunces", serif; font-weight: 600; font-size: 1.32rem; letter-spacing: -0.03em; }
.brand__thin { font-weight: 400; font-style: italic; color: var(--muted); }
.brand__tag {
  font-size: 0.6rem; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--faint); border-left: 1px solid var(--hair-2); padding-left: 12px;
}
.topbar__right { display: flex; align-items: center; gap: 20px; }
.tenant { display: flex; align-items: center; gap: 10px; }
.tenant__lbl { font-size: 0.62rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--faint); }
.tenant__select {
  appearance: none; background: var(--surface-2); color: var(--ivory);
  border: 1px solid var(--hair-2); border-radius: 9px; padding: 7px 30px 7px 12px;
  font: inherit; font-size: 0.85rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23cda35e' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  transition: border-color 0.16s var(--ease-out);
}
.tenant__select:hover { border-color: var(--brass-2); }
.conn {
  font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 7px; color: var(--muted);
}
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.conn--ok { color: var(--jade); }
.conn--wait { color: var(--warn); }
.conn--err { color: var(--danger); }

/* ---------- Layout ---------- */
.wrap { position: relative; z-index: 1; max-width: var(--maxw); margin: 0 auto; padding: clamp(28px, 5vw, 52px) clamp(20px, 5vw, 56px) 80px; }

.lede { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; flex-wrap: wrap; margin-bottom: 40px; }
.lede__name {
  font-family: "Fraunces", serif; font-weight: 500; font-size: clamp(2.1rem, 5.2vw, 3.3rem);
  letter-spacing: -0.04em; line-height: 1.02; text-wrap: balance;
}
.lede__sub { color: var(--muted); font-size: 0.92rem; margin-top: 8px; }
.lede__period { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.lede__range { font-size: 0.92rem; color: var(--ivory); }
.lede__period .eyebrow { align-self: flex-end; }

/* ---------- KPIs (rejilla con jerarquía, NO 6 cards iguales) ---------- */
.kpis { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi {
  position: relative; grid-column: span 4;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--hair); border-radius: var(--r);
  padding: 20px 22px; overflow: hidden;
  opacity: 0; transform: translateY(10px);
  animation: rise 0.6s var(--ease-out) forwards;
}
.kpi--hero { grid-column: span 12; padding: 26px 28px; }
.kpi--sm { grid-column: span 4; }
.kpi::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--brass); opacity: 0.5; }
.kpi--hero::after { background: var(--jade); opacity: 0.7; }
.kpi__label { font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); }
.kpi__value { font-family: "IBM Plex Mono", monospace; font-weight: 500; letter-spacing: -0.03em; line-height: 1; margin-top: 12px; font-size: clamp(1.6rem, 3.4vw, 2.1rem); }
.kpi--hero .kpi__value { font-size: clamp(2.6rem, 7vw, 4rem); color: var(--jade); }
.kpi__unit { font-size: 0.5em; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.kpi__sub { font-size: 0.74rem; color: var(--muted); margin-top: 9px; }

/* ---------- Panels ---------- */
.panel { background: linear-gradient(170deg, var(--surface-2), var(--surface)); border: 1px solid var(--hair); border-radius: var(--r); padding: 24px clamp(18px, 3vw, 28px); margin-bottom: 22px; }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel__title { font-family: "Fraunces", serif; font-weight: 500; font-size: 1.18rem; letter-spacing: -0.02em; }
.panel__hint { color: var(--faint); font-size: 0.8rem; font-weight: 400; }
.legend { display: flex; gap: 16px; font-size: 0.74rem; color: var(--muted); }
.legend__item { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.dot--spend { background: var(--brass); }
.dot--leads { background: var(--jade); }

/* ---------- Chart ---------- */
.chart { width: 100%; height: 260px; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .axis { stroke: var(--hair); stroke-width: 1; }
.chart .axlabel { fill: var(--faint); font-family: "IBM Plex Mono", monospace; font-size: 10px; }
.chart .area { fill: url(#g-spend); }
.chart .line { fill: none; stroke: var(--brass); stroke-width: 2; }
.chart .lead-dot { fill: var(--jade); stroke: var(--ink); stroke-width: 1.5; }
.chart .lead-line { fill: none; stroke: var(--jade); stroke-width: 1.5; stroke-dasharray: 3 4; opacity: 0.7; }

/* ---------- Cols ---------- */
.cols { display: grid; grid-template-columns: 1.7fr 1fr; gap: 22px; align-items: start; }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.dtable th { text-align: left; font-size: 0.62rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); font-weight: 600; padding: 0 14px 12px; border-bottom: 1px solid var(--hair-2); }
.dtable td { padding: 13px 14px; border-bottom: 1px solid var(--hair); }
.dtable tbody tr { transition: background 0.14s var(--ease-out); }
.dtable tbody tr:hover { background: rgba(236, 233, 226, 0.025); }
.dtable .num { text-align: right; font-family: "IBM Plex Mono", monospace; letter-spacing: -0.02em; }
.dtable .lead-pos { color: var(--jade); }

/* ---------- Gate ---------- */
.gate { text-align: center; padding: 8px 6px 4px; }
.gate__shield { font-size: 2rem; opacity: 0.9; }
.gate__lead { font-family: "Fraunces", serif; font-style: italic; font-size: 1.08rem; margin: 12px 0 10px; color: var(--ivory); }
.gate__note { font-size: 0.82rem; color: var(--muted); line-height: 1.55; }
.gate__list { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--hair); }
.gate__empty { font-size: 0.8rem; color: var(--faint); font-style: italic; }

/* ---------- Buttons ---------- */
.btn { font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; border-radius: 9px; padding: 9px 16px; border: 1px solid var(--hair-2); background: transparent; color: var(--ivory); transition: border-color 0.16s var(--ease-out), background 0.16s var(--ease-out), transform 0.1s var(--ease-out); }
.btn--ghost:hover { border-color: var(--brass); color: var(--brass); }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; cursor: progress; }

/* ---------- Foot ---------- */
.foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 30px; color: var(--faint); font-size: 0.74rem; }
.foot__sep { opacity: 0.5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); z-index: 90;
  background: var(--surface-2); border: 1px solid var(--hair-2); color: var(--ivory);
  padding: 12px 18px; border-radius: 10px; font-size: 0.84rem; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.2s var(--ease-out), transform 0.3s var(--ease-out);
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }
.toast--err { border-color: var(--danger); }

@keyframes rise { to { opacity: 1; transform: none; } }
.kpi:nth-child(1) { animation-delay: 0.04s; }
.kpi:nth-child(2) { animation-delay: 0.10s; }
.kpi:nth-child(3) { animation-delay: 0.16s; }
.kpi:nth-child(4) { animation-delay: 0.22s; }
.kpi:nth-child(5) { animation-delay: 0.28s; }
.kpi:nth-child(6) { animation-delay: 0.34s; }

@media (max-width: 820px) {
  .kpi, .kpi--sm { grid-column: span 6; }
  .cols { grid-template-columns: 1fr; }
  .lede { align-items: flex-start; }
  .lede__period { align-items: flex-start; }
  .lede__period .eyebrow, .lede__range { align-self: flex-start; }
}
@media (max-width: 520px) { .kpi, .kpi--sm { grid-column: span 12; } }

@media (prefers-reduced-motion: reduce) {
  .kpi { animation: none; opacity: 1; transform: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ---------- Badges de estado ---------- */
.badge { font-size: 0.6rem; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid currentColor; }
.badge--active { color: var(--jade); }
.badge--paused { color: var(--warn); }
.badge--off { color: var(--faint); }

/* ---------- Eventos del píxel ---------- */
.events { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.ev { border: 1px solid var(--hair); border-radius: 12px; padding: 16px 18px; background: rgba(236, 233, 226, 0.015); }
.ev__name { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.ev__name i { width: 8px; height: 8px; border-radius: 50%; background: var(--jade); box-shadow: 0 0 8px var(--jade); }
.ev__count { font-family: "IBM Plex Mono", monospace; font-size: 1.8rem; font-weight: 500; margin-top: 8px; letter-spacing: -0.03em; }
.ev--quiet .ev__name i { background: var(--faint); box-shadow: none; }

/* ---------- Campañas ---------- */
.camps { display: flex; flex-direction: column; gap: 10px; }
.camp { display: grid; grid-template-columns: 1.6fr repeat(4, 1fr); gap: 14px; align-items: center; padding: 16px 18px; border: 1px solid var(--hair); border-radius: 12px; background: rgba(236, 233, 226, 0.015); transition: border-color 0.16s var(--ease-out); }
.camp:hover { border-color: var(--hair-2); }
.camp__name { font-weight: 600; font-size: 0.95rem; display: flex; flex-direction: column; gap: 6px; }
.camp__name small { font-size: 0.68rem; color: var(--faint); font-weight: 400; letter-spacing: 0.04em; }
.camp__top { display: flex; align-items: center; gap: 10px; }
.camp__metric { text-align: right; }
.camp__metric .v { font-family: "IBM Plex Mono", monospace; font-size: 1.05rem; letter-spacing: -0.02em; }
.camp__metric .l { font-size: 0.6rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); display: block; margin-top: 3px; }
.camp__metric .v.jade { color: var(--jade); }

/* ---------- Creatividades ---------- */
.creatives { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.cre { border: 1px solid var(--hair); border-radius: 12px; overflow: hidden; background: var(--ink-2); transition: transform 0.18s var(--ease-out), border-color 0.18s var(--ease-out); }
.cre:hover { transform: translateY(-3px); border-color: var(--brass-2); }
.cre__thumb { position: relative; aspect-ratio: 1 / 1; background: #0a0c0f center/cover no-repeat; display: flex; align-items: center; justify-content: center; }
.cre__thumb--empty { color: var(--faint); font-size: 0.72rem; }
.cre__play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: rgba(255,255,255,0.9); text-shadow: 0 2px 12px rgba(0,0,0,0.6); }
.cre__body { padding: 12px 14px; }
.cre__name { font-size: 0.8rem; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cre__foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.cre__spend { font-family: "IBM Plex Mono", monospace; font-size: 0.74rem; color: var(--muted); }

/* ---------- Tooltip de la gráfica ---------- */
.chart { position: relative; }
.chart-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--ink); border: 1px solid var(--brass-2); border-radius: 9px; padding: 9px 12px; font-size: 0.76rem; opacity: 0; transform: translate(-50%, -120%); transition: opacity 0.12s var(--ease-out); white-space: nowrap; box-shadow: 0 12px 32px rgba(0,0,0,0.5); }
.chart-tip.show { opacity: 1; }
.chart-tip .d { color: var(--faint); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.chart-tip .s { color: var(--brass); font-family: "IBM Plex Mono", monospace; }
.chart-tip .l { color: var(--jade); font-family: "IBM Plex Mono", monospace; }
.chart .cross { stroke: var(--hair-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.chart .cross.show { opacity: 1; }
.chart .hot { fill: transparent; }

@media (max-width: 700px) {
  .camp { grid-template-columns: 1fr 1fr; gap: 10px; }
  .camp__name { grid-column: span 2; }
}
