/* FrameServer — Mom-Friendly Dark Theme */

:root {
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Droid Sans Mono', monospace;
  --bg-base: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --bg-hover: #262c36;
  --border: #30363d;
  --border-light: #21262d;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-muted: rgba(88, 166, 255, 0.12);

  --success: #3fb950;
  --success-muted: rgba(63, 185, 80, 0.15);
  --danger: #f85149;
  --danger-muted: rgba(248, 81, 73, 0.15);
  --warning: #d29922;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);

  --nav-height: 56px;
  --transition: 150ms ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

/* ── App Layout ──────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main {
  flex: 1;
  padding-top: env(safe-area-inset-top);
  padding-bottom: var(--nav-height);
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* ── Bottom Navigation ───────────────────────────────────────────────────── */

.top-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.nav-tab svg { width: 22px; height: 22px; transition: color var(--transition); }
.nav-tab:hover { color: var(--text-secondary); }
.nav-tab.active { color: var(--accent); }

/* ── Page Structure ──────────────────────────────────────────────────────── */

.page { animation: fadeIn 150ms ease; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg-base);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger-muted);
  color: var(--danger);
  border: 1px solid transparent;
}
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  min-height: 40px;
  width: 40px;
  padding: 0;
  border-radius: var(--radius-md);
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #000;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.upload-btn:hover { background: var(--accent-hover); }

/* ── Upload Progress Banner ──────────────────────────────────────────────── */

.upload-banner {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}
.upload-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
}
.upload-filename { color: var(--text-primary); font-weight: 500; }
.upload-percent { color: var(--accent); font-weight: 600; }
.upload-bar {
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}
.upload-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear;
}

/* ── Media Grid (Videos + Images) ────────────────────────────────────────── */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px;
}

.media-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  cursor: pointer;
}

.media-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }

.media-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-elevated);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb svg { opacity: 0.3; }

/* Type + duration pills — shown below the thumbnail in .media-body */
.media-pills {
  display: flex;
  gap: 5px;
  align-items: center;
}

.media-pill {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 99px;
  line-height: 1.6;
  white-space: nowrap;
}

.media-pill.type-video {
  background: var(--accent-muted);
  color: var(--accent);
}

.media-pill.type-image {
  background: var(--success-muted);
  color: var(--success);
}

.media-pill.duration {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  text-transform: none;
  font-weight: 600;
  font-size: 11px;
}

/* Section header within a page (Geräte tab sections) */
.page-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.page-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.page-section-actions { display: flex; gap: 8px; }
.section-divider { height: 1px; background: var(--border); margin: 8px 16px 0; }

.media-body {
  padding: 10px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.media-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.media-name-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
  min-height: calc(1.4em * 2);
}

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

.media-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.media-actions .btn-ghost { min-height: 36px; width: 36px; padding: 0; border-radius: var(--radius-sm); }

/* ── Kiosk Status Card ───────────────────────────────────────────────────── */

.kiosk-card {
  margin: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.kiosk-status {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.kiosk-indicator {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.kiosk-indicator.playing {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-muted);
  animation: pulse 2s infinite;
}

.kiosk-info { flex: 1; }
.kiosk-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.kiosk-title { font-size: 18px; font-weight: 600; color: var(--text-primary); margin-top: 2px; }
.kiosk-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ── Play Grid (combined videos+playlists on kiosk page) ─────────────────── */

.play-grid-section { padding: 0 16px 16px; }

.play-grid-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  padding-top: 8px;
}

.play-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.play-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.play-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.play-card.active { border-color: var(--success); background: rgba(63,185,80,0.05); }

.play-card-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.play-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.play-card-thumb svg { opacity: 0.35; }

.play-card-body { padding: 8px 10px; }
.play-card-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.35;
}
.play-card-type { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── Video List (kiosk page fallback) ────────────────────────────────────── */

.video-list { display: flex; flex-direction: column; gap: 2px; }

.video-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.video-list-item:hover { background: var(--bg-hover); }
.video-list-item.active { background: var(--accent-muted); }

.video-list-thumb {
  width: 48px; height: 32px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.video-list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-list-info { flex: 1; min-width: 0; }
.video-list-name { font-size: 14px; font-weight: 500; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.video-list-size { font-size: 12px; color: var(--text-muted); }
.video-list-play { color: var(--text-muted); }

/* ── Playlist List View ──────────────────────────────────────────────────── */

.playlist-list { display: flex; flex-direction: column; gap: 10px; padding: 16px; }

.playlist-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  min-height: 68px;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.playlist-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.playlist-card-name { font-size: 17px; font-weight: 600; color: var(--text-primary); }
.playlist-card-count { font-size: 14px; color: var(--text-muted); }

/* ── Playlist Editor ─────────────────────────────────────────────────────── */

.playlist-editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-base);
  z-index: 10;
}

.playlist-name-input {
  flex: 1;
  font-size: 19px;
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-primary);
  padding: 4px 0;
  transition: border-color var(--transition);
}
.playlist-name-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.playlist-editor-actions { display: flex; gap: 8px; flex-shrink: 0; }

