/* Media Gallery panel styles */

.gallery-backdrop {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100dvh;
  z-index: 299; background: rgba(0, 0, 0, 0.65);
}

.gallery-panel {
  position: fixed; top: 0; right: 0; width: 720px; max-width: 98vw; height: 100dvh;
  z-index: 300; background: var(--color-base);
  border-left: 2px solid var(--color-border-strong);
  display: flex; flex-direction: column;
  box-shadow: -6px 0 32px rgba(0, 0, 0, 0.6);
}

.gallery-inner {
  display: flex; flex-direction: column; height: 100%; overflow: hidden;
}

/* Header */
.gallery-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--color-border-strong);
  background: var(--color-panel);
  flex-shrink: 0;
}
.gallery-header > span { font-weight: 600; font-size: 1rem; color: var(--color-text-bright); }
.gallery-header button {
  background: none; border: none; color: var(--color-text-muted);
  cursor: pointer; font-size: 1.1rem; padding: 2px 4px;
  border-radius: 4px; transition: color 0.15s;
}
.gallery-header button:hover { color: #fff; }
#gallery-close { font-size: 1.4rem; line-height: 1; }

/* Filter bar */
.gallery-filter-bar {
  display: flex; gap: 6px; padding: 10px 18px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-panel);
  flex-shrink: 0;
}
.gallery-filter-btn {
  background: var(--color-bg-tertiary); border: 1px solid var(--color-border-strong); color: var(--color-text-muted);
  padding: 3px 12px; border-radius: 20px; font-size: 0.78rem;
  cursor: pointer; transition: all 0.15s;
}
.gallery-filter-btn:hover { background: var(--color-border-strong); color: var(--color-text-bright); }
.gallery-filter-btn.active {
  background: #1f6feb; border-color: #1f6feb; color: #fff;
}

/* Scrollable grid container */
.media-gallery-container {
  flex: 1; overflow-y: auto; padding: 16px 18px;
}
.media-gallery-container::-webkit-scrollbar { width: 6px; }
.media-gallery-container::-webkit-scrollbar-track { background: transparent; }
.media-gallery-container::-webkit-scrollbar-thumb { background: var(--color-border-strong); border-radius: 3px; }

/* Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

/* Individual card */
.gallery-card {
  background: var(--color-panel); border: 1px solid var(--color-border-strong);
  border-radius: 10px; overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}
.gallery-card:hover { border-color: var(--color-accent-link); transform: translateY(-2px); }

.gallery-card-thumb {
  width: 100%; height: 140px; object-fit: cover; display: block;
}
.gallery-card-thumb-placeholder {
  width: 100%; height: 140px; display: flex;
  align-items: center; justify-content: center;
  background: var(--color-base); font-size: 2.5rem;
}
.gallery-card video { width: 100%; height: 140px; object-fit: cover; display: block; }

.gallery-card-body { padding: 8px 10px 10px; }
.gallery-card-name {
  font-size: 0.68rem; color: var(--color-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 3px;
}
.gallery-card-meta { font-size: 0.62rem; color: var(--color-text-muted); }
.gallery-card-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 7px;
}

/* Storage badges */
.badge-azure {
  background: #0078d4; color: #fff;
  font-size: 0.62rem; padding: 2px 6px; border-radius: 4px;
}
.badge-local {
  background: var(--color-border-strong); color: var(--color-text-muted);
  font-size: 0.62rem; padding: 2px 6px; border-radius: 4px;
}

/* Card actions group */
.gallery-card-actions {
  display: flex; gap: 4px; align-items: center;
}

