:root {
  --bg: #061016;
  --surface: #0d1d26;
  --surface-hover: #142b38;
  --header-bg: #0d1424;
  --btn-secondary-bg: #26334d;
  --btn-secondary-hover: #334363;
  --code-bg: #1e293b;
  --code-text: #fdba74;
  --track-bg: #090d16;
  --dropzone-bg: rgba(9, 13, 22, 0.45);
  --border: #1e3b4d;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --purple: #38bdf8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 60px;
}
header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { height: 34px; width: auto; display: block; }
nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
nav button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition: 0.15s;
}
nav button:hover { color: var(--text); background: var(--surface); }
nav button.active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
.watch-live-hero-btn {
  background: rgba(34, 197, 94, 0.14) !important;
  border: 1px solid rgba(34, 197, 94, 0.45) !important;
  color: #4ade80 !important;
  font-weight: 700 !important;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px !important;
}
.watch-live-hero-btn:hover {
  background: rgba(34, 197, 94, 0.24) !important;
  color: #86efac !important;
}
.container { max-width: 1380px; margin: 28px auto; padding: 0 22px; }
.panel { display: none; }
.panel.active { display: block; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 24px;
}
h2 { font-size: 1.2rem; margin-bottom: 6px; }
p.sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 20px; }

/* ==========================================================
   IMPROVED FOLDERS & CATEGORIES GRID (FULL UNTRUNCATED NAMES)
   ========================================================== */
.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.folder-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 13px 15px;
  cursor: pointer;
  transition: 0.15s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  position: relative;
}
.folder-card:hover { border-color: var(--primary); background: var(--surface-hover); }
.folder-card.active {
  border-color: var(--primary);
  background: rgba(16, 185, 129, 0.09);
  box-shadow: 0 0 0 1px var(--primary);
}
.folder-card.drag-target {
  border: 2px dashed var(--primary);
  background: rgba(16, 185, 129, 0.16);
  transform: scale(1.02);
}
.folder-top {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
}
.folder-icon-wrap {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
}
.folder-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.folder-name {
  font-weight: 600;
  font-size: 0.94rem;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
  flex: 1;
}
.folder-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.folder-tools {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.icon-btn {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 0.74rem;
  cursor: pointer;
  line-height: 1.4;
}
.icon-btn:hover { color: var(--text); border-color: var(--border); background: var(--surface); }
.icon-btn.del:hover { color: var(--danger); border-color: rgba(239,68,68,0.4); }

/* Color Swatches */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: 0.15s;
}
.swatch.selected { border-color: var(--text); transform: scale(1.15); }

/* Forms & Buttons */
.form-group { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.92rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 15px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--btn-secondary-hover); }
.btn-warning { background: rgba(234, 179, 8, 0.18); color: #fde047; border: 1px solid rgba(234, 179, 8, 0.35); }
.btn-warning:hover:not(:disabled) { background: rgba(234, 179, 8, 0.28); }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.25); }
.btn-live { background: rgba(34, 197, 94, 0.16); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.35); }
.btn-live:hover:not(:disabled) { background: rgba(34, 197, 94, 0.28); }
.btn-purple { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; border: 1px solid rgba(168, 85, 247, 0.38); }
.btn-purple:hover:not(:disabled) { background: rgba(168, 85, 247, 0.3); }
.btn-sm { padding: 5px 10px; font-size: 0.79rem; }

.status-banner {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: var(--success);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 20px;
  display: none;
  justify-content: space-between;
  align-items: center;
}
.step-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.step-num {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.step-content h3 { font-size: 0.98rem; margin-bottom: 4px; }
.step-content p { font-size: 0.88rem; color: var(--muted); margin-bottom: 10px; }

/* Dropzone & Stacked Queue */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: 0.2s;
  background: var(--dropzone-bg);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: rgba(16, 185, 129, 0.06); }

