/* Layout */
body {
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
}

/* Workspace switcher (Phase 3 MVP). Sits in sidebar-header below the logo.
   Three render modes via JS: dropdown (>1 ws), static text (1 ws),
   muted empty state (0 ws). */
.workspace-switcher {
  position: relative;
  margin-top: 12px;
}

.workspace-switcher-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.workspace-switcher-button:hover {
  border-color: var(--accent);
}

.workspace-switcher-static {
  display: block;
  padding: 4px 2px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
}

.workspace-switcher-static::before {
  content: 'Workspace';
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.workspace-switcher-empty {
  display: block;
  padding: 8px 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* #19: single-workspace view - name + always-visible manage icons (no dropdown). */
.workspace-switcher-single {
  display: flex;
  align-items: center;
  gap: 4px;
}

.workspace-switcher-single .workspace-switcher-static {
  flex: 1;
  min-width: 0;
}

.workspace-switcher-single .workspace-switcher-members,
.workspace-switcher-single .workspace-switcher-pencil {
  visibility: visible;
  align-self: end;
}

.workspace-switcher-button .chev {
  flex-shrink: 0;
  margin-left: 8px;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.workspace-switcher.open .chev {
  transform: rotate(180deg);
}

.workspace-switcher-menu {
  display: none;
  /* Width: detach from the narrow sidebar-header (188px content width). The
     sidebar is z-indexed and the dropdown is free to extend beyond the
     sidebar into the main content area. min/max bounds keep it readable
     for normal-length names without sprawling on extreme cases. */
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 280px;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  max-height: 360px;
  padding: 4px 0;
  overflow-y: auto;
  z-index: 100;
}

.workspace-switcher.open .workspace-switcher-menu {
  display: block;
}

/* #16: sticky type-to-filter search header inside the (scrolling) menu. */
.workspace-switcher-search {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-card);
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.workspace-switcher-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
}

.workspace-switcher-search input:focus {
  outline: none;
  border-color: var(--accent);
}

.workspace-switcher-noresults {
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.workspace-switcher-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13px;
}

.workspace-switcher-item:last-child {
  border-bottom: none;
}

.workspace-switcher-item:hover {
  background: var(--bg-input);
}

/* keyboard-cursor highlight (arrow keys) - same surface as hover */
.workspace-switcher-item.highlighted {
  background: var(--bg-input);
}

.workspace-switcher-item.current {
  font-weight: 600;
}

.workspace-switcher-item .check {
  flex-shrink: 0;
  color: var(--accent);
  width: 14px;
}

.workspace-switcher-item .ws-meta {
  flex: 1;
  min-width: 0;
}

.workspace-switcher-item .ws-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-switcher-item .ws-org {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  /* nowrap + ellipsis: long "Org Name . N devices" lines truncate cleanly
     instead of wrapping onto a second line that doubles row height. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-switcher-pencil {
  flex-shrink: 0;
  visibility: hidden;
  background: none;
  border: none;
  padding: 4px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

.workspace-switcher-item:hover .workspace-switcher-pencil {
  visibility: visible;
}

.workspace-switcher-pencil:hover {
  color: var(--accent);
  background: var(--bg-input);
}

/* Members icon - same shape as the pencil; navigates to #/workspace/:id/members. */
.workspace-switcher-members {
  flex-shrink: 0;
  visibility: hidden;
  background: none;
  border: none;
  padding: 4px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

.workspace-switcher-item:hover .workspace-switcher-members {
  visibility: visible;
}

.workspace-switcher-members:hover {
  color: var(--accent);
  background: var(--bg-input);
}

/* Workspace members page (Phase 2 user-mgmt, slice 2A read-only). Three
   sections render via JS: direct members, via_org access, pending invites.
   Row layout mirrors the sidebar user card's avatar pattern for visual
   continuity. via_org rows are opacity-reduced and invite rows use the
   input-bg shade so the three states are distinguishable at a glance. */
.members-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.member-row--via-org {
  opacity: 0.75;
}

.member-row--invited {
  background: var(--bg-input);
}

.member-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.member-avatar--muted {
  background: var(--text-muted);
}

.member-meta {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-email {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-role {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 8px;
  background: var(--bg-input);
  border-radius: 4px;
  min-width: 60px;
  text-align: center;
}

.member-detail {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  min-width: 110px;
  text-align: right;
}

.member-via-org {
  font-style: italic;
}

.member-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  background: var(--bg-input);
  color: var(--text-muted);
  border-radius: 3px;
  font-weight: 600;
}

/* Slice 2B - mutation affordances. .member-actions is the cell that holds
   per-row admin buttons (remove on direct-member rows, cancel on invited
   rows). via_org rows omit the cell entirely. The role select replaces the
   .member-role div for admins on direct-member rows. */
.member-role-select {
  flex-shrink: 0;
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  min-width: 90px;
  cursor: pointer;
}

.member-role-select:hover {
  border-color: var(--accent);
}

.member-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}

.member-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 6px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

.member-action-btn:hover {
  background: var(--bg-input);
}

.member-action-btn--danger:hover {
  color: var(--danger);
}

.nav-links {
  flex: 1;
  padding: 12px 8px;
  /* Scroll the nav when it's taller than the viewport (short screens, e.g.
     1366x768) so items below the fold (Settings) stay reachable. min-height:0
     is required for a flex child to shrink and scroll instead of overflowing. */
  overflow-y: auto;
  min-height: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: all var(--transition);
  margin-bottom: 2px;
}

.nav-link:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-link.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  color: white;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.35);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

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

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot.offline {
  background: var(--danger);
}

.status-dot.provisioning {
  background: var(--warning);
  animation: pulse 2s infinite;
}

/* v4 liveness (server-derived): healthy=green, degraded=amber+pulse (reconnecting), offline=red (above) */
.status-dot.healthy {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot.degraded {
  background: var(--warning);
  box-shadow: 0 0 6px var(--warning);
  animation: pulse 2s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 32px;
}

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 600;
}

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

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #3730a3);
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.55);
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-danger {
  background: var(--danger-dim);
  color: #fca5a5;
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Device Grid */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
  cursor: pointer;
}

.device-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.25);
  transform: translateY(-2px);
}

