/* HiveOS Image Gallery v1 — styles
 * Spec: directives/agents/noa_product_designer/good_examples/2026-05-18_hiveos-chat_image-gallery-v1.md
 * Uses brandbook v2 tokens defined in assets/styles/hiveos.css. Class prefix: .gallery- */

/* ----- ROUTE SHELL --------------------------------------------------------- */

#gallery-root {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}
#gallery-root.is-visible { opacity: 1; }

/* When gallery is mounted, hide chat-mode chrome elements that don't belong
   to the gallery view. The messages container is repurposed by the controller
   (see gallery.js — it caches innerHTML and swaps). The chat surface in
   index.html is .chat-area#chatMain (older builds used .chat). */
.chat-area.gallery-mode .typing,
.chat-area.gallery-mode .input-area,
.chat-area.gallery-mode .session-bar,
.chat.gallery-mode .typing,
.chat.gallery-mode .input-area,
.chat.gallery-mode .session-bar { display: none !important; }

#btnGallery.is-active {
  color: var(--text-primary);
  background: var(--bg-surface);
}

/* ----- HEADER STRIP -------------------------------------------------------- */

.gallery-header {
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.gallery-title {
  font: 600 15px/1 var(--font-ui);
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin: 0;
}
.gallery-count {
  font: 450 13px/1 var(--font-mono);
  color: var(--text-secondary);
  margin-left: 12px;
  white-space: nowrap;
}

/* ----- TAB SWITCHER (Images / Videos) ------------------------------------- */

.gallery-tabs {
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  padding: 2px;
  height: 28px;
  display: inline-flex;
  gap: 0;
}
.gallery-tab {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 4px 12px;
  border-radius: 4px;
  font: 500 12px/1 var(--font-ui);
  color: var(--text-secondary);
  height: 24px;
  min-width: 72px;
  cursor: pointer;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}
.gallery-tab:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.gallery-tab.is-active {
  background: var(--accent);
  color: var(--text-inverse);
}

/* ----- FILTER CHIPS ------------------------------------------------------- */

.gallery-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font: 500 11px/1 var(--font-ui);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    border-color 120ms var(--ease-out),
    background   120ms var(--ease-out),
    color        120ms var(--ease-out);
  white-space: nowrap;
}
.gallery-chip:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.gallery-chip.is-active {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--text-primary);
}
.gallery-chip-chevron {
  transition: transform 200ms var(--ease-out);
}
.gallery-chip[aria-expanded="true"] .gallery-chip-chevron { transform: rotate(180deg); }

.gallery-chip-popover {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--elev-2);
  padding: 4px;
  z-index: 20;
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
.gallery-chip-popover.is-open {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.gallery-chip-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 4px;
  font: 450 13px/1.2 var(--font-ui);
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.gallery-chip-option:hover { background: rgba(255,255,255,0.04); }
.gallery-chip-option.is-selected { background: var(--accent-tint); }
.gallery-chip-option-count {
  font: 500 11px/1 var(--font-mono);
  color: var(--text-tertiary);
  margin-left: 12px;
}
.gallery-chip-option svg.check { color: var(--accent); width: 14px; height: 14px; flex-shrink: 0; }

/* ----- SEARCH ------------------------------------------------------------- */

.gallery-search-wrap {
  position: relative;
  flex: 1;
  max-width: 280px;
  margin-left: auto;
}
.gallery-search {
  width: 100%;
  height: 28px;
  padding: 0 28px 0 32px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font: 400 12px/1 var(--font-ui);
  color: var(--text-primary);
  outline: none;
  transition: border-color 150ms var(--ease-out), box-shadow 0ms;
}
.gallery-search::placeholder { color: var(--text-tertiary); }
.gallery-search:focus {
  border-color: var(--border-strong);
  box-shadow: var(--elev-focus);
}
.gallery-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  transition: color 150ms var(--ease-out);
}
.gallery-search:focus + .gallery-search-icon,
.gallery-search-wrap.has-text .gallery-search-icon { color: var(--text-secondary); }
.gallery-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: 4px;
}
.gallery-search-clear:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }
.gallery-search-wrap.has-text .gallery-search-clear { display: inline-flex; }

/* ----- GRID + CARDS ------------------------------------------------------- */

.gallery-grid-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: 80px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.gallery-batch-label {
  grid-column: 1 / -1;
  font: 500 11px/1.4 var(--font-ui);
  color: var(--text-tertiary);
  padding: 8px 0 4px 0;
  letter-spacing: 0.01em;
}

