/*
 * Gallery Post Modal - Instagram Style
 * Uses rails_modal_manager for modal management
 */

/* Modal Content Layout */
.gallery-modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

@media (min-width: 768px) {
  .gallery-modal-content {
    flex-direction: row;
    height: 100%;
  }
}

/* Left Side - Media Viewer */
.gallery-modal-media {
  position: relative;
  background: #000;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Mobile: Fixed aspect ratio */
@media (max-width: 767px) {
  .gallery-modal-media {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 50vh;
    transition: max-height 0.3s ease, height 0.3s ease;
  }
}

/* Desktop: 60% width */
@media (min-width: 768px) {
  .gallery-modal-media {
    width: 60%;
    height: 100%;
    min-height: 400px;
  }
}

/* Media Slides Container */
.gallery-media-slides {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.gallery-media-slides.dragging {
  transition: none;
}

/* Individual Slide */
.gallery-media-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-media-slide img,
.gallery-media-slide video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.gallery-media-slide img {
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
}

/* Media Counter Badge */
.gallery-media-counter {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 12px;
  border-radius: 12px;
  z-index: 10;
}

/* Navigation Arrows */
.gallery-media-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.gallery-media-nav:hover {
  background: white;
  transform: translateY(-50%) scale(1.05);
}

.gallery-media-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

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

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

.gallery-media-nav svg {
  width: 20px;
  height: 20px;
  color: #111827;
}

/* Hide nav on mobile - use swipe instead */
@media (max-width: 767px) {
  .gallery-media-nav {
    display: none;
  }
}

/* Dot Indicators */
.gallery-media-indicators {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 10;
}

.gallery-media-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: all 0.2s;
}

.gallery-media-indicator:hover {
  background: rgba(255, 255, 255, 0.8);
}

.gallery-media-indicator.active {
  background: white;
  transform: scale(1.2);
}

/* Sliding window indicators for many items */
.gallery-media-indicators.many .gallery-media-indicator {
  width: 6px;
  height: 6px;
}

.gallery-media-indicators.many .gallery-media-indicator.adjacent {
  width: 5px;
  height: 5px;
  opacity: 0.7;
}

.gallery-media-indicators.many .gallery-media-indicator.far {
  width: 4px;
  height: 4px;
  opacity: 0.4;
}

/* No Media Placeholder */
.gallery-media-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  padding: 40px;
}

.gallery-media-placeholder svg {
  width: 64px;
  height: 64px;
  color: #9ca3af;
  margin-bottom: 12px;
}

/* Right Side - Info Panel */
.gallery-modal-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  overflow: hidden;
  min-width: 0;
  min-height: 0; /* Important for flex scrolling */
}

@media (min-width: 768px) {
  .gallery-modal-panel {
    width: 40%;
    height: 100%; /* Explicit height for desktop */
    border-left: 1px solid #e5e7eb;
  }
}

/* Panel Header */
.gallery-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.gallery-panel-author {
  display: flex;
  align-items: center;
  gap: 10px;
}

.gallery-panel-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #dbeafe;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #2563eb;
  font-weight: 700;
  font-size: 14px;
}

.gallery-panel-author-info {
  display: flex;
  flex-direction: column;
}

.gallery-panel-author-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #111827;
}

.gallery-panel-level {
  font-size: 10px;
  padding: 2px 6px;
  background: #dbeafe;
  color: #2563eb;
  border-radius: 4px;
  font-weight: 500;
}

.gallery-panel-date {
  font-size: 12px;
  color: #6b7280;
}

/* More Menu Button */
.gallery-panel-more {
  position: relative;
}

.gallery-panel-more-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #6b7280;
  transition: background 0.2s;
}

.gallery-panel-more-btn:hover {
  background: #f3f4f6;
}

/* Dropdown Menu */
.gallery-panel-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 50;
  overflow: hidden;
}

.gallery-panel-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: #374151;
  text-align: left;
  text-decoration: none;
  transition: background 0.15s;
}

.gallery-panel-menu-item:hover {
  background: #f3f4f6;
}

.gallery-panel-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.gallery-panel-menu-item.danger {
  color: #dc2626;
}

.gallery-panel-menu-item.warning {
  color: #d97706;
}

