/* App.css — streamlined + modal interaction fix */

/* ===== Theme ===== */
:root {
  --color-bg: #1e1e1e;
  --color-surface: #2a2a2a;
  --color-border: #3d3d3d;
  --color-text: #f5f5f5;
  --color-accent: #51cf66;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  overflow-x: hidden;
}

/* ===== Header ===== */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.file-input {
  position: absolute;
  left: -9999px;
}

.file-input-label {
  background: var(--color-accent);
  border: none;
  color: #000;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.file-input-label:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.file-input-label:hover {
  background: #40c057;
}

.toggle-button {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.toggle-button:hover {
  background: var(--color-border);
}

.toggle-button.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #000;
}

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

.select-control {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23f5f5f5' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 0.8rem;
  padding-right: 1.5rem;
}

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

.video-limit-control,
.zoom-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.video-limit-control input[type="range"],
.zoom-control input[type="range"] {
  accent-color: var(--color-accent);
}


.subfolders-option {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
}

.subfolders-option input {
  accent-color: var(--color-accent);
}

.drop-zone {
  margin: 2rem;
  padding: 4rem;
  border: 2px dashed var(--color-border);
  border-radius: 12px;
  text-align: center;
  color: #888;
  transition: all 0.3s ease;
}

.drop-zone.drag-over {
  border-color: var(--color-accent);
  background: rgba(81, 207, 102, 0.1);
}