.device-card-preview {
  aspect-ratio: 16/9;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.device-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.device-card-preview .no-preview {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 8px;
}

.device-card-preview .no-preview svg {
  opacity: 0.3;
}

.device-card-status {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

/* Device cards render the reused liveness pill (.device-status-badge from device-detail), which brings
   its own bg/padding/shape — so neutralize the dark wrapper for those. Wall cards keep the dark pill
   above for their "NxN wall" label (they share .device-card-status but have no .is-liveness). */
.device-card-status.is-liveness {
  background: none;
  backdrop-filter: none;
  padding: 0;
  border-radius: 0;
}

/* Lift the list pill off the screenshot so it stays legible over any image. */
.device-card-status.is-liveness .device-status-badge {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.device-card-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  padding: 3px 5px;
  display: flex;
  align-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.device-card:hover .device-card-select,
.device-card.selected .device-card-select {
  opacity: 1;
}

.device-card-select input {
  cursor: pointer;
  margin: 0;
}

.device-card.selected {
  outline: 2px solid var(--primary, #3B82F6);
  outline-offset: -2px;
}

/* Wall editor — free-form pan/zoom canvas */
.wall-viewport {
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg-primary);
}

.wall-viewport.panning {
  cursor: grabbing;
}

/* Inner canvas: a 0×0 anchor whose CSS transform supplies pan + zoom.
   All rect children are absolutely positioned in canvas-data coordinates
   and inherit the parent transform. transform-origin is the canvas's
   top-left so pan offsets map cleanly to data → screen pixels. */
.wall-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  /* Disable transition so panning doesn't lag behind the cursor */
}

.wall-zoom-readout {
  position: absolute;
  bottom: 8px;
  right: 12px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.wall-screen {
  position: absolute;
  background: rgba(59, 130, 246, 0.08);
  border: 2px solid var(--primary, #3B82F6);
  border-radius: 4px;
  box-sizing: border-box;
  cursor: move;
  user-select: none;
  touch-action: none;
  overflow: hidden;
}

.wall-screen-overlap {
  position: absolute;
  background: rgba(96, 165, 250, 0.35);
  pointer-events: none;
  display: none;
  z-index: 1;
}

.wall-screen-label {
  position: absolute;
  top: 4px;
  left: 6px;
  right: 24px;
  pointer-events: none;
  z-index: 2;
}

.wall-screen-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary, #fff);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wall-screen-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.wall-screen-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 3;
  width: 20px;
  height: 20px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.wall-screen-remove:hover {
  background: var(--danger, #ef4444);
}

.wall-player {
  position: absolute;
  background: rgba(96, 165, 250, 0.18);
  border: 2px dashed #60a5fa;
  border-radius: 4px;
  box-sizing: border-box;
  cursor: move;
  user-select: none;
  touch-action: none;
  z-index: 5;
  box-shadow: 0 0 0 9999px transparent;
  /* keeps stacking explicit */
}

.wall-player-label {
  position: absolute;
  top: 4px;
  left: 6px;
  pointer-events: none;
  color: #dbeafe;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  font-size: 11px;
  letter-spacing: 1px;
}

/* Selected rect highlight (works for both screens and the player) */
.wall-screen.selected,
.wall-player.selected {
  outline: 3px solid #facc15;
  outline-offset: 1px;
  z-index: 6;
}

/* Fine-position panel inputs */
.wall-pos-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 6px 8px;
  align-items: center;
  font-size: 12px;
}

.wall-pos-grid label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.wall-pos-grid input {
  width: 100%;
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary, #fff);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.wall-pos-grid input:focus {
  outline: 1px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}

/* Eight resize handles, used by both screens and the player */
.wall-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 1px solid #1d4ed8;
  border-radius: 2px;
  z-index: 4;
}

.wall-player .wall-handle {
  border-color: #60a5fa;
}

.wall-handle-nw {
  top: -5px;
  left: -5px;
  cursor: nw-resize;
}

.wall-handle-n {
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: n-resize;
}

.wall-handle-ne {
  top: -5px;
  right: -5px;
  cursor: ne-resize;
}

.wall-handle-e {
  top: 50%;
  right: -5px;
  transform: translateY(-50%);
  cursor: e-resize;
}

.wall-handle-se {
  bottom: -5px;
  right: -5px;
  cursor: se-resize;
}

.wall-handle-s {
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: s-resize;
}

.wall-handle-sw {
  bottom: -5px;
  left: -5px;
  cursor: sw-resize;
}

.wall-handle-w {
  top: 50%;
  left: -5px;
  transform: translateY(-50%);
  cursor: w-resize;
}

/* Wall editor — legacy cells (kept for migration; new editor uses wall-canvas) */
.wall-cell {
  position: relative;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-secondary);
  user-select: none;
}

.wall-cell.occupied {
  background: rgba(59, 130, 246, 0.15);
  border: 2px solid var(--primary, #3B82F6);
  cursor: grab;
}

.wall-cell.occupied:active {
  cursor: grabbing;
}

.wall-cell.drag-over {
  border-color: var(--success, #10b981);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25) inset;
}

.wall-cell-name {
  font-weight: 500;
  padding: 0 6px;
  text-align: center;
}

.wall-cell-pos {
  position: absolute;
  bottom: 4px;
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.wall-cell-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.wall-cell-remove:hover {
  background: var(--danger, #ef4444);
}

.wall-card .wall-card-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.1));
}

.wall-card-grid {
  display: grid;
  gap: 4px;
  width: 65%;
  aspect-ratio: 16/9;
  padding: 8px;
}

.wall-card-cell {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 2px;
}

.wall-card-cell.filled {
  background: rgba(139, 92, 246, 0.5);
  border-color: rgba(139, 92, 246, 0.9);
}

.device-card-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 10px 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
  color: #fff;
  font-size: 11px;
  pointer-events: none;
}

.device-card-progress-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.device-card-progress-label .dcp-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.device-card-progress-label .dcp-time {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.device-card-progress-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.device-card-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary, #3B82F6);
  transition: width 0.9s linear;
}

.device-card-progress-fill.indeterminate {
  background: linear-gradient(90deg, transparent, var(--primary, #3B82F6), transparent);
  background-size: 50% 100%;
  animation: dcp-indeterminate 1.4s linear infinite;
}

@keyframes dcp-indeterminate {
  0% {
    background-position: -50% 0;
  }

  100% {
    background-position: 150% 0;
  }
}

.device-card-body {
  padding: 14px 16px;
}

.device-card-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
}

.device-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 12px;
}

.device-card-meta .meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Device Detail */
.device-detail {
  max-width: 1200px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 13px;
  transition: color var(--transition);
}

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

.device-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.device-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.device-header-left h1 {
  font-size: 22px;
}

.device-status-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.device-status-badge.online {
  background: var(--success-dim);
  color: var(--success);
}

.device-status-badge.offline {
  background: var(--danger-dim);
  color: #fca5a5;
}

.device-status-badge.provisioning {
  background: var(--warning-dim);
  color: var(--warning);
}

/* v4 liveness (server-derived): healthy=green, degraded=amber (reconnecting), offline reuses .offline above */
.device-status-badge.healthy {
  background: var(--success-dim);
  color: var(--success);
}

.device-status-badge.degraded {
  background: var(--warning-dim);
  color: var(--warning);
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
}

.tab:hover {
  color: var(--text-primary);
}

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

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Screenshot Preview */
.screenshot-container {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 16/9;
  position: relative;
  margin-bottom: 20px;
}

.screenshot-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.screenshot-container .no-screenshot {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 8px;
}

/* Remote Control */
.remote-container {
  display: flex;
  gap: 20px;
}

.remote-screen {
  flex: 1;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  cursor: crosshair;
}

.remote-screen canvas {
  width: 100%;
  display: block;
}

.remote-controls {
  width: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.remote-controls .btn {
  width: 100%;
  justify-content: center;
}

/* Playlist */
.playlist-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.playlist-item:hover {
  border-color: var(--border-light);
}

.playlist-item-thumb {
  width: 80px;
  height: 45px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-primary);
  flex-shrink: 0;
}

.playlist-item-info {
  flex: 1;
  min-width: 0;
}

.playlist-item-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

.playlist-item-actions {
  display: flex;
  gap: 4px;
}

/* Info Grid */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 16px;
  transition: box-shadow var(--transition);
}

.info-card:hover {
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
}

.info-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.info-card-value {
  font-size: 20px;
  font-weight: 600;
}

.info-card-value.small {
  font-size: 14px;
}

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--transition);
}

