: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);
  flex-wrap: wrap;
  gap: 1rem;
}

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

/* CPU / Network readout -- same markup and styles as LiveEncoder's header
   stats bar, so the two dashboards read the same way. */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  flex: 1;
  min-width: 260px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 0.85rem;
  font-weight: 600;
}

.cpu-cores {
  display: flex;
  gap: 0.2rem;
  align-items: flex-end;
}

.cpu-core-bar {
  width: 6px;
  height: 16px;
  background: var(--border);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.cpu-core-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--accent);
}

/* Memory readout (see renderMemory in app.js): the box-RAM bar, set apart
   and in its own colour, then one bar per thread heap, then the process's
   total resident memory as a figure. */
.mem-system-bar {
  margin-right: 0.35rem;
}

.mem-system-bar .cpu-core-bar-fill {
  background: var(--green);
}

.mem-rss {
  align-self: center;
  margin-left: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-title {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.build-info {
  font-size: 0.7rem;
  white-space: nowrap;
}

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

.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); }
/* Distinct from "stopped" (which can be started again) -- a terminated
   instance is gone for good, so the row is only good for archiving. */
.state-terminated {
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
  text-decoration: line-through;
}

.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;
}

.srt-source {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.srt-source.srt-state-live {
  color: var(--green);
  font-weight: 600;
}

.srt-source.srt-state-retrying,
.srt-source.srt-state-disabled {
  color: var(--amber);
}

.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;
}

.bulk-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.bulk-actions .secondary-btn {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.bulk-actions .secondary-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.bulk-actions .secondary-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

#bulk-selection-count {
  font-size: 0.85rem;
}

#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-table th:first-child,
#encoder-table td:first-child {
  width: 1.5rem;
  text-align: center;
}

.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 input[type="number"],
.encoder-form select {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.srt-source-fields,
.srt-mode-fields,
.srt-advanced {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border-radius: 8px;
}

/* Same as .remote-source-list: a bare container needs a border to light up. */
.srt-source-fields.field-changed {
  padding: 0.4rem;
  border-style: solid;
  border-width: 1px;
}

.srt-advanced summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}

.srt-advanced[open] {
  padding-left: 0.75rem;
  border-left: 2px solid var(--border);
}

.srt-hint {
  margin: 0;
  font-size: 0.8rem;
  word-break: break-all;
}

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

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

.remote-source-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-radius: 8px;
}

/* This one is a bare container with no border of its own, so the shared
   .field-changed border-color has nothing to apply to -- give it an actual
   border to light up, and padding so the rows don't sit against it. */
.remote-source-list.field-changed {
  padding: 0.4rem;
  border-style: solid;
  border-width: 1px;
}

.remote-source-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.remote-source-row input[type="text"] {
  flex: 1;
}

.remote-source-row button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 0.3rem 0.45rem;
}

.remote-source-row button:hover:not(:disabled) {
  color: var(--text);
}

.remote-source-row button:disabled {
  opacity: 0.35;
  cursor: default;
}

.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;
}

/* Unsaved-change indicators for the encoder settings modal: a changed field
   is highlighted amber, and the button that would persist it turns red,
   until that specific action (Save / Push to Encoder / Resize) succeeds.

   The highlight is a dark amber wash plus a lit border/ring rather than a
   pale fill: these fields keep their light body text (var(--text)), so
   filling them with a light color put near-white text on near-white
   background. Tinting the dark background instead keeps the text at full
   contrast and reads as "modified" on the page's own dark theme. */
.field-changed {
  background: rgba(234, 179, 8, 0.1) !important;
  border-color: var(--amber) !important;
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
}

/* A native checkbox ignores background/border, so mark it with a ring
   around the control itself (the Bounce toggle is the only one). */
input[type="checkbox"].field-changed {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  box-shadow: none;
}

.btn-needs-save {
  background: #c0392b !important;
  /* Explicit: some of these buttons inherit a dark body color rather than
     the white that .modal-actions/.resize-controls set. */
  color: #fff !important;
  border-color: #c0392b !important;
}

.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;
}

.encoder-version {
  color: var(--muted);
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* An older release than the newest published LiveEncoder (Update installs it) */
.encoder-version-behind {
  color: var(--warning, #d9a400);
}

.manager-update-btn {
  font-size: 0.75rem;
  color: var(--warning, #d9a400);
  padding: 0;
}

.update-action {
  white-space: nowrap;
  display: flex;
  gap: 0.4rem;
}

.update-encoder-btn,
.sync-encoder-btn {
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
}

.update-encoder-btn:hover,
.sync-encoder-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.extend-shutdown-btn {
  margin-left: 0.4rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.7rem;
}

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

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

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

.rtmp-push-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.rtmp-push-controls input {
  flex: 1;
  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;
}

.rtmp-push-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;
}

.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); }
/* A publisher that is genuinely connected but is not feeding its encoder
   (a local publish to a Bounce:false encoder). Amber rather than red: it is
   a normal state to be informed about, not a fault. */