.selection-info {
  background: var(--color-accent);
  color: #000;
  padding: 0.3rem 0.8rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ===== App frame ===== */
.app {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Ensure React doesn't interfere with existing styles */
* { box-sizing: border-box; }

/* ===== Base video grid ===== */
.video-grid {
  padding: 1rem;
  gap: 4px;
  width: 100%;
  position: relative;
  flex: 1;
  overflow-y: auto;
  transition: height 0.3s ease; /* keep single transition */
}

/* Video card */
.video-item {
  content-visibility: auto;
  contain-intrinsic-size: 140px 250px;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #2d2d2d;
  cursor: pointer;
  position: relative;
  /* Consolidated transitions (drop duplicate blocks later in file) */
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  will-change: opacity, transform;
}

.video-item.selected { border-color: #007acc; }
.video-item.error { border-color: #ff4444; }

.video-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #2d2d2d;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-container video,
.video-element {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Filename ribbon */
.video-filename {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: #fff;
  padding: 0.5rem;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
}
.video-grid.hide-filenames .video-filename { display: none; }

/* ===== Grid layout (fixed height cards) ===== */
.video-grid.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px;
}
.video-grid.grid .video-item {
  aspect-ratio: 16/9;
  height: 140px;
}

/* ===== Masonry layout scaffolding ===== */
.video-grid.masonry-vertical,
.video-grid.masonry-horizontal { position: relative; }

/* Hide unpositioned items while measuring/placing */
.video-grid.masonry-vertical .video-item,
.video-grid.masonry-horizontal .video-item {
  opacity: 0;
  pointer-events: none;
  contain: layout paint size;
  will-change: transform;
  transform: translateZ(0);
  transition: opacity 0.15s ease !important;
}
.video-grid.masonry-vertical .video-item[data-pos="1"],
.video-grid.masonry-horizontal .video-item[data-pos="1"] {
  opacity: 1;
  pointer-events: auto;
}
/* Prevent transform/height animations during masonry passes */
.video-grid.masonry-vertical .video-item,
.video-grid.masonry-horizontal .video-item { transition-property: opacity !important; }

/* Default placeholder height for masonry (while probing) */
.video-grid.masonry-vertical .video-placeholder,
.video-grid.masonry-vertical .error-indicator { height: 140px; }

/* ===== States: placeholder / error (unified) ===== */
.video-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: linear-gradient(135deg, #1a1a1a, #2d2d2d);
  color: #888;
  text-align: center;
  font-size: 0.9rem;
  padding: 1rem;
  box-sizing: border-box;
}

.error-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: linear-gradient(135deg, #2d1a1a, #3d2d2d);
  color: #ff6b6b;
  text-align: center;
  padding: 1rem;
  box-sizing: border-box;
}

/* Specific error accents */
.error-indicator.error-codec {
  background: linear-gradient(135deg, #2d2a1a, #3d3a2d);
  color: #ffb347;
}
.error-indicator.error-format { /* (kept for clarity) */
  background: linear-gradient(135deg, #2d1a1a, #3d2d2d);
  color: #ff6b6b;
}

/* Playing indicator */
.video-item.playing { box-shadow: 0 0 0 2px #4caf50; }
.video-item.playing::after {
  content: "▶️";
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.8rem;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 4px;
  border-radius: 3px;
  z-index: 2;
}

/* Debug visibility outline */
.video-item[data-visible="true"] {
  border: 1px solid rgba(76, 175, 80, 0.3);
}

/* ===== Context menu ===== */
.context-menu {
  background: #2d2d2d;
  border: 1px solid #404040;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  min-width: 200px;
  overflow: hidden;
  font-family: inherit;
}
.context-menu-header {
  background: #1a1a1a;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #404040;
}
.context-menu-title {
  color: #ccc;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  display: block;
}
.context-menu-items { padding: 0.25rem 0; }
.context-menu-item {
  padding: 0.5rem 0.75rem;
  color: #ddd;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.15s ease;
}
.context-menu-item:hover { background: #404040; color: #fff; }
.context-menu-item:active { background: #007acc; }

/* Ensure inner containers inherit radius */
.video-item .video-element,
.video-item .video-container { border-radius: 8px 8px 0 0; }

/* ===== Loading feedback / misc ===== */
.video-item.loading { opacity: 0.7; }
.video-item.loading .video-placeholder { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.6; } 50% { opacity: 1; } }

.header button:disabled,
.header input:disabled { opacity: 0.5; cursor: not-allowed; transition: opacity 0.3s ease; }

/* “Render in progress” top bar */
.video-grid.rendering { overflow: hidden; }
.video-grid.rendering::after {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #4caf50, #45a049);
  animation: loading-bar 2s ease-in-out infinite;
  z-index: 1000;
}
@keyframes loading-bar { 0%,100% { transform: translateX(-100%); } 50% { transform: translateX(100vw); } }

/* Memory-pressure hinting */
.app[data-memory-pressure="high"] .video-item:not(.visible) { opacity: 0.3; }
.app[data-memory-pressure="critical"] .video-item:not(.visible) { display: none; }

/* ===== Virtual grid (kept) ===== */
.virtual-grid-container {
  background: #1a1a1a;
  width: 100%;
  position: relative;
  will-change: scroll-position;
  transform: translateZ(0);
  scroll-behavior: smooth;
}
.virtual-grid-container::-webkit-scrollbar { width: 12px; }
.virtual-grid-container::-webkit-scrollbar-track { background: #2d2d2d; }
.virtual-grid-container::-webkit-scrollbar-thumb { background: #555; border-radius: 6px; }
.virtual-grid-container::-webkit-scrollbar-thumb:hover { background: #777; }

.virtual-grid-container .video-item {
  will-change: transform;
  transform: translateZ(0);
  transition: none !important;
  contain: layout style paint size;
}
.virtual-grid-container.layout-grid .video-item,
.virtual-grid-container.layout-masonry-vertical .video-item,
.virtual-grid-container.layout-masonry-horizontal .video-item {
  border-radius: 8px;
  overflow: hidden;
}
.virtual-grid-container.hide-filenames .video-filename { display: none; }
.virtual-grid-container .video-container { contain: layout style paint; will-change: auto; }
.virtual-grid-container .video-element { will-change: auto; transform: translateZ(0); }

/* Lightweight hover */
.virtual-grid-container .video-item:hover {
  transform: scale(1.02);
  z-index: 5;
  transition: transform 0.1s ease;
}
.virtual-grid-container .video-item:hover .video-filename { background: rgba(0,0,0,0.9); }

/* Selection + playing badges in virtual */
.virtual-grid-container .video-item.selected { box-shadow: 0 0 0 3px #007acc; z-index: 10; }
.virtual-grid-container .video-item.playing::after {
  content: "▶️";
  position: absolute; top: 4px; right: 4px;
  font-size: 0.7rem;
  background: rgba(0,0,0,0.8);
  padding: 2px 4px; border-radius: 3px; z-index: 5;
}

/* Debug overlay */
.virtual-grid-container + .debug-overlay {
  position: fixed;
  bottom: 20px; right: 20px;
  background: rgba(0,0,0,0.9);
  color: #0f0; padding: 8px; border-radius: 4px;
  font-family: monospace; font-size: 0.7rem;
  z-index: 1001; pointer-events: none;
}

/* High-performance mode */
.virtual-grid-container.performance-mode .video-item {
  contain: strict;
  will-change: transform;
  transform: translateZ(0) scale(1);
}
.virtual-grid-container.performance-mode .video-item:hover {
  transform: translateZ(0) scale(1) !important;
}

/* ===== Fullscreen modal (Linux click fix) ===== */
.fullscreen-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10000;
  cursor: default; /* avoid implying backdrop click */
  background: rgba(0,0,0,0.9);
  /* CRITICAL: disable window drag over the overlay */
  -webkit-app-region: no-drag;
}
.fullscreen-modal * { -webkit-app-region: no-drag; } /* belt & braces */

/* If you render a separate backdrop element, keep it visual-only */
.fullscreen-modal__backdrop { pointer-events: none; }

/* Content area must accept pointer events */
.fullscreen-video-container {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
  pointer-events: auto;
}
.fullscreen-video {
  max-width: 95vw;
  max-height: 95vh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}
.fullscreen-filename {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: #fff;
  padding: 1rem;
  font-size: 1rem;
  text-align: center;
  pointer-events: none;
}

/* ===== Accessibility / reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  .video-item,
  .video-placeholder,
  .debug-info {
    animation: none !important;
    transition: none !important;
  }
  .virtual-grid-container { scroll-behavior: auto; }
  .virtual-grid-container .video-item { transition: none !important; animation: none !important; }
  .virtual-grid-container .video-item:hover { transform: none !important; }
}

/* ===== Responsive tweaks ===== */
@media (max-width: 768px) {
  .video-grid.grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .video-grid.masonry-vertical { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .video-grid.masonry-horizontal .video-item { height: 150px; }

  .debug-info { font-size: 0.6rem !important; padding: 0.2rem 0.5rem !important; }
  .video-placeholder { font-size: 0.8rem; padding: 0.5rem; }
  .error-indicator { font-size: 0.7rem; padding: 0.5rem; }

  .virtual-grid-container { padding-top: 60px; }
  .virtual-grid-container .video-filename { font-size: 0.7rem; padding: 2px 4px; }
}

@media (max-width: 480px) {
  .video-grid.grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .video-grid.masonry-vertical { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .video-grid.masonry-horizontal .video-item { height: 120px; }

  .virtual-grid-container { padding-top: 50px; }
  .virtual-grid-container .video-item { font-size: 0.75rem; }
}
