:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #64727d;
  --line: #d8e0e2;
  --reach: #0f766e;
  --follows: #2563eb;
  --engagement: #9333ea;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

a {
  color: var(--reach);
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.controls,
.kpis,
.dashboard-grid {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
}

.source-pill,
.auth-status,
.page-select,
.primary-button,
.secondary-button,
.range-button {
  min-height: 40px;
  border-radius: 6px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

.source-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.auth-status {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #eef7f5;
  padding: 0 12px;
  color: var(--reach);
  font-weight: 800;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-select {
  max-width: 220px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0 34px 0 10px;
  font-weight: 700;
}

.controls {
  grid-template-columns: auto repeat(2, minmax(150px, 1fr));
  align-items: end;
  margin-bottom: 16px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel);
}

.range-button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 0 14px;
  color: var(--muted);
  cursor: pointer;
}

.range-button:last-child {
  border-right: 0;
}

.range-button.active {
  background: var(--ink);
  color: #ffffff;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--panel);
}

.primary-button {
  border: 0;
  background: var(--reach);
  color: #ffffff;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

a.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.status-panel,
.panel,
.kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  color: var(--muted);
}

.status-panel.error {
  border-color: #f4b4ad;
  color: var(--danger);
  background: #fff4f2;
}

.retry-button {
  min-height: 34px;
  border: 1px solid #f4b4ad;
  border-radius: 6px;
  background: #ffffff;
  color: var(--danger);
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
}

.hidden {
  display: none;
}

.kpis {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 16px;
}

.kpi {
  padding: 18px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
}

.dashboard-grid {
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.4fr);
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.funnel {
  display: grid;
  gap: 12px;
}

.funnel-stage {
  display: grid;
  gap: 6px;
}

.funnel-track {
  position: relative;
  min-height: 58px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.funnel-fill {
  position: absolute;
  inset: 0 auto 0 0;
}

.funnel-content {
  position: relative;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  color: var(--ink);
}

.funnel-label,
.funnel-value {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.funnel-value {
  text-align: right;
}

.funnel-rate {
  color: var(--muted);
  font-size: 0.85rem;
}

.chart-wrap {
  min-height: 320px;
}

#trend-chart {
  width: 100%;
  height: auto;
  overflow: visible;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.legend-item.reach::before { background: var(--reach); }
.legend-item.follows::before { background: var(--follows); }
.legend-item.engagement::before { background: var(--engagement); }

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 8px;
  text-align: right;
}

th:first-child,
td:first-child {
  text-align: left;
}

.policy-shell {
  width: min(880px, calc(100% - 32px));
}

.policy-panel {
  display: grid;
  gap: 20px;
  line-height: 1.65;
}

.policy-panel section {
  display: grid;
  gap: 8px;
}

.policy-panel h2,
.policy-panel p,
.policy-panel ul {
  margin: 0;
}

.policy-panel h2 {
  font-size: 1.1rem;
}

.policy-panel ul {
  padding-left: 22px;
  color: var(--ink);
}

.policy-panel li + li {
  margin-top: 6px;
}

.policy-meta {
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 820px) {
  .topbar,
  .controls,
  .kpis,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .source-pill,
  .auth-status,
  .page-select,
  .secondary-button {
    width: 100%;
    max-width: none;
    justify-content: center;
  }

  .panel-heading {
    display: block;
  }

  .status-panel {
    align-items: stretch;
    flex-direction: column;
  }
}