/* Panel Content - Scrollable */
.gallery-panel-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0; /* Critical for flex scrolling - allows shrinking below content size */
}

/* Post Content */
.gallery-panel-post-content {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
  line-height: 1.6;
  color: #374151;
}

/* Post Content Text - Collapsible */
.gallery-panel-post-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.gallery-panel-post-text.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

/* See More Button */
.gallery-post-see-more {
  display: inline-block;
  margin-top: 8px;
  padding: 0;
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s;
}

.gallery-post-see-more:hover {
  color: #374151;
}

.gallery-post-see-more.hidden {
  display: none;
}

/* Comments Section */
.gallery-panel-comments {
  padding: 12px 16px;
}

.gallery-panel-comments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.gallery-panel-comments-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #111827;
}

.gallery-panel-comments-title svg {
  width: 18px;
  height: 18px;
}

.gallery-panel-comments-sort {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #6b7280;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.gallery-panel-comments-sort:hover {
  background: #f3f4f6;
}

/* Comment Item */
.gallery-comment-item {
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
}

.gallery-comment-item:last-child {
  border-bottom: none;
}

.gallery-comment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.gallery-comment-author {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gallery-comment-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
}

.gallery-comment-name {
  font-size: 13px;
  font-weight: 500;
  color: #111827;
}

.gallery-comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #9ca3af;
}

.gallery-comment-content {
  font-size: 14px;
  color: #374151;
  line-height: 1.5;
  margin-bottom: 8px;
}

.gallery-comment-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gallery-comment-action {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #6b7280;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
}

.gallery-comment-action:hover {
  color: #374151;
}

.gallery-comment-action svg {
  width: 14px;
  height: 14px;
}

.gallery-comment-action.active {
  color: #2563eb;
}

.gallery-comment-action.active svg {
  fill: currentColor;
}

/* Comment Author Badge */
.gallery-comment-author-badge {
  font-size: 10px;
  padding: 2px 6px;
  background: #dbeafe;
  color: #2563eb;
  border-radius: 4px;
  font-weight: 500;
}

/* Comment Avatar small (for replies) */
.gallery-comment-avatar.small {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

/* Reply Form */
.gallery-reply-form {
  margin-top: 10px;
  margin-left: 36px;
  padding: 10px;
  background: #f9fafb;
  border-radius: 8px;
}

.gallery-reply-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  margin-bottom: 8px;
}

.gallery-reply-input:focus {
  border-color: #2563eb;
}

.gallery-reply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.gallery-reply-cancel {
  padding: 6px 12px;
  background: transparent;
  border: none;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
}

.gallery-reply-cancel:hover {
  color: #374151;
}

.gallery-reply-submit {
  padding: 6px 14px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.gallery-reply-submit:hover {
  background: #1d4ed8;
}

.gallery-reply-submit:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* Comment Replies Container */
.gallery-comment-replies {
  margin-top: 10px;
  margin-left: 28px;
  padding-left: 8px;
  border-left: 2px solid #e5e7eb;
}

.gallery-reply-item {
  padding: 8px 0;
}

.gallery-reply-item:last-child {
  padding-bottom: 0;
}

/* Comment Form Login Message */
.gallery-comment-form-login {
  text-align: center;
  padding: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
  color: #6b7280;
}

.gallery-comment-form-login a {
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
}

.gallery-comment-form-login a:hover {
  text-decoration: underline;
}

/* Comments List */
.gallery-comments-list {
  max-height: none;
}

/* Comments Infinite Scroll */
.gallery-comments-loader {
  padding: 12px 0;
}

.gallery-comments-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  color: #6b7280;
  font-size: 13px;
}

.gallery-loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: gallery-spin 0.8s linear infinite;
}

.gallery-comments-end {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: #9ca3af;
  font-size: 13px;
  text-align: center;
}

/* Replies toggle link */
.gallery-comment-replies-toggle {
  margin-top: 8px;
  margin-left: 36px;
  color: #6b7280;
  font-size: 12px;
  cursor: pointer;
}

.gallery-comment-replies-toggle:hover {
  color: #2563eb;
}

/* Panel Footer - Actions */
.gallery-panel-footer {
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px;
  flex-shrink: 0;
  background: white;
}

.gallery-panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.gallery-panel-actions-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

.gallery-action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #374151;
  transition: all 0.2s;
}

