:root {
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee9;
  --panel: #fff;
  --bg: #f4f6fa;
  --blue: #2563eb;
  --green: #16803c;
  --red: #bc2f2f;
  --amber: #a15c00;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(380px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}
h1, h2, p { margin: 0; }
.login-panel h1 { font-size: 24px; }
.login-panel p { margin-top: 4px; color: var(--muted); }
.login-panel input, .login-panel button, .login-button {
  width: 100%;
  min-height: 40px;
  margin-top: 14px;
}
.login-panel button, .login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}
.error { margin-top: 10px; color: var(--red); min-height: 18px; }
header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  padding: 22px 30px 15px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 24px; letter-spacing: 0; }
header p, .mode, label, .panel-head span { color: var(--muted); }
.mode { white-space: nowrap; }
.userbar {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.userbar button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
main { padding: 18px 30px 32px; }
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.tab {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 650;
}
.tab.active {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}
.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.notice, .table-status {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: #fff;
  color: var(--muted);
}
.notice.warn { border-color: #f2c46d; background: #fff8e7; color: var(--amber); }
.notice.bad { border-color: #efb3b3; background: #fff1f1; color: var(--red); }
.wide { grid-column: span 2; }
label { display: block; font-size: 12px; margin-bottom: 5px; }
input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
}
.kpis {
  display: grid;
  grid-template-columns: repeat(8, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.kpi { padding: 12px; min-height: 78px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { margin-top: 7px; font-size: 22px; font-weight: 650; }
.kpi .delta { margin-top: 2px; font-size: 12px; color: var(--muted); }
.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel h2 { font-size: 14px; }
.bars, .quality, .reason-summary { padding: 12px 14px; }
.bar {
  display: grid;
  grid-template-columns: minmax(160px, 230px) 1fr 78px 78px;
  gap: 9px;
  align-items: center;
  min-height: 28px;
}
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { height: 8px; border-radius: 999px; background: #e7ebf3; overflow: hidden; }
.fill { height: 100%; background: var(--blue); }
.quality-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #edf0f5;
  padding: 7px 0;
}
.quality-row:last-child { border-bottom: 0; }
.reason-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}
.reason-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}
.reason-title, .reason-metrics, .reason-shares {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}
.reason-title { justify-content: space-between; }
.reason-title strong { font-size: 13px; }
.reason-metrics, .reason-shares {
  margin-top: 8px;
  color: #475467;
  font-size: 12px;
}
.reason-card p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  background: #edf2ff;
  color: #284aa0;
}
.active, .matched, .ready, .observed, .ads_platform { background: #e8f5ee; color: var(--green); }
.inactive, .ads_only, .pending_api, .pending_validation, .missing_config, .stale, .paid_campaign_not_in_ads, .paid_campaign_id_not_in_ads, .unknown_platform_campaign_label, .low_multi_campaign { background: #fff4df; color: var(--amber); }
.unattributed, .unmatched_unattributed, .ga4_diagnostic, .missing_ga4_campaign_label, .missing_ga4_campaign_id_or_label { background: #f1eafe; color: #5d3dad; }
.no_outbound, .no_ads_revenue, .stale_source, .large_revenue_gap, .expected_no_recent_data { background: #fff1f1; color: var(--red); }
.medium { background: #e8f5ee; color: var(--green); }
.none { background: #f5f7fa; color: var(--muted); }
.table-wrap { overflow: auto; max-height: calc(100vh - 505px); min-height: 330px; }
.sources-wrap, .attribution-wrap { max-height: calc(100vh - 220px); }
.admin-wrap { max-height: calc(100vh - 260px); }
.admin-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 0.6fr) 110px minmax(240px, 1fr) 120px;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.admin-tools button, .row-action {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 650;
  cursor: pointer;
}
.row-action.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
.website-editor {
  min-width: 360px;
  height: 92px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
}
.generated-code {
  color: var(--green);
  font-weight: 650;
  white-space: normal;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td {
  padding: 8px 10px;
  border-bottom: 1px solid #edf0f5;
  text-align: right;
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafd;
  color: #475467;
  font-size: 12px;
}
th[data-sort] { cursor: pointer; user-select: none; }
th:first-child, td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: inherit;
}
th:nth-child(2), td:nth-child(2) {
  position: sticky;
  left: 175px;
  z-index: 2;
  background: inherit;
}
td:first-child { background: #fff; }
td:nth-child(2) { background: #fff; }
th:first-child, th:nth-child(2) { z-index: 4; background: #f8fafd; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2), th:nth-child(3), td:nth-child(3), th:nth-child(4), td:nth-child(4), th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { text-align: left; }
td:first-child, th:first-child { min-width: 175px; max-width: 175px; overflow: hidden; text-overflow: ellipsis; }
td:nth-child(2) { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.good { color: var(--green); font-weight: 650; }
.bad { color: var(--red); font-weight: 650; }
.empty { color: #98a2b3; }
@media (max-width: 1200px) {
  .filters { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}