.source-unused { background: rgba(234, 179, 8, 0.15); color: var(--amber); }

.rtmp-stream-unused .key,
.rtmp-stream-unused .meta { opacity: 0.75; }

.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;
}

/* The full RTMP URL in a publisher row. Monospace so host/app/key line up
   between rows at a glance, and clamped so a long remote URL can't push the
   stats off the end -- the full value is in the title attribute. */
.rtmp-stream-header .rtmp-url {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  color: var(--text);
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.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,
.recheck-bounce-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,
.recheck-bounce-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;
}

/* ---- Monitor Wall ---- */

.wall-body {
  min-height: 100vh;
}

.wall-login-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  font-size: 1.1rem;
}

.wall-login-notice a {
  color: var(--accent);
}

.wall-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

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

.wall-header .link-btn {
  margin-left: auto;
}

.wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
}

.wall-tile {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.wall-tile-warning {
  border-color: var(--amber);
}

.wall-tile-error {
  border-color: var(--red);
}

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

.wall-tile-name {
  font-weight: 600;
}

.wall-tile-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.wall-tile-warning .wall-tile-badge {
  color: var(--amber);
}

.wall-tile-error .wall-tile-badge {
  color: var(--red);
}

.wall-tile-reason {
  font-size: 0.8rem;
  font-weight: 600;
  min-height: 1.1em;
}

.wall-tile-warning .wall-tile-reason {
  color: var(--amber);
}

.wall-tile-error .wall-tile-reason {
  color: var(--red);
}

.wall-tile-video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: black;
}

.wall-tile-video-wrap video {
  width: 100%;
  height: 100%;
  display: block;
}

.wall-tile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem;
}

.wall-tile-status {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.wall-ok {
  color: var(--green);
}

.wall-bad {
  color: var(--amber);
}

/* Tabs + Logs -- deliberately the same class names, sizes and behavior as
   LiveEncoder's own tab strip and Logs tab, so switching between a manager
   page and an encoder page doesn't mean relearning the layout. */
.tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tab-btn {
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--text);
  border-color: var(--accent);
}

.logs-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.logs-controls .secondary-btn {
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}

.logs-controls .secondary-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.logs-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  font-size: 0.75rem;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- Archive ---- */

.section-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Archive is destructive-ish (it takes encoders out of service), so it
   reads as red rather than borrowing the accent color every other button in
   the header uses. */
.danger-btn {
  color: var(--red);
}

.danger-btn:hover:not(:disabled) {
  border-color: var(--red);
}

.danger-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Same click-to-sort affordance as the Encoders table. */
#archive-table th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

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