.progress-bar-fill.success {
  background: var(--success);
}

.progress-bar-fill.warning {
  background: var(--warning);
}

.progress-bar-fill.danger {
  background: var(--danger);
}

/* Content Library */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.content-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all var(--transition);
}

.content-item:hover {
  border-color: var(--border-light);
}

.content-item-preview {
  aspect-ratio: 16/9;
  background: var(--bg-primary);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content-item-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content-item-preview .video-icon {
  color: var(--text-muted);
}

.content-item-body {
  padding: 10px 12px;
}

.content-item-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.content-item-size {
  font-size: 11px;
  color: var(--text-muted);
}

.content-item-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 12px 10px;
  gap: 4px;
}

/* Upload Area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 24px;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.05);
}

.upload-area svg {
  margin: 0 auto 12px;
  color: var(--text-muted);
}

.upload-area p {
  color: var(--text-secondary);
  font-size: 14px;
}

.upload-area .upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

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

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 440px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

.modal-description {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* Form Elements */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  transition: border-color var(--transition);
}

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

.pairing-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 8px;
  font-family: 'Courier New', monospace;
}

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

/* Toast */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  max-width: 360px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  min-width: 280px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(8px);
}

.toast.success {
  border-left: 4px solid var(--success);
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.08), var(--bg-card));
}