.queue-container {
  display: none;
  margin-top: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.queue-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
}
.queue-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  flex-shrink: 0;
}
.queue-item.active { border-color: var(--primary); }
.queue-item.completed { border-color: rgba(34, 197, 94, 0.35); }
.queue-item.error { border-color: rgba(239, 68, 68, 0.45); }
.queue-item.canceled { opacity: 0.55; }
.queue-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.88rem;
}
.queue-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.queue-filename {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.q-pending { background: rgba(148, 163, 184, 0.16); color: var(--muted); }
.q-paused { background: rgba(234, 179, 8, 0.18); color: #fde047; }
.q-optimizing { background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }
.q-uploading { background: rgba(249, 115, 22, 0.2); color: #fdba74; }
.q-completed { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.q-canceled { background: rgba(148, 163, 184, 0.14); color: var(--muted); }
.q-error { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.queue-item-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 5px;
}
.progress-bar { width: 100%; height: 7px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.2s; }
.queue-item.completed .progress-fill { background: var(--success); }
.queue-item.optimizing .progress-fill { background: var(--purple); }

/* Bulk Multi-Select Toolbar */
.bulk-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.45);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.bulk-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bulk-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  width: auto;
  min-width: 170px;
}

/* ==========================================================
   BALANCED VIDEO LIBRARY TABLE & UNCROWDED ACTION ROWS
   ========================================================== */
table.library-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 10px; border-bottom: 1px solid var(--border); font-size: 0.88rem; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; user-select: none; }
th.sortable, span.sortable { cursor: pointer; transition: color 0.15s; }
th.sortable:hover, span.sortable:hover { color: var(--text); }
th.sort-active, span.sort-active { color: var(--primary); }

.col-check   { width: 34px; }
.col-video   { width: 31%; }
.col-folder  { width: 16%; }
.col-size    { width: 9%; }
.col-stats   { width: 16%; }
.col-status  { width: 8%; }
.col-actions { width: 20%; min-width: 270px; }

.video-title-text {
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--surface-hover); }
tbody tr.row-selected { background: rgba(16, 185, 129, 0.08); }
tbody tr.dragging { opacity: 0.45; }
tbody tr.drag-over-row { border-top: 2px solid var(--primary); }
.drag-handle { cursor: grab; color: var(--muted); padding-right: 8px; font-size: 1rem; user-select: none; flex-shrink: 0; }
.row-check { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.badge { padding: 3px 8px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; display: inline-block; }
.badge-active { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.badge-disabled { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #4ade80;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: pulseDot 1.3s infinite;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.actions-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.folder-select-inline {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.83rem;
  width: 100%;
  min-width: 145px;
  cursor: pointer;
}
.folder-select-inline:focus { border-color: var(--primary); }

@media (max-width: 1080px) {
  table.library-table { table-layout: auto; }
}

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.68);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 680px; padding: 24px;
  max-height: 92vh; overflow-y: auto;
  transition: all 0.18s ease;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }

/* Full-Screen Mode for Live Watch Room */
.modal-backdrop.fullscreen-backdrop { padding: 0; }
.modal.is-fullscreen {
  max-width: 100vw !important;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  border: none;
  padding: 20px 28px;
}
.modal.is-fullscreen .session-feed {
  max-height: calc(100vh - 285px);
}

/* Re-Encode Warning Modal */
.encode-file-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 12px 0;
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.encode-file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.encode-file-row:last-child { border-bottom: none; padding-bottom: 0; }

/* Player Customizer Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (max-width: 640px) { .theme-grid { grid-template-columns: repeat(2, 1fr); } }
.theme-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px;
  cursor: pointer;
  transition: 0.15s;
}
.theme-card:hover { border-color: var(--primary); }
.theme-card.active {
  border-color: var(--primary);
  background: rgba(16, 185, 129, 0.1);
  box-shadow: 0 0 0 1px var(--primary);
}
.theme-card-title { font-weight: 700; font-size: 0.86rem; margin-bottom: 3px; color: var(--text); }
.theme-card-desc { font-size: 0.74rem; color: var(--muted); line-height: 1.35; }
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin-bottom: 16px;
}
.ctrl-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.84rem;
  cursor: pointer;
  color: var(--text);
}
.ctrl-toggle input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.default-actions-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 16px;
}
.promo-preset-banner {
  background: linear-gradient(90deg, rgba(168,85,247,0.14), rgba(16,185,129,0.12));
  border: 1px solid rgba(168,85,247,0.4);
  border-radius: 8px;
  padding: 11px 14px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Live Stats & Isolated Viewer Banner */
