:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #dfe2e7;
  --text: #1c2026;
  --muted: #687080;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c4372f;
  --warn: #9a6700;
  --ok: #1f8a4c;
  --log-bg: #0f1216;
  --log-text: #d5dae1;
  --log-muted: #7c8592;
  --log-error: #ff8a80;
  --log-warn: #f2c66d;
  --log-notice: #8ab4f8;
  --mark: #5a4a00;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #181c21;
    --border: #2a3038;
    --text: #e3e7ec;
    --muted: #8d96a3;
    --accent: #5b8ff0;
    --danger: #ff8a80;
    --warn: #f2c66d;
    --ok: #5fd38d;
    --log-bg: #0b0d10;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.conn::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.conn[data-state="live"]::before {
  background: var(--ok);
}
.conn[data-state="paused"]::before,
.conn[data-state="connecting"]::before {
  background: var(--warn);
}
.conn[data-state="error"]::before {
  background: var(--danger);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth {
  width: min(440px, calc(100% - 32px));
  margin: 12vh auto 0;
  padding: 20px;
}

.auth label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.row {
  display: flex;
  gap: 8px;
}

.row input {
  flex: 1;
  min-width: 0;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.error {
  margin: 10px 0 0;
  color: var(--danger);
}

input,
select,
button {
  font: inherit;
  color: inherit;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  padding: 0 10px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  background: var(--panel);
  white-space: nowrap;
}

button:hover {
  border-color: var(--muted);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.ghost {
  border-color: transparent;
  color: var(--muted);
}

.viewer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
}

.viewer[hidden] {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > span {
  color: var(--muted);
  font-size: 12px;
}

.field.grow {
  flex: 1;
  min-width: 180px;
}

.field select#process {
  min-width: 220px;
}

.segmented {
  display: inline-flex;
}

.segmented button {
  border-radius: 0;
  min-width: 52px;
}

.segmented button:first-child {
  border-radius: 6px 0 0 6px;
}

.segmented button:last-child {
  border-radius: 0 6px 6px 0;
  margin-left: -1px;
}

.segmented button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  position: relative;
}

.log-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.log {
  height: 100%;
  overflow: auto;
  padding: 10px 0;
  border-radius: 8px;
  background: var(--log-bg);
  color: var(--log-text);
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.line {
  padding: 0 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.line:hover {
  background: rgba(255, 255, 255, 0.04);
}

.line.bad {
  color: var(--log-error);
}

.line.warn {
  color: var(--log-warn);
}

.line.notice {
  color: var(--log-notice);
  font-style: italic;
}

.line[hidden] {
  display: none;
}

.log mark {
  background: var(--mark);
  color: inherit;
  border-radius: 2px;
}

.empty {
  padding: 0 14px;
  color: var(--log-muted);
}

.jump {
  position: absolute;
  right: 18px;
  bottom: 16px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 640px) {
  .viewer {
    padding: 10px;
  }
  .field select#process {
    min-width: 0;
    width: 100%;
  }
  .field,
  .field.grow {
    flex: 1 1 100%;
  }
}