.toast.error {
  border-left: 4px solid var(--danger);
  background: linear-gradient(90deg, rgba(248, 113, 113, 0.08), var(--bg-card));
}

.toast.info {
  border-left: 4px solid var(--accent);
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.08), var(--bg-card));
}

.toast.warning {
  border-left: 4px solid var(--warning);
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.08), var(--bg-card));
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  margin: 0 auto 16px;
  opacity: 0.3;
}

.empty-state h3 {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  max-width: 360px;
  margin: 0 auto;
}

/* Settings */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.settings-section h3 {
  font-size: 16px;
  margin-bottom: 16px;
}

/* Assign Modal */
.assign-content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
}

.assign-content-item {
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
}

.assign-content-item:hover {
  border-color: var(--accent);
}

.assign-content-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.assign-content-item img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
}

.assign-content-item-name {
  padding: 6px 8px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Upload progress */
.upload-progress {
  margin-top: 16px;
}

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

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

/* Help tooltips */
.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: help;
  position: relative;
  margin-left: 6px;
  flex-shrink: 0;
}

.help-tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: normal;
  width: 250px;
  z-index: 1000;
  box-shadow: var(--shadow);
  margin-bottom: 6px;
  line-height: 1.4;
}

/* Table wrapper: enables horizontal scroll when table min-width exceeds viewport */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile hamburger toggle */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 44px;
  height: 44px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 150;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 140;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .nav-link {
    min-height: 44px;
    padding: 10px 14px;
  }

  .content {
    margin-left: 0;
    padding: 16px;
    padding-top: 68px;
  }

  .page-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .device-grid {
    grid-template-columns: 1fr;
  }

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

  .info-grid {
    grid-template-columns: 1fr;
  }

  .remote-container {
    flex-direction: column;
  }

  .remote-controls {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .modal {
    width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
  }

  .tab {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .playlist-item {
    flex-wrap: wrap;
  }

  /* Dashboard stats stack to single column */
  .dash-stats-row {
    flex-direction: column;
  }

  .dash-stats-row .info-card {
    flex: none;
  }

  /* Content-library 3-up toolbar stacks vertically */
  .content-toolbar {
    flex-direction: column;
  }

  .content-toolbar>div[style*="width:320px"] {
    width: auto !important;
  }

  /* Schedule controls: allow wrap and widen select to full row */
  .schedule-controls {
    gap: 8px;
  }

  .schedule-controls>select {
    flex: 1 1 100%;
  }

  .schedule-controls>button,
  .schedule-controls>span {
    flex: 0 1 auto;
  }

  /* Tap targets: minimum 44px height for interactive elements */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 8px 12px;
  }

  .btn-icon {
    min-width: 40px;
    min-height: 40px;
  }

  /* Form inputs: 16px font to prevent iOS focus zoom; 44px tap target */
  .input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="url"],
  input[type="search"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .pairing-input {
    font-size: 24px;
    letter-spacing: 6px;
  }

  /* Modals: adjust padding at 95vw so content doesn't touch edges */
  .modal-header,
  .modal-footer {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  /* Toast container: full-width bar instead of 280px fixed to right */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .assign-content-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* FullCalendar Dark Theme Overrides */
:root {
  --fc-page-bg-color: var(--bg-card);
  --fc-neutral-bg-color: var(--bg-secondary);
  --fc-neutral-text-color: var(--text-secondary);
  --fc-border-color: var(--border);

  --fc-button-text-color: var(--text-primary);
  --fc-button-bg-color: var(--bg-input);
  --fc-button-border-color: var(--border);
  --fc-button-hover-bg-color: var(--bg-card-hover);
  --fc-button-hover-border-color: var(--accent);
  --fc-button-active-bg-color: var(--accent);
  --fc-button-active-border-color: var(--accent);

  --fc-event-bg-color: var(--primary);
  --fc-event-border-color: var(--primary);
  --fc-event-text-color: #ffffff;
  --fc-event-selected-overlay-color: rgba(0, 0, 0, 0.25);

  --fc-today-bg-color: var(--bg-input);
  --fc-now-indicator-color: var(--danger);
}

.fc {
  color: var(--text-primary);
  font-family: inherit;
}

.fc-theme-standard td,
.fc-theme-standard th {
  border-color: var(--border);
}

.fc-timegrid-slot-label-cushion,
.fc-timegrid-axis-cushion {
  color: var(--text-muted);
}

/* Event Aesthetics Improvement */
.fc-event,
.fc-timegrid-event,
.fc-daygrid-event {
  background-color: rgba(99, 102, 241, 0.12) !important;
  border: none !important;
  border-left: 3px solid var(--primary) !important;
  border-radius: 4px !important;
  margin: 1px 2px !important;
}

.fc-event:hover {
  background-color: rgba(99, 102, 241, 0.22) !important;
}

.fc-event-main {
  color: var(--text-primary) !important;
  font-weight: 500;
  padding: 2px 4px;
  font-size: 13px;
}

.fc-timegrid-event .fc-event-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==================== UI Redesign: Folder Tree ==================== */
.folder-tree {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 8px;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  flex-shrink: 0;
}

.folder-tree-filter {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 12px;
  margin-bottom: 8px;
  box-sizing: border-box;
}

.folder-tree-filter:focus {
  outline: none;
  border-color: var(--accent);
}

.folder-tree-filter::placeholder {
  color: var(--text-muted);
}

.folder-tree-node {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition);
  user-select: none;
  position: relative;
}

.folder-tree-node:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.folder-tree-node.active {
  background: var(--bg-selected);
  color: var(--text-primary);
  font-weight: 500;
}

.folder-tree-node .folder-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: transform 0.15s ease;
  font-size: 10px;
}