.playlist-item-list {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  gap: 8px;
}

.playlist-section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 0 8px;
}

.playlist-video-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  transition: border-color var(--transition);
}

.playlist-video-item[draggable="true"] { cursor: grab; }
.playlist-video-item[draggable="true"]:active { cursor: grabbing; }
.playlist-video-item.dragging { opacity: 0.35; }
.playlist-video-item.drag-over { border-top: 2px solid var(--accent); }

.drag-handle {
  color: var(--text-muted);
  font-size: 16px;
  cursor: grab;
  padding: 0 2px;
  flex-shrink: 0;
}

.video-name {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.4;
}

.remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  line-height: 1;
  flex-shrink: 0;
}
.remove-btn:hover { color: var(--danger); background: var(--danger-muted); }

/* Duration stepper for images in playlist */
.duration-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.duration-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1;
  flex-shrink: 0;
}
.duration-btn:hover { border-color: var(--accent); color: var(--accent); }

.duration-value {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
  white-space: nowrap;
}

.playlist-add-btn {
  margin: 4px 16px 20px;
  width: calc(100% - 32px);
}

/* ── Empty States ────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state svg { opacity: 0.3; }
.empty-state h3 { font-size: 18px; color: var(--text-secondary); }
.empty-state p { font-size: 14px; max-width: 280px; }

.empty-state.small { padding: 32px 16px; }
.empty-state.small p { font-size: 13px; }

/* ── Device Groups ───────────────────────────────────────────────────────── */

.device-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 16px;
}

.device-group-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.device-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-group-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.device-group-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
}

.device-group-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.device-grid-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-grid-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 16px 4px;
  font-style: italic;
}

/* ── Device Cards ────────────────────────────────────────────────────────── */

.device-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  transition: background 150ms ease, border-color 150ms ease,
              box-shadow 150ms ease, transform 150ms ease;
  cursor: pointer;
}
.device-card:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transform: translateY(-1px);
}
.device-card.offline { opacity: 0.65; }

/* Header row: dot · name · IP */
.dc-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 2px;
}
.dc-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}
.device-card.online  .dc-status-dot,
.device-card.playing .dc-status-dot { background: var(--success); }
.device-card.playing .dc-status-dot { animation: dc-pulse 1.4s ease-in-out infinite; }
@keyframes dc-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.75); }
}
.dc-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.dc-ip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
  cursor: pointer; user-select: none;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.dc-ip:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-muted); }
.dc-ip svg   { width: 11px; height: 11px; flex-shrink: 0; }

/* Status badge: dot + label */
.dc-status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
  flex-shrink: 0;
}
.device-card.online  .dc-status-badge,
.device-card.playing .dc-status-badge { color: var(--success); border-color: rgba(63,185,80,0.35); background: var(--success-muted); }

/* Position indicator (#1, #2 …) */
.dc-position {
  font-size: 17px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Shared 3-column grid for all detail rows ─────────────────────────────
   col 1: label  (68px — wide enough for SPEICHER + breathing room)
   col 2: bar / text content  (flex)
   col 3: value  (90px — fixed so both bars end at identical x)          */
.dc-video-row,
.dc-progress,
.dc-stat-row,
.dc-playlist,
.dc-assigned {
  display: grid;
  grid-template-columns: 80px 1fr 90px;
  column-gap: 10px;
  align-items: center;
}

/* Text-only rows: filename and playlist name span cols 2–3 */
.dc-video-name,
.dc-playlist-name { grid-column: 2 / -1; }

/* Idle row has no label — use block so text fills naturally */
.dc-assigned.idle { display: block; }

/* Vertical spacing */
.dc-video-row  { align-items: baseline; margin-top: 8px; }
.dc-progress   { margin-top: 5px; }
.dc-stat-row   { margin-top: 7px; }
.dc-playlist   { align-items: baseline; margin-top: 7px; }
.dc-assigned   { align-items: baseline; margin-top: 7px; }

/* Label */
.dc-stat-lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
}

/* Video filename */
.dc-video-name {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Progress bar */
.dc-progress-track {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  grid-column: 2 / -1; /* bar spans cols 2+3 — timecode is the label in col 1 */
}
.dc-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
}

/* Timecode — inherits dc-stat-lbl; only adds tabular nums for steady digit width */
.dc-timecode { font-variant-numeric: tabular-nums; }

