:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a8985;
  --accent: #2a78d6;
  --series-1: #2a78d6;   /* blue  – clicks / users */
  --series-2: #eb6834;   /* orange – impressions / sessions */
  --series-3: #1baf7a;   /* aqua – pageviews */
  --good: #008300;
  --bad: #e34948;
  --grid: #e8e7e3;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232322;
  --border: #2e2e2c;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #8b8a83;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good: #3fae3f;
  --bad: #e66767;
  --grid: #262625;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.45 -apple-system, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.logo { color: var(--accent); font-size: 18px; }
.crumb { color: var(--text-3); font-weight: 400; }
.crumb:not(:empty)::before { content: "/ "; }
.controls { display: flex; align-items: center; gap: 10px; }
.account { color: var(--text-3); font-size: 12px; }
.account button { margin-left: 6px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer;
  color: var(--text-2); font-size: 13px;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 5px 10px;
  border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text-2);
}
.btn:hover { color: var(--text); border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 9px 16px; }
.btn.link { border: 0; background: none; padding: 0; color: var(--accent); }

/* ---------- layout ---------- */
main { max-width: 1400px; margin: 0 auto; padding: 24px; }
.loading, .empty { color: var(--text-3); padding: 48px; text-align: center; }
.error { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border: 1px solid var(--bad); color: var(--text); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; white-space: pre-wrap; }

.hero { max-width: 560px; margin: 80px auto; text-align: center; }
.hero h1 { font-size: 26px; margin: 0 0 8px; }
.hero p { color: var(--text-2); }
.hero ol { text-align: left; color: var(--text-2); }
.hero code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 28px 0 12px; }
.section-title h2 { margin: 0; font-size: 16px; }
.section-title .sub { color: var(--text-3); font-size: 12px; }
.section-title:first-child { margin-top: 0; }

/* ---------- KPI tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12px; margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--text-3); }
.delta .prev { color: var(--text-3); }

/* ---------- overview table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11.5px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface); position: sticky; top: 0; }
th:first-child, td:first-child { text-align: left; }
th.group { text-align: center; border-bottom: 0; padding-bottom: 2px; color: var(--text-3); }
th.gsc { color: var(--series-1); }
th.ga { color: var(--series-2); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.is-hidden { opacity: .5; }
td .site { font-weight: 600; }
td .meta { color: var(--text-3); font-size: 11.5px; display: block; }
td .d { font-size: 11px; display: block; }
td .d.up { color: var(--good); } td .d.down { color: var(--bad); } td .d.flat { color: var(--text-3); }
td.na { color: var(--text-3); }
tfoot td { font-weight: 600; border-top: 2px solid var(--border); border-bottom: 0; }
.tag { display: inline-block; white-space: nowrap; font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); margin-left: 6px; vertical-align: middle; }
.tag.warn { color: var(--bad); }
td .key { max-width: 420px; overflow: hidden; text-overflow: ellipsis; display: block; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(480px, 1fr)); gap: 12px; }
.chart { position: relative; }
.chart svg { width: 100%; height: 220px; display: block; overflow: visible; }
.chart .legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.chart .legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart .legend i { width: 12px; height: 2px; display: inline-block; border-radius: 1px; }
.axis text { fill: var(--text-3); font-size: 11px; }
.grid line { stroke: var(--grid); stroke-width: 1; }
.series path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series .area { fill-opacity: .08; stroke: none; }
.crosshair { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.hover-dot { stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; min-width: 140px;
}
.tooltip .t { color: var(--text-3); margin-bottom: 4px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .r b { font-variant-numeric: tabular-nums; }

/* ---------- detail grid ---------- */
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.detail-head h1 { margin: 0; font-size: 22px; }
.detail-head .meta { color: var(--text-3); font-size: 12.5px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: var(--surface-2); padding: 3px 9px; border-radius: 999px; color: var(--text-2); }
.tile-live .live, .pill .live { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
td.rt { color: var(--text-3); }
td.rt.has-live { color: var(--good); font-weight: 600; }
select { font: inherit; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  main { padding: 12px; }
  .topbar { padding: 8px 12px; flex-wrap: wrap; row-gap: 8px; position: static; }
  .brand { font-size: 14px; }
  .brand > span:nth-child(2) { display: none; } /* hide "Personal Dashboard" text, keep logo + crumb */
  .crumb:not(:empty)::before { content: ""; }
  .controls { width: 100%; justify-content: space-between; gap: 6px; }
  .account { display: none; }
  .seg button { padding: 5px 8px; font-size: 12px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .value { font-size: 20px; }
  .tile .label .tag { display: none; }
  .charts, .two { grid-template-columns: 1fr; gap: 8px; }
  .chart svg { height: 180px; }
  .card { padding: 12px; }
  th, td { padding: 7px 8px; font-size: 12.5px; }
  td .meta { white-space: normal; }
  td .key { max-width: 180px; }
  .section-title { flex-wrap: wrap; margin: 18px 0 8px; }
  .detail-head h1 { font-size: 18px; }
  .hero { margin: 40px auto; }
}
