@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #f9fafb;
  --card: #ffffff;
  --text: #1f2937;
  --ink: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --soft: #f3f4f6;
  --brand: #4f46e5;
  --brand-600: #4f46e5;
  --brand-500: #6366f1;
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --chart: #6366f1;
  --chart-fill: rgba(99, 102, 241, 0.16);
  --up: #059669;
  --down: #e11d48;
  --pending-bg: #fef3c7;
  --pending-fg: #b45309;
  --page-bar: #ffedd5;
  --browser-bar: #d1fae5;
  --source-bar: #e0e7ff;
  --geo-bar: #dbeafe;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.1), 0 2px 8px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --header-h: 72px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #1e1b4b;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.03em;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: block;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  color: var(--ink);
  font-weight: 500;
  font-size: 14px;
  padding: 4px 0;
  position: relative;
}
.grid-dots {
  width: 22px;
  height: 22px;
  color: #374151;
}
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  padding: 6px;
  z-index: 40;
  display: none;
}
.user-menu.open { display: block; }
.user-menu button {
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.user-menu button:hover { background: var(--soft); }

.wrap {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px 40px 64px;
}

/* Sites home */
.sites-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 12px 0 18px;
}
.sites-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid #eef0f3;
  margin-bottom: 18px;
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px 12px;
  width: 220px;
  color: var(--faint);
}
.search input {
  border: 0;
  outline: none;
  width: 100%;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}
.search input::placeholder { color: #9ca3af; }
.toolbar-right { display: flex; align-items: center; gap: 12px; }

.select-btn, .ghost-btn, .icon-btn {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--ink);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.select-btn { min-width: 148px; justify-content: space-between; }
.primary-btn {
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25);
}
.primary-btn:hover { filter: brightness(1.05); }

.sites-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.site-card {
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  min-height: 198px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: box-shadow .15s ease, transform .15s ease;
}
.site-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.site-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--ink);
  font-size: 15px;
}
.site-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--soft);
}
.site-icon img { width: 20px; height: 20px; }
.site-icon.lg { width: 40px; height: 40px; border-radius: 12px; }
.site-icon.all { background: var(--brand); color: #fff; }
.spark {
  width: 100%;
  height: 72px;
  margin: 14px 0 8px;
}
.site-card-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: auto;
  gap: 12px;
}
.stat-xl { font-size: 28px; font-weight: 700; color: var(--ink); letter-spacing: -0.03em; line-height: 1; }
.stat-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--up);
  white-space: nowrap;
}
.change.down { color: var(--down); }
.change.flat { color: var(--muted); }
.pending {
  background: var(--pending-bg);
  color: var(--pending-fg);
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 4px 8px;
}
.all-stats {
  display: flex;
  gap: 36px;
  margin-top: auto;
}
.all-stats .lbl { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

/* Dashboard chrome */
.dash-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 6px 0 16px;
}
.dash-left, .dash-right { display: flex; align-items: center; gap: 14px; }
.site-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  padding: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  position: relative;
}
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18);
}
.live-dot.on {
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.period-btn, .filter-btn, .kebab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: #374151;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 8px;
}
.period-btn {
  background: #f3f4f6;
  padding: 6px 10px;
}
.period-btn:hover, .filter-btn:hover, .kebab-btn:hover { background: #eef0f3; }
.period-nav { display: inline-flex; align-items: center; gap: 2px; }
.period-nav .arrow {
  border: 0;
  background: transparent;
  color: #4b5563;
  padding: 4px 2px;
}
.kebab-btn { font-size: 18px; letter-spacing: 1px; padding: 4px 8px; }

.dropdown {
  position: relative;
}
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  padding: 6px;
  z-index: 50;
  display: none;
}
.menu.open { display: block; }
.menu.wide { min-width: 260px; }
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 10px;
  border: 0;
  background: none;
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
  text-align: left;
}
.menu-item:hover { background: var(--soft); }
.menu-item.active { background: var(--brand-50); color: var(--brand); font-weight: 600; }
.menu-item .hint { color: var(--faint); font-size: 12px; font-weight: 600; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-dates {
  display: grid;
  gap: 8px;
  padding: 8px 10px 10px;
}
.menu-dates label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.menu-dates input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}

