:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #172033;
  --muted: #647084;
  --line: #dbe2ec;
  --accent: #2563eb;
  --accent-2: #0f766e;
  --warning: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 8px 28px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 760;
}

h2 {
  font-size: 15px;
  font-weight: 720;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

button,
.link-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 620;
  cursor: pointer;
  text-decoration: none;
}

button {
  padding: 8px 12px;
}

button:hover,
.link-button:hover {
  border-color: #b8c4d6;
}

.tab.is-active,
form button[type="submit"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 11px;
  background: var(--surface-2);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px 28px 42px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 94px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
  line-height: 1;
}

.split-grid,
.ops-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: 18px;
}

.ops-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

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

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  background: #fafbfe;
}

.event-list,
.response-list,
.job-list,
.analytics-grid {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.event,
.response,
.job,
.analytic {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

code,
pre {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.response {
  grid-template-columns: minmax(0, 1fr) auto;
}

.response h3,
.job h3,
.analytic h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 720;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  white-space: nowrap;
}

.badge.new {
  background: #e0f2fe;
  color: #075985;
}

.badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.badge.warning {
  background: #fef3c7;
  color: var(--warning);
}

.form-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 650;
}

input,
select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

.toggle {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
}

.toggle input {
  min-height: auto;
  width: auto;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button.is-active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

.log-output {
  min-height: 460px;
  max-height: 64vh;
  margin: 0;
  padding: 16px;
  overflow: auto;
  background: #111827;
  color: #d1d5db;
  border-radius: 0 0 8px 8px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.summary-output {
  min-height: 220px;
  margin: 14px;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--text);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.analytics-extra {
  padding: 0 14px 14px;
  min-width: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172033;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.empty {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1020px) {
  .topbar,
  .split-grid,
  .ops-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .topbar {
    padding: 14px;
  }

  main {
    padding: 14px;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .tab {
    width: 100%;
  }

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

  .metric {
    min-height: 84px;
    padding: 12px;
  }

  .metric strong {
    font-size: 24px;
  }

  .panel-head,
  .response {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .response {
    display: grid;
  }
}

@media (max-width: 430px) {
  .tabs {
    grid-template-columns: 1fr;
  }
}
