:root {
  color: #f5f7fa;
  background: #0d0f12;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #0d0f12;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

.topbar {
  height: 64px;
  padding: 0 clamp(18px, 4vw, 56px);
  border-bottom: 1px solid #292d33;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #121519;
}

.brand {
  color: #f7f8fa;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 680;
  text-decoration: none;
}

.brand-mark {
  width: 18px;
  height: 18px;
  background: #29d391;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.connection {
  color: #a7adb6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #858b94;
}

.connection[data-state="connecting"] .status-dot {
  background: #f1b743;
  animation: pulse 1.2s infinite;
}

.connection[data-state="live"] .status-dot {
  background: #29d391;
}

.connection[data-state="error"] .status-dot {
  background: #ff5d68;
}

main {
  width: min(1180px, calc(100% - 36px));
  margin: clamp(24px, 5vh, 56px) auto 48px;
}

.viewer {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid #2d3239;
  border-radius: 6px;
  background: #050607;
}

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050607;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #f0f2f5;
  background: #050607;
  pointer-events: none;
}

.empty-state strong {
  margin-top: 6px;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 620;
  letter-spacing: 0;
}

.empty-state > span {
  color: #888f99;
  font-size: 14px;
}

.signal {
  height: 34px;
  display: flex;
  align-items: end;
  gap: 5px;
}

.signal span {
  width: 5px;
  border-radius: 2px 2px 0 0;
  background: #29d391;
}

.signal span:nth-child(1) { height: 12px; }
.signal span:nth-child(2) { height: 23px; }
.signal span:nth-child(3) { height: 34px; }

.live-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 6px 8px;
  border-radius: 4px;
  display: none;
  align-items: center;
  gap: 6px;
  color: #fff;
  background: rgba(13, 15, 18, 0.82);
  font-size: 11px;
  font-weight: 750;
}

.live-badge span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff4250;
}

.viewer.is-live .empty-state {
  display: none;
}

.viewer.is-live .live-badge {
  display: inline-flex;
}

.controls {
  padding: 22px 0 0;
}

.stream-form {
  display: grid;
  grid-template-columns: minmax(120px, 0.65fr) minmax(180px, 1.35fr) 96px 80px;
  gap: 12px;
  align-items: end;
}

label {
  min-width: 0;
  display: grid;
  gap: 7px;
}

label span,
.stream-meta span {
  color: #979ea8;
  font-size: 12px;
  font-weight: 600;
}

input,
button,
select {
  height: 42px;
  border: 1px solid #343941;
  border-radius: 5px;
}

input {
  min-width: 0;
  width: 100%;
  padding: 0 12px;
  color: #f5f7fa;
  outline: none;
  background: #171a1f;
}

select {
  min-width: 108px;
  padding: 0 32px 0 12px;
  color: #f5f7fa;
  outline: none;
  background: #171a1f;
}

input:focus {
  border-color: #29d391;
  box-shadow: 0 0 0 3px rgba(41, 211, 145, 0.12);
}

button {
  padding: 0 16px;
  color: #d7dbe1;
  background: #20242a;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #292e35;
}

button.primary {
  border-color: #29d391;
  color: #07100d;
  background: #29d391;
  font-weight: 700;
}

button.primary:hover:not(:disabled) {
  background: #4bdfa6;
}

button:disabled {
  opacity: 0.42;
  cursor: default;
}

button.is-active {
  border-color: #f1b743;
  color: #f1c66c;
}

.stream-meta {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid #292d33;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.stream-meta > div {
  min-width: 0;
  display: grid;
  gap: 7px;
}

code {
  overflow: hidden;
  color: #c9ced5;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagnostics {
  margin-top: 34px;
  padding-top: 26px;
  border-top: 1px solid #292d33;
}

.diagnostics-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.diagnostics h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 680;
  letter-spacing: 0;
}

.sei-connection {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #9299a3;
  font-size: 12px;
}

.sei-connection span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #858b94;
}

.sei-connection[data-state="connecting"] span {
  background: #f1b743;
  animation: pulse 1.2s infinite;
}

.sei-connection[data-state="live"] span { background: #29d391; }
.sei-connection[data-state="error"] span { background: #ff5d68; }

.diagnostic-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.diagnostic-actions button {
  min-width: 68px;
}

.filter-field {
  gap: 5px;
}

.auto-scroll {
  height: 42px;
  padding: 0 8px;
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  color: #b7bdc5;
  font-size: 12px;
  white-space: nowrap;
}

.auto-scroll input {
  width: 15px;
  height: 15px;
  accent-color: #29d391;
}

.stats {
  margin-top: 22px;
  padding: 16px 0;
  border-top: 1px solid #24282e;
  border-bottom: 1px solid #24282e;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

.stats > div {
  min-width: 0;
  padding: 0 16px;
  border-right: 1px solid #292d33;
  display: grid;
  gap: 5px;
}

.stats > div:first-child { padding-left: 0; }
.stats > div:last-child { border-right: 0; }

.stats span {
  color: #858d97;
  font-size: 11px;
  font-weight: 600;
}

.stats strong {
  overflow: hidden;
  color: #f2f4f6;
  font-size: 18px;
  font-weight: 650;
  text-overflow: ellipsis;
}

.event-list {
  height: min(520px, 52vh);
  min-height: 260px;
  margin-top: 16px;
  overflow: auto;
  border: 1px solid #292d33;
  border-radius: 6px;
  background: #101317;
}

.sei-empty {
  min-height: 258px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #cbd0d6;
}

.sei-empty[hidden] { display: none; }

.sei-empty span {
  color: #747c86;
  font-size: 12px;
}

.event-row {
  padding: 14px 16px 16px;
  border-bottom: 1px solid #252a30;
}

.event-row:last-child { border-bottom: 0; }
.event-row.is-issue { border-left: 3px solid #ff5d68; }
.event-row.is-sei { border-left: 3px solid #29d391; }

.event-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.event-header strong {
  color: #dfe3e8;
  font-size: 12px;
}

.event-row.is-issue .event-header strong { color: #ff8991; }

.event-header time {
  color: #777f89;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.event-fields {
  margin-top: 11px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px 20px;
}

.event-field {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.event-field.wide { grid-column: 1 / -1; }

.event-field span {
  color: #767e88;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
}

.event-field code {
  overflow: auto;
  color: #cbd1d8;
  line-height: 1.55;
  overflow-wrap: anywhere;
  text-overflow: clip;
  white-space: pre-wrap;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

@media (max-width: 680px) {
  .topbar {
    height: 56px;
    padding: 0 16px;
  }

  main {
    width: 100%;
    margin: 0 auto 32px;
  }

  .viewer {
    border-width: 0 0 1px;
    border-radius: 0;
  }

  .controls {
    padding: 18px 16px 0;
  }

  .stream-form {
    grid-template-columns: 1fr 1fr;
  }

  .stream-field {
    grid-column: auto;
  }

  .stream-form button {
    width: 100%;
  }

  .stream-meta {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .diagnostics {
    margin: 28px 16px 0;
    padding-top: 22px;
  }

  .diagnostics-header {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }

  .diagnostic-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filter-field { grid-column: 1 / -1; }
  .filter-field select { width: 100%; }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    row-gap: 18px;
  }

  .stats > div {
    padding: 0 12px;
  }

  .stats > div:nth-child(3) { border-right: 0; }
  .stats > div:nth-child(4) { padding-left: 0; }

  .event-list {
    height: 460px;
  }

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

@media (max-width: 390px) {
  .connection {
    max-width: 132px;
  }

  #statusText {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .connection[data-state="connecting"] .status-dot {
    animation: none;
  }
}
