:root {
  color-scheme: dark;
  --bg: #0b0c0e;
  --surface: #14161a;
  --surface-2: #1c1e23;
  --surface-3: #282a2e;
  --line: #414755;
  --line-soft: #2c2e33;
  --text: #e2e2e8;
  --muted: #9da3b5;
  --blue: #4b8eff;
  --blue-soft: #adc6ff;
  --red: #d0021b;
  --red-soft: #ffb4aa;
  --green: #53e16f;
  --green-soft: #72fe88;
  --warn: #ffb4aa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  padding-bottom: 96px;
}

button, input, select, textarea {
  font: inherit;
}

button, select, input, textarea {
  border: 1px solid var(--line);
  background: #090a0c;
  color: var(--text);
  border-radius: 4px;
  min-height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 88px;
  padding: 10px 12px;
  resize: vertical;
}

button {
  cursor: pointer;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #061832;
}

button.danger {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

a { color: var(--blue-soft); }

.button-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 12px;
  background: var(--blue);
  color: #061832;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  text-transform: uppercase;
}

.studio-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 22, 26, .96);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
}

.signal {
  color: var(--blue-soft);
  font-size: 18px;
}

.header-actions, .actions, .inline-form, .chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.icon-button {
  min-width: 38px;
  padding: 0;
}

.live-chip, .status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 4px;
  padding: 0 9px;
  background: var(--surface-3);
  color: var(--muted);
  border: 1px solid var(--line-soft);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.live-chip.live {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.status-pill.ok, .ok { color: var(--green); }
.status-pill.warn, .warn { color: var(--warn); }
.status-pill.bad, .bad { color: var(--red-soft); }

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

.view {
  display: none;
  gap: 16px;
}

.view.active {
  display: grid;
}

.page-title h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 72px);
  line-height: 1;
  letter-spacing: 0;
}

.page-title.compact h1 {
  font-size: 28px;
}

.page-title p {
  color: var(--muted);
  font-size: 18px;
  margin: 10px 0 0;
}

.panel, .stat-card, .login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h2, .panel h2 {
  margin: 0;
  font-size: 20px;
}

.panel-kicker {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 900;
  margin-bottom: 10px;
}

.hero-status {
  display: grid;
  gap: 12px;
}

.video-stage {
  min-height: 230px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 20%, rgba(75, 142, 255, .18), transparent 32%),
    #050608;
}

.video-stage p {
  position: absolute;
  bottom: 34px;
  margin: 0;
  color: var(--muted);
}

.no-video {
  color: rgba(226, 226, 232, .15);
  font-size: 68px;
}

.stage-badge {
  position: absolute;
  bottom: 58px;
  border: 1px solid var(--line);
  background: #07080b;
  color: var(--red-soft);
  padding: 8px 28px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .08em;
}

.stage-badge.live {
  background: var(--red);
  color: white;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-grid, .history-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.metric-grid div, .stat-card {
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 12px;
}

.metric-grid span, .stat-card span, .destination-card span, .profile-card span, .session-row span, .settings-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-grid strong, .stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.stat-card.health {
  border-left-color: var(--green);
  border-left-width: 3px;
}

.chart-card {
  margin-top: 12px;
  background: #0b0c0e;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  overflow: hidden;
}

.chart-card svg {
  display: block;
  width: 100%;
  height: 170px;
}

.grid-lines line {
  stroke: #242832;
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke-width: 3;
}

.chart-line.green { stroke: var(--green); }
.chart-line.blue { stroke: var(--blue-soft); }

.field-list, .stack-form, .stack-list, .destination-list, .event-list, .chat-list, .session-list, .table-list, .oauth-grid {
  display: grid;
  gap: 10px;
}

.studio-grid, .studio-main, .studio-side {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.field-list label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 900;
}

.field-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 10px;
}

.field-row > span:first-child {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 900;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: none;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.secret {
  letter-spacing: .18em;
}

.destination-card, .profile-card, .session-row, .table-row, .settings-row, .copy-row, .oauth-card, .signup-card, .user-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.destination-card .actions, .profile-card .actions, .oauth-card .actions, .signup-card .actions, .user-card .actions {
  grid-column: 1 / -1;
}

.oauth-card small, .signup-card small, .user-card small, .destination-card small, .settings-row small {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.destination-card {
  grid-template-columns: 1fr;
}

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

.destination-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
}

.destination-card.collapsed {
  opacity: .82;
}

.destination-config {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
}

.destination-config input[name="url"],
.destination-config input[name="streamKey"],
.destination-config-footer {
  grid-column: 1 / -1;
}

.destination-config-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.platform-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: var(--blue);
  color: #061832;
  font-weight: 900;
}

.event-row, .chat-message {
  display: grid;
  grid-template-columns: 72px auto auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 6px 0;
  border-bottom: 1px solid rgba(65, 71, 85, .38);
}

.event-row time, .chat-message time {
  color: #626b81;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
}

