/* =========================
   GLOBAL
   ========================= */
body {
  background-color: #111;
  color: #eee;
  margin: 0;
  padding: 0;
}

/* Remove extra spacing in container */
.container-fluid {
  padding-top: 0;
}

/* Wrap page contents */
.gallery-container {
  position: relative;
}

/* Drag-and-drop upload highlight on the media grid */
#mediaGrid.gallery-drag-over {
  outline: 2px dashed #4a9eff;
  outline-offset: 8px;
  border-radius: 0.5rem;
  background: rgba(74, 158, 255, 0.06);
}

/* =========================
   STICKY HEADER (breadcrumb + folders + media title + sort)
   ========================= */

/* Breadcrumb */
.breadcrumb {
  background: transparent;
  margin-bottom: 0.5rem;
}
.breadcrumb a {
  color: #ccc;
}
.breadcrumb a:hover {
  color: #fff;
}
.breadcrumb-item.active {
  color: #fff;
  font-weight: 600;
}

/* =========================
   FOLDERS
   ========================= */
.folder-tile {
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  border-radius: 0.5rem;
  background: #1a1a1a;
}
.folder-tile:hover {
  background: #262626;
}
.folder-thumb-placeholder {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 0.5rem;
  background: #1a1a1a;
}
.folder-icon {
  font-size: 4.5rem;
  line-height: 1;
  color: #f4b400;
  transition: opacity 0.15s ease;
}
.folder-thumb-placeholder .tile-spinner {
  display: none; /* only shown once the tile is tapped, see .is-loading below */
}

/* Instant feedback the moment a folder is tapped — the destination page
   (esp. one with lots of unthumbnailed videos) can take a moment to load,
   so show a spinner right away instead of leaving the tap looking dead. */
.folder-tile.is-loading {
  background: #262626;
}
.folder-tile.is-loading .folder-icon {
  opacity: 0.25;
}
.folder-tile.is-loading .tile-spinner {
  display: block;
}
.folder-name {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  text-align: center;
  word-break: break-all;
  padding: 0 2px;
}

/* =========================
   MEDIA GRID (images + videos)
   ========================= */
.media-tile {
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.5rem;
  background: #1a1a1a;
  display: flex;
  flex-direction: column;
}
.media-tile:hover {
  background: #262626;
}

/* Image thumbnails */
.thumb-img {
  width: 100%;
  aspect-ratio: 3 / 4;   /* change to 1 / 1 if you want square thumbs */
  border-radius: 0.5rem;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Wrapper used for image + video thumbs so we can center a spinner over
   the tile while the thumbnail (esp. video frames, generated on demand)
   is still loading. */
.thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 0.5rem;
  overflow: hidden;
  background: #1a1a1a;
}
.thumb-wrap.loaded .thumb-img { opacity: 1; }
.thumb-wrap .tile-spinner { display: block; }
.thumb-wrap.loaded .tile-spinner { display: none; }

/* Video thumbnail placeholder (used if a thumb frame can't be generated) */
.video-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 0.5rem;
  background: radial-gradient(circle at 30% 30%, #333, #000);
}

.video-thumb-icon {
  font-size: 2.5rem;
  color: #0d6efd; /* Bootstrap primary blue */
}

/* Video with real thumbnail frame */
.video-thumb-wrapper .thumb-img {
  aspect-ratio: 3 / 4;
  width: 100%;
  height: 100%;
}
.video-thumb-wrapper .video-thumb-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 0 8px rgba(0,0,0,0.8);
  z-index: 2;
}
/* If the on-demand video thumb fails (e.g. corrupt clip, ffmpeg unavailable),
   JS adds this class and hides the broken <img>, falling back to the plain
   dark placeholder look with just the play icon. */
.video-thumb-wrapper.thumb-error {
  background: radial-gradient(circle at 30% 30%, #333, #000);
}
.video-thumb-wrapper.thumb-error .thumb-img { display: none; }

/* =========================
   LOADING SPINNER
   ========================= */
.tile-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.15);
  border-top-color: #f4b400;
  animation: tile-spin 0.7s linear infinite;
  z-index: 1;
}
@keyframes tile-spin {
  to { transform: rotate(360deg); }
}


/* Document placeholders (PDF / Word / Excel) */
.doc-thumb-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 0.5rem;
  background: #1a1a1a;
}
.doc-thumb-icon {
  font-size: 4.5rem;
  line-height: 1;
}
.doc-pdf .doc-thumb-icon   { color: #dc3545; }
.doc-word .doc-thumb-icon  { color: #2b579a; }
.doc-excel .doc-thumb-icon { color: #217346; }

/* Document preview in modal */
#modalDocHtml {
  width: 100%;
  max-height: calc(100vh - 140px);
  overflow: auto;
  background: #fff;
  color: #111;
  padding: 1rem;
  border-radius: 4px;
  text-align: left;
}
#modalDocHtml table {
  border-collapse: collapse;
  font-size: 0.85rem;
}
#modalDocHtml table td, #modalDocHtml table th {
  border: 1px solid #ccc;
  padding: 3px 6px;
}

/* Filename under thumbnail */
.thumb-caption {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  text-align: center;
  word-break: break-all;
  padding: 0 2px;
}

/* =========================
   TILE SIZE (custom widths — Bootstrap's row-cols tops out at 6,
   not enough range for Tiny/Extra Small)
   ========================= */
#mediaGrid > .col { flex: 0 0 auto; position: relative; }

/* =========================
   SELECT MODE (New Folder / Delete / Rename)
   ========================= */
