/* ==========================================================================
   Ad-account data module
   Replaces the old 22-row scrolling table: a KPI bento, a real distribution
   histogram, and per-campaign bar rows that expand. Table is opt-in.
   ========================================================================== */

/* ---------- KPI bento ---------- */
.kpi {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-3);
}

.kpi-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-5);
  background: var(--bg-2);
  overflow: hidden;
  transition: border-color var(--d-med) ease, transform var(--d-med) var(--ease-quart);
}
.kpi-card:hover { border-color: var(--border-2); transform: translateY(-3px); }

.kpi-lead {
  grid-column: 1 / -1;
  background:
    radial-gradient(110% 130% at 0% 0%, oklch(70% 0.175 256 / 12%), transparent 55%),
    var(--surface);
  border-color: var(--border-2);
  padding: var(--s-6);
}

.kpi-k {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  line-height: 1.4;
  color: var(--muted-2);
}

.kpi-v {
  font-family: var(--font-mono);
  font-size: clamp(1.5rem, 1.15rem + 1.6vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.06em;
  color: var(--text);
  line-height: 1.05;
  margin-top: var(--s-2);
}

.kpi-lead .kpi-v {
  font-size: clamp(2.6rem, 1.9rem + 3.4vw, 4.2rem);
  color: var(--accent);
}

.kpi-n { font-size: var(--t-xs); color: var(--muted); margin-top: var(--s-2); line-height: 1.5; }
.kpi-n b { color: var(--text-2); font-weight: 600; }

/* meter used on CTR / cost cards */
.kpi-meter {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: var(--s-4);
  overflow: hidden;
}
.kpi-meter i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 1.3s var(--ease-expo) 0.15s;
}
.kpi-card.in .kpi-meter i { width: var(--w, 30%); }

/* ---------- Distribution histogram (real per-ad purchases) ---------- */
.hist { margin-top: var(--s-6); }

.hist-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.hist-head span {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted-2);
}

.hist-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 62px;
}

.hist-bars i {
  flex: 1;
  min-width: 0;
  height: 0;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  opacity: 0.55;
  transition: height 0.9s var(--ease-expo), opacity var(--d-fast) ease;
}
.hist.in .hist-bars i { height: var(--h); }
.hist-bars i:hover { opacity: 1; }
.hist-bars i[data-zero="1"] {
  height: 2px !important;
  background: var(--border-3);
  opacity: 1;
}

.hist-foot {
  display: flex;
  justify-content: space-between;
  margin-top: var(--s-2);
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  letter-spacing: 0.06em;
  color: var(--muted-2);
}

@media (min-width: 720px) {
  .kpi { grid-template-columns: repeat(4, 1fr); }
  .kpi-lead { grid-column: span 2; grid-row: span 2; display: flex; flex-direction: column; }
  .kpi-lead .hist { margin-top: auto; padding-top: var(--s-6); }
  .hist-bars { height: 78px; }
}

/* ---------- Source note ---------- */
.src {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  margin-top: var(--s-5);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  letter-spacing: -0.03em;
  color: var(--muted-2);
  line-height: 1.6;
}
.src svg { flex-shrink: 0; margin-top: 2px; color: var(--accent); }

/* ---------- Controls ---------- */
.ctl {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  margin-top: var(--s-12);
  padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--border);
}

.ctl-group { display: flex; flex-direction: column; gap: var(--s-2); }

.ctl-lbl {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted-2);
}

.ctl-btns {
  display: flex;
  gap: var(--s-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  margin-inline: calc(var(--edge) * -1);
  padding-inline: var(--edge);
}
.ctl-btns::-webkit-scrollbar { display: none; }

.ctl-btns button {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  letter-spacing: -0.03em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: var(--s-2) var(--s-4);
  min-height: 38px;
  white-space: nowrap;
  transition: color var(--d-fast) ease, border-color var(--d-fast) ease, background var(--d-fast) ease;
}
.ctl-btns button:hover { color: var(--text); border-color: var(--border-2); }
.ctl-btns button[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

@media (min-width: 800px) {
  .ctl { flex-direction: row; align-items: flex-end; justify-content: space-between; gap: var(--s-8); }
  .ctl-btns { margin-inline: 0; padding-inline: 0; overflow: visible; }
}

/* ---------- Campaign rows ---------- */
.camps { display: flex; flex-direction: column; }

.camp { border-bottom: 1px solid var(--border); }

.camp-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--s-2) var(--s-4);
  align-items: center;
  padding-block: var(--s-4);
  min-height: 62px;
  transition: background var(--d-fast) ease;
}
.camp-btn:hover { background: oklch(90% 0.02 260 / 3%); }

