/* 
 * File: core/css/gallery.css
 * Purpose: Horizontal scroll snap gallery on desktop, vertical 2-column cards on mobile.
 */

:root {
  --scrollbar-width: 12px;
}

/* Gallery Widget Overrides */
.gallery-container {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.gallery-slider-stage {
  display: none;
}

.gallery-thumbnail-area {
  display: contents;
}

@media (min-width: 768px) {
  /* .gallery-thumbnail-area display: contents moved to base */

  .gallery-container:not(:has(.gallery-empty-state:not([hidden]))) {
    gap: 8px;
  }

  .gallery-slider-stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-header);
    box-shadow: var(--panel-shadow);
  }

  .gallery-slider-image {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    display: grid;
    place-items: center;
    padding: 16px;
    background: color-mix(in srgb, var(--bg-main) 75%, transparent);
  }

  .gallery-slider-image img {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: none;
    max-height: none;
    object-fit: contain;
    transform: translate(-50%, -50%);
    transition: transform 0.2s ease;
  }

  .gallery-slider-properties {
    flex: 0 0 480px;
    display: flex;
    min-width: 0;
    padding: 10px;
    box-sizing: border-box;
    flex-direction: column;
    gap: 10px;
    border-left: 1px solid var(--border-color);
    height: 100%;
  }

  .gallery-slider-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .gallery-slider-fields-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .gallery-slider-field {
    display: flex;
    align-items: baseline;
    gap: 8px;
    background: var(--bg-secondary);
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
  }

  .gallery-slider-field span {
    flex: 0 0 80px;
    color: var(--accent-color);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
  }

  .gallery-slider-field strong,
  .gallery-slider-description p {
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
  }

  .gallery-slider-field strong {
    min-width: 0;
  }

  .gallery-slider-description {
    flex: 1 1 auto;
    overflow-y: auto;
  }

  .gallery-slider-description p {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
  }

  .gallery-slider-actions {
    display: flex;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
  }

  .gallery-slider-action {
    display: inline-flex;
    min-height: 38px;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-main);
    color: var(--text-main);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
  }

  .gallery-slider-action:hover,
  .gallery-slider-action.is-looping {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: var(--btn-active-text);
  }

  .panel-wrapper {
    flex: 0 0 157px;
    height: 157px;
    gap: 10px;
    padding: 3px 2px 22px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
  }

  .panel {
    flex: 0 0 var(--thumbnail-width, 113px);
    width: var(--thumbnail-width, 113px);
    height: 127px;
    cursor: pointer;
  }

  .panel-image {
    height: calc(100% - 26px);
  }

  .panel-data {
    display: flex;
    height: 26px;
    min-height: 26px;
    padding: 4px 6px;
  }

  .panel-title {
    font-size: 0.7rem;
    line-height: 1.2;
    margin: 0;
    color: var(--text-main);
  }

  .panel.is-selected {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  }
}

.panel-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: row;
  gap: 12px;
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
  scrollbar-width: auto;
  scrollbar-color: var(--border-color) var(--bg-outer);
  width: auto;
}

/* Scrollbar Customization */
.panel-wrapper::-webkit-scrollbar { height: 16px; }
.panel-wrapper::-webkit-scrollbar-track { background: var(--bg-outer); border-radius: 8px; }
.panel-wrapper::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 8px; }
.panel-wrapper::-webkit-scrollbar-thumb:hover { background: var(--accent-color); }

.gallery-empty-state {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg-main) 88%, transparent);
}

.gallery-empty-state[hidden] {
  display: none;
}

.gallery-empty-state-card {
  width: min(400px, 100%);
  padding: 24px;
  box-sizing: border-box;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-header);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
  text-align: center;
}

.gallery-empty-state-card h2 {
  margin: 0 0 8px;
  color: var(--accent-color);
  font-size: 1.2rem;
}

.gallery-empty-state-card p {
  margin: 0;
}

.gallery-empty-criteria {
  display: grid;
  gap: 6px;
  margin: 18px 0;
  text-align: left;
}

.gallery-empty-criteria div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 10px;
  border-radius: 4px;
  background: var(--bg-main);
}

.gallery-empty-criteria dt {
  color: var(--accent-color);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.gallery-empty-criteria dd {
  margin: 0;
  color: var(--text-main);
  text-align: right;
}

.gallery-empty-rebuild-btn {
  min-height: 38px;
  padding: 8px 18px;
  border: 1px solid var(--accent-color);
  border-radius: 6px;
  background: var(--accent-color);
  color: var(--btn-active-text);
  cursor: pointer;
  font-weight: 600;
}

/* Desktop Minimalist Panel (Vertical Stack: Image Top, Title Below) */
.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  flex: 0 0 auto;
  scroll-snap-align: start;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  padding: 0;
  width: auto;
}

.panel-image {
  flex: 1 1 auto;
  min-height: 0;
  height: calc(100% - 38px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  overflow: hidden;
  padding: 0;
  margin: 0;
  min-width: 0; 
  max-width: 100%;
  width: auto;
  position: relative; 
}

.img-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  background: transparent;
  cursor: pointer;
}

