:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border: #30363d;
  --accent: #1DB954;
  --accent-hover: #1ed760;
  --accent-dim: rgba(29, 185, 84, 0.15);
  --danger: #f85149;
  --danger-hover: #da3633;
  --warning: #e3b341;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --live-red: #ff4444;
  --broadcast-orange: #ff6b35;
  --sidebar-width: 220px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

@keyframes blink-pause {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.btn-blink {
  animation: blink-pause 1.2s ease-in-out infinite;
}

@keyframes blink-danger {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.blink-danger {
  animation: blink-danger 1s step-start infinite;
  color: var(--danger);
  font-weight: 700;
}

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 540px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h2 { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.modal-box .form-section { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; flex-wrap: wrap; }
.radio-group { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.radio-group label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.modal-track-list { max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; margin-top: 8px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo span { font-size: 22px; }

.sidebar-status {
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot.idle { background: var(--text-dim); }
.status-dot.music { background: var(--accent); animation: pulse-green 1.5s infinite; }
.status-dot.broadcast { background: var(--broadcast-orange); animation: pulse-orange 1.5s infinite; }
.status-dot.live { background: var(--live-red); animation: pulse-red 1.5s infinite; }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29,185,84,0.6); }
  50% { box-shadow: 0 0 0 5px rgba(29,185,84,0); }
}
@keyframes pulse-orange {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,53,0.6); }
  50% { box-shadow: 0 0 0 5px rgba(255,107,53,0); }
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,68,68,0.6); }
  50% { box-shadow: 0 0 0 5px rgba(255,68,68,0); }
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--bg-tertiary); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); border-left-color: var(--accent); }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

/* ── Main Content ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar h2 { font-size: 16px; font-weight: 600; }

/* Right-hand topbar group: scroll horizontally rather than wrap on small screens. */
#topbarRight {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
#topbarRight > * { flex-shrink: 0; }