.camp-name {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  letter-spacing: -0.03em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.camp-flag {
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-pill);
  padding: 2px 7px;
}

.camp-val {
  grid-row: 1;
  grid-column: 2;
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  justify-self: end;
}
.camp-val b {
  font-family: var(--font-mono);
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: -0.05em;
  color: var(--text);
}
.camp-val span { font-size: 0.625rem; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.07em; }
.camp.is-zero .camp-val b { color: var(--muted-2); }

.camp-track {
  grid-column: 1 / -1;
  grid-row: 2;
  height: 4px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.camp-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.85s var(--ease-expo);
}
/* a row with no value for the active metric shows a dashed, inert track
   rather than a zero-length bar that would read as a rendering bug */
.camp.no-val .camp-fill {
  background: repeating-linear-gradient(
    90deg,
    var(--border-3) 0 4px,
    transparent 4px 8px
  );
  width: 100% !important;
  transition: none;
  opacity: 0.45;
}

.camp-sub {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-4);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: -0.02em;
  color: var(--muted-2);
}
.camp-sub em { font-style: normal; color: var(--text-2); }

/* expandable detail */
.camp-det { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--d-med) var(--ease-quart); }
.camp[data-open="true"] .camp-det { grid-template-rows: 1fr; }
.camp-det > div { overflow: hidden; }

.camp-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-4);
  padding: var(--s-2) 0 var(--s-6);
}

.camp-cell .k {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-2);
}
.camp-cell .v {
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--text-2);
  margin-top: 3px;
}

@media (min-width: 720px) {
  .camp-btn {
    grid-template-columns: 200px 1fr 120px;
    grid-template-rows: auto;
    align-items: center;
    gap: var(--s-5);
    padding-block: var(--s-4);
  }
  .camp-name { grid-row: 1; grid-column: 1; }
  .camp-track { grid-row: 1; grid-column: 2; }
  .camp-val { grid-row: 1; grid-column: 3; }
  .camp-sub { grid-row: 2; grid-column: 2 / -1; margin-top: var(--s-1); }
  .camp-grid { grid-template-columns: repeat(4, 1fr); }
}

/* empty state when a filter matches nothing */
.camps-empty {
  padding: var(--s-10) 0;
  text-align: center;
  font-size: var(--t-sm);
  color: var(--muted-2);
}

/* ---------- Totals bar ---------- */
.totals {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-4);
  margin-top: var(--s-6);
  padding: var(--s-5);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
}

.totals .k {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-2);
}
.totals .v {
  font-family: var(--font-mono);
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: -0.05em;
  color: var(--text);
  margin-top: 3px;
}
.totals .v.hl { color: var(--accent); }

@media (min-width: 720px) {
  .totals { grid-template-columns: repeat(5, 1fr); }
}

/* ---------- Raw table (opt-in) ---------- */
.raw-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-6);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  letter-spacing: -0.03em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: var(--s-3) var(--s-5);
  min-height: 44px;
  transition: color var(--d-fast) ease, border-color var(--d-fast) ease;
}
.raw-toggle:hover { color: var(--accent); border-color: var(--accent-line); }
.raw-toggle .ic { transition: transform var(--d-med) var(--ease-expo); }
.raw-toggle[aria-expanded="true"] .ic { transform: rotate(180deg); }

.raw-wrap { margin-top: var(--s-5); }
.raw-wrap[hidden] { display: none; }

.raw-hint {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--muted-2);
  margin-bottom: var(--s-3);
}

.raw-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  -webkit-overflow-scrolling: touch;
}

table.raw {
  width: 100%;
  min-width: 660px;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

table.raw th {
  position: sticky;
  top: 0;
  text-align: left;
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-2);
}

table.raw td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

table.raw tbody tr:hover td { background: oklch(90% 0.02 260 / 3%); }
table.raw td.hl { color: var(--accent); font-weight: 600; }
table.raw tr.zero td { color: var(--muted-2); }
table.raw tr.zero td.hl { color: var(--muted-2); }

table.raw tfoot td {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  border-top: 1px solid var(--border-2);
  border-bottom: none;
  position: sticky;
  bottom: 0;
}
table.raw tfoot td.hl { color: var(--accent); }

/* ---------- Honesty callout ---------- */
.honest {
  margin-top: var(--s-6);
  display: flex;
  gap: var(--s-4);
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-2);
}

.honest .mk {
  font-family: var(--font-mono);
  font-size: var(--t-lg);
  color: var(--muted-2);
  line-height: 1;
  flex-shrink: 0;
}
.honest p { font-size: var(--t-sm); color: var(--muted); line-height: 1.7; }
.honest b { color: var(--text-2); font-weight: 600; }