.gallery-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  transition:
    border-color 150ms var(--ease-out),
    box-shadow   150ms var(--ease-out),
    transform    150ms var(--ease-out);
}
.gallery-thumb img,
.gallery-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}
.gallery-thumb:hover {
  border-color: var(--border-strong);
  box-shadow: var(--elev-2);
  transform: scale(1.02);
}
.gallery-thumb.is-batch-member {
  border-left-color: rgba(94,106,210,0.35);
  border-left-width: 2px;
}
.gallery-thumb.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.gallery-thumb-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 35%,
    rgba(0,0,0,0) 65%, rgba(0,0,0,0.40) 100%);
  opacity: 0;
  transition: opacity 150ms var(--ease-out);
  pointer-events: none;
}
.gallery-thumb:hover .gallery-thumb-overlay,
.gallery-thumb.is-selected .gallery-thumb-overlay { opacity: 1; }

.gallery-thumb-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  background: rgba(26,29,33,0.80);
  border: 1.5px solid rgba(255,255,255,0.40);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 120ms var(--ease-out), background 120ms var(--ease-out), border-color 120ms var(--ease-out);
  cursor: pointer;
  z-index: 2;
  padding: 0;
}
.gallery-thumb:hover .gallery-thumb-checkbox,
.gallery-thumb.is-selected .gallery-thumb-checkbox { opacity: 1; }
.gallery-thumb.is-selected .gallery-thumb-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}
.gallery-thumb-checkbox svg { display: none; }
.gallery-thumb.is-selected .gallery-thumb-checkbox svg { display: block; }

.gallery-thumb-hide {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: rgba(26,29,33,0.80);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 120ms var(--ease-out), background 120ms var(--ease-out), color 120ms var(--ease-out);
  cursor: pointer;
  z-index: 2;
  border: 0;
  color: var(--text-secondary);
}
.gallery-thumb:hover .gallery-thumb-hide { opacity: 1; }
.gallery-thumb-hide:hover { background: rgba(239,68,68,0.30); color: var(--danger); }

.gallery-thumb-video-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  gap: 4px;
  font: 600 10px/1 var(--font-ui);
  color: rgba(255,255,255,0.90);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}

/* Skeleton shimmer while thumbnail loads */
.gallery-thumb.is-loading {
  background: linear-gradient(90deg,
    var(--bg-surface) 0%, var(--bg-elevated) 50%, var(--bg-surface) 100%);
  background-size: 200% 100%;
  animation: gallery-shimmer 1500ms linear infinite;
}
@keyframes gallery-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ----- BULK SELECT STICKY BAR --------------------------------------------- */

.gallery-bulk-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  height: 48px;
  padding: 0 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  box-shadow: var(--elev-3);
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.gallery-bulk-bar.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.gallery-bulk-count {
  font: 600 13px/1 var(--font-ui);
  color: var(--text-primary);
}
.gallery-bulk-divider {
  width: 1px;
  height: 20px;
  background: var(--border-default);
}
.gallery-bulk-btn {
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-md);
  font: 500 12px/1 var(--font-ui);
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}
.gallery-bulk-btn.is-primary {
  background: var(--accent);
  color: var(--text-inverse);
}
.gallery-bulk-btn.is-primary:hover { background: var(--accent-hover); }
.gallery-bulk-btn.is-secondary {
  border: 1px solid var(--border-default);
}
.gallery-bulk-btn.is-secondary:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.gallery-bulk-btn.is-ghost { color: var(--text-tertiary); padding: 0 10px; }
.gallery-bulk-btn.is-ghost:hover { color: var(--text-primary); }

/* ----- EMPTY STATES ------------------------------------------------------- */

.gallery-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 24px;
  max-width: 360px;
  margin: 64px auto;
}
.gallery-empty.is-visible { display: flex; }
.gallery-empty-icon { color: var(--text-tertiary); margin-bottom: 20px; }
.gallery-empty-title {
  font: 600 15px/1.4 var(--font-ui);
  color: var(--text-primary);
  margin: 0 0 8px 0;
}
.gallery-empty-body {
  font: 450 13px/1.5 var(--font-ui);
  color: var(--text-secondary);
  max-width: 320px;
  margin: 0 0 16px 0;
}
.gallery-empty-cta {
  height: 36px;
  padding: 0 16px;
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font: 500 13px/1 var(--font-ui);
  cursor: pointer;
  transition: border-color 150ms var(--ease-out), background 150ms var(--ease-out);
}
.gallery-empty-cta:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

/* ----- LIGHTBOX ----------------------------------------------------------- */