.folder-tree-node .folder-chevron.expanded {
  transform: rotate(90deg);
}

.folder-tree-node .folder-icon {
  flex-shrink: 0;
  color: #fbbf24;
  display: inline-flex;
}

.folder-tree-node .folder-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-tree-node .folder-badge {
  flex-shrink: 0;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

.folder-tree-node.active .folder-badge {
  background: var(--accent-dim);
  color: #c7d2fe;
}

.folder-tree-children {
  padding-left: 22px;
  position: relative;
}

.folder-tree-children::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
  opacity: 0.5;
}

.folder-tree-node.drop-target {
  background: var(--bg-selected);
  outline: 1px dashed var(--accent);
}

/* ==================== View Toggle (Grid / List / Table) ==================== */
.view-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.view-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 30px;
}

.view-toggle-btn:last-child {
  border-right: none;
}

.view-toggle-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.view-toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.view-toggle-btn.active svg {
  color: #fff;
}

.view-toggle-btn svg {
  color: var(--text-muted);
}

/* ==================== Content List View ==================== */
.content-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.content-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  cursor: pointer;
}

.content-list-item:hover {
  border-color: var(--border-light);
  background: var(--bg-card-hover);
}

.content-list-item.selected {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.content-list-thumb {
  width: 72px;
  height: 40px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-primary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content-list-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content-list-thumb .video-icon,
.content-list-thumb .file-icon {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.content-list-body {
  flex: 1;
  min-width: 0;
}

.content-list-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-list-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.content-list-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ==================== Content Table View ==================== */
.content-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.content-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.content-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  font-weight: 600;
  white-space: nowrap;
}

.content-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}

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

.content-table tbody tr {
  transition: background var(--transition);
  cursor: pointer;
}

.content-table tbody tr:hover {
  background: var(--bg-hover);
}

.content-table tbody tr.selected {
  background: var(--bg-selected);
}

.content-table .cell-thumb {
  width: 80px;
  padding: 4px 12px;
}

.content-table .cell-thumb img {
  width: 72px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  background: var(--bg-primary);
}

.content-table .cell-actions {
  text-align: right;
  white-space: nowrap;
}

.content-table .cell-check {
  width: 32px;
  text-align: center;
}

.content-table input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ==================== Type Badges ==================== */
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.type-badge.video {
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
}

.type-badge.image {
  color: #86efac;
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.3);
}

