/* ========== CSS VARIABLES - MATCHING MAIN SITE ========== */
:root {
  --app-primary: #0A84FF;
  --app-secondary: #5E5CE6;
  --app-background: #000000;
  --app-card-bg: #1C1C1E;
  --app-card-secondary: #2C2C2E;
  --app-text-primary: #FFFFFF;
  --app-text-secondary: #8E8E93;
  --app-border-radius: 12px;
  --app-success: #30D158;
  --app-error: #FF453A;
  --app-warning: #FFD60A;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--app-card-secondary) var(--app-card-bg);
}

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

::-webkit-scrollbar-track {
  background: var(--app-card-bg);
  border-radius: 4px;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--app-primary);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, sans-serif;
  line-height: 1.6;
  background-color: var(--app-background);
  color: var(--app-text-primary);
  padding: 20px;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  background-color: var(--app-card-bg);
  border-radius: var(--app-border-radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  padding: 24px;
}

h1 {
  text-align: center;
  margin-bottom: 24px;
  color: var(--app-text-primary);
  font-weight: 700;
  font-size: 28px;
}

h2 {
  margin-bottom: 16px;
  color: var(--app-primary);
  font-weight: 600;
  font-size: 18px;
}

.upload-container, .files-container {
  margin-bottom: 32px;
}

form {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

input[type="file"] {
  flex-grow: 1;
  padding: 12px 16px;
  border: 1px solid var(--app-card-secondary);
  border-radius: var(--app-border-radius);
  background-color: var(--app-card-secondary);
  color: var(--app-text-primary);
  font-size: 14px;
}

input[type="file"]::file-selector-button {
  background-color: var(--app-primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  margin-right: 12px;
  font-weight: 500;
}

button {
  padding: 12px 20px;
  background-color: var(--app-primary);
  color: white;
  border: none;
  border-radius: var(--app-border-radius);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  font-size: 14px;
}

button:hover {
  background-color: #007AFF;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

/* Files actions container */
.files-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* Download All button styling */
#downloadAllBtn {
  background-color: var(--app-secondary);
}

#downloadAllBtn:hover {
  background-color: #4B4ACF;
}

/* Download status message */
.download-all-status {
  margin: 12px 0;
  padding: 12px 16px;
  border-radius: var(--app-border-radius);
  background-color: rgba(10, 132, 255, 0.15);
  color: var(--app-primary);
  border: 1px solid var(--app-primary);
  font-weight: 600;
}

#refreshBtn {
  margin-bottom: 0;
}

#filesList {
  border: 1px solid var(--app-card-secondary);
  border-radius: var(--app-border-radius);
  padding: 16px;
  max-height: none;
  overflow-y: auto;
  background-color: var(--app-card-secondary);
}

/* ========== VIDEO GALLERY GRID ========== */
.video-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  padding: 8px;
}

.file-item {
  display: flex;
  flex-direction: column;
  background-color: var(--app-card-bg);
  border-radius: var(--app-border-radius);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.file-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.file-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.file-preview video,
.file-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview .play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  background: rgba(10, 132, 255, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.file-preview .play-overlay:hover {
  background: var(--app-primary);
  transform: translate(-50%, -50%) scale(1.1);
}

.file-preview .play-overlay svg {
  width: 28px;
  height: 28px;
  fill: white;
  margin-left: 4px;
}

.file-type-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--app-text-secondary);
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.chunk-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: linear-gradient(135deg, #0A84FF 0%, #5E5CE6 100%);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(10, 132, 255, 0.4);
}

.chunk-group {
  border: 1px solid rgba(10, 132, 255, 0.3);
}

.play-all-btn {
  background: linear-gradient(135deg, #0A84FF 0%, #5E5CE6 100%) !important;
}

.expand-chunks-btn {
  background: rgba(255, 255, 255, 0.1) !important;
}

.video-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-info {
  padding: 16px;
}

.file-name {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--app-text-primary);
  font-size: 14px;
  word-break: break-word;
}

.file-meta {
  font-size: 12px;
  color: var(--app-text-secondary);
  margin-bottom: 12px;
}

.file-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-actions button {
  flex: 1;
  min-width: 80px;
  padding: 10px 12px;
  font-size: 12px;
  border-radius: 8px;
}

/* ========== PLAYER MODAL ========== */
#player {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#player.is-visible {
  display: flex;
}

.media-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