.gallery-lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease-out);
}
.gallery-lightbox-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 280ms var(--ease-out), transform 280ms var(--ease-out);
}
.gallery-lightbox.is-open {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.gallery-lightbox-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: min(1200px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  pointer-events: auto;
}
.gallery-lightbox-media {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.gallery-lightbox-media img,
.gallery-lightbox-media video {
  max-width: 100%;
  max-height: calc(100vh - 240px);
  object-fit: contain;
  border-radius: var(--radius-md);
  display: block;
}
.gallery-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: rgba(26,29,33,0.75);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 120ms var(--ease-out), color 120ms var(--ease-out), opacity 120ms;
}
.gallery-lightbox-nav:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.gallery-lightbox-nav.prev { left: -56px; }
.gallery-lightbox-nav.next { right: -56px; }
.gallery-lightbox-nav.is-disabled { opacity: 0.25; pointer-events: none; }
.gallery-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: rgba(26,29,33,0.80);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-tertiary);
  z-index: 41;
  transition: color 120ms var(--ease-out), background 120ms var(--ease-out);
}
.gallery-lightbox-close:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}
.gallery-lightbox-meta {
  margin-top: 16px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-start;
  gap: 24px;
  max-width: 100%;
  flex-wrap: wrap;
}
.gallery-meta-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gallery-meta-label {
  font: 600 10px/1 var(--font-ui);
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.gallery-meta-value {
  font: 450 13px/1.3 var(--font-ui);
  color: var(--text-primary);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-meta-value.is-mono {
  font: 500 11px/1.3 var(--font-mono);
  color: var(--text-secondary);
}
.gallery-meta-value.is-path {
  font: 500 11px/1.3 var(--font-mono);
  color: var(--text-tertiary);
  direction: rtl;
  text-align: left;
}
.gallery-lightbox-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.gallery-lightbox-btn {
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-md);
  font: 500 12px/1 var(--font-ui);
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out), border-color 150ms var(--ease-out);
  text-decoration: none;
}
.gallery-lightbox-btn.is-primary {
  background: var(--accent);
  color: var(--text-inverse);
}
.gallery-lightbox-btn.is-primary:hover { background: var(--accent-hover); }
.gallery-lightbox-btn.is-secondary { border: 1px solid var(--border-default); }
.gallery-lightbox-btn.is-secondary:hover { color: var(--text-primary); border-color: var(--border-strong); }
.gallery-lightbox-btn.is-ghost { color: var(--text-tertiary); }
.gallery-lightbox-btn.is-ghost:hover { color: var(--danger); }

/* ----- HIDE CONFIRM MODAL ------------------------------------------------- */

.gallery-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.64);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease-out);
}
.gallery-modal-backdrop.is-open { opacity: 1; pointer-events: auto; }
.gallery-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.97);
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 480px;
  width: calc(100vw - 48px);
  box-shadow: var(--elev-3);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms var(--ease-out), transform 280ms var(--ease-out);
}
.gallery-modal.is-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}
.gallery-modal-title {
  font: 600 15px/1.4 var(--font-ui);
  color: var(--text-primary);
  margin: 0 0 16px 0;
  padding-right: 32px;
}
.gallery-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 24px;
  height: 24px;
  background: transparent;
  border: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-modal-close:hover { color: var(--text-secondary); }
.gallery-modal-body {
  font: 450 13px/1.55 var(--font-ui);
  color: var(--text-secondary);
  margin: 0;
}
.gallery-modal-path {
  margin-top: 8px;
  font: 500 11px/1.4 var(--font-mono);
  color: var(--text-tertiary);
  direction: rtl;
  text-align: left;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.gallery-modal-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.gallery-modal-btn {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  font: 500 13px/1 var(--font-ui);
  cursor: pointer;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}
.gallery-modal-btn.is-cancel {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}
.gallery-modal-btn.is-cancel:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}
.gallery-modal-btn.is-confirm {
  background: var(--accent);
  color: var(--text-inverse);
  border: 0;
}
.gallery-modal-btn.is-confirm:hover { background: var(--accent-hover); }

/* ----- MOBILE BREAKPOINT -------------------------------------------------- */

@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  .gallery-grid-area { padding: 12px; padding-bottom: 96px; }
  .gallery-header {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 16px;
    gap: 8px;
  }
  .gallery-search-wrap { max-width: none; flex: 1; margin-left: 0; }
  .gallery-bulk-bar {
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(12px);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    justify-content: space-between;
    width: 100%;
  }
  .gallery-bulk-bar.is-visible { transform: translateY(0); }
  .gallery-thumb-checkbox { width: 28px; height: 28px; top: 6px; left: 6px; }
  .gallery-thumb-hide { width: 32px; height: 32px; }
  .gallery-lightbox { padding: 0; }
  .gallery-lightbox-inner { max-width: 100vw; max-height: 100vh; }
  .gallery-lightbox-media img,
  .gallery-lightbox-media video { max-height: calc(100vh - 200px); border-radius: 0; }
  .gallery-lightbox-nav { bottom: 80px; top: auto; transform: none; }
  .gallery-lightbox-nav.prev { left: 16px; }
  .gallery-lightbox-nav.next { right: 16px; }
  .gallery-modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    top: auto;
    bottom: 0;
    left: 0;
    transform: translateY(0);
    max-width: 100%;
    width: 100%;
  }
  .gallery-modal.is-open { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-thumb { transition: none; }
  .gallery-thumb:hover { transform: none; }
  .gallery-thumb.is-loading { animation: none; background: var(--bg-surface); }
  .gallery-bulk-bar, .gallery-lightbox, .gallery-modal,
  .gallery-lightbox-backdrop, .gallery-modal-backdrop { transition-duration: 0ms !important; }
}