.viewer-filter-bar {
  display: none;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: rgba(168, 85, 247, 0.14);
  border: 1px solid rgba(168, 85, 247, 0.45);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.seg-tabs {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.seg-tabs button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.seg-tabs button.active { background: var(--primary); color: #fff; }
.seg-tabs.purple button.active { background: var(--purple); color: #fff; }
.seg-tabs.green button.active { background: var(--success); color: #052e16; }
.clickable-user { cursor: pointer; transition: 0.15s; }
.clickable-user:hover { color: var(--primary) !important; text-decoration: underline; }
.geo-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 0.76rem;
  color: var(--text);
}
.video-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(249, 115, 22, 0.14);
  border: 1px solid rgba(249, 115, 22, 0.35);
  color: #fdba74;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.video-chip:hover { background: rgba(249, 115, 22, 0.25); }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; text-align: center; }
.stat-box .val { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.stat-box .lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; margin-top: 3px; }

/* ==========================================================
   LIVE SESSION PROGRESS FEED & 1-LINE COMPACT VIEW
   ========================================================== */
.session-feed {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  max-height: 440px;
  overflow-y: auto;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.session-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.session-item.is-live {
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(34, 197, 94, 0.05);
}
.session-item.compact-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 9px;
  padding: 6px 10px;
  min-height: 52px;
  flex-shrink: 0;
  overflow: hidden;
}
.compact-thumb-box {
  position: relative;
  width: 70px;
  height: 39px;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
}
.compact-thumb-box video,
.compact-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.compact-thumb-time {
  position: absolute;
  bottom: 2px;
  right: 3px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.compact-meta-col {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}
.compact-video-name {
  display: inline-block;
  max-width: 135px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(249, 115, 22, 0.14);
  border: 1px solid rgba(249, 115, 22, 0.35);
  color: #fdba74;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}
.compact-video-name:hover {
  background: rgba(249, 115, 22, 0.25);
}
.compact-geo-text {
  display: inline-block;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.74rem;
  color: var(--text);
}
.compact-ip-chip {
  display: none;
  max-width: 145px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.modal.is-fullscreen .compact-ip-chip {
  display: inline-block;
}
.compact-track-col {
  flex: 1 1 80px;
  min-width: 70px;
}
.compact-stats-col {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.compact-last-active {
  color: var(--muted);
  font-size: 0.72rem;
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
}
.session-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
  flex-wrap: wrap;
}
.session-meta { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.session-status-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tag-live { background: rgba(34, 197, 94, 0.18); color: #4ade80; }
.tag-done { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
.tag-ended { background: rgba(148, 163, 184, 0.15); color: var(--muted); }
.tag-repeat { background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }
.session-track-wrap { position: relative; width: 100%; height: 11px; }
.session-track {
  position: relative;
  width: 100%;
  height: 11px;
  background: var(--track-bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.session-curr-fill {
  position: absolute;
  top: 0; bottom: 0;
  background: var(--primary);
  border-radius: 2px;
  transition: left 0.35s ease, width 0.35s ease;
}
.session-item.is-live .session-curr-fill { background: #16a34a; }

/* Bright, High-Contrast Current Location Marker */
.session-playhead {
  position: absolute;
  top: -4px;
  width: 5px;
  height: 19px;
  background: #fde047;
  border: 1px solid #ffffff;
  border-radius: 3px;
  box-shadow: 0 0 8px #fde047, 0 0 14px #22c55e;
  transform: translateX(-50%);
  transition: left 0.35s ease;
  z-index: 4;
}
.session-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  gap: 8px;
  flex-wrap: wrap;
}
.session-bottom-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.watch-live-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #4ade80;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 99px;
  cursor: pointer;
  flex-shrink: 0;
  transition: 0.15s;
}
.watch-live-pill-btn:hover { background: rgba(34, 197, 94, 0.25); color: #bbf7d0; }
.watch-live-pill-btn.is-open {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}
.live-monitor-drawer {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.live-monitor-screen {
  position: relative;
  width: 200px;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.live-monitor-screen video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.live-monitor-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  background: rgba(0, 0, 0, 0.78);
  color: #4ade80;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.funnel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 0.85rem; }
.funnel-label { width: 95px; color: var(--muted); }
.funnel-track { flex: 1; height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.funnel-bar { height: 100%; background: var(--success); border-radius: 99px; transition: width 0.3s; }
.funnel-pct { width: 65px; text-align: right; font-weight: 600; }

.two-col-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 720px) { .two-col-stats { grid-template-columns: 1fr; } }

/* Interactive Chart Explorer */
.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 270px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}
#analyticsCanvas { width: 100%; height: 100%; display: block; }
.chart-tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 0.78rem;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 10;
  white-space: nowrap;
}
.legend-row {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }

code { background: var(--code-bg); padding: 2px 6px; border-radius: 4px; font-size: 0.83rem; color: var(--code-text); }
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--surface);
  border: 1px solid var(--primary); color: var(--text); padding: 12px 18px;
  border-radius: 8px; font-size: 0.9rem; display: none; z-index: 100;
  box-shadow: 0 10px 25px rgba(0,0,0,0.28);
}
.auth-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.auth-link:hover { color: var(--text); }

/* =====================================================================
   LIGHT THEME CONTRAST & BADGE OVERRIDES
   ===================================================================== */
[data-theme-mode="light"] .card,
[data-theme-mode="light"] .modal,
[data-theme-mode="light"] header {
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}
[data-theme-mode="light"] .watch-live-hero-btn {
  background: rgba(5, 150, 105, 0.12) !important;
  border-color: rgba(5, 150, 105, 0.45) !important;
  color: #047857 !important;
}
[data-theme-mode="light"] .watch-live-hero-btn:hover {
  background: rgba(5, 150, 105, 0.2) !important;
  color: #065f46 !important;
}
[data-theme-mode="light"] .btn-live,
[data-theme-mode="light"] .badge-active,
[data-theme-mode="light"] .live-pill,
[data-theme-mode="light"] .tag-live,
[data-theme-mode="light"] .q-completed,
[data-theme-mode="light"] .watch-live-pill-btn {
  background: rgba(5, 150, 105, 0.14);
  border-color: rgba(5, 150, 105, 0.35);
  color: #047857;
}
[data-theme-mode="light"] .btn-warning,
[data-theme-mode="light"] .q-paused {
  background: rgba(217, 119, 6, 0.14);
  border-color: rgba(217, 119, 6, 0.35);
  color: #b45309;
}
[data-theme-mode="light"] .btn-danger,
[data-theme-mode="light"] .badge-disabled,
[data-theme-mode="light"] .q-error,
[data-theme-mode="light"] .watch-live-pill-btn.is-open {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.32);
  color: #b91c1c;
}
[data-theme-mode="light"] .btn-purple,
[data-theme-mode="light"] .q-optimizing,
[data-theme-mode="light"] .tag-repeat {
  background: rgba(124, 58, 237, 0.12);
  border-color: rgba(124, 58, 237, 0.32);
  color: #6d28d9;
}
[data-theme-mode="light"] .tag-done {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}
[data-theme-mode="light"] .video-chip,
[data-theme-mode="light"] .compact-video-name,
[data-theme-mode="light"] .q-uploading {
  background: rgba(234, 88, 12, 0.12);
  border-color: rgba(234, 88, 12, 0.32);
  color: #c2410c;
}
[data-theme-mode="light"] .status-banner {
  background: rgba(5, 150, 105, 0.12);
  border-color: rgba(5, 150, 105, 0.35);
  color: #065f46;
}
[data-theme-mode="light"] .session-playhead {
  background: #f59e0b;
  border-color: #0f172a;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.8);
}

/* =====================================================================
   MOBILE RESPONSIVE OVERRIDES (PHONES & SMALL TABLETS <= 768px)
   ===================================================================== */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  header .brand {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  header nav button,
  header nav a,
  header nav select {
    font-size: 0.78rem !important;
    padding: 7px 10px !important;
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }
  #headerUserBadge {
    width: 100%;
    text-align: center;
    padding: 4px 0 !important;
    order: 10;
  }
  .container {
    padding: 12px 10px !important;
  }
  .card {
    padding: 16px 14px !important;
    border-radius: 10px;
  }
  #tab-library .card > div[style*="grid-template-columns"],
  #coverModal .modal > div[style*="grid-template-columns"],
  #playerModal .modal > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  #watchLiveModal {
    padding: 0 !important;
    align-items: flex-end;
  }
  #watchLiveModalBox {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    padding: 14px 12px 28px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  #watchLiveModalBox .modal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
  }
  #watchLiveModalBox .modal-header > div:last-child {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  #toggleLoadsViewBtn {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: center;
    padding: 9px 12px !important;
    font-size: 0.84rem !important;
  }
  #watchDensityTabs {
    grid-column: 1 / -1;
    display: flex;
    width: 100%;
  }
  #watchDensityTabs button {
    flex: 1;
    justify-content: center;
  }
  #watchFullscreenBtn {
    display: none !important;
  }
  #viewerFilterBar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }
  #viewerFilterBar > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  #watchLiveModalBox .stat-grid,
  #chartModal .stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  #watchLiveModalBox .stat-grid .stat-box:last-child {
    grid-column: 1 / -1;
  }
  .stat-box {
    padding: 10px 8px !important;
  }
  .stat-box .val {
    font-size: 1.25rem !important;
  }
  .stat-box .lbl {
    font-size: 0.72rem !important;
  }
  #sessionFeed {
    max-height: 52vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }
  #sessionFeed > div,
  .session-row,
  .session-card {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 10px !important;
    font-size: 0.82rem !important;
  }
  #sessionFeed .progress-wrap,
  #sessionFeed [style*="flex: 1"],
  #sessionFeed [style*="flex:1"] {
    min-width: 100% !important;
    order: 3;
  }
  .two-col-stats {
    grid-template-columns: 1fr !important;
    gap: 18px !important;
  }
  #locationsPanel,
  #watchReferrersWrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #chartModal {
    padding: 0 !important;
  }
  #chartModal .modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    padding: 14px 12px 24px !important;
    overflow-y: auto !important;
  }
  .chart-toolbar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }
  .chart-toolbar select {
    width: 100% !important;
  }
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px !important;
  }
  header nav select {
    font-size: 0.8rem !important;
  }
}

