/* Midnyte — reporting and tracker components (Results, links, event
   forwarding, media library, install) on the pearl tokens in pearl.css.
   Legacy control markup emitted by the page scripts (<button class="primary
   small">, .btn, raw inputs) is styled here at zero specificity with :where(),
   so any named component rule always wins and nothing needs !important. */

:root {
  --plane: var(--pl-canvas); --surface: var(--pl-raised-flat); --surface-2: var(--pl-hover);
  --ink: var(--pl-ink); --ink-2: var(--pl-ink-2); --muted: var(--pl-muted);
  --border: var(--pl-line); --border-solid: var(--pl-line);
  --good: var(--pl-good); --warning: var(--pl-warn); --critical: var(--pl-bad); --up: var(--pl-good);
  --radius: var(--pl-r-md); --font: var(--pl-font); --mono: var(--pl-mono);
}

/* ---- legacy controls (inside the app only) ---- */
:where(.pl-main, .pl-drawer) :where(button, .btn):not(:where([class*="pl-"])) {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 16px;
  border-radius: 24px; border: 1px solid var(--pl-raised-line); background: var(--pl-raised); box-shadow: var(--pl-shadow-btn);
  font: inherit; font-size: 13.5px; font-weight: 560; color: var(--pl-ink); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform .15s, background .15s;
}
:where(.pl-main, .pl-drawer) :where(button, .btn):not(:where([class*="pl-"])):hover { transform: translateY(-1px); background: var(--pl-raised-flat); }
:where(.pl-main, .pl-drawer) :where(button.primary, .btn.primary, .btn-primary) { color: var(--pl-primary-ink); background: var(--pl-primary); border-color: var(--pl-primary-line); box-shadow: inset 0 1px 1px #ffffff36, 0 10px 17px #51463b29; }
:where(.pl-main, .pl-drawer) :where(button.primary, .btn.primary, .btn-primary):hover { background: var(--pl-primary-hover); }
:where(.pl-main, .pl-drawer) :where(button.ghost, .btn.ghost) { background: transparent; box-shadow: none; border-color: transparent; color: var(--pl-ink-2); }
:where(.pl-main, .pl-drawer) :where(button.ghost, .btn.ghost):hover { background: var(--pl-hover); }
:where(.pl-main, .pl-drawer) :where(button.small, .btn.small) { min-height: 34px; padding: 5px 13px; font-size: 12.5px; }
:where(.pl-main, .pl-drawer) :where(button:disabled, .btn[aria-disabled="true"]) { opacity: .55; cursor: not-allowed; transform: none; }
:where(.pl-main, .pl-drawer) :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]), select, textarea) {
  min-height: 40px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--pl-field-line);
  background: var(--pl-field); box-shadow: var(--pl-field-shadow); font: inherit; font-size: 14px; color: var(--pl-ink); min-width: 0; max-width: 100%;
}
:where(.pl-main, .pl-drawer) :where(textarea) { line-height: 1.5; }
:where(.pl-main, .pl-drawer) :where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--pl-accent); width: 17px; height: 17px; }
:where(.pl-main, .pl-drawer) :where(label) { font-size: 13px; color: var(--pl-ink-2); font-weight: 560; }
:where(.pl-main, .pl-drawer) :where(select option) { color: #141417; background: #fff; }

.wrap { max-width: none !important; margin: 0; padding: 0; }
.spacer { flex: 1; }
.hide { display: none !important; }
.dim { color: var(--pl-muted); }
.mono { font-family: var(--pl-mono); font-size: 12.5px; }
.linkish { color: var(--pl-accent-ink); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.pos { color: var(--pl-good); } .neg { color: var(--pl-bad); }
.err { color: var(--pl-bad); font-size: 13.5px; }

/* ---- filter bar ---- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 16px 18px; margin-bottom: 18px;
  border-radius: var(--pl-r-md); border: 1px solid var(--pl-raised-line); background: var(--pl-sheet); box-shadow: var(--pl-shadow-card);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12.5px; color: var(--pl-muted); font-weight: 560; }
.field > select, .field > input, .field > textarea { width: 100%; max-width: 100%; }
.grid > * { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; border-radius: 20px; font-size: 12.5px; background: var(--pl-accent-wash); color: var(--pl-accent-ink); }
.chip b { font-weight: 640; }
:where(.pl-main) .chip button { min-height: 0; padding: 0 6px; border: 0; background: none; box-shadow: none; color: inherit; font-size: 16px; line-height: 1; }

/* ---- cards and tiles ---- */
.card { border: 1px solid var(--pl-raised-line); border-radius: var(--pl-r-md); background: var(--pl-sheet); box-shadow: var(--pl-shadow-card); padding: 20px 22px; margin-bottom: 18px; min-width: 0; }
.card > h2, .card > h3, .card-head h2, .card-head h3 { margin: 0 0 3px; font-size: 18px; font-weight: 640; letter-spacing: -.4px; }
.card .sub, .sub { color: var(--pl-muted); font-size: 13.5px; margin: 0 0 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { padding: 15px 16px; border-radius: 20px; border: 1px solid var(--pl-raised-line); background: var(--pl-raised); box-shadow: var(--pl-shadow-raised); min-width: 0; }
.tile .k { font-size: 12.5px; color: var(--pl-muted); font-weight: 560; }
.tile .v { font-size: 24px; font-weight: 680; letter-spacing: -.9px; margin-top: 2px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .n { font-size: 12.5px; color: var(--pl-muted); margin-top: 3px; }
.tile.accent .v { color: var(--pl-accent-ink); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 560; background: var(--pl-hover); color: var(--pl-ink-2); box-shadow: inset 0 0 0 1px var(--pl-line-soft); }
.pill.good { background: var(--pl-good-wash); color: var(--pl-good); box-shadow: none; }
.pill.bad { background: var(--pl-bad-wash); color: var(--pl-bad); box-shadow: none; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; border-radius: 14px; }
.table-wrap:focus-visible { outline: 2px solid var(--pl-focus); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 10px 12px; text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; white-space: normal; min-width: 150px; }
table.data thead th { position: sticky; top: 0; z-index: 1; background: var(--pl-raised-flat); color: var(--pl-muted); font-size: 12px; font-weight: 620; border-bottom: 1px solid var(--pl-line); cursor: pointer; user-select: none; }
table.data thead th:hover { color: var(--pl-ink); }
table.data thead th .dir { color: var(--pl-accent); }
table.data tbody tr { border-bottom: 1px solid var(--pl-line-soft); }
table.data tbody tr:hover { background: var(--pl-hover); }
table.data td.num { font-variant-numeric: tabular-nums; }
table.data tfoot td { padding: 10px 12px; font-weight: 650; border-top: 1px solid var(--pl-line); text-align: right; }
table.data tfoot td:first-child { text-align: left; }
.trunc { display: block; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-cell { position: relative; }
.bar-cell .fill { position: absolute; left: 0; top: 5px; bottom: 5px; background: var(--q1); opacity: .6; border-radius: 0 4px 4px 0; z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }
.empty { padding: 34px 16px; text-align: center; color: var(--pl-muted); font-size: 14px; }

/* ---- charts ---- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--pl-muted); font-size: 11.5px; font-family: var(--pl-font); }
.chart text.value { fill: var(--pl-ink-2); font-weight: 600; }
.chart .line { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--pl-raised-flat); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 12px; }
.legend .item { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--pl-ink-2); cursor: pointer; }
.legend .item.off { opacity: .4; }
.legend .swatch { width: 12px; height: 4px; border-radius: 3px; }
.tooltip { position: absolute; pointer-events: none; z-index: 30; min-width: 140px; padding: 10px 12px; border-radius: 14px; font-size: 13px; background: var(--pl-raised-flat); border: 1px solid var(--pl-raised-line); box-shadow: 0 10px 24px #3a2f4526; transform: translate(-50%, -108%); opacity: 0; transition: opacity .1s; color: var(--pl-ink); }
.tooltip.on { opacity: 1; }
.tooltip .t { font-weight: 650; margin-bottom: 4px; }
.tooltip .r { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tooltip .r .l { display: inline-flex; align-items: center; gap: 6px; color: var(--pl-ink-2); }
.tooltip .r b { font-variant-numeric: tabular-nums; }
.funnel { display: flex; flex-direction: column; gap: 4px; }
.funnel .step { display: grid; grid-template-columns: 128px 1fr; align-items: center; gap: 12px; }
.funnel .step .lbl { font-size: 13px; color: var(--pl-ink-2); }
.funnel .step .track { position: relative; height: 32px; background: var(--pl-hover); border-radius: 0 10px 10px 0; box-shadow: inset 0 0 0 1px var(--pl-line-soft); }
.funnel .step .fill { position: absolute; inset: 0 auto 0 0; border-radius: 0 10px 10px 0; }
.funnel .step .n { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-weight: 650; font-variant-numeric: tabular-nums; color: #fff; }
.funnel .step .n.outside { left: auto; color: var(--pl-ink); }
.funnel .drop { grid-column: 2; font-size: 12px; color: var(--pl-muted); padding: 1px 0 3px 10px; }

/* ---- in-page tabs (Results: performance, products, orders, spend, events) ---- */
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 18px; border-radius: 24px; background: var(--pl-hover); box-shadow: inset 0 0 0 1px var(--pl-line-soft); width: max-content; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
:where(.pl-main) .tabs button { min-height: 36px; padding: 6px 15px; border-radius: 20px; border: 0; background: none; box-shadow: none; font-size: 13.5px; color: var(--pl-ink-2); font-weight: 530; }
:where(.pl-main) .tabs button:hover { transform: none; background: var(--pl-hover); }
:where(.pl-main) .tabs button.on { background: var(--pl-raised); box-shadow: var(--pl-shadow-btn); color: var(--pl-ink); font-weight: 640; }

/* ---- misc ---- */
.toast { display: none; }
code.snippet { display: block; font-family: var(--pl-mono); font-size: 12.5px; word-break: break-all; white-space: pre-wrap; background: var(--pl-field); border: 1px solid var(--pl-field-line); border-radius: 12px; padding: 12px 14px; }
.note { border-radius: 16px; padding: 12px 16px; font-size: 13.5px; color: var(--pl-ink-2); background: var(--pl-info-wash); }
.note.warn { background: var(--pl-warn-wash); }
.data-quality { display: flex; gap: 10px; flex-wrap: wrap; margin: -6px 0 18px; }

@media (max-width: 620px) {
  .filters { padding: 12px; }
  .filters .field { flex: 1 1 140px; }
  .trunc { max-width: 22ch; }
  .card { padding: 16px; }
  .tile .v { font-size: 20px; }
}

/* Tracking links: form beside the results on wide screens, stacked on phones and tablets. */
.links-layout { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .links-layout { grid-template-columns: minmax(330px, 400px) minmax(0, 1fr); } }