.gallery-action-btn:hover {
  background: #f3f4f6;
}

.gallery-action-btn.active {
  color: #dc2626;
}

.gallery-action-btn.active.like {
  color: #2563eb;
}

.gallery-action-btn.active.bookmark {
  color: #f59e0b;
}

.gallery-action-btn svg {
  width: 22px;
  height: 22px;
}

.gallery-panel-stats {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: #6b7280;
}

.gallery-panel-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Comment Form */
.gallery-comment-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.gallery-comment-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.gallery-comment-input:focus {
  border-color: #2563eb;
}

.gallery-comment-submit {
  padding: 8px 16px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.gallery-comment-submit:hover {
  background: #1d4ed8;
}

.gallery-comment-submit:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* Mobile Swipe Handle */
.gallery-swipe-handle {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 10px 8px 6px;
  background: white;
  cursor: grab;
  touch-action: none;
  transition: background 0.2s;
}

@media (max-width: 767px) {
  .gallery-swipe-handle {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
}

.gallery-swipe-handle:active {
  cursor: grabbing;
  background: #f3f4f6;
}

.gallery-swipe-handle.swiping-up,
.gallery-swipe-handle.swiping-down {
  background: #f3f4f6;
}

.gallery-swipe-handle-bar {
  width: 36px;
  height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  transition: all 0.2s;
}

.gallery-swipe-handle:active .gallery-swipe-handle-bar,
.gallery-swipe-handle.swiping-up .gallery-swipe-handle-bar,
.gallery-swipe-handle.swiping-down .gallery-swipe-handle-bar {
  background: #9ca3af;
  width: 44px;
}

.gallery-swipe-handle-text {
  font-size: 10px;
  color: #9ca3af;
}

/* Mobile Media Collapsed State */
@media (max-width: 767px) {
  .gallery-modal-media {
    transition: max-height 0.3s ease, height 0.3s ease;
  }

  .gallery-modal-media.collapsed {
    height: 120px !important;
    max-height: 120px !important;
    aspect-ratio: auto !important;
  }

  .gallery-modal-media.collapsed .gallery-media-slides {
    height: 100%;
  }

  .gallery-modal-media.collapsed .gallery-media-slide img,
  .gallery-modal-media.collapsed .gallery-media-slide video {
    max-height: 100%;
    object-fit: cover;
  }

  .gallery-modal-media.collapsed .gallery-media-nav {
    width: 28px;
    height: 28px;
  }

  .gallery-modal-media.collapsed .gallery-media-nav svg {
    width: 14px;
    height: 14px;
  }

  .gallery-modal-media.collapsed .gallery-media-counter {
    font-size: 10px;
    padding: 2px 8px;
  }

  .gallery-modal-media.collapsed .gallery-media-indicators {
    bottom: 8px;
  }

  .gallery-modal-media.collapsed .gallery-media-indicator {
    width: 6px;
    height: 6px;
  }

  /* Panel expanded state */
  .gallery-modal-panel.expanded {
    flex: 1;
  }
}

/* Loading State */
.gallery-modal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  color: #6b7280;
}

.gallery-modal-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: gallery-spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes gallery-spin {
  to { transform: rotate(360deg); }
}

/* Empty Comments */
.gallery-comments-empty {
  text-align: center;
  padding: 24px;
  color: #9ca3af;
  font-size: 14px;
}

/* Video Controls */
.gallery-media-video-controls {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 24px;
  z-index: 10;
}

.gallery-video-control-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: white;
  transition: background 0.2s;
}

.gallery-video-control-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.gallery-video-control-btn svg {
  width: 18px;
  height: 18px;
}

/* Play Overlay */
.gallery-media-play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 5;
  transition: opacity 0.2s;
}

.gallery-media-play-overlay:hover {
  background: rgba(0, 0, 0, 0.4);
}

.gallery-media-play-overlay svg {
  width: 64px;
  height: 64px;
  color: white;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Responsive adjustments */
@media (max-width: 767px) {
  .gallery-panel-header {
    padding: 10px 12px;
  }

  .gallery-panel-post-content {
    padding: 12px;
  }

  .gallery-panel-comments {
    padding: 10px 12px;
  }

  .gallery-panel-footer {
    padding: 10px 12px;
  }
}