.panel-image img {
  height: 100%;
  width: auto;
  object-fit: contain;
  display: block;
}

.panel-data {
  flex: 0 0 auto;
  height: 38px;
  padding: 6px 10px;
  box-sizing: border-box;
  background: var(--bg-main);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.panel-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* Hidden by default on desktop - minimalist title only */
.panel-mobile-meta {
  display: none;
}

/* Navigation Buttons */
.gallery-nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-header);
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.gallery-nav-prev {
  left: 12px;
}

.gallery-nav-next {
  right: 12px;
}

.gallery-nav-btn:hover:not(:disabled) {
  background: var(--bg-main);
  border-color: var(--accent-color);
  color: var(--accent-color);
  transform: translateY(-50%) scale(1.08);
}

.gallery-nav-btn:active:not(:disabled) {
  transform: translateY(-50%) scale(0.95);
}

.gallery-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Mobile: Vertical List of Two-Column Cards (Picture Left 45%, Property Panel Right 55%) */
@media (max-width: 767px) {
  .gallery-container {
    height: calc(100dvh - 140px);
  }
  .panel-wrapper {
    flex-direction: column !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    gap: 12px;
    padding: 8px !important;
    width: 100%;
    height: 100%;
    flex: 1 1 auto;
    min-height: 0;
    scroll-snap-type: none !important;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  .gallery-thumbnail-controls {
    display: none !important;
  }
  .panel {
    flex-direction: row !important;
    width: 100% !important;
    height: 140px !important;
    flex: 0 0 140px !important;
    border-radius: 6px;
  }
  .panel-image {
    width: 45% !important;
    min-width: 45% !important;
    height: 100% !important;
    border-right: 1px solid var(--border-color);
    border-radius: 6px 0 0 6px;
  }
  .panel-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    border-radius: 6px 0 0 6px;
  }
  .panel-data {
    width: 55% !important;
    height: 100% !important;
    border-top: none;
    border-left: 1px solid var(--border-color);
    padding: 10px 12px;
    justify-content: center;
  }
  .panel-mobile-meta {
    display: flex !important;
    flex-direction: column;
    gap: 2px;
    font-size: 0.72rem;
    opacity: 0.8;
  }
  .panel-title {
    text-align: left;
  }
  .gallery-nav-btn {
    display: none;
  }
}

/* Landscape Mobile Layout */
@media (orientation: landscape) and (max-height: 600px) {
  .panel {
    flex-direction: row;
    width: 80vw;
  }
  .panel-image {
    width: 45%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    border-radius: 6px 0 0 6px;
  }
  .panel-data {
    width: 55% !important;
    height: 100% !important;
    border-top: none;
    border-left: 1px solid var(--border-color);
    padding: 10px 12px;
    justify-content: center;
  }
  .panel-mobile-meta {
    display: flex !important;
    flex-direction: column;
    gap: 2px;
    font-size: 0.72rem;
    opacity: 0.8;
  }
  .panel-title {
    text-align: center;
  }
  .gallery-nav-btn {
    display: none;
  }
}

/* Modal Styling */
.gallery-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.gallery-modal-overlay.active {
  display: flex;
}
.gallery-modal {
  background: var(--bg-header);
  border-radius: 6px;
  width: 90vw;
  height: 85vh;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  position: relative;
  display: flex;
  flex-direction: row;
  transition: width 0.3s ease;
  overflow: hidden;
  padding: 0;
}
.gallery-modal-close-x {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 1.75rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-main);
  z-index: 1000;
}
.gallery-modal-body {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.gallery-modal-image-col {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.03);
  overflow: hidden;
  padding: 16px;
}
#modalImg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.gallery-modal-data-col {
  flex: 0 0 380px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 1px solid var(--border-color);
  padding: 24px;
  box-sizing: border-box;
}

