:root {
  color-scheme: light;
  --background: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --surface-muted: #f5f3f4;
  --ink: #1b1c1d;
  --primary: #041627;
  --secondary: #505f76;
  --muted: #667085;
  --border: #e2e8f0;
  --border-strong: #c4c6cd;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #ba1a1a;
  --success: #059669;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--background);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  padding: 0 20px;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
}

input {
  min-height: 44px;
}

textarea {
  min-height: 112px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(37, 99, 235, 0.16);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--primary);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 40px;
}

h2 {
  color: var(--primary);
  font-size: 18px;
  font-weight: 700;
  line-height: 24px;
}

.app-body {
  min-height: 100vh;
}

.side-nav {
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  left: 0;
  padding: 16px;
  position: fixed;
  top: 0;
  width: 256px;
  z-index: 20;
}

.brand {
  align-items: center;
  color: #0f172a;
  display: flex;
  justify-content: center;
  width: 100%;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 140px;
  height: auto;
}

.top-title {
  color: #0f172a;
  display: block;
  font-size: 18px;
  font-weight: 800;
  line-height: 22px;
}

.nav-links {
  display: grid;
  gap: 6px;
}

.nav-link {
  align-items: center;
  border-left: 4px solid transparent;
  border-radius: 0 6px 6px 0;
  color: #334155;
  display: flex;
  gap: 8px;
  min-height: 42px;
  padding: 8px 12px;
  text-decoration: none;
}

.nav-link:hover {
  background: #ffffff;
  color: #0f172a;
}

.nav-link.is-active {
  background: #ffffff;
  border-left-color: #0f172a;
  color: #0f172a;
  font-weight: 800;
}

.material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
  vertical-align: middle;
}

.app-frame {
  min-height: 100vh;
  padding-left: 256px;
}

.top-bar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.shell {
  margin: 0 auto;
  max-width: 1440px;
  padding: 32px;
  width: 100%;
}

.page-heading {
  align-items: flex-end;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-heading p {
  color: #44474c;
  font-size: 14px;
  line-height: 20px;
  margin-top: 4px;
}

.login-body {
  background: var(--background);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.login-view {
  width: min(100%, 440px);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 18px;
  padding: 28px;
  width: 100%;
}

.eyebrow {
  color: var(--secondary);
  font-family: "Public Sans", Inter, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 16px;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.auth-status {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: right;
}

.session-actions {
  display: flex;
  justify-content: flex-end;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  align-items: center;
  background: #ffffff;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--secondary);
  display: inline-flex;
  gap: 4px;
  min-height: 36px;
  padding: 0 8px 0 12px;
}

.user-menu-trigger:hover,
.user-menu-trigger:focus-visible,
.user-menu:focus-within .user-menu-trigger {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--primary);
}

.user-menu-panel {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 160px;
  opacity: 0;
  padding: 6px;
  pointer-events: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  transform: translateY(-4px);
  transition: opacity 120ms ease, transform 120ms ease;
  z-index: 30;
}

.user-menu:hover .user-menu-panel,
.user-menu:focus-within .user-menu-panel,
.user-menu.is-open .user-menu-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.user-menu:hover .user-menu-trigger,
.user-menu:focus-within .user-menu-trigger,
.user-menu.is-open .user-menu-trigger {
  border-color: var(--border);
}

.menu-item {
  background: transparent;
  border-radius: 6px;
  color: var(--primary);
  display: block;
  font-weight: 700;
  min-height: 36px;
  padding: 0 10px;
  text-align: left;
  width: 100%;
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--surface-soft);
  color: var(--danger);
}

.auth-button {
  min-height: 36px;
  padding: 0 12px;
  width: auto;
}

.secondary-button,
.preset-button {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--secondary);
  min-height: 36px;
  padding: 0 12px;
}

.secondary-button:hover:not(:disabled),
.preset-button:hover:not(:disabled) {
  background: var(--surface-soft);
  color: var(--primary);
}

.icon-button {
  align-items: center;
  display: inline-flex;
  gap: 6px;
  white-space: nowrap;
}

.badge {
  background: #eef1f5;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  padding: 5px 12px;
}

.badge-ok {
  background: #e8f5ef;
  border-color: #b9dbc9;
  color: var(--success);
}

.status-detail,
.panel p {
  color: var(--muted);
  font-size: 14px;
}

.endpoint-note {
  color: var(--muted);
  font-size: 14px;
  margin: -8px 0 16px;
}

.endpoint-note code {
  color: var(--ink);
  font-size: 0.9em;
  font-weight: 700;
}

.panel {
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px;
}

.controls {
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 190px) minmax(150px, 190px) minmax(190px, auto) auto;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 800;
  gap: 7px;
}

.date-presets {
  align-items: center;
  align-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}

.preset-button {
  font-size: 13px;
}

.preset-button.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.preset-button.is-selected:hover:not(:disabled) {
  background: var(--accent-dark);
  color: #ffffff;
}

.input-section {
  align-items: end;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 24px;
  max-width: 860px;
}

.textarea-label span {
  color: var(--primary);
  font-size: 18px;
  line-height: 24px;
}

#campaign-count {
  color: var(--muted);
  font: inherit;
}

#campaign-ids {
  font-weight: 400;
}

.metric-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 24px;
}

.metric-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 24px;
}