/* Hamburger toggle — hidden on desktop, shown on mobile via media query */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  margin-right: 6px;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 90;
}
.sidebar-overlay.open { display: block; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Sections ── */
.section { display: none; }
.section.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ── Now Playing ── */
.now-playing {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.now-playing-thumb {
  width: 80px;
  height: 80px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.now-playing-info { flex: 1; min-width: 0; }

.now-playing-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.now-playing-author { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

.progress-bar-container { margin-bottom: 8px; }

.progress-bar {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 1s linear;
  width: 0%;
}

.progress-time {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ── Mode Badge ── */
.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.mode-badge.idle { background: var(--bg-tertiary); color: var(--text-muted); }
.mode-badge.music { background: var(--accent-dim); color: var(--accent); }
.mode-badge.broadcast { background: rgba(255,107,53,0.15); color: var(--broadcast-orange); }
.mode-badge.live { background: rgba(255,68,68,0.15); color: var(--live-red); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 28px; min-width: 28px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Track title links */
a.track-link { color: inherit; text-decoration: none; }
a.track-link:hover { color: var(--accent); text-decoration: underline; }

/* Video ID badge */
.vid-id { font-family: monospace; font-size: 10px; color: var(--text-muted); background: var(--bg-tertiary); border-radius: 3px; padding: 0 4px; margin-left: 4px; vertical-align: middle; user-select: all; }

/* ── Inputs ── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-select option { background: var(--bg-secondary); }

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-row .form-input { flex: 1; }

/* ── Search Results ── */
.search-results { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.search-result-item:hover { border-color: var(--accent); }

.search-result-thumb {
  width: 48px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-primary);
  flex-shrink: 0;
}

.search-result-info { flex: 1; min-width: 0; }
.search-result-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-meta { font-size: 11px; color: var(--text-muted); }

/* ── Playlist Table ── */
.playlist-table { width: 100%; border-collapse: collapse; }

.playlist-table th {
  text-align: left;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.playlist-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

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

.playlist-table tr:hover td { background: var(--bg-tertiary); }

.drag-handle {
  cursor: grab;
  color: var(--text-dim);
  padding-right: 8px;
  font-size: 16px;
  user-select: none;
}

.drag-handle:active { cursor: grabbing; }

.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.type-badge.youtube { background: rgba(255,0,0,0.15); color: #ff4444; }
.type-badge.upload { background: rgba(29,185,84,0.15); color: var(--accent); }
.type-badge.rtmp { background: rgba(255,107,53,0.15); color: var(--broadcast-orange); }

.timecode-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 2px 6px;
  width: 80px;
  transition: all 0.15s;
}

.timecode-input:focus {
  background: var(--bg-primary);
  border-color: var(--accent);
  color: var(--text);
  outline: none;
}

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-primary);
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.upload-zone .icon { font-size: 40px; margin-bottom: 12px; }
.upload-zone p { color: var(--text-muted); font-size: 14px; margin-bottom: 6px; }
.upload-zone small { color: var(--text-dim); font-size: 12px; }

.upload-progress {
  margin-top: 16px;
  display: none;
}

.upload-progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.upload-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s;
}

.upload-progress-text { font-size: 12px; color: var(--text-muted); }

/* ── RTMP Info ── */
.rtmp-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.rtmp-info-item { }
.rtmp-info-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; }
.rtmp-info-value {
  font-family: 'Courier New', monospace;
  font-size: 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  word-break: break-all;
}

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  padding: 2px;
  transition: color 0.15s;
  flex-shrink: 0;
}

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

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  max-width: 300px;
}

.toast.success { background: #1a3a2a; color: var(--accent); border: 1px solid var(--accent); }
.toast.error { background: #3a1a1a; color: var(--danger); border: 1px solid var(--danger); }
.toast.info { background: var(--bg-secondary); color: var(--text); border: 1px solid var(--border); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Live status ── */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(255,68,68,0.15);
  color: var(--live-red);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live-red);
  animation: pulse-red 1s infinite;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Responsive ── */
@media (max-width: 768px) {
  /* Off-canvas slide-in sidebar with full labels */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-logo h1 span:last-child,
  .sidebar-status span,
  .nav-item span:not(.icon) { display: inline; }

  .sidebar-toggle { display: inline-block; }

  .main { width: 100%; }
  .topbar { padding: 0 12px; height: 52px; }
  .topbar h2 { font-size: 15px; flex-shrink: 0; }

  /* Topbar right: single line, horizontally swipeable (touch scroll). */
  #topbarRight {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    margin-left: 8px;
    padding-bottom: 2px;
    /* Subtle fade hint on the right edge to suggest scrollability */
    mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
  }
  #topbarRight::-webkit-scrollbar { display: none; }
  #topbarRight > * { scroll-snap-align: start; }

  .content { padding: 14px; }
  .card { padding: 14px; margin-bottom: 14px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .rtmp-info-grid { grid-template-columns: 1fr; }

  /* Now-playing: stack thumbnail above info */
  .now-playing { flex-direction: column; align-items: stretch; }
  .now-playing-thumb { width: 100%; height: auto; max-height: 200px; }

  /* Modals take nearly the full screen */
  .modal-overlay { padding: 10px; }
  .modal-box { padding: 16px; max-height: 92vh; }

  /* Tables: allow horizontal scroll instead of overflowing */
  .playlist-table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Buttons easier to tap */
  .btn { min-height: 38px; }

  /* Playlist toolbar reorder: move the "Rechercher sur YouTube" row directly
     under the playlist tabs (source selector), push filters further down. */
  .pl-toolbar-card { display: flex; flex-direction: column; }
  .pl-toolbar-card > #plTabsRow      { order: 1; }
  .pl-toolbar-card > #plYtSearchRow  { order: 2; }
  .pl-toolbar-card > #plUrlRow       { order: 3; }
  .pl-toolbar-card > #plFilterRow    { order: 4; margin-top: 4px; }
  .pl-toolbar-card > #plSearchResults{ order: 5; }

  /* Playlist track row actions: keep the icon, hide the text label */
  .pl-track-actions .btn-label { display: none; }
  .pl-track-actions .btn       { padding-left: 8px; padding-right: 8px; min-width: 38px; }
}

@media (max-width: 480px) {
  .content { padding: 10px; }
  .topbar h2 { font-size: 14px; }
  #clockDisplay { display: none; }
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }

/* Drag & drop track highlight */
.drag-over-track {
  border-top: 2px solid var(--accent) !important;
  background: var(--accent-dim, rgba(88,101,242,.12)) !important;
}

/* Playlist inline tabs scrollable row */
#playlistTabs::-webkit-scrollbar { height: 4px; }
#playlistTabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.row-actions { display: flex; gap: 4px; align-items: center; }

.dragging { opacity: 0.5; background: var(--bg-tertiary) !important; }
.drag-over-row td { border-top: 2px solid var(--accent); }

/* ── Cache status dots ─────────────────────────────────────────────────── */
.cache-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
}
.cache-dot-ok       { background: #27ae60; }
.cache-dot-inflight { background: #f39c12; animation: pulse 1.2s ease-in-out infinite; }
.cache-dot-pending  { background: #e74c3c; }
.cache-dot-none     { display: none; }

.queue-cache-dot {
  margin-left: 4px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