/* Download button */
.gallery-download-btn {
  background: #238636; border: 1px solid #2ea043; color: #fff;
  font-size: 0.6rem; padding: 2px 7px; border-radius: 4px;
  cursor: pointer; transition: background 0.15s;
  display: inline-flex; align-items: center; gap: 3px;
}
.gallery-download-btn:hover { background: #2ea043; }

/* Template button */
.gallery-template-btn {
  background: rgba(88,166,255,0.12); border: 1px solid rgba(88,166,255,0.3); color: var(--color-accent-link, #58a6ff);
  font-size: 0.6rem; padding: 2px 7px; border-radius: 4px;
  cursor: pointer; transition: all 0.15s;
}
.gallery-template-btn:hover { background: rgba(88,166,255,0.25); border-color: #58a6ff; }

/* Delete button */
.gallery-delete-btn {
  background: var(--color-btn-danger-bg); border: 1px solid var(--color-btn-danger-border); color: var(--color-error);
  font-size: 0.6rem; padding: 2px 7px; border-radius: 4px;
  cursor: pointer; transition: all 0.2s;
  min-width: 20px; text-align: center;
}
.gallery-delete-btn:hover { background: var(--color-btn-danger-border); }
.gallery-delete-btn.delete-confirm-1 {
  border-color: #f85149; color: #f85149;
  min-width: 42px; font-weight: 600;
}
.gallery-delete-btn.delete-confirm-2 {
  background: #da3633; border-color: #da3633; color: #fff;
  min-width: 52px; font-weight: 700;
}

/* Stats bar */
.gallery-stats {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: 0.73rem; color: var(--color-text-muted);
  padding: 0 0 12px; margin-bottom: 4px;
  border-bottom: 1px solid var(--color-border);
}
.gallery-stats .stat { display: flex; align-items: center; gap: 4px; }

/* Empty state */
.gallery-empty {
  text-align: center; padding: 48px 20px; color: var(--color-text-muted);
}
.gallery-empty-icon { font-size: 3rem; margin-bottom: 12px; }
.gallery-empty-text { font-size: 0.85rem; }

/* Loading */
.gallery-loading {
  text-align: center; padding: 32px; color: var(--color-text-muted); font-size: 0.85rem;
}

/* Lightbox overlay for image preview */
.gallery-lightbox {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.88);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.gallery-lightbox img {
  max-width: 90vw; max-height: 90vh;
  border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,0.8);
}
/* Lightbox toolbar */
.gallery-lightbox-toolbar {
  position: absolute; top: 16px; right: 20px;
  display: flex; gap: 8px; align-items: center; z-index: 501;
}
.gallery-lightbox-dl,
.gallery-lightbox-template {
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25);
  color: #fff; font-size: 0.82rem; font-weight: 600;
  padding: 6px 14px; border-radius: 8px;
  cursor: pointer; transition: background 0.15s;
  backdrop-filter: blur(8px);
  display: inline-flex; align-items: center; gap: 5px;
}
.gallery-lightbox-dl:hover { background: #238636; border-color: #2ea043; }
.gallery-lightbox-template:hover { background: rgba(88,166,255,0.35); border-color: #58a6ff; }
.gallery-lightbox-close {
  background: none; border: none; color: #fff;
  font-size: 2rem; cursor: pointer; line-height: 1;
  min-width: 44px; min-height: 44px;
}

@media (max-width: 760px) {
  .gallery-panel {
    width: 100vw; height: 100dvh;
    border-left: none; border-radius: 0;
  }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .gallery-header {
    padding-top: max(14px, env(safe-area-inset-top));
  }
  .gallery-header button {
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
  }
  .gallery-filter-btn {
    min-height: 36px; padding: 6px 14px; font-size: 0.82rem;
    -webkit-tap-highlight-color: transparent;
  }
  .gallery-filter-bar {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; flex-wrap: nowrap;
  }
  .gallery-filter-bar::-webkit-scrollbar { display: none; }
  .gallery-delete-btn,
  .gallery-download-btn,
  .gallery-template-btn {
    min-width: 36px; min-height: 36px; padding: 6px 10px; font-size: 0.72rem;
  }
  .gallery-lightbox-toolbar {
    top: max(16px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
  }
  .gallery-lightbox-close {
    top: auto; right: auto;
  }
  .media-gallery-container {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .gallery-card-thumb,
  .gallery-card-thumb-placeholder,
  .gallery-card video { height: 120px; }
  .gallery-stats { font-size: 0.68rem; gap: 8px; }
}

/* Very small phone gallery grid */
@media (max-width: 380px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
  .gallery-card-thumb,
  .gallery-card-thumb-placeholder,
  .gallery-card video { height: 100px; }
  .gallery-card-body { padding: 6px 8px 8px; }
  .gallery-card-name { font-size: 0.62rem; }
}
