/* ============================================================
   gallery.css — Styles for galleries.html and gallery.html
   ============================================================ */

/* ── CSS Variables ── */
:root {
  --overlay-bg: 50, 50, 50;
}

/* ── Page content wrapper ── */
.gallery-page {
  padding: 20px;
}

/* ── Gallery list grid ── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.gallery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
}

.gallery-card:hover { border-color: var(--accent); }

.gallery-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.gallery-card-thumb img,
.gallery-card-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-card-thumb .gallery-thumb-placeholder {
  color: var(--muted);
  opacity: 0.3;
}

.gallery-card-thumb .gallery-thumb-placeholder .icon {
  width: 40px;
  height: 40px;
}

.gallery-card-info {
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.gallery-card-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card-count {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.gallery-card-actions {
  display: flex;
  gap: 6px;
  padding: 0 10px 10px;
  justify-content: space-between;
  align-items: center;
}

.gallery-card-type-indicator {
  display: flex;
  align-items: center;
  color: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

/* ── Gallery header bar (single gallery page) ── */
.gallery-header-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  /*margin-left: 0px;  */
}

.gallery-title-display {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gallery-title-type-indicator {
  flex-shrink: 0;
  color: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

/* ── Item grid (view mode) ── */
.gallery-item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--gallery-item-minw, 300px), 1fr));
  gap: 14px;
}

.gallery-item-grid.layout-fixed {
  grid-template-columns: repeat(auto-fill, var(--gallery-item-minw, 300px));
  justify-content: center;
}

.gallery-item-cell {
  position: relative;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
  aspect-ratio: var(--gallery-item-ratio, 1.78);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item-cell:hover { border-color: var(--accent); }

.gallery-item-cell img,
.gallery-item-cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* Placeholder for missing thumb */
.gallery-item-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--muted);
  opacity: 0.3;
}

.gallery-item-placeholder .icon {
  width: 32px;
  height: 32px;
}

/* Tooltip on hover */
.gallery-item-cell .gallery-item-tooltip {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(var(--overlay-bg), 0.75);
  padding: 2px 10px;
  pointer-events: none;
}

.gallery-item-cell:hover .gallery-item-tooltip { display: block; }

.gallery-item-tooltip-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-item-tooltip-desc {
  font-size: 0.55rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* ── Media modal (fullscreen overlay) ── */
.gallery-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5000;
}

.gallery-modal-backdrop.open { display: flex; }

.gallery-modal-inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gallery-modal-close {
  position: absolute;
  top: -30px;
  right: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: border-color 0.15s, color 0.15s;
}

.gallery-modal-close:hover { border-color: var(--accent); color: var(--accent); }

.gallery-modal-download { /* Download Button */
  position: absolute;
  top: -30px;
  right: 34px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: border-color 0.15s, color 0.15s;
}

.gallery-modal-download-icon-filled { display: none; }

.gallery-modal-download:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.gallery-modal-download:hover .gallery-modal-download-icon-outline { display: none; }
.gallery-modal-download:hover .gallery-modal-download-icon-filled  { display: block; }

.gallery-modal-download:active {
  border-color: var(--accent);
  color: var(--accent);
}

.gallery-modal-meta {
  text-align: center;
  width: 100%;
}

.gallery-modal-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.gallery-modal-desc {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 4px;
}

.gallery-modal-media {
  max-width: 90vw;
  max-height: calc(90vh - 80px);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-modal-media img,
.gallery-modal-media video {
  max-width: 100%;
  max-height: calc(90vh - 80px);
  border-radius: 8px;
  display: block;
}

.tag-filter-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 10px;
  opacity: 0.5;
}

.tag-input-box {
  min-height: unset;
  width: 260px;
}

.tag-input-body {
  padding: 10px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tag-input-error {
  font-size: 0.75rem;
  color: var(--danger);
  min-height: 1em;
  line-height: 1.4;
}

/* ── Tag filter button (narrow 3-dot button) ── */
.icon-button--filter {
  padding-left: 4px;
  padding-right: 4px;
  width: 18px;
  justify-content: center;
}

.icon-button--filter .icon-filter-dots {
  width: 7px;
  height: 20px;
  stroke-width: 0; /* circles use fill/stroke directly in SVG */
}

.icon-button--filter.filter-active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 124, 255, 0.3);
}

/* ── Tag filter modal ── */
.tag-filter-box {
  min-height: unset;
}

.tag-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.12s;
  border-radius: 6px;
  min-width: 0;
}

.tag-filter-row:hover { background: var(--surface2); }

.tag-filter-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}

.tag-filter-label {
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.tag-filter-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
}

/* ── Segmented toggle (Global / Gallery pill selector) ── */
.seg-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 2px;
}

.seg-toggle-btn {
  flex: 1;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

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

/* ── Tag-apply sub-header (view mode) ── */
.tag-apply-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  z-index: 90;
  flex-wrap: wrap;
}

/* Tag-apply dropdown — mirrors nav-menu pattern */
.tag-apply-menu {
  position: relative;
}

.tag-apply-menu-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.tag-apply-menu-btn:hover { border-color: var(--accent); color: var(--text); }

.tag-apply-menu-btn.has-selection {
  border-color: var(--accent);
  color: var(--text);
}