.type-badge.youtube {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}

.type-badge.widget {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.3);
}

.type-badge.remote {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.3);
}

.type-badge.folder {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.3);
}

/* ==================== Selection Toolbar ==================== */
.selection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-selected);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  animation: slideInDown 0.25s ease;
}

.selection-bar .count {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-right: 8px;
  flex-shrink: 0;
}

.selection-bar .spacer {
  flex: 1;
}

@keyframes slideInDown {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==================== Add Content Modal (2-column layout) ==================== */
.add-modal-layout {
  display: flex;
  gap: 16px;
  height: 460px;
  min-height: 0;
}

.add-modal-sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding-right: 14px;
  min-height: 0;
}

.add-modal-sidebar .folder-tree {
  flex: 1;
  max-height: none;
  border: none;
  border-radius: 0;
  padding: 0;
  overflow-y: auto;
  background: transparent;
}

.add-modal-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.add-modal-folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.add-modal-folder-header .folder-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-modal-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  align-content: start;
  padding-right: 4px;
}

.add-modal-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all var(--transition);
  position: relative;
}

.add-modal-item:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-sm);
}

.add-modal-item.selected {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.add-modal-item .item-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.add-modal-item .item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.add-modal-item .item-thumb .video-icon {
  color: var(--text-muted);
}

.add-modal-item .item-body {
  padding: 6px 8px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-modal-item .item-name {
  flex: 1;
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-modal-item .item-check {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.add-modal-item .item-add-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all var(--transition);
  z-index: 2;
}

.add-modal-item .item-add-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.add-modal-item .item-add-btn.added {
  background: var(--success-dim);
  color: var(--success);
  border-color: var(--success);
  cursor: default;
}

.add-modal-item .item-add-btn.adding {
  opacity: 0.6;
  cursor: wait;
}

.add-modal-item .item-add-all-btn {
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.add-modal-item .item-add-all-btn:hover {
  box-shadow: 0 3px 12px rgba(99, 102, 241, 0.5);
  transform: translateY(-1px);
}

.add-modal-item .item-add-all-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.add-modal-item .item-add-all-btn.added-all {
  background: var(--success-dim);
  color: var(--success);
}

/* ==================== Segmented Control ==================== */
.segmented {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.segmented-btn {
  padding: 6px 14px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

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

.segmented-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* ==================== Playlist cards (improved) ==================== */
.playlist-card {
  position: relative;
}

.playlist-card .playlist-card-preview {
  height: 100px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -20px -20px 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.playlist-card .playlist-card-preview .preview-icon {
  color: var(--accent);
  opacity: 0.6;
}

.playlist-card .playlist-card-preview .preview-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.playlist-card .playlist-card-preview .preview-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(15, 22, 41, 0.85), transparent 60%);
}

.playlist-card .playlist-card-preview .preview-status {
  position: absolute;
  bottom: 8px;
  left: 20px;
  display: flex;
  gap: 6px;
}

.playlist-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.3px;
}

.playlist-status-pill.published {
  background: var(--success-dim);
  color: var(--success);
}

.playlist-status-pill.draft {
  background: var(--warning-dim);
  color: var(--warning);
}

.playlist-status-pill.auto {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ==================== Breadcrumb chips ==================== */
.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 13px;
}

.breadcrumb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}

.breadcrumb-chip:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.breadcrumb-chip.current {
  background: var(--bg-selected);
  color: var(--text-primary);
  border-color: var(--accent-dim);
  font-weight: 500;
}

.breadcrumb-sep {
  color: var(--text-muted);
  font-size: 11px;
}

/* ==================== Toolbar (page-level) ==================== */
.page-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.page-toolbar .spacer {
  flex: 1;
}

/* ==================== Add-content dropdown (Content Library) ==================== */
.add-content-dropdown {
  position: relative;
  display: inline-block;
}

.add-content-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 5px;
  z-index: 100;
  animation: slideInDown 0.2s ease;
}

.add-content-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.add-content-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.add-content-dropdown-item svg {
  color: var(--accent);
  flex-shrink: 0;
}

.add-content-dropdown-item .item-label {
  flex: 1;
}

.add-content-dropdown-item .item-desc {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-top: 1px;
}

/* ==================== Responsive for new components ==================== */
@media (max-width: 768px) {
  .add-modal-layout {
    flex-direction: column;
    height: auto;
  }

  .add-modal-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 10px;
    max-height: 180px;
  }

  .add-modal-main {
    min-height: 300px;
  }

  .view-toggle {
    width: 100%;
  }

  .view-toggle-btn {
    flex: 1;
    justify-content: center;
  }

  .content-table-wrap {
    max-width: 100%;
  }

  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .page-toolbar .spacer {
    display: none;
  }

  .page-toolbar>.input {
    max-width: none !important;
  }

  .folder-tree {
    max-height: 200px;
  }
}
/* Image zoom on hover */
#currentScreenshot { transition: transform 0.2s ease, box-shadow 0.2s ease; }
#currentScreenshot:hover { transform: scale(1.05); z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }

.item-thumbnail { transition: transform 0.2s ease, box-shadow 0.2s ease; cursor: zoom-in; }
.item-thumbnail:hover { transform: scale(1.08); z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,0.3); position: relative; }