.metric-card p {
  color: #44474c;
  font-family: "Public Sans", Inter, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 16px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.metric-card strong {
  color: var(--primary);
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 32px;
}

.metric-card span {
  align-items: center;
  display: inline-flex;
  gap: 4px;
  font-family: "Public Sans", Inter, sans-serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 16px;
  margin-top: 8px;
}

.error {
  background: #fff0f1;
  border: 1px solid #f0bdc2;
  border-radius: 8px;
  color: var(--danger);
  font-weight: 700;
  margin: 0 0 16px;
  padding: 12px 14px;
}

.loading-state {
  align-items: center;
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e3a8a;
  display: inline-flex;
  font-weight: 800;
  gap: 10px;
  margin: 0 0 16px;
  padding: 12px 14px;
}

.loader {
  animation: loader-spin 800ms linear infinite;
  border: 3px solid rgba(37, 99, 235, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  height: 20px;
  width: 20px;
}

@keyframes loader-spin {
  to {
    transform: rotate(360deg);
  }
}

.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 18px;
  overflow: hidden;
}

.results-header {
  align-items: flex-start;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 18px;
}

.endpoint-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.results-actions {
  align-items: flex-end;
  display: grid;
  gap: 10px;
  justify-items: end;
}

.collapse-button {
  align-items: center;
  display: inline-flex;
  gap: 6px;
  width: auto;
}

.collapse-button .material-symbols-outlined {
  font-size: 18px;
}

dl {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0;
  min-width: 132px;
  padding: 10px 12px;
}

dt {
  color: var(--muted);
  font-family: "Public Sans", Inter, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

dd {
  color: var(--primary);
  font-size: 18px;
  font-weight: 800;
  margin: 2px 0 0;
}

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

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

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

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

thead th {
  background: var(--surface-soft);
  color: #44474c;
  font-family: "Public Sans", Inter, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

thead th[aria-sort] {
  padding: 0;
}

.sort-button {
  align-items: center;
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  gap: 4px;
  justify-content: flex-end;
  letter-spacing: inherit;
  min-height: 100%;
  padding: 14px 18px;
  text-align: inherit;
  text-transform: inherit;
  width: 100%;
}

.sort-button::after {
  color: var(--muted);
  content: "unfold_more";
  direction: ltr;
  display: inline-block;
  font-family: "Material Symbols Outlined";
  font-size: 16px;
  font-feature-settings: "liga";
  font-style: normal;
  font-weight: normal;
  letter-spacing: normal;
  line-height: 1;
  opacity: 0.65;
  text-transform: none;
  white-space: nowrap;
}

th:first-child .sort-button {
  justify-content: flex-start;
}

thead th[aria-sort="ascending"] .sort-button::after {
  content: "arrow_upward";
  opacity: 1;
}

thead th[aria-sort="descending"] .sort-button::after {
  content: "arrow_downward";
  opacity: 1;
}

.sort-button:hover:not(:disabled),
.sort-button:focus-visible {
  color: inherit;
  background: #e9edf3;
}

tbody {
  color: var(--primary);
  font-family: "Public Sans", Inter, sans-serif;
  font-size: 13px;
  font-weight: 500;
}

tbody th {
  font-size: 13px;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

.positive {
  color: var(--success);
  font-weight: 800;
}

.negative {
  color: var(--danger);
  font-weight: 800;
}

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

.daily-section,
.hourly-section {
  border-top: 1px solid var(--border);
}

.daily-heading,
.section-heading {
  padding: 18px 18px 4px;
}

.daily-section table {
  min-width: 1120px;
}

.hourly-breakdown-table {
  min-width: 1120px;
}

.hourly-table {
  min-width: 0;
  table-layout: auto;
}

.hourly-table th,
.hourly-table td {
  padding: 10px 8px;
  width: 1%;
}

.hourly-table thead th {
  font-size: 10px;
  line-height: 13px;
  white-space: normal;
}

.hourly-table .sort-button {
  padding: 10px 8px;
}

.hourly-table tbody th,
.hourly-table tbody td {
  font-size: 12px;
}

.campaign-table {
  min-width: 1040px;
}

.empty-state {
  color: var(--muted);
  font-weight: 700;
  padding: 28px 18px;
  text-align: center !important;
}

@media (max-width: 920px) {
  .side-nav {
    bottom: auto;
    flex-direction: row;
    gap: 16px;
    overflow-x: auto;
    right: 0;
    width: auto;
  }

  .brand {
    flex: 0 0 auto;
    justify-content: flex-start;
    width: auto;
  }

  .nav-links {
    display: flex;
    flex: 1;
    min-width: max-content;
  }

  .app-frame {
    padding-left: 0;
    padding-top: 90px;
  }

  .top-bar {
    position: static;
  }

  .shell {
    padding: 24px 16px;
  }

  .page-heading,
  .results-header,
  .controls,
  .input-section {
    display: grid;
    grid-template-columns: 1fr;
  }

  .auth-status {
    align-items: flex-start;
    text-align: left;
  }

  .session-actions {
    justify-content: flex-start;
  }

  .user-menu-panel {
    left: 0;
    right: auto;
  }

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

  .endpoint-counts {
    justify-content: stretch;
  }

  .endpoint-counts dl {
    flex: 1;
  }

  .results-actions {
    justify-items: stretch;
  }
}

@media (max-width: 620px) {
  .top-bar {
    align-items: flex-start;
    display: grid;
    gap: 12px;
  }

  .brand {
    justify-content: flex-start;
  }

  .brand-logo {
    max-width: 110px;
  }

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

  button:not(.auth-button):not(.secondary-button):not(.preset-button) {
    width: 100%;
  }
}
