:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1a1d24;
  --muted: #6b7280;
  --line: #e4e6eb;
  --brand: #6366f1;
  --brand-dark: #4f46e5;
  --good: #16a34a;
  --bad: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-dark); }

/* ---- layout ---- */
.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 1.25rem 4rem; }

/* ---- header ---- */
header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: 60px;
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand span { color: var(--brand); }
.tabs { display: flex; gap: .25rem; margin-left: 1rem; }
.tab {
  border: 0; background: transparent; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--muted);
  padding: .5rem .85rem; border-radius: 8px;
}
.tab:hover { background: var(--bg); }
.tab.active { color: var(--brand-dark); background: #eef0fe; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: .85rem; }
.who { font-size: .85rem; color: var(--muted); }

/* ---- cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card + .card, .stack > * + * { margin-top: 1.25rem; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 1rem; }
.muted { color: var(--muted); }

/* ---- buttons ---- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: .55rem .95rem;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: .35rem .6rem; font-size: .82rem; }
.btn-danger { color: var(--bad); }
.btn-link { border: 0; background: none; color: var(--brand-dark); cursor: pointer; font: inherit; padding: 0; }

/* ---- forms ---- */
label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; }
input[type=text], input[type=url], select {
  width: 100%; font: inherit;
  padding: .55rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid #c7cbfb; border-color: var(--brand); }
.form-row { display: flex; flex-wrap: wrap; gap: .85rem; align-items: end; }
.form-row > div { flex: 1 1 170px; }
.form-row > button { flex: 0 0 auto; }

/* ---- agency scope bar ---- */
.scopebar { background: #eef0fe; border-bottom: 1px solid var(--line); }
.scopebar-inner {
  max-width: 1080px; margin: 0 auto; padding: .55rem 1.25rem;
  display: flex; align-items: center; gap: .5rem; font-size: .88rem;
}
.scopebar select { width: auto; }
.field-error { color: var(--bad); font-size: .85rem; margin-top: .6rem; }

/* ---- created banner ---- */
.created {
  margin-top: 1rem; padding: .9rem 1rem; border-radius: 8px;
  background: #ecfdf3; border: 1px solid #bbf7d0;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.created code { font-weight: 700; }

/* ---- table ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: .3rem; }
.dest { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; }
.pill-on { background: #ecfdf3; color: var(--good); }
.pill-off { background: #fef2f2; color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* ---- KPI cards ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }
.kpi .n { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.kpi .l { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: .2rem; }

/* ---- charts / map ---- */
.chart-box { position: relative; height: 260px; }
#heatmap, #drill-map { height: 380px; border-radius: 8px; overflow: hidden; }
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }
.src-split { display: flex; gap: 1.5rem; }
.src-split .n { font-size: 1.5rem; font-weight: 800; }

/* ---- modal ---- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 17, 21, .55);
  display: grid; place-items: center; padding: 1.5rem; z-index: 50;
}
.modal {
  background: var(--card); border-radius: var(--radius);
  padding: 1.5rem; max-width: 340px; width: 100%; text-align: center;
}
.modal h3 { margin: 0 0 1rem; }
#qr-canvas img { border-radius: 8px; }
.modal .qr-url { font-size: .8rem; color: var(--muted); word-break: break-all; margin: .8rem 0; }
.modal-actions { display: flex; gap: .5rem; justify-content: center; margin-top: .5rem; }

/* ---- drill-down ---- */
.mini-tables { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
.mini-tables h4 { margin: 0 0 .4rem; font-size: .85rem; }
.drill-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

@media (max-width: 720px) {
  .form-row, .kpis, .row2, .mini-tables { grid-template-columns: 1fr; }
}