.panel {
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.metric {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 16px 18px 14px;
  border-right: 1px solid #f1f2f4;
  min-height: 92px;
}
.metric:last-child { border-right: 0; }
.metric.active { background: #f3f4f6; }
.metric-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9ca3af;
  margin-bottom: 8px;
}
.metric-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.metric-value .change { font-size: 13px; position: relative; top: -1px; }

.chart-wrap {
  padding: 8px 8px 16px;
  position: relative;
}
.chart-svg { width: 100%; height: 320px; display: block; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: #111827;
  color: #fff;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  display: none;
  z-index: 5;
  transform: translate(-50%, -120%);
  white-space: nowrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
}
.card {
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.card-tabs {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 18px 0;
  border-bottom: 1px solid #f3f4f6;
}
.tab {
  background: none;
  border: 0;
  padding: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9ca3af;
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.card-expand {
  margin-left: auto;
  border: 0;
  background: none;
  color: #9ca3af;
  padding: 0 0 10px;
}
.card-body { padding: 10px 8px 12px; flex: 1; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 8px;
  position: relative;
  font-size: 14px;
  color: var(--ink);
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
}
.row .bar {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 8px;
  opacity: 0.9;
  z-index: 0;
}
.row .name, .row .count { position: relative; z-index: 1; }
.row .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .count { color: var(--ink); font-variant-numeric: tabular-nums; }
.row:hover { filter: brightness(0.99); }
.favicon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.empty-inline {
  color: var(--muted);
  font-size: 14px;
  padding: 28px 16px;
  text-align: center;
}

.map-wrap {
  height: 260px;
  padding: 8px 12px 16px;
}
.map-wrap svg { width: 100%; height: 100%; display: block; }
.map-wrap path {
  stroke: #fff;
  stroke-width: 0.4;
  fill: #e5e7eb;
}
.map-wrap path.has-data { fill: #818cf8; }
.map-legend {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  color: var(--faint);
  font-size: 11px;
  padding: 0 16px 10px;
}

.goals-card { margin-top: 18px; min-height: 280px; }
.goals-empty {
  text-align: center;
  padding: 72px 32px 80px;
}
.goals-empty h3 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}
.goals-empty p {
  margin: 0 auto 22px;
  max-width: 560px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}
.goals-actions { display: flex; justify-content: center; gap: 12px; }
.secondary-btn {
  background: #fff;
  border: 1px solid #d1d5db;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
}

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 14px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--brand-50);
  color: #3730a3;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 500;
}
.chip button {
  border: 0;
  background: none;
  color: inherit;
  padding: 0;
  font-size: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 24px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: min(480px, 100%);
  padding: 22px;
  box-shadow: var(--shadow-lg);
}
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 13px; font-weight: 500; color: #374151; }
.field input, .field select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.code {
  background: #f3f4f6;
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  overflow: auto;
  color: #111827;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.login-card {
  width: min(400px, calc(100% - 32px));
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}
.login-card h1 { margin: 14px 0 6px; font-size: 22px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.err { color: #e11d48; font-size: 13px; margin: 0 0 10px; min-height: 18px; }

@media (max-width: 1100px) {
  .sites-grid, .grid-2, .metrics { grid-template-columns: 1fr 1fr; }
  .metrics { overflow: auto; }
}
@media (max-width: 720px) {
  .app-header, .wrap { padding-left: 16px; padding-right: 16px; }
  .sites-grid, .grid-2, .metrics { grid-template-columns: 1fr; }
  .sites-toolbar { flex-direction: column; align-items: stretch; }
}

.period-control {
  display: inline-flex;
  align-items: center;
  background: #f3f4f6;
  border-radius: 8px;
  padding-right: 2px;
}
.period-control .period-btn { background: transparent; }
.period-control .arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: #4b5563;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.period-control .arrow:hover { background: #e5e7eb; }
.all-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }

.live-pill {
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 6px;
}
.live-pill:hover { color: var(--ink); background: #f3f4f6; }
.current-menu { left: 0; right: auto; min-width: 300px; max-width: 420px; }
.menu-heading { padding: 8px 10px 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.menu-empty { padding: 10px; color: var(--muted); font-size: 13px; }

.row-wide { grid-template-columns: 1fr auto auto; }
.row .rate { position: relative; z-index: 1; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; min-width: 48px; text-align: right; }
.row .subhint { color: var(--faint); font-size: 11px; font-weight: 500; }
.row-wrap { display: flex; align-items: center; gap: 2px; }
.row-wrap .row { flex: 1; }
.icon-btn { border: 0; background: none; color: var(--faint); padding: 4px 8px; font-size: 16px; }
.icon-btn:hover { color: var(--ink); }
.card-footer { padding: 8px 10px 4px; }
.panel-toolbar { display: flex; align-items: center; gap: 12px; padding: 4px 10px 10px; }
.text-btn { border: 0; background: none; color: var(--brand); font-size: 13px; font-weight: 600; padding: 4px 0; }
.text-btn:hover { text-decoration: underline; }
.hint-block { color: var(--muted); font-size: 13px; line-height: 1.5; padding: 8px 10px 4px; }
.hint-block code, .goals-empty code { font-size: 12px; }

.funnel-card { padding: 8px 10px 16px; border-bottom: 1px solid #f3f4f6; }
.funnel-card:last-of-type { border-bottom: 0; }
.funnel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.funnel-actions { display: flex; gap: 12px; }
.funnel-step-bar { position: relative; margin: 6px 0; border-radius: 8px; overflow: hidden; min-height: 40px; background: #f9fafb; }
.funnel-fill { position: absolute; inset: 0 auto 0 0; background: var(--brand-100); }
.funnel-step-meta { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; font-size: 13px; }
.funnel-step-meta span:last-child { color: var(--muted); white-space: nowrap; }

.explore-toolbar { display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 10px 12px; align-items: end; }
.explore-toolbar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.explore-toolbar select, .explore-toolbar input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 160px;
  color: var(--ink);
  font-weight: 500;
}
.table-wrap { overflow: auto; }
.explore-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.explore-table th, .explore-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #f3f4f6; }
.explore-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer; user-select: none; }
.explore-table th.num, .explore-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.explore-table tbody tr:hover { background: #f9fafb; }

.modal.wide { width: min(640px, 100%); max-height: calc(100vh - 48px); overflow: auto; }
.funnel-step { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.field textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  outline: none;
  min-height: 84px;
  resize: vertical;
  font: inherit;
}
.field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }

.settings-page { max-width: 820px; }
.settings-lead { color: var(--muted); margin: -8px 0 20px; }
.settings-card {
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 16px;
}
.settings-card h2 { margin: 0 0 10px; font-size: 16px; }
.settings-card p { color: var(--muted); font-size: 14px; line-height: 1.55; }
.settings-card.danger { border-color: #fecdd3; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; margin: 8px 0; color: var(--ink); }
.check input { margin-top: 3px; }
.danger-btn {
  background: #fff;
  color: #be123c;
  border: 1px solid #fecdd3;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
}
.danger-btn:hover { background: #fff1f2; }

.field input::placeholder, .field textarea::placeholder { color: #9ca3af; }
