:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #dbe3ee;
  --line-strong: #c8d3e1;
  --text: #172033;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 18px 44px rgba(29, 39, 59, 0.08);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.08), transparent 310px),
    var(--bg);
  font-family: var(--font);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 22px auto 40px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-row span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
}

.source-tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.source-tabs a {
  min-width: 96px;
  padding: 8px 12px;
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.source-tabs a.active {
  background: var(--accent);
  color: #fff;
}

.toolbar {
  display: grid;
  grid-template-columns: 140px 150px 150px minmax(240px, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 5px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 7px 9px;
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 112px;
  padding: 14px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1;
}

.metric-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(520px, 0.85fr);
  gap: 14px;
  margin-top: 14px;
}

.lower-grid {
  grid-template-columns: 1fr;
}

.geo-grid {
  grid-template-columns: 1fr;
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.panel-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.panel-filter {
  min-width: 132px;
}

.panel-filter select {
  min-height: 34px;
  padding: 5px 8px;
  font-size: 13px;
}

.no-campaign-status .panel-filter {
  display: none;
}

.no-campaign-status .campaign-table-wrap th:first-child,
.no-campaign-status .campaign-table-wrap td:first-child {
  display: none;
}

.chart-panel {
  min-width: 0;
}

canvas {
  display: block;
  width: 100%;
  padding: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.table-wrap {
  overflow: auto;
}

.tall-table {
  max-height: 560px;
}

.wide-table table {
  min-width: 1360px;
}

.campaign-table-wrap table {
  min-width: 1540px;
}

.no-campaign-app .campaign-table-wrap table {
  min-width: 1320px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f9;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2),
.app-name,
.campaign-name {
  text-align: left;
}

tbody tr:hover {
  background: #f8fbff;
}

.campaign-name,
.app-name {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.campaign-name {
  min-width: 620px;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  line-height: 1.35;
}

.app-name {
  max-width: 260px;
}

.status-badge,
.alert-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-badge {
  justify-content: center;
  min-width: 38px;
  padding-inline: 8px;
}

.status-badge.active {
  background: #dcfce7;
  color: #166534;
}

.status-badge.stopped {
  background: #fee2e2;
  color: #991b1b;
}

.status-badge.unknown {
  background: #e2e8f0;
  color: #475569;
}

.alert-badge {
  margin: 2px;
  background: #fee2e2;
  color: #991b1b;
}

.alert-row {
  background: #fff7ed;
}

.alert-row:hover {
  background: #ffedd5;
}

.metric-alert {
  color: #b91c1c;
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.empty-state {
  width: min(720px, calc(100% - 32px));
  margin: 80px auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .content-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1480px);
    margin-top: 12px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .status-row {
    justify-content: start;
  }

  .toolbar,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }
}