.item-thumbnail .zoom-overlay {
  display: none !important;
  transition: opacity 0.2s ease;
}

.item-thumbnail:hover .zoom-overlay {
  display: flex !important;
}

/* Playlist View Toggle & Thumbview (Icon lớn) Mode */
.view-toggle-btn.active {
  background: var(--accent) !important;
  color: #fff !important;
}

.playlist-container.thumbview-grid,
#playlistItems.thumbview-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important;
  gap: 16px !important;
  padding: 6px 0 !important;
}

.playlist-container.thumbview-grid .playlist-item,
#playlistItems.thumbview-grid .playlist-item {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  padding: 0 !important;
  border-radius: 10px !important;
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  overflow: hidden !important;
  position: relative !important;
  cursor: default !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease !important;
}

.playlist-container.thumbview-grid .playlist-item:hover,
#playlistItems.thumbview-grid .playlist-item:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 28px rgba(0,0,0,0.4) !important;
  border-color: var(--accent) !important;
}

.playlist-container.thumbview-grid .playlist-item-thumb,
#playlistItems.thumbview-grid .item-thumbnail {
  width: 100% !important;
  height: 150px !important;
  border-radius: 0 !important;
  background: #090d16 !important;
  position: relative !important;
  overflow: hidden !important;
  cursor: zoom-in !important;
  transform: none !important;
  box-shadow: none !important;
}

