:root {
  --bg: #0b0f14;
  --bg-elev: #121820;
  --bg-card: #161d27;
  --line: #273140;
  --text: #eef2f6;
  --muted: #8b98a8;
  --accent: #3d8fd1;
  --live: #2f9e6a;
  --stale: #c9a227;
  --none: #6d7a89;
  --error: #d15a5a;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  --font: "DM Sans", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

code { font-family: var(--mono); font-size: 0.86em; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1.4rem 1.75rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #10161e 0%, var(--bg) 100%);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.35rem;
}

.brand-mark {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--accent);
}

.env-badge, .merchant-count {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  color: var(--muted);
}

.env-badge {
  border-color: color-mix(in srgb, var(--error) 45%, var(--line));
  color: #f0b4b4;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.2vw, 1.85rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle { margin: 0.2rem 0 0; color: var(--muted); }

.today-note {
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.info {
  cursor: help;
  opacity: 0.85;
}

.live-controls {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid color-mix(in srgb, var(--live) 40%, var(--line));
  background: color-mix(in srgb, var(--live) 12%, transparent);
  color: var(--live);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.live-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 55%, transparent);
  animation: pulse 2.4s ease-out infinite;
}

.live-pill.paused {
  color: var(--muted);
  border-color: var(--line);
  background: transparent;
}
.live-pill.paused .dot { animation: none; background: var(--muted); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 45%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.refresh-meta {
  text-align: right;
  font-size: 0.86rem;
}

.muted { color: var(--muted); }

.auto-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  justify-content: flex-end;
  margin-top: 0.45rem;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn.csv {
  width: 100%;
  margin-top: 0.65rem;
  font-weight: 600;
}
.btn.csv.busy { opacity: 0.7; }

.banner {
  margin: 0.75rem 1.75rem 0;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
}
.banner.warn {
  border: 1px solid color-mix(in srgb, var(--stale) 50%, var(--line));
  background: color-mix(in srgb, var(--stale) 12%, transparent);
  color: #e6d08a;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1rem 1.75rem 0.35rem;
}

.kpi {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
  min-height: 104px;
}
.kpi .label {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.kpi .value {
  margin-top: 0.35rem;
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.kpi .sec {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.75rem 0.4rem;
  align-items: end;
}
.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar select, .toolbar input {
  font: inherit;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  min-width: 140px;
}

.section-head {
  padding: 0.6rem 1.75rem 0.55rem;
}
.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}
.section-head p { margin: 0.2rem 0 0; font-size: 0.86rem; }

.merchant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.85rem;
  padding: 0 1.75rem 1.25rem;
}

.m-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.m-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  transform: translateY(-1px);
}
.m-card.ERROR { border-color: color-mix(in srgb, var(--error) 45%, var(--line)); }
.m-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}
.m-id {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}
.mono-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #1d2733;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
  color: #c5d2e0;
}
.m-name { font-weight: 650; }
.m-vert { font-size: 0.78rem; color: var(--muted); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  white-space: nowrap;
}
.status.LIVE { color: var(--live); background: color-mix(in srgb, var(--live) 14%, transparent); }
.status.STALE { color: var(--stale); background: color-mix(in srgb, var(--stale) 14%, transparent); }
.status.NO_TRAFFIC { color: var(--none); background: color-mix(in srgb, var(--none) 14%, transparent); }
.status.ERROR { color: var(--error); background: color-mix(in srgb, var(--error) 14%, transparent); }

.m-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.86rem;
}
.m-metrics strong {
  display: block;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.m-metrics span { color: var(--muted); font-size: 0.75rem; }
.types {
  margin-top: 0.55rem;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.2em;
}
.hint {
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.activity-section { padding-bottom: 1.5rem; }
.activity-list {
  margin: 0 1.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
}
.act-row {
  display: grid;
  grid-template-columns: 110px 1fr 1.2fr;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.act-row:last-child { border-bottom: 0; }
.act-row time { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }

.foot {
  padding: 1rem 1.75rem 2rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
}

.drawer[hidden] { display: none; }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}
.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100vw);
  height: 100vh;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  z-index: 50;
  overflow: auto;
  padding: 1.25rem 1.25rem 2rem;
  box-shadow: var(--shadow);
}
.drawer-close {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.drawer h2 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.drawer .meta { color: var(--muted); font-size: 0.88rem; margin-bottom: 1rem; }
.big-num {
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 0.2rem 0 1rem;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
  background: var(--bg-card);
}
.panel h3 {
  margin: 0 0 0.55rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.bars .bar-row {
  display: grid;
  grid-template-columns: 52px 1fr 42px;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.28rem;
  font-size: 0.78rem;
}
.bars .track {
  height: 8px;
  border-radius: 999px;
  background: #1c2530;
  overflow: hidden;
}
.bars .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  font-size: 0.9rem;
}
.stat-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}
.stat-grid strong {
  display: block;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}
.reasons { font-size: 0.86rem; }
.reasons li { margin: 0.25rem 0; color: var(--muted); }

@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .act-row { grid-template-columns: 90px 1fr; }
  .act-row .etype { grid-column: 2; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr; }
  .topbar, .toolbar, .section-head, .merchant-grid, .activity-list, .foot, .banner {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .merchant-grid { grid-template-columns: 1fr; }
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  text-align: center;
}

.login-card h1 {
  margin: 0.5rem 0 0.75rem;
  font-size: 1.35rem;
}

.login-sub {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.login-error {
  color: #ffb4b4;
  background: rgba(209, 90, 90, 0.12);
  border: 1px solid rgba(209, 90, 90, 0.35);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  margin-bottom: 1rem;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  text-decoration: none;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #dadce0;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.55rem 0.25rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.user-avatar-fallback {
  display: inline-grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.user-name {
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