.sticky-save-bar {
  position: sticky;
  bottom: -24px;
  z-index: 25;
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin: 18px -24px -24px;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.45);
}

.sticky-save-bar.is-dirty {
  border-top-color: rgba(251, 191, 36, 0.55);
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.08) 0%, var(--surface) 100%);
}

.dirty-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fde047;
  background: rgba(234, 179, 8, 0.16);
  border: 1px solid rgba(234, 179, 8, 0.42);
  padding: 4px 10px;
  border-radius: 99px;
}

/* =====================================================================
   SECTION SURFACE CONTRAST (UPLOAD, FOLDERS & VIDEOS)
   - Dark themes: notably lighter than --surface for clear separation
   - Light themes: Medium Slate header + shaded gray cards + crisp text
   ===================================================================== */

/* Dark themes (default): lift the 3 main cards noticeably above --bg / --surface */
.card:has(#dropzone),
.card:has(#youtubeUrlInput),
.card:has(#folderGrid),
.card:has(#videoTableBody) {
  background: color-mix(in srgb, var(--surface) 90%, #ffffff 10%);
  border-color: color-mix(in srgb, var(--border) 80%, #ffffff 20%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

/* Keep inner tiles & rows crisp against the lifted card background */
.card:has(#folderGrid) .folder-card {
  background: color-mix(in srgb, var(--bg) 72%, var(--surface) 28%);
}
.card:has(#folderGrid) .folder-card:hover {
  background: color-mix(in srgb, var(--surface-hover) 82%, #ffffff 18%);
}
.card:has(#folderGrid) .folder-card.active {
  background: color-mix(in srgb, var(--primary) 18%, var(--surface) 82%);
}

#videoTableBody tr:hover {
  background: color-mix(in srgb, var(--surface-hover) 82%, #ffffff 18%);
}

/* Light themes: Medium Slate top header, shaded gray cards, and high-contrast dark text */
[data-theme-mode="light"] {
  --bg: color-mix(in srgb, #e2e8f0 85%, var(--primary) 15%);
  --surface: #e8edf3;
  --header-bg: #bcc8d8;
  --text: #0f172a;
  --muted: #334155;
}

[data-theme-mode="light"] header {
  background: #bcc8d8 !important;
  border-bottom: 1px solid #94a3b8 !important;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.10);
  color: #0f172a !important;
}

[data-theme-mode="light"] header nav button {
  color: #1e293b !important;
  font-weight: 600;
}

[data-theme-mode="light"] header nav button:hover,
[data-theme-mode="light"] header nav button.active {
  background: #a6b5c8 !important;
  color: #090e1a !important;
  border-color: #8496ad !important;
}

[data-theme-mode="light"] #headerUserBadge,
[data-theme-mode="light"] header span,
[data-theme-mode="light"] header select {
  color: #0f172a !important;
}

[data-theme-mode="light"] header select {
  background: #d5dee9 !important;
  border-color: #8496ad !important;
}

[data-theme-mode="light"] .card:has(#dropzone),
[data-theme-mode="light"] .card:has(#youtubeUrlInput),
[data-theme-mode="light"] .card:has(#folderGrid),
[data-theme-mode="light"] .card:has(#videoTableBody) {
  background: color-mix(in srgb, var(--surface) 82%, #0f172a 18%);
  border-color: color-mix(in srgb, var(--border) 72%, #0f172a 28%);
  color: #0f172a;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.09);
}

[data-theme-mode="light"] .card h2,
[data-theme-mode="light"] .card h3,
[data-theme-mode="light"] .video-title-text,
[data-theme-mode="light"] .folder-name {
  color: #090e1a !important;
}

[data-theme-mode="light"] .card p.sub,
[data-theme-mode="light"] .card label,
[data-theme-mode="light"] .folder-bottom,
[data-theme-mode="light"] th {
  color: #334155 !important;
}

[data-theme-mode="light"] .card:has(#folderGrid) .folder-card {
  background: color-mix(in srgb, var(--surface) 92%, #0f172a 8%);
  border-color: color-mix(in srgb, var(--border) 78%, #0f172a 22%);
}
[data-theme-mode="light"] .card:has(#folderGrid) .folder-card:hover {
  background: color-mix(in srgb, var(--surface) 86%, #0f172a 14%);
}
[data-theme-mode="light"] .card:has(#folderGrid) .folder-card.active {
  background: color-mix(in srgb, var(--primary) 18%, var(--surface) 82%);
}

[data-theme-mode="light"] .dropzone,
[data-theme-mode="light"] input,
[data-theme-mode="light"] select,
[data-theme-mode="light"] textarea,
[data-theme-mode="light"] .folder-select-inline {
  background: color-mix(in srgb, var(--surface) 94%, #0f172a 6%);
  color: #0f172a;
}

[data-theme-mode="light"] #videoTableBody tr:hover {
  background: color-mix(in srgb, var(--surface) 86%, #0f172a 14%);
}

/* =====================================================================
   VIDEO LIST ROW DIVIDERS, ALTERNATING STRIPING & HOVER (DARK & LIGHT)
   ===================================================================== */
#videoTableBody tr td {
  border-bottom: 1px solid color-mix(in srgb, var(--border) 62%, #ffffff 38%) !important;
  padding-top: 15px;
  padding-bottom: 15px;
}

#videoTableBody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.025);
}

#videoTableBody tr:hover,
#videoTableBody tr:nth-child(even):hover {
  background: color-mix(in srgb, var(--surface-hover) 82%, #ffffff 18%);
}

#videoTableBody tr:last-child td {
  border-bottom: none !important;
}

/* Light themes: crisp slate divider line, subtle striping & hover */
[data-theme-mode="light"] #videoTableBody tr td {
  border-bottom: 1px solid color-mix(in srgb, var(--border) 58%, #0f172a 42%) !important;
}

[data-theme-mode="light"] #videoTableBody tr:nth-child(even) {
  background: rgba(15, 23, 42, 0.035);
}

[data-theme-mode="light"] #videoTableBody tr:hover,
[data-theme-mode="light"] #videoTableBody tr:nth-child(even):hover {
  background: color-mix(in srgb, var(--surface) 86%, #0f172a 14%);
}

@media (max-width: 860px) { #vccSplitGrid { grid-template-columns: 1fr !important; } }

/* Restore Horizontal Scrolling for Watch Live Session Rows on Mobile */
@media (max-width: 768px) {
  #watchLiveModalBox #sessionFeed,
  #vccSessionFeed,
  .session-feed {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #watchLiveModalBox #sessionFeed > div,
  #vccSessionFeed > div,
  .session-feed > div {
    min-width: max-content;
  }
}

/* Wider Global Live Watch Room + Horizontal Scroll Safety for 1-Line Rows */
#watchLiveModalBox.is-fullscreen {
  max-width: 98vw !important;
  width: 98vw !important;
}

#sessionFeed {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#sessionFeed .session-item.compact-row {
  min-width: 940px;
}
