* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0d1117;
  color: #e6edf3;
}

a {
  color: #7cc9ff;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #30363d;
  background: #161b22;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }

.userbox {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: .85rem;
}

.nav {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid #30363d;
  font-size: .9rem;
}
.nav a { text-decoration: none; }
.nav a:hover { text-decoration: underline; }

.content {
  padding: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}

.card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 16px;
}
.card.small {
  max-width: 460px;
  margin: 48px auto;
}

label {
  display: block;
  margin-bottom: 10px;
  font-size: .9rem;
}

input, select, textarea, button {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
  font-size: .9rem;
}

button { cursor: pointer; }
button:hover { background: #1c2129; }
button.danger { background: #d83b3b; border-color: #d83b3b; font-weight: 700; }
button.danger:hover { background: #b82e2e; }

.btn {
  display: inline-block;
  width: auto;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #21262d;
  color: #e6edf3;
  cursor: pointer;
  font-size: .85rem;
}
.btn:hover { background: #30363d; }
.btn.primary { background: #238636; border-color: #238636; color: #fff; }
.btn.primary:hover { background: #2ea043; }
.btn.danger { background: #d83b3b; border-color: #d83b3b; color: #fff; }
.btn.sm { padding: 3px 8px; font-size: .78rem; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid #30363d;
  text-align: left;
  padding: 6px 8px;
  font-size: .85rem;
}
th { font-weight: 600; color: #8b949e; }

.error { color: #ff8a8a; }
.ok { color: #8aff9b; }
.warn { color: #ffd479; }
.muted { color: #8b949e; font-size: .85rem; }

.inline { display: inline-block; width: auto; }
.inline button { width: auto; }
.mt { margin-top: 10px; }

/* Generic form layout helpers (used by Users / Stream Keys) */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-stack label {
  margin-bottom: 0;
}
.form-stack .muted {
  margin: 0;
}
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  cursor: pointer;
  font-size: .88rem;
}
.check-row input[type="checkbox"] {
  width: auto;
  margin: 0;
}
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 10px;
  margin: 4px 0;
}
/* Guest key preset: Master Twitch visibly off + inert */
label.guest-preset-twitch-off {
  opacity: 0.5;
  cursor: not-allowed;
}
label.guest-preset-twitch-off input {
  cursor: not-allowed;
}
.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

/* Management pages (Users / Stream Keys) */
.management-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.management-alerts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.management-list-card {
  padding: 0;
  overflow: hidden;
}
.card-head {
  padding: 14px 16px;
  border-bottom: 1px solid #30363d;
  background: #131820;
}
.card-head h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}
.card-head .muted {
  margin: 0;
}
.mgmt-list-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.mgmt-list-head-row .btn {
  flex-shrink: 0;
  margin-top: 2px;
}
.table-wrap {
  overflow-x: auto;
}
.table-wrap table {
  min-width: 880px;
}
.management-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}
.card-head-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.card-head-inline h2 {
  margin: 0;
}
.disabled-panel {
  border-style: dashed;
  border-color: #475569;
  background: #121826;
}
.empty-edit-state {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed #475569;
  border-radius: 8px;
  background: #0d1420;
}

.mgmt-dialog {
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 0;
  background: #161b22;
  color: #e6edf3;
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}
.mgmt-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.mgmt-dialog .dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #30363d;
}
.mgmt-dialog .dialog-head h2 {
  margin: 0;
  font-size: 1.1rem;
}
.mgmt-dialog .dialog-body {
  padding: 16px 18px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

/* Director grid */
.director-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 768px) {
  .director-grid { grid-template-columns: 1fr; }
}

.director-panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 16px;
}
.director-panel h2 { margin-top: 0; font-size: 1rem; }
.director-panel h3 { margin: 1rem 0 .5rem; font-size: .9rem; color: #8b949e; }

.source-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
  cursor: pointer;
  transition: border-color .15s;
}
.source-card:hover { border-color: #58a6ff; }
.source-card.selected { border-color: #58a6ff; background: #0e1926; }
.source-card.live { border-left: 3px solid #d29922; }
.source-card.live-ready { border-left: 3px solid #3fb950; }
.source-card.dragging { opacity: .6; }
.source-card .drag-handle {
  font-family: monospace;
  font-size: .78rem;
  color: #6e7681;
  align-self: flex-end;
  margin-bottom: -2px;
}
.source-card .source-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.source-card .source-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.source-card .name { font-weight: 600; font-size: .9rem; }
.source-card .meta { font-size: .78rem; color: #8b949e; }
.source-card .badges { display: flex; gap: 6px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-ready {
  background: #238636;
  color: #fff;
}
.badge-not-ready {
  background: #30363d;
  color: #8b949e;
}
/* Streamer page: encoder is publishing — distinct from green “Ready” */
.badge-encoder-live {
  background: linear-gradient(145deg, #f85149 0%, #c93c37 100%);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 0 14px rgba(248, 81, 73, 0.55);
  animation: badge-encoder-live-pulse 2.2s ease-in-out infinite;
}
@keyframes badge-encoder-live-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.12) inset,
      0 0 12px rgba(248, 81, 73, 0.45);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.18) inset,
      0 0 22px rgba(248, 81, 73, 0.75);
  }
}

.toggle-ready-btn {
  flex-shrink: 0;
}

.source-routes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.quick-route-btn {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #8b949e;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.quick-route-btn:hover {
  border-color: #1f6feb;
  color: #e6edf3;
}
.quick-route-active {
  border-color: #3fb950;
  color: #3fb950;
}
.quick-route-active:hover {
  border-color: #3fb950;
  color: #56d364;
}
.source-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: .9rem;
}

.self-managed-card .output-row {
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
  background: #0d1117;
}
.self-managed-card .output-row .muted {
  margin-left: 10px;
}
.self-managed-card .check-row {
  margin: 0;
}

.cb-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin: 4px 0;
  font-size: .9rem;
}
.cb-label input[type="checkbox"] { width: auto; }

.output-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.output-slot {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 14px;
  border: 2px solid #30363d;
  border-radius: 8px;
  background: #0d1117;
  cursor: pointer;
  transition: border-color .15s;
}
.output-slot:hover { border-color: #238636; }
.output-slot.targeted { border-color: #238636; }
.output-slot.drop-hover {
  border-color: #58a6ff;
  box-shadow: 0 0 0 2px rgba(88, 166, 255, .15);
}
.output-slot .slot-name { font-weight: 700; font-size: .95rem; }
.output-slot .slot-target { font-size: .82rem; color: #8b949e; }
.output-slot .slot-actions {
  margin-top: 4px;
}

.obs-tweaks {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid #30363d;
  border-radius: 8px;
  background: #0d1117;
}
.obs-btn-group {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #30363d;
}
.obs-btn-label {
  font-size: .78rem;
  color: #8b949e;
  padding: 5px 8px;
  white-space: nowrap;
  background: #161b22;
  border-right: 1px solid #30363d;
}
.obs-tweak-btn {
  border: none;
  background: #21262d;
  color: #c9d1d9;
  font-size: .78rem;
  padding: 5px 10px;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-right: 1px solid #30363d;
  white-space: nowrap;
}
.obs-tweak-btn:last-child { border-right: none; }
.obs-tweak-btn:hover { background: #30363d; }
.obs-tweak-btn.obs-tweak-active {
  background: #238636;
  color: #fff;
  font-weight: 600;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}
.queue-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #30363d;
  border-radius: 999px;
  padding: 2px 8px 2px 10px;
  background: #111827;
}
.queue-chip-primary {
  border-color: #1f6feb;
}
.queue-chip-active {
  border-color: #3fb950;
}
.queue-chip-name {
  font-size: .78rem;
  color: #e6edf3;
  white-space: nowrap;
}
.queue-remove {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: 999px;
  padding: 0;
  line-height: 16px;
  border: 1px solid #3b4552;
  background: #0d1117;
  color: #c9d1d9;
  cursor: pointer;
}
.queue-remove:hover {
  border-color: #d83b3b;
  color: #ffb3b3;
}
.queue-force {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: 999px;
  padding: 0;
  line-height: 16px;
  font-size: .6rem;
  border: 1px solid #3b4552;
  background: #0d1117;
  color: #58a6ff;
  cursor: pointer;
}
.queue-force:hover {
  border-color: #238636;
  background: #238636;
  color: #fff;
}
.queue-pos {
  font-size: .68rem;
  font-weight: 700;
  color: #8b949e;
  min-width: 14px;
  text-align: center;
}
.queue-dot-live, .queue-dot-ready, .queue-dot-streaming, .queue-dot-off {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.queue-dot-live    { background: #3fb950; }
.queue-dot-ready   { background: #1f6feb; }
.queue-dot-streaming { background: #d29922; }
.queue-dot-off     { background: #484f58; }
.queue-actions {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
}
.queue-move {
  width: 16px;
  height: 11px;
  min-width: 16px;
  padding: 0;
  border: 1px solid #3b4552;
  border-radius: 3px;
  background: #0d1117;
  color: #8b949e;
  font-size: .5rem;
  line-height: 9px;
  cursor: pointer;
  text-align: center;
}
.queue-move:hover {
  border-color: #1f6feb;
  color: #e6edf3;
}

#wire-panel {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px 16px;
}

/* Checkbox grid for guest keys */
.checkbox-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 4px 0 8px;
}
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  cursor: pointer;
}
.checkbox-group input[type="checkbox"] {
  width: auto;
}

/* Guest page */
.guest-container {
  max-width: 520px;
  margin: 40px auto;
}
.guest-container .card { margin-bottom: 16px; }

.copy-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 6px 0;
}
.copy-row input {
  flex: 1;
  font-family: monospace;
  font-size: .85rem;
}
.copy-row .btn { flex-shrink: 0; }

/* Full URL visible for long panel « Voir » (sp1) links */
.stream-page-url-visible {
  margin: 10px 0 4px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #30363d;
  background: #0d1117;
  max-height: 12rem;
  overflow: auto;
}
.stream-page-url-code {
  display: block;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  word-break: break-all;
  white-space: pre-wrap;
  color: #8b949e;
}

.guest-container .card-section-title {
  font-size: .8rem;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 16px 0 6px;
}
.guest-container .card-section-title:first-child {
  margin-top: 0;
}

.streamer-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.streamer-page-actions .btn {
  width: auto;
}

.conn-detail-wrap {
  margin-top: 8px;
}
.conn-mode-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #8b949e;
  margin-bottom: 6px;
}
.conn-protocol-select {
  width: 100%;
  max-width: 100%;
  padding: 8px 10px;
  font-size: 0.95rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
  margin-bottom: 8px;
}
.conn-hint {
  margin: 0 0 10px;
  font-size: 0.88rem;
  line-height: 1.45;
}
.conn-browser-actions {
  margin-top: 8px;
}
.conn-browser-actions .btn {
  width: auto;
}