/* Modal Form Controls */
.gallery-modal-form-group {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
}
.gallery-modal-desc-group {
  flex: 1 1 auto;
  min-height: 40px;
}
.gallery-modal-form-group label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent-color);
  margin: 0 0 2px 0;
}
.gallery-modal-data-col input,
.gallery-modal-data-col textarea {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 6px;
  width: 100%;
  font-size: 0.85rem;
  box-sizing: border-box;
}
.gallery-modal-data-col input {
  height: 30px;
}
.gallery-modal-form-row {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}
.gallery-modal-form-row .gallery-modal-form-group {
  flex: 1 1 0;
  min-width: 0;
}
#modalDesc {
  flex: 1 1 auto;
  min-height: 40px;
  resize: none;
  overflow-y: auto;
}
.gallery-modal-footer {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border-color);
}
.gallery-modal-btn-close {
  flex: 0 0 calc(50% - 6px);
  width: calc(50% - 6px);
  min-width: 0;
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  height: 40px !important;
}
.gallery-modal-btn-loop {
  flex: 0 0 calc(50% - 6px);
  width: calc(50% - 6px);
  min-width: 0;
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  border-radius: 6px;
  height: 40px !important;
}
.gallery-modal-btn-loop.is-looping {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.gallery-modal-btn-download {
  flex: 0 0 calc(50% - 6px);
  width: calc(50% - 6px);
  min-width: 0;
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  border-radius: 6px;
  height: 40px !important;
  text-decoration: none;
}

.gallery-slider-download.is-protected,
.gallery-modal-btn-download.is-protected {
  cursor: not-allowed !important;
  opacity: 0.6;
}

.gallery-slider-download.is-archived,
.gallery-modal-btn-download.is-archived {
  opacity: 0.3;
  pointer-events: none;
  cursor: default;
}


/* Filter Modal */
.gallery-filter-modal {
  width: min(400px, 90vw);
  height: auto;
  max-height: 90vh;
  padding: 16px;
}
.filter-modal-title {
  margin-top: 0;
  color: var(--accent-color);
  font-size: 1.2rem;
}
.filter-modal-body {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 5px 0;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.filter-group strong {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-main);
}
.filter-group select {
  width: 100%;
  padding: 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-main);
  color: var(--text-main);
  font-size: 0.9rem;
}
.filter-modal-footer {
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}
.filter-reset-btn {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

/* Landscape Mobile Modal Fixes */
@media (orientation: landscape) and (max-height: 600px) {
  .gallery-modal { width: 96vw; height: 94vh; padding: 10px 16px; }
  .gallery-modal-body { gap: 10px; overflow-y: auto; }
  .gallery-modal-close-x { top: 5px; right: 8px; font-size: 1.5rem; }
}

/* Maximized Desktop Grid Layout Mode */
@media (min-width: 768px) {
  body.layout-maximized .gallery-slider-stage {
    display: none;
  }

  body.layout-maximized .gallery-container {
    height: 100% !important;
    min-height: 0;
    overflow: hidden !important;
  }

  body.layout-maximized .panel-wrapper {
    display: flex !important;
    flex-wrap: wrap !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-content: flex-start !important;
    gap: 16px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scroll-snap-type: none !important;
    padding: 24px 32px !important;
    height: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  body.layout-maximized .panel {
    flex: 1 1 240px !important;
    min-width: 200px !important;
    max-width: 300px !important;
    height: 280px !important;
    flex-direction: column !important;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  }

  body.layout-maximized .panel-image {
    width: 100% !important;
    height: calc(280px - 38px) !important;
    flex: 1 1 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
  }

  body.layout-maximized .panel-image img {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
  }

  body.layout-maximized .panel-data {
    height: 38px !important;
    flex: 0 0 38px !important;
    width: 100% !important;
    border-top: 1px solid var(--border-color) !important;
    border-left: none !important;
  }

  body.layout-maximized .panel-mobile-meta {
    display: none !important;
  }

  body.layout-maximized .gallery-nav-btn {
    display: none !important;
  }

  body.layout-maximized .panel-wrapper::-webkit-scrollbar {
    width: 14px;
    height: auto;
  }
}

@media (min-width: 768px) {
  body:not(.layout-maximized) .gallery-thumbnail-area {
    flex: 0 0 157px;
    position: relative;
    display: block;
    min-width: 0;
    margin-top: 8px;
  }

  body:not(.layout-maximized) .panel-wrapper {
    width: 100%;
    height: 157px;
    margin-top: 0;
    gap: 10px;
    padding: 3px 2px 22px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
  }

  body:not(.layout-maximized) .panel {
    flex: 0 0 var(--thumbnail-width, 113px);
    width: var(--thumbnail-width, 113px);
    height: 127px;
    cursor: pointer;
  }

  body:not(.layout-maximized) .panel-image {
    height: calc(100% - 26px);
  }

  body:not(.layout-maximized) .panel-data {
    display: flex;
    height: 26px;
    min-height: 26px;
    padding: 4px 6px;
  }

  body:not(.layout-maximized) .panel-title {
    font-size: 0.7rem;
    line-height: 1.2;
    margin: 0;
    color: var(--text-main);
  }

  body:not(.layout-maximized) .panel.is-selected {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  }

  body:not(.layout-maximized) .gallery-nav-btn {
    position: static;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    z-index: 1;
    transform: none;
  }

  body:not(.layout-maximized) .gallery-thumbnail-controls {
    display: flex;
    gap: 6px;
    position: absolute;
    right: 10px;
    bottom: 27px;
    z-index: 100;
    padding: 4px;
    border: 1px solid #3f3f3f;
    border-radius: 999px;
    background: #4a4a4a;
  }

  [data-theme="dark"] body:not(.layout-maximized) .gallery-thumbnail-controls {
    border-color: #000;
    background: #000;
  }

  body:not(.layout-maximized) .gallery-nav-btn:hover:not(:disabled) {
    transform: none;
  }
}