/* Playlist / assigned name */
.dc-playlist-name {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Idle state */
.dc-assigned.idle { font-style: italic; font-size: 11px; color: var(--text-muted); }

/* Storage bar */
.dc-stat-track {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  grid-column: 2 / -1; /* no value label — bar spans full remaining width */
}
.dc-stat-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
}
.dc-stat-fill.warn { background: var(--danger); }
.dc-stat-val {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

/* ── Status Badges ───────────────────────────────────────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online  { background: var(--success); }
.status-dot.playing { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.status-dot.offline { background: var(--text-muted); }

/* ── Device Detail View ──────────────────────────────────────────────────── */

.device-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-base);
  z-index: 10;
}

.device-detail-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.device-detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.device-now-playing { margin-bottom: 8px; }

.device-section { padding: 16px; }
.device-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.available-video-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.available-video-item:last-child { border-bottom: none; }

/* ── Modals ──────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.modal h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.modal p {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}
.modal-icon.danger { background: var(--danger-muted); color: var(--danger); }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.modal-wide { max-width: 600px; }
.modal-form { text-align: left; }
.modal-form h3 { text-align: left; }

/* ── Form Elements ───────────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.form-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text-primary);
  transition: var(--transition);
  min-height: 48px;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

select.form-input { cursor: pointer; }

#deviceCredentialsJson {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 12px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', 'Liberation Mono', monospace;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
  margin: 0;
  color: var(--text-secondary);
  cursor: text;
  user-select: all;
}

/* ── Media Picker Modal ──────────────────────────────────────────────────── */

.media-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px 2px;
  margin-top: 12px;
}

.picker-item {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.picker-item:hover { border-color: var(--accent); }
.picker-item.selected { border-color: var(--accent); background: var(--accent-muted); }

.picker-item-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.picker-item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.picker-item-thumb svg { opacity: 0.3; }
.picker-item-name { padding: 6px 8px; font-size: 12px; color: var(--text-secondary); word-break: break-word; line-height: 1.3; }

.picker-duration-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 6px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.picker-duration-row label { font-size: 14px; color: var(--text-secondary); }

.picker-duration-row input {
  width: 72px;
  padding: 10px 12px;
  font-size: 15px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-align: center;
  min-height: 44px;
}

.picker-duration-row input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Credentials & Add Device Modal ─────────────────────────────────────── */

.modal-wide.modal-form { max-width: 560px; }

/* ── Toast Notifications ─────────────────────────────────────────────────── */

#toastContainer {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  max-width: 300px;
}
.toast.toast-visible { opacity: 1; transform: translateY(0); }
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--danger); }
.toast.toast-info    { border-left: 3px solid var(--accent); }

/* ── Section Headers ─────────────────────────────────────────────────────── */

.section-header {
  padding: 16px 16px 4px;
}

/* ── Asset Preview Modal ─────────────────────────────────────────────────── */

.preview-modal-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-close-btn {
  position: absolute;
  top: -48px;
  right: 0;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

#previewContent img {
  max-width: min(90vw, 900px);
  max-height: 85vh;
  border-radius: var(--radius-lg);
  object-fit: contain;
  display: block;
}

#previewContent video {
  max-width: min(90vw, 900px);
  max-height: 85vh;
  border-radius: var(--radius-lg);
  display: block;
  outline: none;
}

/* ── Device Timeline ─────────────────────────────────────────────────────── */

.device-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-timeline-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.device-timeline-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.device-timeline-timecode {
  font-size: 13px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
}

.device-timeline-bar-wrap {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}

.device-timeline-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s linear;
  min-width: 4px;
}

.device-timeline-elapsed {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Device Detail Sections ─────────────────────────────────────────────── */

.detail-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.detail-assign-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.now-playing-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-muted);
  min-height: 48px;
  display: flex;
  align-items: center;
}

/* ── Device Content Picker ───────────────────────────────────────────────── */

.device-picker-list {
  max-height: 55vh;
  overflow-y: auto;
  margin: 0 -24px -28px;
  border-top: 1px solid var(--border);
}

.device-picker-item {
  padding: 14px 24px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
  color: var(--text-primary);
  transition: background var(--transition);
}

.device-picker-item:hover { background: var(--bg-elevated); }
.device-picker-item:last-child { border-bottom: none; }

/* ── Device Loop List ───────────────────────────────────────────────────── */

.device-loop-list {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  overflow-x: auto;
  padding: 8px 0 4px;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
  min-height: 165px;
}

.device-loop-list:empty::before {
  content: 'Noch kein Inhalt zugewiesen';
  display: block;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 80px;
}

.device-loop-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 226px;
  position: relative;
}