.archive-date {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Reasons are free text and can be long -- clamp the column so one verbose
   entry can't push the Actions column off screen. The full text is in the
   title attribute (and in View JSON). */
.archive-reason {
  display: inline-block;
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.json-view {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 60vh;
  overflow: auto;
  white-space: pre;
  margin: 0;
}

.modal-actions .secondary-btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.modal-actions .secondary-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Inbound RTMP quality ----
   Same styles in LiveManager and LiveEncoder, so the two ends of a bounce
   read the same way side by side. */

.quality-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  vertical-align: middle;
}

.quality-good { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.quality-warn { background: rgba(234, 179, 8, 0.15); color: var(--amber); }
.quality-bad { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.quality-measuring { background: rgba(139, 147, 161, 0.15); color: var(--muted); }

.quality-panel {
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
}

.quality-panel-title {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.quality-issues {
  margin: 0 0 0.6rem;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.quality-issue-bad { color: var(--red); }
.quality-issue-warn { color: var(--amber); }

.quality-ok {
  color: var(--green);
  margin: 0 0 0.6rem;
}

/* Per-second arrival bitrate for the last minute -- bursting (the 0 / 40
   Mbps sawtooth of a stalling feed) is obvious at a glance here in a way no
   single average can show. */
.quality-bars {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 40px;
  margin-bottom: 0.6rem;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.quality-bars span {
  flex: 1;
  min-width: 1px;
  background: var(--accent);
  border-radius: 1px 1px 0 0;
}

.quality-panel .quality-table {
  width: 100%;
  border-collapse: collapse;
  background: none;
  border-radius: 0;
}

.quality-panel .quality-table th,
.quality-panel .quality-table td {
  padding: 0.25rem 1rem 0.25rem 0;
  border-bottom: none;
  font-size: 0.82rem;
  text-align: left;
  vertical-align: top;
}

.quality-panel .quality-table th {
  color: var(--muted);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

.quality-value-warn { color: var(--amber); font-weight: 600; }
.quality-value-bad { color: var(--red); font-weight: 600; }

/* Inside an expanded publisher row: indented to line up with the client
   table below it, and divided from it. */
.rtmp-clients .quality-panel {
  padding-left: 2.25rem;
  border-bottom: 1px solid var(--border);
}

/* ---- Narrow / portrait mobile ----
   Desktop layout is untouched above; everything below only kicks in on
   narrow viewports. */

@media (max-width: 720px) {
  .quality-panel .quality-table th {
    white-space: normal;
  }

  .rtmp-clients .quality-panel {
    padding-left: 1rem;
  }

  header {
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .header-title {
    flex-wrap: wrap;
  }

  .stats-bar {
    min-width: 0;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 0.6rem 1.25rem;
  }

  .header-actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 0.5rem 1rem;
  }

  .header-actions .tabs {
    flex-basis: 100%;
    flex-wrap: wrap;
  }

  .tabs .tab-btn {
    flex: 1;
  }

  main {
    padding: 1rem;
  }

  .section-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #encoder-search,
  #archive-search {
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  /* The encoder table has ~14 columns -- no amount of squeezing fits that on
     a phone, so let it (and the others) scroll sideways inside their own box
     rather than widening the whole page. */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th, td {
    padding: 0.45rem 0.6rem;
    font-size: 0.82rem;
  }

  #encoder-table td,
  #archive-table td {
    white-space: nowrap;
  }

  #encoder-table .remote-source {
    display: inline-block;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .archive-reason {
    max-width: 12rem;
  }

  .rtmp-stream-header {
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
  }

  .rtmp-stream-header .key {
    min-width: 0;
  }

  .rtmp-stream-header .meta {
    flex-basis: 100%;
    gap: 0.3rem 0.75rem;
    min-width: 0;
  }

  .rtmp-stream-header .rtmp-url {
    max-width: 100%;
  }

  .rtmp-clients th, .rtmp-clients td,
  .rtmp-no-clients {
    padding-left: 1rem;
  }

  /* Modals: use the full width and scroll internally, since the encoder
     settings form is taller than a phone screen. */
  .modal {
    align-items: flex-start;
    padding: 0.5rem;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
  }

  .rtmp-push-controls,
  .resize-controls {
    flex-wrap: wrap;
  }

  .rtmp-push-controls input,
  .resize-controls select {
    flex-basis: 100%;
  }

  .rtmp-push-controls button,
  .resize-controls button {
    flex: 1;
  }

  .remote-source-row input[type="text"] {
    min-width: 0;
  }

  #preview-video {
    max-height: 45vh;
  }

  .logs-controls select {
    flex: 1;
    min-width: 0;
  }

  .logs-text {
    max-height: 60vh;
  }

  /* Monitor wall */
  .wall-header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }

  .wall-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
    padding: 1rem;
    gap: 0.75rem;
  }

  /* iOS Safari zooms the page when focusing an input under 16px. */
  input[type="text"], input[type="password"], input[type="search"], select,
  .login-card input, .encoder-form input[type="text"] {
    font-size: 16px;
  }
}

@media (max-width: 380px) {
  .login-card {
    width: calc(100vw - 2rem);
    padding: 1.5rem;
  }

  .tab-btn {
    padding: 0.4rem 0.6rem;
  }
}

/* ---- Entrypoints (LiveEncoder access links) ---- */

/* The edit modal gains a section here, which can push it past the bottom of
   a laptop screen -- scroll inside the card instead of off the page. */
#encoder-modal .modal-card {
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.access-links-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.access-link-row {
  display: grid;
  grid-template-columns: minmax(6rem, auto) auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.access-link-row:last-child {
  border-bottom: none;
}

.access-link-url {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--muted);
  word-break: break-all;
}

.access-link-status.enabled { color: var(--green); }
.access-link-status.revoked { color: var(--red); }

.entrypoint-card {
  width: min(90vw, 520px);
}

.entrypoint-actions {
  gap: 0.5rem;
}

/* .modal-actions .secondary-btn sets its own text color; keep Delete red. */
.entrypoint-actions .danger-btn {
  color: var(--red);
}

.entrypoint-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.entrypoint-report p {
  margin: 0.35rem 0 0;
}

.entrypoint-report ul {
  margin: 0.2rem 0 0.4rem;
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.entrypoint-report .report-updated { color: var(--green); }
.entrypoint-report .report-offline,
.entrypoint-report .report-not-found { color: var(--amber); }
.entrypoint-report .report-error { color: var(--red); }

.srt-cue {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}