.tag-apply-menu-btn .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--muted);
}

.tag-apply-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-y: auto;
  max-height: 260px;
  z-index: 500;
  min-width: 150px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.tag-apply-menu.open .tag-apply-dropdown { display: block; }

.tag-apply-dropdown-section {
  padding: 4px 0;
}

.tag-apply-dropdown-header {
  padding: 4px 12px 2px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.7;
}

.tag-apply-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 7px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  transition: background 0.12s, color 0.12s;
}

.tag-apply-option:hover { background: var(--surface2); color: var(--text); }
.tag-apply-option.selected { color: var(--accent); }

.tag-apply-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
  opacity: 0.5;
}

/* Active tag-apply button state */
.icon-button--tag-apply.tag-apply-active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 124, 255, 0.3);
}

/* Tag-apply selection overlay on item cells */
.gallery-item-cell.tag-apply-mode {
  cursor: pointer;
}

.gallery-item-cell.tag-apply-tagged {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Force the hover tooltip visible when tagged */
.gallery-item-cell.tag-apply-tagged .gallery-item-tooltip {
  display: block;
}

/* Checkmark badge */
.tag-apply-check {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.tag-apply-check .icon {
  width: 11px;
  height: 11px;
  color: #fff;
}

.gallery-item-cell.tag-apply-tagged .tag-apply-check {
  display: flex;
}

/* ── Edit mode — item stack ── */
.gallery-edit-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gallery-edit-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.gallery-edit-item.pending-delete {
  background: rgba(var(--color-red), 0.08);
  border-color: rgba(var(--color-red), 0.4);
}

.gallery-edit-item.item-hidden {
  opacity: 0.4;
}

/* Drag handle */
.gallery-drag-handle {
  color: var(--muted);
  cursor: grab;
  opacity: 0.4;
  display: flex;
  align-items: center;
  padding-top: 2px;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.gallery-drag-handle:hover { opacity: 1; }
.gallery-drag-handle:active { cursor: grabbing; }
.gallery-drag-handle .icon { width: 16px; height: 16px; }

/* Thumb preview in edit row */
.gallery-edit-thumb {
  width: 80px;
  min-height: 54px;
  height: auto;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface2);
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-edit-thumb img,
.gallery-edit-thumb video {
  width: 100%;
  height: auto;
  display: block;
}

.gallery-edit-thumb .gallery-item-placeholder { opacity: 0.25; }
.gallery-edit-thumb .gallery-item-placeholder .icon { width: 20px; height: 20px; }

/* Edit row fields */
.gallery-edit-fields {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.gallery-edit-row-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

/* Drag drop indicators */
.gallery-edit-item.drag-over-before {
  border-top: 3px solid var(--accent);
}
.gallery-edit-item.drag-over-after {
  border-bottom: 3px solid var(--accent);
}

/* View-mode drag handle (tag-apply / reorder session) */
.view-drag-handle {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  background: rgba(0,0,0,0.45);
  border-radius: 4px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: grab;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
  pointer-events: none;
}

.view-drag-handle .icon {
  width: 12px;
  height: 12px;
  color: #fff;
}

.view-drag-handle:active { cursor: grabbing; }

/* Show handle when tag-apply mode is active */
.gallery-item-cell.tag-apply-mode .view-drag-handle {
  display: flex;
  pointer-events: auto;
}

.gallery-item-cell.tag-apply-mode:hover .view-drag-handle {
  opacity: 1;
}

/* Grid drag indicators — left/right since items flow in a grid */
.gallery-item-cell.drag-over-before {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: -4px 0 0 0 var(--accent);
}

.gallery-item-cell.drag-over-after {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: 4px 0 0 0 var(--accent);
}
.card-action-btn.cover-active {
  border-color: rgba(var(--color-orange), 0.7);
  color: var(--warning);
  background: rgba(var(--color-orange), 0.1);
}

/* ── Tag management panel (edit mode) ── */
.gallery-tag-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.gallery-tag-panel-label {
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ── Edit mode toolbar ── */
.gallery-edit-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Loading / empty states ── */
.gallery-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gallery-spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Newly uploaded item highlight (session-only, class never saved) ── */
.gallery-edit-item.item-new {
  background: rgba(var(--color-blue), 0.08);
  border-color: rgba(var(--color-blue), 0.4);
}

/* ── Missing thumbnail warning ── */
.gallery-edit-item.thumb-missing {
  background: rgba(var(--color-orange), 0.08);
  border-color: rgba(var(--color-orange), 0.4);
}

/* ── Warning filter ── */
#warningFilterBtn.active {
  opacity: 1;
  color: var(--warning);
  border-color: var(--warning);
}

.gallery-edit-stack.filter-warnings .gallery-edit-item[data-has-warning="0"] {
  display: none;
}

.gallery-edit-thumb.thumb-missing-icon {
  color: var(--warning);
}

/* ── Edit item status indicators ── */
.edit-status-indicators {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.edit-status-row {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
  white-space: nowrap;
  cursor: default;
}

.edit-status-row.edit-status-empty,
.edit-status-row.edit-status-missing {
  color: var(--warning);
}

.edit-status-icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.edit-status-empty-box {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