.device-loop-thumb {
  width: 210px;
  height: 118px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: block;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.device-loop-thumb-placeholder {
  width: 210px;
  height: 118px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.device-loop-item-name {
  font-size: 11px;
  color: var(--text-secondary);
  width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 4px;
  text-align: center;
}

.device-loop-item-pills {
  margin-top: 5px;
  display: flex;
  justify-content: center;
  min-height: 20px;
}

/* Remove button — top right */
.device-loop-item-remove {
  position: absolute;
  top: -6px;
  right: 2px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  font-size: 15px;
  line-height: 1;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.device-loop-item-remove:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-muted);
}

/* Edit (duration) button — top left, images only */
.device-loop-item-edit {
  position: absolute;
  top: -6px;
  left: 2px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  font-size: 11px;
  line-height: 1;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.device-loop-item-edit:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-muted);
}

/* Inline duration editor */
.loop-dur-edit {
  display: flex;
  align-items: center;
  gap: 3px;
  justify-content: center;
}

.loop-dur-input {
  width: 46px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 10px;
  padding: 1px 4px;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}

.loop-dur-input::-webkit-outer-spin-button,
.loop-dur-input::-webkit-inner-spin-button { -webkit-appearance: none; }

.loop-dur-ok {
  background: var(--accent-muted);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-size: 10px;
  padding: 1px 4px;
  cursor: pointer;
  line-height: 1.4;
}

.loop-dur-ok:hover { background: var(--accent); color: #fff; }

.device-loop-arrow {
  color: var(--text-muted);
  font-size: 16px;
  padding: 0 2px;
  margin-top: 50px;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}

/* Currently-playing item highlight */
.device-loop-item.is-current .device-loop-thumb,
.device-loop-item.is-current .device-loop-thumb-placeholder {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}

/* Skip button — centered overlay on the current item's thumbnail */
.device-loop-item-skip {
  position: absolute;
  top: 59px; /* half of 118px thumb height */
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.55);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  padding: 0;
  z-index: 2;
  transition: background var(--transition), border-color var(--transition);
}
.device-loop-item-skip:hover {
  background: rgba(88, 166, 255, 0.75);
  border-color: var(--accent);
}

/* ── Media Filter Bar ───────────────────────────────────────────────────── */

.media-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 12px;
  flex-wrap: wrap;
}

.media-search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.media-search-input {
  width: 100%;
  padding: 7px 32px 7px 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}
.media-search-input:focus { border-color: var(--accent); }
.media-search-input::placeholder { color: var(--text-muted); }

.media-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}
.media-search-clear:hover { color: var(--text-primary); }

.media-filter-pills {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.filter-pill {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-pill:hover { background: var(--bg-elevated); color: var(--text-primary); }
.filter-pill.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

.media-sort-select {
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Storage Stats Bar ───────────────────────────────────────────────────── */

.storage-stats {
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
}

.storage-stats-info {
  display: flex;
  gap: 16px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.storage-bar-wrap {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.storage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ── Device Disk Bar (in device detail) ─────────────────────────────────── */

.device-disk-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

.device-disk-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s ease;
}

.device-disk-bar.warn { background: var(--danger); }

.device-disk-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}


/* ── Device Name Inline Rename Input ────────────────────────────────────── */

.device-name-input {
  font-size: 16px;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 4px 8px;
  outline: none;
  min-width: 180px;
  flex: 1;
}

.device-rename-btn {
  opacity: 0.5;
  transition: opacity var(--transition);
}
.device-rename-btn:hover { opacity: 1; }

/* ── Playlist Duplicate Button ───────────────────────────────────────────── */

.playlist-card {
  display: flex;
  align-items: center;
  gap: 8px;
}
.playlist-card-main {
  flex: 1;
  min-width: 0;
}
.playlist-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.playlist-duplicate-btn,
.playlist-delete-btn {
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition), border-color var(--transition);
}
.playlist-card:hover .playlist-duplicate-btn,
.playlist-card:hover .playlist-delete-btn { opacity: 1; }

.playlist-delete-btn:hover {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
  background: var(--danger-muted) !important;
}

/* (section-divider defined above near page-section-header) */

/* ── Upload List (per-file progress) ─────────────────────────────────────── */

.upload-list {
  margin: 0 16px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.upload-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}
.upload-list-item:last-child { border-bottom: none; }

.upload-list-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  min-width: 0;
}

.upload-list-bar-wrap {
  width: 80px;
  flex-shrink: 0;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-list-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s;
}

.upload-list-status {
  width: 28px;
  flex-shrink: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
}
.upload-list-status.done { color: var(--success); }
.upload-list-status.error { color: var(--danger); }

/* ── Utilities ───────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--success-muted); }
  50%       { box-shadow: 0 0 0 8px transparent; }
}
