/* Instagram-style grid layout */
.aie-explore-wrapper {
  max-width: 935px; /* typical instagram width */
  margin: 0 auto;
  padding: 20px;
}

.aie-explore-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 28px;
}

@media (max-width: 768px) {
  .aie-explore-grid {
    grid-gap: 3px;
    padding: 0;
  }
}

.aie-grid-item {
  position: relative;
  background: #efefef;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.aie-grid-image-wrapper {
  width: 100%;
  height: 100%;
}

.aie-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.aie-grid-item-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.aie-grid-item:hover .aie-grid-item-overlay {
  opacity: 1;
}

.aie-grid-stats {
  display: flex;
  gap: 20px;
  font-weight: 700;
  font-size: 16px;
}

.aie-grid-stats span {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Modal Styling */
.aie-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.65);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 40px;
}

.aie-modal.hidden {
  display: none !important;
}

.aie-modal-content-container {
  display: flex;
  width: 100%;
  max-width: 900px;
  height: clamp(400px, 90vh, 900px); /* Fixed height for split view */
  background: #fff;
  border-radius: 4px; /* instagram is slightly rounded */
  overflow: hidden;
  position: relative;
}

.aie-modal-media {
  flex: 1 1 55%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.aie-modal-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.aie-modal-sidebar {
  flex: 0 0 45%;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-left: 1px solid #efefef;
}

.aie-modal-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #efefef;
  gap: 14px;
}

.aie-modal-header img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.aie-modal-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #262626;
  line-height: 18px;
}

.aie-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-size: 14px;
  color: #262626;
  padding-bottom: 20px;
}

/* Custom scrollbar for comments */
.aie-modal-body::-webkit-scrollbar {
  width: 4px;
}
.aie-modal-body::-webkit-scrollbar-thumb {
  background: #ccc; 
  border-radius: 4px;
}

.aie-modal-caption {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
}

.aie-modal-caption img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.caption-text {
  flex: 1;
  word-break: break-word;
  line-height: 18px;
}

.aie-modal-caption h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: inline;
  margin-right: 5px;
}

.aie-modal-comments {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.aie-comment {
  display: flex;
  gap: 14px;
  font-size: 14px;
  line-height: 18px;
}

.aie-comment img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.aie-comment-content {
  flex: 1;
  word-break: break-word;
}

.aie-comment-author {
  font-weight: 600;
  margin-right: 5px;
  color: #262626;
}

.aie-comment-date {
  font-size: 12px;
  color: #8e8e8e;
  margin-top: 6px;
  font-weight: 400;
}

.aie-modal-footer {
  padding: 14px 16px;
  border-top: 1px solid #efefef;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aie-modal-actions {
  display: flex;
  gap: 16px;
}

.aie-action-btn {
  font-size: 24px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
}
.aie-action-btn:hover {
  opacity: 0.5;
}

.aie-modal-likes {
  font-size: 14px;
  color: #262626;
}

.aie-read-more-btn {
  display: block;
  text-align: center;
  background: #efefef;
  color: #262626;
  padding: 8px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s;
  margin-top: 5px;
}

.aie-read-more-btn:hover {
  background: #dbdbdb;
  color: #262626;
}

.aie-modal-comment-input-container {
  padding: 14px 16px;
  border-top: 1px solid #efefef;
}

#aie-comment-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

#aie-comment-text {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  padding: 8px 0;
}

#aie-comment-submit {
  background: none;
  border: none;
  color: #0095f6;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
}

#aie-comment-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.aie-modal-close {
  position: absolute;
  top: 15px;
  right: 25px;
  background: none;
  border: none;
  color: white;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  z-index: 100000;
  padding: 10px;
}

/* Spinner */
.aie-loading-comments {
  text-align: center;
  padding: 20px;
}

.aie-spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0,0,0,0.1);
  border-radius: 50%;
  border-top-color: #333;
  animation: spin 1s ease-in-out infinite;
}

@media (max-width: 768px) {
  .aie-modal {
    padding: 0;
  }
  .aie-modal-content-container {
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  .aie-modal-media {
    flex: 0 0 45vh;
  }
  .aie-modal-sidebar {
    flex: 1;
    max-width: none;
  }
  .aie-modal-close {
    color: #fff;
    text-shadow: 0 0 4px rgba(0,0,0,0.5);
  }
}

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