.chat-message strong {
  color: var(--name-color, var(--blue-soft));
}

.chat-message p {
  margin: 0;
  font-size: 16px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.chat-platform {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.chat-console .chat-list {
  max-height: 460px;
  overflow: auto;
}

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

.overlay-preview {
  min-height: 140px;
  margin-top: 12px;
  border: 1px solid var(--line-soft);
  background: #050608;
  border-radius: 4px;
  padding: 12px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
}

.preview-message {
  width: 132px;
  height: 10px;
  margin-top: 70px;
  background: var(--line);
  border-radius: 2px;
}

.preview-message.short {
  width: 84px;
  margin-top: 5px;
}

.fanout-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.fanout-panel span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 900;
}

.fanout-panel strong {
  display: block;
  margin-top: 4px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 20px;
  color: var(--blue-soft);
}

.switch-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.switch-label input {
  position: absolute;
  opacity: 0;
}

.switch {
  width: 62px;
  height: 34px;
  border-radius: 999px;
  background: #33373f;
  border: 1px solid var(--line);
  position: relative;
}

.switch::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 4px;
  transition: transform .15s ease;
}

.switch-label input:checked + .switch {
  background: var(--blue);
}

.switch-label input:checked + .switch::after {
  transform: translateX(27px);
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.chat-form {
  display: grid;
  grid-template-columns: 120px 120px minmax(0, 1fr) auto;
  margin-top: 12px;
}

.compact-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.page-actions {
  margin: 4px 0 10px;
}

.danger-zone {
  border-color: var(--red);
}

.danger-zone button {
  width: 100%;
  border-color: rgba(255, 180, 170, .5);
  background: rgba(208, 2, 27, .18);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 14px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(11, 12, 14, .98);
}

.bottom-nav button {
  min-height: 68px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
}

.bottom-nav button.active {
  color: var(--green);
}

.bottom-nav span {
  display: block;
  font-size: 10px;
}

.app-footer {
  display: flex;
  justify-content: center;
  gap: 18px;
  color: var(--muted);
  font-size: 12px;
  padding: 20px 20px 8px;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.signup-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(5, 6, 8, .68), rgba(5, 6, 8, .9)),
    url("https://images.unsplash.com/photo-1542751371-adc38448a05e?auto=format&fit=crop&w=1800&q=80") center / cover fixed;
}

.signup-shell {
  width: min(980px, 100%);
  display: grid;
  gap: 18px;
}

.signup-hero {
  display: grid;
  align-content: end;
  min-height: 320px;
}

.signup-hero h1 {
  max-width: 760px;
  margin: 28px 0 10px;
  font-size: clamp(42px, 8vw, 82px);
  line-height: 1;
}

.signup-hero p {
  max-width: 640px;
  color: var(--text);
  font-size: 18px;
}

.signup-panel h2 {
  margin: 0 0 14px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  padding: 24px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #061832;
  font-weight: 900;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--blue-soft);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 900;
  margin: 0 0 4px;
}

.login-panel h1 {
  margin: 0 0 18px;
}

.form-error {
  color: var(--red-soft);
  min-height: 20px;
  margin: 10px 0 0;
}

@media (min-width: 900px) {
  body {
    padding-bottom: 0;
  }

  .app-shell {
    padding-bottom: 40px;
  }

  .studio-grid {
    grid-template-columns: minmax(0, 1.22fr) minmax(340px, .78fr);
  }

  #view-destinations.active,
  #view-chat.active,
  #view-settings.active {
    grid-template-columns: minmax(0, 1fr) minmax(360px, .72fr);
  }

  #view-destinations .page-title,
  #view-chat .chat-console,
  #view-history .page-title,
  #view-history .page-actions,
  #view-settings .page-title {
    grid-column: 1 / -1;
  }

  #view-history.active {
    grid-template-columns: minmax(0, 1fr) minmax(360px, .72fr);
  }

  #view-history .history-stats {
    grid-template-columns: 1fr;
  }

  .bottom-nav {
    top: 68px;
    right: auto;
    bottom: auto;
    width: 88px;
    height: calc(100vh - 68px);
    grid-template-columns: 1fr;
    grid-auto-rows: 78px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .app-shell, .app-footer {
    margin-left: 88px;
  }
}

@media (max-width: 720px) {
  .studio-header {
    height: 56px;
    padding-inline: 14px;
  }

  .brand {
    font-size: 20px;
  }

  .app-shell {
    padding: 14px;
  }

  .inline-form, .chat-form, .metric-grid, .history-stats, .field-row, .destination-config {
    grid-template-columns: 1fr;
  }

  .destination-card, .destination-card.compact, .destination-head, .profile-card, .session-row, .table-row, .settings-row, .user-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .destination-card .status-pill,
  .destination-head .check-row,
  .destination-head button,
  .profile-card .actions,
  .session-row > div:last-child {
    grid-column: 1 / -1;
  }

  .app-footer {
    padding-bottom: 84px;
  }
}