.select-action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #171c22;
  border: 1px solid #2a323c;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
}
.select-action-bar.d-none { display: none !important; }
.select-count {
  font-size: 13px;
  color: #8b93a1;
  font-weight: 600;
  margin-right: 4px;
}

/* Checkbox overlay — hidden unless select mode is active on the grid */
.tile-select-overlay {
  display: none;
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 5;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  border-radius: 6px;
  cursor: pointer;
}
.tile-select-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #4a9eff;
}
#mediaGrid.select-mode .tile-select-overlay { display: flex; }
/* In select mode, clicks should toggle the checkbox rather than open the
   folder/media viewer — gallery.js intercepts the click, this just stops
   the tile itself looking clickable-elsewhere while it's happening. */
#mediaGrid.select-mode .folder-tile,
#mediaGrid.select-mode .media-tile { cursor: pointer; }
#mediaGrid.select-mode .col.is-selected .folder-tile,
#mediaGrid.select-mode .col.is-selected .media-tile {
  outline: 2px solid #4a9eff;
  outline-offset: -2px;
  background: #16283f;
}

/* =========================
   PER-TILE "..." MENU (Open / Open With / Rename / Delete / Details)
   ========================= */
.tile-menu {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 6;
}
.tile-menu-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  border: none;
  border-radius: 6px;
  color: #fff;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.tile-menu-btn:hover { background: rgba(0,0,0,0.85); }
/* Hide Bootstrap's default caret-after on the toggle — the three-dots icon is enough. */
.tile-menu-btn::after { display: none; }

.col:hover .tile-menu-btn,
.tile-menu-btn:focus,
.tile-menu.show .tile-menu-btn {
  opacity: 1;
}
/* Touch devices have no hover state — keep it dimly visible so it's discoverable. */
@media (hover: none) {
  .tile-menu-btn { opacity: 0.85; }
}

.tile-menu-list {
  font-size: 13px;
  min-width: 170px;
  --bs-dropdown-link-hover-bg: #262626;
  --bs-dropdown-link-hover-color: #fff;
}

/* Select mode already has its own Rename/Delete in the action bar —
   hide the per-tile menu then to avoid two competing controls. */
#mediaGrid.select-mode .tile-menu { display: none; }

/* =========================
   DETAILS MODAL
   ========================= */
.details-list .details-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #262626;
  font-size: 13.5px;
}
.details-list .details-row:last-child { border-bottom: none; }
.details-list dt { color: #8b93a1; font-weight: 500; flex-shrink: 0; }
.details-list dd { margin: 0; text-align: right; word-break: break-word; }

.grid-tiny    > .col { width: 20%; }        /* mobile: 5 cols */
.grid-xsmall  > .col { width: 25%; }        /* mobile: 4 cols */
.grid-small   > .col { width: 33.3333%; }   /* mobile: 3 cols */
.grid-medium  > .col { width: 50%; }        /* mobile: 2 cols */
.grid-large   > .col { width: 100%; }       /* mobile: 1 col */

@media (min-width: 576px) {
  .grid-tiny    > .col { width: 14.2857%; } /* sm: 7 cols */
  .grid-xsmall  > .col { width: 16.6667%; } /* sm: 6 cols */
  .grid-small   > .col { width: 20%; }      /* sm: 5 cols */
  .grid-medium  > .col { width: 25%; }      /* sm: 4 cols */
  .grid-large   > .col { width: 50%; }      /* sm: 2 cols */
}

@media (min-width: 992px) {
  .grid-tiny    > .col { width: 10%; }      /* lg: 10 cols */
  .grid-xsmall  > .col { width: 12.5%; }    /* lg: 8 cols */
  .grid-small   > .col { width: 16.6667%; } /* lg: 6 cols */
  .grid-medium  > .col { width: 20%; }      /* lg: 5 cols */
  .grid-large   > .col { width: 33.3333%; } /* lg: 3 cols */
}

/* =========================
   SORT BUTTONS
   ========================= */
.sort-group .btn.active {
  background-color: #f8f9fa !important;
  color: #000 !important;
}

/* Keep sort buttons compact on phones */
@media (max-width: 576px) {
  .sort-group .btn {
    padding: 0.25rem 0.4rem;
    font-size: 0.65rem;
  }
}

/* =========================
   MODAL VIEWER
   ========================= */
#mediaModal .modal-dialog {
  max-width: 95vw;
  margin: 1rem auto;
}

#mediaModal .modal-content {
  background: #000;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Modal header layout */
#mediaModal .modal-header {
  flex: 0 0 auto;
  border-bottom: 1px solid #222;
  flex-direction: column;
  align-items: stretch;
}

#mediaModal .modal-title {
  font-size: 0.9rem;
  word-break: break-all; /* long filenames */
}


#mediaModal .modal-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  height: calc(100vh - 120px);
}

/* Image & Video responsive scaling in modal */
#modalImage,
#modalVideo {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #000;
}

/* Modal footer (navigation) */
#mediaModal .modal-footer {
  border-top: 1px solid #222;
}

/* Buttons inside modal */
#btnPrev,
#btnNext,
#btnFullscreen {
  min-width: 40px;
}

/* Big-media buffering spinner — shown while the full-size image/video is
   still downloading (esp. over the Cloudflare tunnel, which is slower than
   the thumbnail already shown in the grid). */
.modal-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #4a9eff;
  animation: tile-spin 0.8s linear infinite;
}

/* =========================
   MOBILE TWEAKS
   ========================= */
@media (max-width: 768px) {
  #mediaModal .modal-body {
    height: calc(100vh - 140px);
  }
}