.playlist-container.thumbview-grid .playlist-item-thumb img,
#playlistItems.thumbview-grid .item-thumbnail img {
  width: 100% !important;
  height: 150px !important;
  object-fit: cover !important;
  transition: transform 0.3s ease !important;
}

.playlist-container.thumbview-grid .playlist-item-thumb:hover img,
#playlistItems.thumbview-grid .item-thumbnail:hover img {
  transform: scale(1.06) !important;
}

.playlist-container.thumbview-grid .drag-handle,
#playlistItems.thumbview-grid .drag-handle {
  position: absolute !important;
  top: 8px !important;
  left: 8px !important;
  z-index: 10 !important;
  background: rgba(15, 23, 42, 0.75) !important;
  backdrop-filter: blur(4px) !important;
  border-radius: 4px !important;
  padding: 4px 6px !important;
  color: #fff !important;
  cursor: grab !important;
  opacity: 0.8 !important;
}

.playlist-container.thumbview-grid .drag-handle:hover,
#playlistItems.thumbview-grid .drag-handle:hover {
  opacity: 1 !important;
}

.playlist-container.thumbview-grid .playlist-item-info,
#playlistItems.thumbview-grid .playlist-item-info {
  padding: 12px 14px 8px !important;
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 6px !important;
}

.playlist-container.thumbview-grid .playlist-item-name,
#playlistItems.thumbview-grid .playlist-item-name {
  font-size: 13px !important;
  font-weight: 600 !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
  line-height: 1.4 !important;
}

.playlist-container.thumbview-grid .playlist-item-meta,
#playlistItems.thumbview-grid .playlist-item-meta {
  font-size: 11px !important;
  color: var(--text-muted) !important;
  margin-top: auto !important;
}

.playlist-container.thumbview-grid .playlist-item-actions,
#playlistItems.thumbview-grid .playlist-item-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  padding: 8px 12px !important;
  border-top: 1px solid rgba(255,255,255,0.06) !important;
  background: rgba(0,0,0,0.15) !important;
  gap: 6px !important;
}

.playlist-container.thumbview-grid .item-duration-wrap,
#playlistItems.thumbview-grid .item-duration-wrap {
  padding: 0 14px !important;
  margin-bottom: 4px !important;
}
