:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #667084;
  --line: #d9dee7;
  --green: #1f8f5f;
  --blue: #2867b2;
  --amber: #b7791f;
  --red: #bf3f3f;
  --ink-soft: #eef2f6;
  --shadow: 0 8px 24px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 720;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
  font-weight: 700;
}

#subtitle,
.panel-head span,
.kpi span,
td,
th,
.feed,
pre {
  font-size: 13px;
}

#subtitle {
  color: var(--muted);
  margin-top: 5px;
}

main {
  padding: 20px 28px 36px;
  display: grid;
  gap: 18px;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.pill.ok {
  color: #0f6b42;
  border-color: #b8ddca;
  background: #eef8f2;
}

.pill.warn {
  color: #83560c;
  border-color: #e6cf9d;
  background: #fff8e8;
}

.pill.bad {
  color: #8a2525;
  border-color: #e4b7b7;
  background: #fff0f0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
}

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

.kpi {
  min-height: 92px;
  padding: 14px 14px 12px;
}

.kpi strong {
  display: block;
  font-size: 28px;
  line-height: 1.1;
  margin-top: 10px;
}

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

.chart-grid,
.split-grid,
.bottom-grid {
  display: grid;
  gap: 18px;
}

.chart-grid {
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
}

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

.bottom-grid {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
}

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

.panel.wide {
  min-height: 330px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 10px;
}

.panel-head span {
  color: var(--muted);
  text-align: right;
}

.chart-panel-head {
  align-items: flex-start;
  flex-wrap: wrap;
}

.chart-title {
  display: grid;
  gap: 3px;
}

.chart-title span {
  text-align: left;
}

.chart-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.chart-legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend i {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.listings-head {
  align-items: flex-start;
  flex-wrap: wrap;
}

.listings-head > div:first-child {
  display: grid;
  gap: 3px;
}

.segmented button {
  height: 28px;
  min-width: 62px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.segmented button:hover,
.segmented button:focus-visible {
  color: var(--text);
  background: #eef2f6;
  outline: none;
}

.segmented button.active {
  color: #174a7c;
  background: #e8f1fb;
  font-weight: 700;
}

canvas {
  width: 100%;
  height: 260px;
  display: block;
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(120px, 2fr) 44px;
  gap: 10px;
  align-items: center;
  min-height: 24px;
}

.bar-row .label,
.bar-row .value {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  display: block;
  height: 8px;
  background: var(--ink-soft);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--blue);
}

.bars.compact .bar-fill {
  background: var(--amber);
}

.table-wrap {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f9fafb;
  font-weight: 650;
}

td a {
  color: var(--blue);
  text-decoration: none;
}

td a:hover {
  text-decoration: underline;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-book {
  color: #174a7c;
  background: #e8f1fb;
}

.status-lottery {
  color: #83560c;
  background: #fff8e8;
}

.status-unknown {
  color: #4b5563;
  background: #eef2f6;
}

.event-layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(280px, 1.1fr);
  gap: 12px;
  min-height: 360px;
}

.event-queue {
  display: grid;
  align-content: start;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  padding-right: 2px;
}

.event-card {
  width: 100%;
  min-height: 86px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.event-card:hover,
.event-card:focus-visible,
.event-card.selected {
  border-color: #9bb9dc;
  background: #f2f7fc;
  outline: none;
}

.event-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-card span:not(.event-badge),
.event-card time {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 66px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.event-added {
  color: #0f6b42;
  background: #e8f7ef;
}

.event-removed {
  color: #8a2525;
  background: #fff0f0;
}

.event-changed {
  color: #83560c;
  background: #fff8e8;
}

.event-detail {
  min-width: 0;
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
}

.detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

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

.event-detail h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

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

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.detail-field {
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.detail-field strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.detail-link {
  display: inline-flex;
  align-items: center;
  height: 32px;
  margin-top: 12px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.detail-link:hover {
  text-decoration: underline;
}

.changed-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.changed-fields span {
  padding: 4px 8px;
  border-radius: 999px;
  background: #fff8e8;
  color: #83560c;
  font-size: 12px;
}

.raw-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.raw-row {
  display: grid;
  grid-template-columns: minmax(88px, 0.45fr) minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  font-size: 12px;
}

.raw-row span {
  color: var(--muted);
}

.raw-row code {
  color: #303946;
  white-space: normal;
  overflow-wrap: anywhere;
}

pre {
  min-height: 220px;
  max-height: 360px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: #dbe4ee;
  line-height: 1.5;
}

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

@media (max-width: 1100px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

  .chart-grid,
  .split-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }

  .event-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  main {
    padding: 14px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
  }

  .segmented button {
    flex: 0 0 auto;
  }

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

  .raw-row {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 21px;
  }
}