#player.is-visible .media-modal-backdrop {
  opacity: 1;
}

.media-modal-dialog {
  position: relative;
  width: min(900px, 90vw);
  max-height: 90vh;
  background: var(--app-card-bg);
  border-radius: var(--app-border-radius);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  animation: modal-pop 0.25s ease;
}

@keyframes modal-pop {
  from {
    transform: translateY(12px) scale(0.97);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.media-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.media-modal-header h3 {
  color: var(--app-primary);
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.media-modal-close {
  background: transparent;
  border: none;
  color: var(--app-text-secondary);
  padding: 6px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.media-modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--app-text-primary);
}

.media-modal-content {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
  border-radius: var(--app-border-radius);
  overflow: hidden;
  min-height: 320px;
  max-height: calc(90vh - 120px);
}

.media-modal-content video,
.media-modal-content audio,
.media-modal-content img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 100%;
}

body.modal-open {
  overflow: hidden;
}

#uploadStatus {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--app-border-radius);
  font-weight: 500;
}

.success {
  background-color: rgba(48, 209, 88, 0.15);
  color: var(--app-success);
  border: 1px solid var(--app-success);
}

.error {
  background-color: rgba(255, 69, 58, 0.15);
  color: var(--app-error);
  border: 1px solid var(--app-error);
}

/* Storage status styles */
#storageStatus {
  margin: 16px 0;
  padding: 12px 16px;
  border-radius: var(--app-border-radius);
  text-align: center;
  font-size: 14px;
}

.status-connected {
  background-color: rgba(48, 209, 88, 0.15);
  color: var(--app-success);
  border: 1px solid var(--app-success);
}

.status-local {
  background-color: rgba(255, 214, 10, 0.15);
  color: var(--app-warning);
  border: 1px solid var(--app-warning);
}

.storage-indicator {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 8px;
  text-transform: uppercase;
}

.storage-s3 {
  background-color: rgba(48, 209, 88, 0.2);
  color: var(--app-success);
}

.storage-local {
  background-color: rgba(255, 214, 10, 0.2);
  color: var(--app-warning);
}

/* Delete button styling */
.delete-btn {
  background-color: var(--app-error);
}

.delete-btn:hover {
  background-color: #E03E35;
}

/* Play button styling */
.play-btn {
  background-color: var(--app-success);
}

.play-btn:hover {
  background-color: #28B84E;
}

/* Download button styling */
.download-btn {
  background-color: var(--app-secondary);
}

.download-btn:hover {
  background-color: #4B4ACF;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  body {
    padding: 12px;
  }
  
  .container {
    padding: 16px;
  }
  
  h1 {
    font-size: 22px;
  }
  
  .video-gallery {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  form {
    flex-direction: column;
  }
  
  .files-actions {
    flex-direction: column;
  }
  
  .files-actions button {
    width: 100%;
  }
}

/* ========== FILTER CONTROLS ========== */
.filter-controls {
  background-color: var(--app-card-secondary);
  border-radius: var(--app-border-radius);
  padding: 16px;
  margin-bottom: 16px;
}

.search-box {
  display: flex;
  align-items: center;
  background-color: var(--app-card-bg);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
  gap: 12px;
}

.search-box svg {
  color: var(--app-text-secondary);
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--app-text-primary);
  font-size: 14px;
  outline: none;
}

.search-box input::placeholder {
  color: var(--app-text-secondary);
}

.filter-row {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  color: var(--app-text-secondary);
  font-size: 13px;
  white-space: nowrap;
}

.filter-group select {
  background-color: var(--app-card-bg);
  color: var(--app-text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.filter-group select:hover {
  border-color: var(--app-primary);
}

.filter-group select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
}

.file-count {
  margin-left: auto;
  color: var(--app-text-secondary);
  font-size: 13px;
  font-weight: 500;
}

/* ========== EMPTY STATE ========== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--app-text-secondary);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 16px;
}

/* ========== NO RESULTS STATE ========== */
.no-results {
  text-align: center;
  padding: 48px 24px;
  color: var(--app-text-secondary);
}

.no-results svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.no-results p {
  font-size: 14px;
}

@media (max-width: 768px) {
  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .filter-group {
    width: 100%;
  }
  
  .filter-group select {
    flex: 1;
  }
  
  .file-count {
    margin-left: 0;
    text-align: center;
    margin-top: 8px;
  }
}
