:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #0a0a0a;
  --muted: #6b7280;
  --faint: #9aa0a6;
  --line: #ececec;
  --accent: #ff6b1a;
  --good: #0e7a2c;
  --bad: #b23a1a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------------- buttons + fields ---------------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: 10px; transition: all .15s ease;
}
.btn:hover { border-color: #d8d8d8; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f0f1f3; }
.btn-block { width: 100%; padding: 12px; margin-top: 8px; }
.field {
  width: 100%; font: inherit; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; margin-bottom: 14px; outline: none;
}
.field:focus { border-color: var(--accent); }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

/* ---------------- login ---------------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 34px 30px; box-shadow: var(--shadow);
}
.brand-mark { font-weight: 800; letter-spacing: -.01em; color: var(--accent); margin-bottom: 22px; font-size: 15px; }
.login-title { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 6px; }
.login-sub { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 22px; }
.login-note { color: var(--faint); font-size: 12px; text-align: center; margin-top: 16px; min-height: 16px; }
.login-note.is-error { color: var(--bad); }

/* ---------------- portal shell ---------------- */
.portal { min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.client-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.client-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.admin-switch { display: flex; align-items: center; gap: 8px; }
.admin-tag { font-size: 11px; font-weight: 700; color: var(--accent); background: #fff2ea; padding: 3px 8px; border-radius: 6px; }
.client-switch { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }

.range-tabs { display: inline-flex; background: #f0f1f3; border-radius: 10px; padding: 3px; }
.range-tab { font: inherit; font-size: 13px; font-weight: 600; border: none; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.range-tab.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.portal-main { max-width: 1180px; margin: 0 auto; padding: 26px 28px 60px; }

/* ---------------- platform tabs (Google / Microsoft / All) ---------------- */
.platform-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.platform-tab {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  background: transparent; border: none; border-bottom: 2px solid transparent;
  padding: 10px 16px; margin-bottom: -1px; cursor: pointer; transition: color .12s ease;
}
.platform-tab:hover { color: var(--ink); }
.platform-tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------------- KPI grid ---------------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.kpi-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.kpi-value.is-empty { color: var(--faint); font-weight: 700; }
.kpi-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.kpi-delta { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.kpi-delta.is-good { color: var(--good); background: #e7f4ea; }
.kpi-delta.is-bad { color: var(--bad); background: #fae9e4; }
.kpi-delta.is-neutral { color: var(--muted); background: #f0f1f3; }
.kpi-delta-note { font-size: 11px; color: var(--faint); }
.kpi-foot .spark { margin-left: auto; display: block; width: 88px; height: 28px; }

/* ---------------- cards + charts ---------------- */
.chart-stack { display: grid; gap: 16px; margin-bottom: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card-head { margin-bottom: 14px; }
.card-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.card-sub { font-size: 13px; color: var(--muted); margin: 4px 0 0; }

.perf-chart-wrap { position: relative; width: 100%; }
.perf-chart { width: 100%; height: auto; display: block; }
.perf-tooltip {
  position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 9px 11px; font-size: 12px; min-width: 150px;
}
.perf-tt-day { font-weight: 700; margin-bottom: 6px; }
.perf-tt-row { display: flex; align-items: center; gap: 7px; padding: 2px 0; color: var(--muted); }
.perf-tt-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.perf-tt-val { margin-left: auto; font-weight: 700; color: var(--ink); }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: right; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table td { text-align: right; padding: 9px 12px; border-bottom: 1px solid #f4f4f4; white-space: nowrap; }
.data-table tr:hover td { background: #fafbfc; }
.col-strong { font-weight: 700; color: var(--accent); }

/* ---------------- launch marker ---------------- */
.launch-note {
  display: flex; align-items: flex-start; gap: 10px;
  background: #fff7f2; border: 1px solid #ffd9c2; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 18px; font-size: 13px; line-height: 1.5; color: var(--ink);
}
.launch-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-top: 5px; flex: 0 0 auto; box-shadow: 0 0 0 3px rgba(255,107,26,.15); }
.launch-note-text strong { font-weight: 700; }
.table-empty { text-align: center !important; color: var(--muted); padding: 22px 12px !important; }

/* ---------------- footer + toast ---------------- */
.portal-footer { text-align: center; color: var(--faint); font-size: 12px; padding: 28px 0 0; }
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toast { background: #0a0a0a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); }
.toast.is-error { background: var(--bad); }
.toast.is-success { background: var(--good); }

@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .portal-main { padding: 18px 16px 50px; }
  .kpi-value { font-size: 22px; }
}
