:root {
  --bg: #12151a;
  --surface: #1b1f27;
  --border: #2b303b;
  --text: #e6e8eb;
  --muted: #8b93a1;
  --accent: #3b82f6;
  --green: #22c55e;
  --amber: #eab308;
  --red: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.view {
  min-height: 100vh;
}

#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.login-card input {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.login-card button {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}

.error {
  color: var(--red);
  font-size: 0.85rem;
  margin: 0;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}

.link-btn:hover {
  color: var(--text);
}

main {
  padding: 1.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
}

tr:last-child td {
  border-bottom: none;
}

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

a:hover {
  text-decoration: underline;
}

.state-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.state-running { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.state-stopped { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.state-pending, .state-stopping, .state-shutting-down {
  background: rgba(234, 179, 8, 0.15); color: var(--amber);
}
.state-unknown { background: rgba(139, 147, 161, 0.15); color: var(--muted); }

.actions button {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  margin-right: 0.4rem;
}

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

.auto-stop {
  color: var(--muted);
  font-size: 0.8rem;
}

.auto-stop.pending {
  color: var(--amber);
  font-weight: 600;
}

.bounce-flag {
  font-size: 0.8rem;
  font-weight: 600;
}

.bounce-flag-on { color: var(--green); }
.bounce-flag-off { color: var(--muted); }

.remote-source {
  color: var(--muted);
  font-size: 0.8rem;
  word-break: break-all;
}

.remote-source-active {
  color: var(--green);
  font-weight: 600;
}

.remote-source-mismatch {
  color: var(--amber);
  font-weight: 600;
  text-decoration: underline dotted;
  cursor: help;
}

.actions button.start:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
.actions button.stop:hover:not(:disabled) { border-color: var(--red); color: var(--red); }

h2 {
  font-size: 1rem;
  margin: 2rem 0 0.75rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2rem;
}

.section-header h2 {
  margin: 0;
}

.encoder-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

#encoder-search {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  min-width: 220px;
}

.encoder-toolbar .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.encoder-toolbar .checkbox-label input {
  width: auto;
}

#encoder-table th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

#encoder-table th[data-sort]:hover {
  color: var(--accent);
}

#encoder-table th[data-sort] .sort-indicator {
  margin-left: 0.25rem;
  color: var(--accent);
}

.encoder-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.encoder-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.encoder-form input[type="text"] {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.encoder-form .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

.encoder-form .checkbox-label input {
  width: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
}

.muted {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.resize-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.resize-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.resize-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  max-width: 100%;
}

.resize-controls select {
  flex: 1;
  /* Flex items default to min-width: auto, which floors shrinking at the
     content's intrinsic width — without this, a <select> with long option
     text (e.g. the variant-capacity descriptions) pushes past the modal's
     edge instead of shrinking to fit, taking the button with it. */
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resize-controls button {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

#resize-price-change {
  margin-top: 0.5rem;
}

.price-increase { color: var(--red); }
.price-decrease { color: var(--green); }

.desired-size-mismatch {
  color: var(--amber);
  font-weight: 600;
}

.rtmp-tree {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.rtmp-stream {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.rtmp-stream-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  user-select: none;
}

.rtmp-stream-header .caret {
  width: 0.7rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.rtmp-stream.expanded .caret {
  transform: rotate(90deg);
}

.source-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}

.source-local { background: rgba(139, 147, 161, 0.15); color: var(--muted); }
.source-remote { background: rgba(59, 130, 246, 0.15); color: var(--accent); }

.rtmp-stream-header .key {
  font-weight: 600;
  min-width: 8rem;
}

.rtmp-stream-header .meta {
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.bounce-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
}

.bounce-active { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.bounce-idle { background: rgba(139, 147, 161, 0.15); color: var(--muted); }
.bounce-disabled { background: rgba(234, 179, 8, 0.15); color: var(--amber); }

.rtmp-clients {
  display: none;
  border-top: 1px solid var(--border);
}

.rtmp-stream.expanded .rtmp-clients {
  display: block;
}

.rtmp-clients table {
  border-radius: 0;
  width: 100%;
}

.rtmp-clients th, .rtmp-clients td {
  padding: 0.4rem 0.9rem 0.4rem 2.25rem;
  font-size: 0.82rem;
}

.rtmp-no-clients {
  padding: 0.5rem 0.9rem 0.5rem 2.25rem;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
}

.whois {
  color: var(--muted);
  font-size: 0.75rem;
  font-style: italic;
}

.preview-btn {
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.75rem;
}

.preview-btn:hover {
  border-color: var(--accent);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  width: min(90vw, 720px);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

#preview-video {
  width: 100%;
  max-height: 60vh;
  background: black;
  border-radius: 8px;
}
