:root {
  color-scheme: light dark;
  --bg: light-dark(#f5f7f8, #0f1416);
  --surface: light-dark(#ffffff, #171e21);
  --surface-soft: light-dark(#edf2f0, #1d2927);
  --text: light-dark(#17201d, #edf4f1);
  --muted: light-dark(#64706c, #a9b6b1);
  --border: light-dark(#dce4e1, #2b3733);
  --green: light-dark(#13795b, #48c49a);
  --orange: light-dark(#c76712, #f2a45f);
  --blue: light-dark(#366bc8, #79a4f0);
  --red: light-dark(#b84040, #ef7979);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.app-heading { display: flex; align-items: center; gap: 20px; }
.product-brand { display: grid; gap: 1px; padding-right: 20px; border-right: 1px solid var(--border); color: var(--text); text-decoration: none; }
.product-brand strong { font-size: 1.18rem; line-height: 1; letter-spacing: -.04em; }
.product-brand span { color: var(--muted); font: italic .68rem Georgia, serif; }

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.5rem, 3vw, 2.15rem); font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 650; }
.eyebrow { color: var(--green); font-size: .72rem; font-weight: 750; letter-spacing: .11em; margin-bottom: 4px; }
.viewer { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .88rem; }
.viewer-identity { display: grid; justify-items: end; gap: 3px; }
.role-badge {
  padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--green) 55%, var(--border));
  border-radius: 999px;
  color: var(--green);
  font-size: .63rem;
  font-weight: 750;
  letter-spacing: .08em;
}
.viewer button {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

main { width: min(1180px, calc(100% - 32px)); margin: 28px auto 52px; }
.toolbar { display: flex; align-items: end; gap: 14px; flex-wrap: wrap; }
.toolbar label { display: grid; gap: 6px; color: var(--muted); font-size: .8rem; }
.toolbar input, .toolbar select {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface);
}
.toolbar select { min-width: 170px; cursor: pointer; }
.duration { min-height: 42px; display: grid; align-content: center; padding-inline: 5px; }
.duration span { font-size: 1.05rem; font-weight: 700; }
.duration small { color: var(--muted); }
.freshness {
  min-height: 42px;
  display: grid;
  align-content: center;
  gap: 2px;
  margin-left: auto;
  padding: 7px 11px;
  border: 1px solid color-mix(in srgb, var(--green) 45%, var(--border));
  border-radius: 9px;
  background: var(--surface);
  color: var(--green);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.freshness strong { font-size: .78rem; }
.freshness small { color: var(--muted); font-size: .72rem; }
.freshness.stale { border-color: color-mix(in srgb, var(--orange) 55%, var(--border)); color: var(--orange); }
.freshness:hover, .freshness:focus-visible { border-color: currentColor; }

.secondary-button, .icon-button, .text-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}
.secondary-button { min-height: 34px; border-radius: 8px; padding: 6px 10px; }
.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.35rem;
  line-height: 1;
}
.text-button {
  justify-self: start;
  border: 0;
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-size: .76rem;
}

.integrations-dialog, .sync-details-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 40px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  background: var(--bg);
  box-shadow: 0 24px 80px color-mix(in srgb, #000 60%, transparent);
}
.integrations-dialog::backdrop, .sync-details-dialog::backdrop { background: rgb(0 0 0 / 62%); backdrop-filter: blur(3px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.dialog-heading h2 { margin: 2px 0 0; font-size: 1.2rem; }

.sync-timezone-note, .sync-job-summary, .sync-empty {
  color: var(--muted);
  font-size: .78rem;
}
.sync-timezone-note { margin: 9px 0 0; }
.sync-timezone-note strong { color: var(--text); }
.sync-source-list { display: grid; gap: 9px; margin-top: 16px; }
.sync-source-card {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.sync-source-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sync-source-heading strong { font-size: .88rem; }
.sync-source-status {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.sync-source-status.ok { border-color: color-mix(in srgb, var(--green) 48%, var(--border)); color: var(--green); }
.sync-source-status.error { border-color: color-mix(in srgb, var(--red) 48%, var(--border)); color: var(--red); }
.sync-source-status.running, .sync-source-status.syncing { border-color: color-mix(in srgb, var(--blue) 48%, var(--border)); color: var(--blue); }
.sync-source-card dl {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 5px 14px;
  margin: 0;
  font-size: .74rem;
}
.sync-source-card dt { color: var(--muted); }
.sync-source-card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.sync-job-summary { margin: 14px 0 0; }

.integration-card {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.integration-card[hidden] { display: none; }
.integration-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.integration-card-heading > div { display: grid; gap: 3px; }
.integration-card-heading strong { font-size: .86rem; }
.integration-card-heading small { color: var(--muted); font-size: .74rem; }
.integration-card form { display: grid; grid-template-columns: 1fr 1fr; align-items: end; gap: 9px; }
.integration-card form[hidden] { display: none; }
.integration-card label { display: grid; gap: 5px; color: var(--muted); font-size: .74rem; }
.integration-card input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
  background: var(--bg);
}
.integration-card form > button {
  grid-column: 1 / -1;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 7px 12px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
}
.integration-card form > button:disabled { opacity: .65; cursor: wait; }
.connected-badge {
  padding: 4px 9px;
  border: 1px solid color-mix(in srgb, var(--green) 55%, var(--border));
  border-radius: 999px;
  color: var(--green);
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .08em;
}

.channel-tabs {
  display: flex;
  gap: 26px;
  margin-top: 20px;
  border-bottom: 1px solid var(--border);
}
.channel-tabs button {
  min-height: 42px;
  margin-bottom: -1px;
  padding: 7px 2px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font-weight: 650;
  cursor: pointer;
}
.channel-tabs button[aria-selected="true"] {
  border-bottom-color: var(--green);
  color: var(--text);
}

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 20px 0; }
.stats article {
  display: grid;
  gap: 8px;
  min-height: 92px;
  align-content: center;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.stats span { color: var(--muted); font-size: .8rem; }
.stats strong { font-size: clamp(1.2rem, 2.2vw, 1.65rem); font-variant-numeric: tabular-nums; }

.panel {
  margin-top: 14px;
  padding: clamp(16px, 3vw, 26px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.chart-controls { display: flex; align-items: end; justify-content: flex-end; gap: 18px; flex-wrap: wrap; }
.chart-controls label { display: grid; gap: 4px; color: var(--muted); font-size: .72rem; }
.chart-controls select {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .78rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend [hidden] { display: none; }
.legend i { width: 18px; height: 3px; border-radius: 2px; }
.legend .spend { background: var(--blue); }
.legend .placed { background: var(--orange); }
.legend .completed { background: var(--green); }
.scale-note { color: var(--muted); font-size: .78rem; }

.reconciliation-status {
  display: grid;
  justify-items: end;
  gap: 3px;
  color: var(--green);
}
.reconciliation-status strong {
  padding: 4px 9px;
  border: 1px solid color-mix(in srgb, var(--green) 55%, var(--border));
  border-radius: 999px;
  font-size: .68rem;
  letter-spacing: .08em;
}
.reconciliation-status strong.warning {
  color: var(--orange);
  border-color: color-mix(in srgb, var(--orange) 60%, var(--border));
}
.reconciliation-status small { color: var(--muted); font-size: .72rem; }
.truth-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.truth-stats article {
  display: grid;
  gap: 5px;
  padding: 13px;
  border-radius: 10px;
  background: var(--surface-soft);
}
.truth-stats span { color: var(--muted); font-size: .76rem; }
.truth-stats strong { font-size: 1.22rem; font-variant-numeric: tabular-nums; }
.truth-stats small { color: var(--muted); font-size: .68rem; line-height: 1.35; }
.source-table-wrap { margin-top: 18px; overflow-x: auto; }
.source-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.source-table th, .source-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.source-table th:first-child { text-align: left; }
.source-table tbody th { font-weight: 550; }
.source-table thead th { color: var(--muted); font-size: .72rem; font-weight: 600; }
.source-table tfoot th, .source-table tfoot td { border-bottom: 0; font-weight: 700; }
.source-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.source-dot.paid-meta { background: #8b5cf6; }
.source-dot.paid-google { background: var(--blue); }
.source-dot.organic-search { background: var(--green); }
.source-dot.organic-social { background: #23b5a9; }
.source-dot.owned { background: var(--orange); }
.source-dot.referral { background: #d16ba5; }
.source-dot.unverified-google { background: #d5a742; }
.source-dot.unverified-mixed { background: #c9845c; }
.source-dot.direct { background: var(--muted); }
.truth-note { margin-top: 12px; color: var(--muted); font-size: .72rem; line-height: 1.5; }

.chart { position: relative; min-height: 340px; margin-top: 15px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .frame { stroke: var(--border); fill: transparent; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .axis-title { fill: var(--text); font-size: 12px; }
.chart .guide { stroke: var(--text); stroke-opacity: .45; }

.funnel { display: grid; gap: 12px; margin-top: 20px; }
.funnel-row { display: grid; grid-template-columns: 105px minmax(80px, 1fr) 88px; align-items: center; gap: 12px; }
.funnel-label { color: var(--muted); font-size: .82rem; text-align: right; }
.funnel-track { height: 24px; background: var(--surface-soft); border-radius: 5px; overflow: hidden; }
.funnel-bar { height: 100%; min-width: 2px; background: var(--blue); }
.funnel-row:last-child .funnel-bar { background: var(--green); }
.funnel-value { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; font-variant-numeric: tabular-nums; }
.funnel-value small { color: var(--muted); }

.limitations { display: flex; gap: 10px; margin-top: 16px; color: var(--muted); font-size: .82rem; }
.limitations strong { color: var(--text); white-space: nowrap; }
.error { margin: 18px 0; padding: 12px; color: var(--red); border: 1px solid var(--red); border-radius: 9px; }
.chart-tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  min-width: 205px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 8px 30px color-mix(in srgb, var(--text) 14%, transparent);
  font-size: .78rem;
}
.tooltip-line { display: flex; justify-content: space-between; gap: 18px; padding-top: 4px; }
.tooltip-label { display: inline-flex; align-items: center; gap: 7px; }
.tooltip-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; }
.tooltip-dot.spend { background: var(--blue); }
.tooltip-dot.placed { background: var(--orange); }
.tooltip-dot.completed { background: var(--green); }

@media (max-width: 800px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .truth-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 540px) {
  .app-header { align-items: flex-start; }
  .app-heading { align-items: flex-start; gap: 12px; }
  .product-brand { padding-right: 12px; }
  .viewer { display: grid; justify-items: end; }
  .freshness { width: 100%; margin-left: 0; }
  .integration-card form { grid-template-columns: 1fr; }
  main { width: min(100% - 22px, 1180px); margin-top: 18px; }
  .stats { grid-template-columns: 1fr; }
  .chart { min-height: 300px; }
  .truth-stats { grid-template-columns: 1fr; }
  .reconciliation-status { width: 100%; justify-items: start; }
  .source-table { min-width: 570px; }
  .funnel-row { grid-template-columns: 82px minmax(65px, 1fr) 76px; gap: 8px; }
  .funnel-label { font-size: .74rem; }
  .limitations { display: grid; }
}
